blob: 105d4cdd95075888d90377b0355ba97c13ddebe2 [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"
21#include "query.hpp"
22#include "registries/privilege_registry.hpp"
23#include "task_messages.hpp"
24
Ed Tanousd43cd0c2020-09-30 20:46:53 -070025#include <boost/asio/post.hpp>
26#include <boost/asio/steady_timer.hpp>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080027#include <sdbusplus/bus/match.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050028
29#include <chrono>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080030#include <memory>
James Feist46229572020-02-19 15:11:58 -080031#include <variant>
32
33namespace redfish
34{
35
36namespace task
37{
38constexpr size_t maxTaskCount = 100; // arbitrary limit
39
Ed Tanouscf9e4172022-12-21 09:30:16 -080040// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
James Feist46229572020-02-19 15:11:58 -080041static std::deque<std::shared_ptr<struct TaskData>> tasks;
42
James Feist32898ce2020-03-10 16:16:52 -070043constexpr bool completed = true;
44
James Feistfe306722020-03-12 16:32:08 -070045struct Payload
46{
Ed Tanous4e23a442022-06-06 09:57:26 -070047 explicit Payload(const crow::Request& req) :
James Feistfe306722020-03-12 16:32:08 -070048 targetUri(req.url), httpOperation(req.methodString()),
Ed Tanousb31cef62022-06-30 17:51:46 -070049 httpHeaders(nlohmann::json::array()),
50 jsonBody(nlohmann::json::parse(req.body, nullptr, false))
James Feistfe306722020-03-12 16:32:08 -070051 {
52 using field_ns = boost::beast::http::field;
53 constexpr const std::array<boost::beast::http::field, 7>
54 headerWhitelist = {field_ns::accept, field_ns::accept_encoding,
55 field_ns::user_agent, field_ns::host,
56 field_ns::connection, field_ns::content_length,
57 field_ns::upgrade};
58
James Feistfe306722020-03-12 16:32:08 -070059 if (jsonBody.is_discarded())
60 {
61 jsonBody = nullptr;
62 }
63
Gunnar Mills1214b7e2020-06-04 10:11:30 -050064 for (const auto& field : req.fields)
James Feistfe306722020-03-12 16:32:08 -070065 {
66 if (std::find(headerWhitelist.begin(), headerWhitelist.end(),
67 field.name()) == headerWhitelist.end())
68 {
69 continue;
70 }
71 std::string header;
72 header.reserve(field.name_string().size() + 2 +
73 field.value().size());
74 header += field.name_string();
75 header += ": ";
76 header += field.value();
77 httpHeaders.emplace_back(std::move(header));
78 }
79 }
80 Payload() = delete;
81
82 std::string targetUri;
83 std::string httpOperation;
84 nlohmann::json httpHeaders;
85 nlohmann::json jsonBody;
86};
87
James Feist46229572020-02-19 15:11:58 -080088struct TaskData : std::enable_shared_from_this<TaskData>
89{
90 private:
Patrick Williams59d494e2022-07-22 19:26:55 -050091 TaskData(
92 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
93 const std::shared_ptr<TaskData>&)>&& handler,
94 const std::string& matchIn, size_t idx) :
James Feist46229572020-02-19 15:11:58 -080095 callback(std::move(handler)),
Ed Tanous23a21a12020-07-25 04:45:05 +000096 matchStr(matchIn), index(idx),
James Feist46229572020-02-19 15:11:58 -080097 startTime(std::chrono::system_clock::to_time_t(
98 std::chrono::system_clock::now())),
99 status("OK"), state("Running"), messages(nlohmann::json::array()),
100 timer(crow::connections::systemBus->get_io_context())
101
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500102 {}
James Feist46229572020-02-19 15:11:58 -0800103
104 public:
Ed Tanousd609fd62020-09-28 19:08:03 -0700105 TaskData() = delete;
106
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500107 static std::shared_ptr<TaskData>& createTask(
Patrick Williams59d494e2022-07-22 19:26:55 -0500108 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500109 const std::shared_ptr<TaskData>&)>&& handler,
110 const std::string& match)
James Feist46229572020-02-19 15:11:58 -0800111 {
112 static size_t lastTask = 0;
113 struct MakeSharedHelper : public TaskData
114 {
115 MakeSharedHelper(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500116 std::function<bool(boost::system::error_code,
Patrick Williams59d494e2022-07-22 19:26:55 -0500117 sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500118 const std::shared_ptr<TaskData>&)>&& handler,
Ed Tanous23a21a12020-07-25 04:45:05 +0000119 const std::string& match2, size_t idx) :
120 TaskData(std::move(handler), match2, idx)
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500121 {}
James Feist46229572020-02-19 15:11:58 -0800122 };
123
124 if (tasks.size() >= maxTaskCount)
125 {
Ed Tanous02cad962022-06-30 16:50:15 -0700126 const auto& last = tasks.front();
James Feist46229572020-02-19 15:11:58 -0800127
128 // destroy all references
129 last->timer.cancel();
130 last->match.reset();
131 tasks.pop_front();
132 }
133
134 return tasks.emplace_back(std::make_shared<MakeSharedHelper>(
135 std::move(handler), match, lastTask++));
136 }
137
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500138 void populateResp(crow::Response& res, size_t retryAfterSeconds = 30)
James Feist46229572020-02-19 15:11:58 -0800139 {
140 if (!endTime)
141 {
142 res.result(boost::beast::http::status::accepted);
143 std::string strIdx = std::to_string(index);
144 std::string uri = "/redfish/v1/TaskService/Tasks/" + strIdx;
Ed Tanous14766872022-03-15 10:44:42 -0700145
146 res.jsonValue["@odata.id"] = uri;
147 res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
148 res.jsonValue["Id"] = strIdx;
149 res.jsonValue["TaskState"] = state;
150 res.jsonValue["TaskStatus"] = status;
151
James Feist46229572020-02-19 15:11:58 -0800152 res.addHeader(boost::beast::http::field::location,
153 uri + "/Monitor");
154 res.addHeader(boost::beast::http::field::retry_after,
155 std::to_string(retryAfterSeconds));
156 }
157 else if (!gave204)
158 {
159 res.result(boost::beast::http::status::no_content);
160 gave204 = true;
161 }
162 }
163
Ed Tanousd609fd62020-09-28 19:08:03 -0700164 void finishTask()
James Feist46229572020-02-19 15:11:58 -0800165 {
166 endTime = std::chrono::system_clock::to_time_t(
167 std::chrono::system_clock::now());
168 }
169
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500170 void extendTimer(const std::chrono::seconds& timeout)
James Feist46229572020-02-19 15:11:58 -0800171 {
James Feist46229572020-02-19 15:11:58 -0800172 timer.expires_after(timeout);
173 timer.async_wait(
174 [self = shared_from_this()](boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700175 if (ec == boost::asio::error::operation_aborted)
176 {
177 return; // completed successfully
178 }
179 if (!ec)
180 {
181 // change ec to error as timer expired
182 ec = boost::asio::error::operation_aborted;
183 }
184 self->match.reset();
Patrick Williams59d494e2022-07-22 19:26:55 -0500185 sdbusplus::message_t msg;
Ed Tanous002d39b2022-05-31 08:59:27 -0700186 self->finishTask();
187 self->state = "Cancelled";
188 self->status = "Warning";
189 self->messages.emplace_back(
190 messages::taskAborted(std::to_string(self->index)));
191 // Send event :TaskAborted
192 self->sendTaskEvent(self->state, self->index);
193 self->callback(ec, msg, self);
194 });
James Feistfd9ab9e2020-05-19 13:48:07 -0700195 }
196
Ed Tanous56d23962022-02-14 20:42:02 -0800197 static void sendTaskEvent(const std::string_view state, size_t index)
Sunitha Harishe7686572020-07-15 02:32:44 -0500198 {
199 std::string origin =
200 "/redfish/v1/TaskService/Tasks/" + std::to_string(index);
201 std::string resType = "Task";
202 // TaskState enums which should send out an event are:
203 // "Starting" = taskResumed
204 // "Running" = taskStarted
205 // "Suspended" = taskPaused
206 // "Interrupted" = taskPaused
207 // "Pending" = taskPaused
208 // "Stopping" = taskAborted
209 // "Completed" = taskCompletedOK
210 // "Killed" = taskRemoved
211 // "Exception" = taskCompletedWarning
212 // "Cancelled" = taskCancelled
213 if (state == "Starting")
214 {
215 redfish::EventServiceManager::getInstance().sendEvent(
216 redfish::messages::taskResumed(std::to_string(index)), origin,
217 resType);
218 }
219 else if (state == "Running")
220 {
221 redfish::EventServiceManager::getInstance().sendEvent(
222 redfish::messages::taskStarted(std::to_string(index)), origin,
223 resType);
224 }
225 else if ((state == "Suspended") || (state == "Interrupted") ||
226 (state == "Pending"))
227 {
228 redfish::EventServiceManager::getInstance().sendEvent(
229 redfish::messages::taskPaused(std::to_string(index)), origin,
230 resType);
231 }
232 else if (state == "Stopping")
233 {
234 redfish::EventServiceManager::getInstance().sendEvent(
235 redfish::messages::taskAborted(std::to_string(index)), origin,
236 resType);
237 }
238 else if (state == "Completed")
239 {
240 redfish::EventServiceManager::getInstance().sendEvent(
241 redfish::messages::taskCompletedOK(std::to_string(index)),
242 origin, resType);
243 }
244 else if (state == "Killed")
245 {
246 redfish::EventServiceManager::getInstance().sendEvent(
247 redfish::messages::taskRemoved(std::to_string(index)), origin,
248 resType);
249 }
250 else if (state == "Exception")
251 {
252 redfish::EventServiceManager::getInstance().sendEvent(
253 redfish::messages::taskCompletedWarning(std::to_string(index)),
254 origin, resType);
255 }
256 else if (state == "Cancelled")
257 {
258 redfish::EventServiceManager::getInstance().sendEvent(
259 redfish::messages::taskCancelled(std::to_string(index)), origin,
260 resType);
261 }
262 else
263 {
264 BMCWEB_LOG_INFO << "sendTaskEvent: No events to send";
265 }
266 }
267
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500268 void startTimer(const std::chrono::seconds& timeout)
James Feistfd9ab9e2020-05-19 13:48:07 -0700269 {
270 if (match)
271 {
272 return;
273 }
Patrick Williams59d494e2022-07-22 19:26:55 -0500274 match = std::make_unique<sdbusplus::bus::match_t>(
275 static_cast<sdbusplus::bus_t&>(*crow::connections::systemBus),
James Feistfd9ab9e2020-05-19 13:48:07 -0700276 matchStr,
Patrick Williams59d494e2022-07-22 19:26:55 -0500277 [self = shared_from_this()](sdbusplus::message_t& message) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700278 boost::system::error_code ec;
James Feistfd9ab9e2020-05-19 13:48:07 -0700279
Ed Tanous002d39b2022-05-31 08:59:27 -0700280 // callback to return True if callback is done, callback needs
281 // to update status itself if needed
282 if (self->callback(ec, message, self) == task::completed)
283 {
284 self->timer.cancel();
285 self->finishTask();
James Feistfd9ab9e2020-05-19 13:48:07 -0700286
Ed Tanous002d39b2022-05-31 08:59:27 -0700287 // Send event
288 self->sendTaskEvent(self->state, self->index);
Sunitha Harishe7686572020-07-15 02:32:44 -0500289
Ed Tanous002d39b2022-05-31 08:59:27 -0700290 // reset the match after the callback was successful
291 boost::asio::post(
292 crow::connections::systemBus->get_io_context(),
293 [self] { self->match.reset(); });
294 return;
295 }
James Feistfd9ab9e2020-05-19 13:48:07 -0700296 });
297
298 extendTimer(timeout);
James Feiste5d50062020-05-11 17:29:00 -0700299 messages.emplace_back(messages::taskStarted(std::to_string(index)));
Sunitha Harishe7686572020-07-15 02:32:44 -0500300 // Send event : TaskStarted
301 sendTaskEvent(state, index);
James Feist46229572020-02-19 15:11:58 -0800302 }
303
Patrick Williams59d494e2022-07-22 19:26:55 -0500304 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500305 const std::shared_ptr<TaskData>&)>
James Feist46229572020-02-19 15:11:58 -0800306 callback;
307 std::string matchStr;
308 size_t index;
309 time_t startTime;
310 std::string status;
311 std::string state;
312 nlohmann::json messages;
313 boost::asio::steady_timer timer;
Patrick Williams59d494e2022-07-22 19:26:55 -0500314 std::unique_ptr<sdbusplus::bus::match_t> match;
James Feist46229572020-02-19 15:11:58 -0800315 std::optional<time_t> endTime;
James Feistfe306722020-03-12 16:32:08 -0700316 std::optional<Payload> payload;
James Feist46229572020-02-19 15:11:58 -0800317 bool gave204 = false;
George Liu6868ff52021-01-02 11:37:41 +0800318 int percentComplete = 0;
James Feist46229572020-02-19 15:11:58 -0800319};
320
321} // namespace task
322
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700323inline void requestRoutesTaskMonitor(App& app)
James Feist46229572020-02-19 15:11:58 -0800324{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700325 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/Monitor/")
Ed Tanoused398212021-06-09 17:05:54 -0700326 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700327 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700328 [&app](const crow::Request& req,
329 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
330 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000331 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700332 {
333 return;
334 }
335 auto find = std::find_if(
336 task::tasks.begin(), task::tasks.end(),
337 [&strParam](const std::shared_ptr<task::TaskData>& task) {
338 if (!task)
339 {
340 return false;
341 }
James Feist46229572020-02-19 15:11:58 -0800342
Ed Tanous002d39b2022-05-31 08:59:27 -0700343 // we compare against the string version as on failure
344 // strtoul returns 0
345 return std::to_string(task->index) == strParam;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700346 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700347
348 if (find == task::tasks.end())
349 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800350 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700351 return;
352 }
353 std::shared_ptr<task::TaskData>& ptr = *find;
354 // monitor expires after 204
355 if (ptr->gave204)
356 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800357 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700358 return;
359 }
360 ptr->populateResp(asyncResp->res);
361 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700362}
363
364inline void requestRoutesTask(App& app)
365{
366 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700367 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700368 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700369 [&app](const crow::Request& req,
370 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
371 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000372 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700373 {
374 return;
375 }
376 auto find = std::find_if(
377 task::tasks.begin(), task::tasks.end(),
378 [&strParam](const std::shared_ptr<task::TaskData>& task) {
379 if (!task)
380 {
381 return false;
382 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700383
Ed Tanous002d39b2022-05-31 08:59:27 -0700384 // we compare against the string version as on failure
385 // strtoul returns 0
386 return std::to_string(task->index) == strParam;
James Feist46229572020-02-19 15:11:58 -0800387 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700388
389 if (find == task::tasks.end())
390 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800391 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700392 return;
393 }
394
Ed Tanous02cad962022-06-30 16:50:15 -0700395 const std::shared_ptr<task::TaskData>& ptr = *find;
Ed Tanous002d39b2022-05-31 08:59:27 -0700396
397 asyncResp->res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
398 asyncResp->res.jsonValue["Id"] = strParam;
399 asyncResp->res.jsonValue["Name"] = "Task " + strParam;
400 asyncResp->res.jsonValue["TaskState"] = ptr->state;
401 asyncResp->res.jsonValue["StartTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700402 redfish::time_utils::getDateTimeStdtime(ptr->startTime);
Ed Tanous002d39b2022-05-31 08:59:27 -0700403 if (ptr->endTime)
404 {
405 asyncResp->res.jsonValue["EndTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700406 redfish::time_utils::getDateTimeStdtime(*(ptr->endTime));
Ed Tanous002d39b2022-05-31 08:59:27 -0700407 }
408 asyncResp->res.jsonValue["TaskStatus"] = ptr->status;
409 asyncResp->res.jsonValue["Messages"] = ptr->messages;
410 asyncResp->res.jsonValue["@odata.id"] =
411 "/redfish/v1/TaskService/Tasks/" + strParam;
412 if (!ptr->gave204)
413 {
414 asyncResp->res.jsonValue["TaskMonitor"] =
415 "/redfish/v1/TaskService/Tasks/" + strParam + "/Monitor";
416 }
417 if (ptr->payload)
418 {
419 const task::Payload& p = *(ptr->payload);
420 asyncResp->res.jsonValue["Payload"]["TargetUri"] = p.targetUri;
421 asyncResp->res.jsonValue["Payload"]["HttpOperation"] =
422 p.httpOperation;
423 asyncResp->res.jsonValue["Payload"]["HttpHeaders"] = p.httpHeaders;
424 asyncResp->res.jsonValue["Payload"]["JsonBody"] = p.jsonBody.dump(
425 2, ' ', true, nlohmann::json::error_handler_t::replace);
426 }
427 asyncResp->res.jsonValue["PercentComplete"] = ptr->percentComplete;
428 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700429}
James Feist46229572020-02-19 15:11:58 -0800430
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700431inline void requestRoutesTaskCollection(App& app)
James Feist46229572020-02-19 15:11:58 -0800432{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700433 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/")
Ed Tanoused398212021-06-09 17:05:54 -0700434 .privileges(redfish::privileges::getTaskCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700435 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700436 [&app](const crow::Request& req,
437 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000438 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700439 {
440 return;
441 }
442 asyncResp->res.jsonValue["@odata.type"] =
443 "#TaskCollection.TaskCollection";
444 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService/Tasks";
445 asyncResp->res.jsonValue["Name"] = "Task Collection";
446 asyncResp->res.jsonValue["Members@odata.count"] = task::tasks.size();
447 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
448 members = nlohmann::json::array();
James Feist46229572020-02-19 15:11:58 -0800449
Ed Tanous002d39b2022-05-31 08:59:27 -0700450 for (const std::shared_ptr<task::TaskData>& task : task::tasks)
451 {
452 if (task == nullptr)
453 {
454 continue; // shouldn't be possible
455 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700456 nlohmann::json::object_t member;
457 member["@odata.id"] =
458 "redfish/v1/TaskService/Tasks/" + std::to_string(task->index);
459 members.emplace_back(std::move(member));
Ed Tanous002d39b2022-05-31 08:59:27 -0700460 }
461 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700462}
zhanghch058d1b46d2021-04-01 11:18:24 +0800463
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700464inline void requestRoutesTaskService(App& app)
James Feist46229572020-02-19 15:11:58 -0800465{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700466 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/")
Ed Tanoused398212021-06-09 17:05:54 -0700467 .privileges(redfish::privileges::getTaskService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700468 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700469 [&app](const crow::Request& req,
470 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000471 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700472 {
473 return;
474 }
475 asyncResp->res.jsonValue["@odata.type"] =
476 "#TaskService.v1_1_4.TaskService";
477 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService";
478 asyncResp->res.jsonValue["Name"] = "Task Service";
479 asyncResp->res.jsonValue["Id"] = "TaskService";
480 asyncResp->res.jsonValue["DateTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700481 redfish::time_utils::getDateTimeOffsetNow().first;
Ed Tanous002d39b2022-05-31 08:59:27 -0700482 asyncResp->res.jsonValue["CompletedTaskOverWritePolicy"] = "Oldest";
James Feist46229572020-02-19 15:11:58 -0800483
Ed Tanous002d39b2022-05-31 08:59:27 -0700484 asyncResp->res.jsonValue["LifeCycleEventOnTaskStateChange"] = true;
James Feist46229572020-02-19 15:11:58 -0800485
Ed Tanous002d39b2022-05-31 08:59:27 -0700486 auto health = std::make_shared<HealthPopulate>(asyncResp);
487 health->populate();
488 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
489 asyncResp->res.jsonValue["ServiceEnabled"] = true;
490 asyncResp->res.jsonValue["Tasks"]["@odata.id"] =
491 "/redfish/v1/TaskService/Tasks";
492 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700493}
James Feist46229572020-02-19 15:11:58 -0800494
495} // namespace redfish