blob: cfe6c3ee1a7a4d0887e6a2aa031e8f3523d97259 [file] [log] [blame]
James Feist46229572020-02-19 15:11:58 -08001/*
2// Copyright (c) 2020 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
19#include "dbus_utility.hpp"
20#include "event_service_manager.hpp"
Ed Tanousd093c992023-01-19 19:01:49 -080021#include "health.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080022#include "query.hpp"
23#include "registries/privilege_registry.hpp"
24#include "task_messages.hpp"
25
Ed Tanousd43cd0c2020-09-30 20:46:53 -070026#include <boost/asio/post.hpp>
27#include <boost/asio/steady_timer.hpp>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080028#include <sdbusplus/bus/match.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050029
30#include <chrono>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080031#include <memory>
James Feist46229572020-02-19 15:11:58 -080032#include <variant>
33
34namespace redfish
35{
36
37namespace task
38{
39constexpr size_t maxTaskCount = 100; // arbitrary limit
40
Ed Tanouscf9e4172022-12-21 09:30:16 -080041// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
James Feist46229572020-02-19 15:11:58 -080042static std::deque<std::shared_ptr<struct TaskData>> tasks;
43
James Feist32898ce2020-03-10 16:16:52 -070044constexpr bool completed = true;
45
James Feistfe306722020-03-12 16:32:08 -070046struct Payload
47{
Ed Tanous4e23a442022-06-06 09:57:26 -070048 explicit Payload(const crow::Request& req) :
James Feistfe306722020-03-12 16:32:08 -070049 targetUri(req.url), httpOperation(req.methodString()),
Ed Tanousb31cef62022-06-30 17:51:46 -070050 httpHeaders(nlohmann::json::array()),
51 jsonBody(nlohmann::json::parse(req.body, nullptr, false))
James Feistfe306722020-03-12 16:32:08 -070052 {
53 using field_ns = boost::beast::http::field;
54 constexpr const std::array<boost::beast::http::field, 7>
55 headerWhitelist = {field_ns::accept, field_ns::accept_encoding,
56 field_ns::user_agent, field_ns::host,
57 field_ns::connection, field_ns::content_length,
58 field_ns::upgrade};
59
James Feistfe306722020-03-12 16:32:08 -070060 if (jsonBody.is_discarded())
61 {
62 jsonBody = nullptr;
63 }
64
Gunnar Mills1214b7e2020-06-04 10:11:30 -050065 for (const auto& field : req.fields)
James Feistfe306722020-03-12 16:32:08 -070066 {
67 if (std::find(headerWhitelist.begin(), headerWhitelist.end(),
68 field.name()) == headerWhitelist.end())
69 {
70 continue;
71 }
72 std::string header;
73 header.reserve(field.name_string().size() + 2 +
74 field.value().size());
75 header += field.name_string();
76 header += ": ";
77 header += field.value();
78 httpHeaders.emplace_back(std::move(header));
79 }
80 }
81 Payload() = delete;
82
83 std::string targetUri;
84 std::string httpOperation;
85 nlohmann::json httpHeaders;
86 nlohmann::json jsonBody;
87};
88
James Feist46229572020-02-19 15:11:58 -080089struct TaskData : std::enable_shared_from_this<TaskData>
90{
91 private:
Patrick Williams59d494e2022-07-22 19:26:55 -050092 TaskData(
93 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
94 const std::shared_ptr<TaskData>&)>&& handler,
95 const std::string& matchIn, size_t idx) :
James Feist46229572020-02-19 15:11:58 -080096 callback(std::move(handler)),
Ed Tanous23a21a12020-07-25 04:45:05 +000097 matchStr(matchIn), index(idx),
James Feist46229572020-02-19 15:11:58 -080098 startTime(std::chrono::system_clock::to_time_t(
99 std::chrono::system_clock::now())),
100 status("OK"), state("Running"), messages(nlohmann::json::array()),
101 timer(crow::connections::systemBus->get_io_context())
102
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500103 {}
James Feist46229572020-02-19 15:11:58 -0800104
105 public:
Ed Tanousd609fd62020-09-28 19:08:03 -0700106 TaskData() = delete;
107
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500108 static std::shared_ptr<TaskData>& createTask(
Patrick Williams59d494e2022-07-22 19:26:55 -0500109 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500110 const std::shared_ptr<TaskData>&)>&& handler,
111 const std::string& match)
James Feist46229572020-02-19 15:11:58 -0800112 {
113 static size_t lastTask = 0;
114 struct MakeSharedHelper : public TaskData
115 {
116 MakeSharedHelper(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500117 std::function<bool(boost::system::error_code,
Patrick Williams59d494e2022-07-22 19:26:55 -0500118 sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500119 const std::shared_ptr<TaskData>&)>&& handler,
Ed Tanous23a21a12020-07-25 04:45:05 +0000120 const std::string& match2, size_t idx) :
121 TaskData(std::move(handler), match2, idx)
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500122 {}
James Feist46229572020-02-19 15:11:58 -0800123 };
124
125 if (tasks.size() >= maxTaskCount)
126 {
Ed Tanous02cad962022-06-30 16:50:15 -0700127 const auto& last = tasks.front();
James Feist46229572020-02-19 15:11:58 -0800128
129 // destroy all references
130 last->timer.cancel();
131 last->match.reset();
132 tasks.pop_front();
133 }
134
135 return tasks.emplace_back(std::make_shared<MakeSharedHelper>(
136 std::move(handler), match, lastTask++));
137 }
138
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500139 void populateResp(crow::Response& res, size_t retryAfterSeconds = 30)
James Feist46229572020-02-19 15:11:58 -0800140 {
141 if (!endTime)
142 {
143 res.result(boost::beast::http::status::accepted);
144 std::string strIdx = std::to_string(index);
145 std::string uri = "/redfish/v1/TaskService/Tasks/" + strIdx;
Ed Tanous14766872022-03-15 10:44:42 -0700146
147 res.jsonValue["@odata.id"] = uri;
148 res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
149 res.jsonValue["Id"] = strIdx;
150 res.jsonValue["TaskState"] = state;
151 res.jsonValue["TaskStatus"] = status;
152
James Feist46229572020-02-19 15:11:58 -0800153 res.addHeader(boost::beast::http::field::location,
154 uri + "/Monitor");
155 res.addHeader(boost::beast::http::field::retry_after,
156 std::to_string(retryAfterSeconds));
157 }
158 else if (!gave204)
159 {
160 res.result(boost::beast::http::status::no_content);
161 gave204 = true;
162 }
163 }
164
Ed Tanousd609fd62020-09-28 19:08:03 -0700165 void finishTask()
James Feist46229572020-02-19 15:11:58 -0800166 {
167 endTime = std::chrono::system_clock::to_time_t(
168 std::chrono::system_clock::now());
169 }
170
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500171 void extendTimer(const std::chrono::seconds& timeout)
James Feist46229572020-02-19 15:11:58 -0800172 {
James Feist46229572020-02-19 15:11:58 -0800173 timer.expires_after(timeout);
174 timer.async_wait(
175 [self = shared_from_this()](boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700176 if (ec == boost::asio::error::operation_aborted)
177 {
178 return; // completed successfully
179 }
180 if (!ec)
181 {
182 // change ec to error as timer expired
183 ec = boost::asio::error::operation_aborted;
184 }
185 self->match.reset();
Patrick Williams59d494e2022-07-22 19:26:55 -0500186 sdbusplus::message_t msg;
Ed Tanous002d39b2022-05-31 08:59:27 -0700187 self->finishTask();
188 self->state = "Cancelled";
189 self->status = "Warning";
190 self->messages.emplace_back(
191 messages::taskAborted(std::to_string(self->index)));
192 // Send event :TaskAborted
193 self->sendTaskEvent(self->state, self->index);
194 self->callback(ec, msg, self);
195 });
James Feistfd9ab9e2020-05-19 13:48:07 -0700196 }
197
Ed Tanous56d23962022-02-14 20:42:02 -0800198 static void sendTaskEvent(const std::string_view state, size_t index)
Sunitha Harishe7686572020-07-15 02:32:44 -0500199 {
200 std::string origin =
201 "/redfish/v1/TaskService/Tasks/" + std::to_string(index);
202 std::string resType = "Task";
203 // TaskState enums which should send out an event are:
204 // "Starting" = taskResumed
205 // "Running" = taskStarted
206 // "Suspended" = taskPaused
207 // "Interrupted" = taskPaused
208 // "Pending" = taskPaused
209 // "Stopping" = taskAborted
210 // "Completed" = taskCompletedOK
211 // "Killed" = taskRemoved
212 // "Exception" = taskCompletedWarning
213 // "Cancelled" = taskCancelled
214 if (state == "Starting")
215 {
216 redfish::EventServiceManager::getInstance().sendEvent(
217 redfish::messages::taskResumed(std::to_string(index)), origin,
218 resType);
219 }
220 else if (state == "Running")
221 {
222 redfish::EventServiceManager::getInstance().sendEvent(
223 redfish::messages::taskStarted(std::to_string(index)), origin,
224 resType);
225 }
226 else if ((state == "Suspended") || (state == "Interrupted") ||
227 (state == "Pending"))
228 {
229 redfish::EventServiceManager::getInstance().sendEvent(
230 redfish::messages::taskPaused(std::to_string(index)), origin,
231 resType);
232 }
233 else if (state == "Stopping")
234 {
235 redfish::EventServiceManager::getInstance().sendEvent(
236 redfish::messages::taskAborted(std::to_string(index)), origin,
237 resType);
238 }
239 else if (state == "Completed")
240 {
241 redfish::EventServiceManager::getInstance().sendEvent(
242 redfish::messages::taskCompletedOK(std::to_string(index)),
243 origin, resType);
244 }
245 else if (state == "Killed")
246 {
247 redfish::EventServiceManager::getInstance().sendEvent(
248 redfish::messages::taskRemoved(std::to_string(index)), origin,
249 resType);
250 }
251 else if (state == "Exception")
252 {
253 redfish::EventServiceManager::getInstance().sendEvent(
254 redfish::messages::taskCompletedWarning(std::to_string(index)),
255 origin, resType);
256 }
257 else if (state == "Cancelled")
258 {
259 redfish::EventServiceManager::getInstance().sendEvent(
260 redfish::messages::taskCancelled(std::to_string(index)), origin,
261 resType);
262 }
263 else
264 {
265 BMCWEB_LOG_INFO << "sendTaskEvent: No events to send";
266 }
267 }
268
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500269 void startTimer(const std::chrono::seconds& timeout)
James Feistfd9ab9e2020-05-19 13:48:07 -0700270 {
271 if (match)
272 {
273 return;
274 }
Patrick Williams59d494e2022-07-22 19:26:55 -0500275 match = std::make_unique<sdbusplus::bus::match_t>(
276 static_cast<sdbusplus::bus_t&>(*crow::connections::systemBus),
James Feistfd9ab9e2020-05-19 13:48:07 -0700277 matchStr,
Patrick Williams59d494e2022-07-22 19:26:55 -0500278 [self = shared_from_this()](sdbusplus::message_t& message) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700279 boost::system::error_code ec;
James Feistfd9ab9e2020-05-19 13:48:07 -0700280
Ed Tanous002d39b2022-05-31 08:59:27 -0700281 // callback to return True if callback is done, callback needs
282 // to update status itself if needed
283 if (self->callback(ec, message, self) == task::completed)
284 {
285 self->timer.cancel();
286 self->finishTask();
James Feistfd9ab9e2020-05-19 13:48:07 -0700287
Ed Tanous002d39b2022-05-31 08:59:27 -0700288 // Send event
289 self->sendTaskEvent(self->state, self->index);
Sunitha Harishe7686572020-07-15 02:32:44 -0500290
Ed Tanous002d39b2022-05-31 08:59:27 -0700291 // reset the match after the callback was successful
292 boost::asio::post(
293 crow::connections::systemBus->get_io_context(),
294 [self] { self->match.reset(); });
295 return;
296 }
James Feistfd9ab9e2020-05-19 13:48:07 -0700297 });
298
299 extendTimer(timeout);
James Feiste5d50062020-05-11 17:29:00 -0700300 messages.emplace_back(messages::taskStarted(std::to_string(index)));
Sunitha Harishe7686572020-07-15 02:32:44 -0500301 // Send event : TaskStarted
302 sendTaskEvent(state, index);
James Feist46229572020-02-19 15:11:58 -0800303 }
304
Patrick Williams59d494e2022-07-22 19:26:55 -0500305 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500306 const std::shared_ptr<TaskData>&)>
James Feist46229572020-02-19 15:11:58 -0800307 callback;
308 std::string matchStr;
309 size_t index;
310 time_t startTime;
311 std::string status;
312 std::string state;
313 nlohmann::json messages;
314 boost::asio::steady_timer timer;
Patrick Williams59d494e2022-07-22 19:26:55 -0500315 std::unique_ptr<sdbusplus::bus::match_t> match;
James Feist46229572020-02-19 15:11:58 -0800316 std::optional<time_t> endTime;
James Feistfe306722020-03-12 16:32:08 -0700317 std::optional<Payload> payload;
James Feist46229572020-02-19 15:11:58 -0800318 bool gave204 = false;
George Liu6868ff52021-01-02 11:37:41 +0800319 int percentComplete = 0;
James Feist46229572020-02-19 15:11:58 -0800320};
321
322} // namespace task
323
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700324inline void requestRoutesTaskMonitor(App& app)
James Feist46229572020-02-19 15:11:58 -0800325{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700326 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/Monitor/")
Ed Tanoused398212021-06-09 17:05:54 -0700327 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700328 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700329 [&app](const crow::Request& req,
330 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
331 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000332 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700333 {
334 return;
335 }
336 auto find = std::find_if(
337 task::tasks.begin(), task::tasks.end(),
338 [&strParam](const std::shared_ptr<task::TaskData>& task) {
339 if (!task)
340 {
341 return false;
342 }
James Feist46229572020-02-19 15:11:58 -0800343
Ed Tanous002d39b2022-05-31 08:59:27 -0700344 // we compare against the string version as on failure
345 // strtoul returns 0
346 return std::to_string(task->index) == strParam;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700347 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700348
349 if (find == task::tasks.end())
350 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800351 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700352 return;
353 }
354 std::shared_ptr<task::TaskData>& ptr = *find;
355 // monitor expires after 204
356 if (ptr->gave204)
357 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800358 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700359 return;
360 }
361 ptr->populateResp(asyncResp->res);
362 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700363}
364
365inline void requestRoutesTask(App& app)
366{
367 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700368 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700369 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700370 [&app](const crow::Request& req,
371 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
372 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000373 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700374 {
375 return;
376 }
377 auto find = std::find_if(
378 task::tasks.begin(), task::tasks.end(),
379 [&strParam](const std::shared_ptr<task::TaskData>& task) {
380 if (!task)
381 {
382 return false;
383 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700384
Ed Tanous002d39b2022-05-31 08:59:27 -0700385 // we compare against the string version as on failure
386 // strtoul returns 0
387 return std::to_string(task->index) == strParam;
James Feist46229572020-02-19 15:11:58 -0800388 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700389
390 if (find == task::tasks.end())
391 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800392 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700393 return;
394 }
395
Ed Tanous02cad962022-06-30 16:50:15 -0700396 const std::shared_ptr<task::TaskData>& ptr = *find;
Ed Tanous002d39b2022-05-31 08:59:27 -0700397
398 asyncResp->res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
399 asyncResp->res.jsonValue["Id"] = strParam;
400 asyncResp->res.jsonValue["Name"] = "Task " + strParam;
401 asyncResp->res.jsonValue["TaskState"] = ptr->state;
402 asyncResp->res.jsonValue["StartTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700403 redfish::time_utils::getDateTimeStdtime(ptr->startTime);
Ed Tanous002d39b2022-05-31 08:59:27 -0700404 if (ptr->endTime)
405 {
406 asyncResp->res.jsonValue["EndTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700407 redfish::time_utils::getDateTimeStdtime(*(ptr->endTime));
Ed Tanous002d39b2022-05-31 08:59:27 -0700408 }
409 asyncResp->res.jsonValue["TaskStatus"] = ptr->status;
410 asyncResp->res.jsonValue["Messages"] = ptr->messages;
411 asyncResp->res.jsonValue["@odata.id"] =
412 "/redfish/v1/TaskService/Tasks/" + strParam;
413 if (!ptr->gave204)
414 {
415 asyncResp->res.jsonValue["TaskMonitor"] =
416 "/redfish/v1/TaskService/Tasks/" + strParam + "/Monitor";
417 }
418 if (ptr->payload)
419 {
420 const task::Payload& p = *(ptr->payload);
421 asyncResp->res.jsonValue["Payload"]["TargetUri"] = p.targetUri;
422 asyncResp->res.jsonValue["Payload"]["HttpOperation"] =
423 p.httpOperation;
424 asyncResp->res.jsonValue["Payload"]["HttpHeaders"] = p.httpHeaders;
425 asyncResp->res.jsonValue["Payload"]["JsonBody"] = p.jsonBody.dump(
426 2, ' ', true, nlohmann::json::error_handler_t::replace);
427 }
428 asyncResp->res.jsonValue["PercentComplete"] = ptr->percentComplete;
429 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700430}
James Feist46229572020-02-19 15:11:58 -0800431
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700432inline void requestRoutesTaskCollection(App& app)
James Feist46229572020-02-19 15:11:58 -0800433{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700434 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/")
Ed Tanoused398212021-06-09 17:05:54 -0700435 .privileges(redfish::privileges::getTaskCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700436 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700437 [&app](const crow::Request& req,
438 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000439 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700440 {
441 return;
442 }
443 asyncResp->res.jsonValue["@odata.type"] =
444 "#TaskCollection.TaskCollection";
445 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService/Tasks";
446 asyncResp->res.jsonValue["Name"] = "Task Collection";
447 asyncResp->res.jsonValue["Members@odata.count"] = task::tasks.size();
448 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
449 members = nlohmann::json::array();
James Feist46229572020-02-19 15:11:58 -0800450
Ed Tanous002d39b2022-05-31 08:59:27 -0700451 for (const std::shared_ptr<task::TaskData>& task : task::tasks)
452 {
453 if (task == nullptr)
454 {
455 continue; // shouldn't be possible
456 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700457 nlohmann::json::object_t member;
458 member["@odata.id"] =
459 "redfish/v1/TaskService/Tasks/" + std::to_string(task->index);
460 members.emplace_back(std::move(member));
Ed Tanous002d39b2022-05-31 08:59:27 -0700461 }
462 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700463}
zhanghch058d1b46d2021-04-01 11:18:24 +0800464
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700465inline void requestRoutesTaskService(App& app)
James Feist46229572020-02-19 15:11:58 -0800466{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700467 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/")
Ed Tanoused398212021-06-09 17:05:54 -0700468 .privileges(redfish::privileges::getTaskService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700469 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700470 [&app](const crow::Request& req,
471 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000472 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700473 {
474 return;
475 }
476 asyncResp->res.jsonValue["@odata.type"] =
477 "#TaskService.v1_1_4.TaskService";
478 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService";
479 asyncResp->res.jsonValue["Name"] = "Task Service";
480 asyncResp->res.jsonValue["Id"] = "TaskService";
481 asyncResp->res.jsonValue["DateTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700482 redfish::time_utils::getDateTimeOffsetNow().first;
Ed Tanous002d39b2022-05-31 08:59:27 -0700483 asyncResp->res.jsonValue["CompletedTaskOverWritePolicy"] = "Oldest";
James Feist46229572020-02-19 15:11:58 -0800484
Ed Tanous002d39b2022-05-31 08:59:27 -0700485 asyncResp->res.jsonValue["LifeCycleEventOnTaskStateChange"] = true;
James Feist46229572020-02-19 15:11:58 -0800486
Ed Tanous002d39b2022-05-31 08:59:27 -0700487 auto health = std::make_shared<HealthPopulate>(asyncResp);
488 health->populate();
489 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
490 asyncResp->res.jsonValue["ServiceEnabled"] = true;
491 asyncResp->res.jsonValue["Tasks"]["@odata.id"] =
492 "/redfish/v1/TaskService/Tasks";
493 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700494}
James Feist46229572020-02-19 15:11:58 -0800495
496} // namespace redfish