blob: fe3b9908bbf46731ef675b0b9f13b1f665c7276b [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
John Edward Broadbent7e860f12021-04-08 15:57:16 -070018#include <app.hpp>
Ed Tanousd43cd0c2020-09-30 20:46:53 -070019#include <boost/asio/post.hpp>
20#include <boost/asio/steady_timer.hpp>
Ed Tanousb9d36b42022-02-26 21:42:46 -080021#include <dbus_utility.hpp>
Ed Tanous45ca1b82022-03-25 13:07:27 -070022#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070023#include <registries/privilege_registry.hpp>
James Feiste5d50062020-05-11 17:29:00 -070024#include <task_messages.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050025
26#include <chrono>
James Feist46229572020-02-19 15:11:58 -080027#include <variant>
28
29namespace redfish
30{
31
32namespace task
33{
34constexpr size_t maxTaskCount = 100; // arbitrary limit
35
36static std::deque<std::shared_ptr<struct TaskData>> tasks;
37
James Feist32898ce2020-03-10 16:16:52 -070038constexpr bool completed = true;
39
James Feistfe306722020-03-12 16:32:08 -070040struct Payload
41{
Ed Tanous4e23a442022-06-06 09:57:26 -070042 explicit Payload(const crow::Request& req) :
James Feistfe306722020-03-12 16:32:08 -070043 targetUri(req.url), httpOperation(req.methodString()),
Ed Tanousb31cef62022-06-30 17:51:46 -070044 httpHeaders(nlohmann::json::array()),
45 jsonBody(nlohmann::json::parse(req.body, nullptr, false))
James Feistfe306722020-03-12 16:32:08 -070046 {
47 using field_ns = boost::beast::http::field;
48 constexpr const std::array<boost::beast::http::field, 7>
49 headerWhitelist = {field_ns::accept, field_ns::accept_encoding,
50 field_ns::user_agent, field_ns::host,
51 field_ns::connection, field_ns::content_length,
52 field_ns::upgrade};
53
James Feistfe306722020-03-12 16:32:08 -070054 if (jsonBody.is_discarded())
55 {
56 jsonBody = nullptr;
57 }
58
Gunnar Mills1214b7e2020-06-04 10:11:30 -050059 for (const auto& field : req.fields)
James Feistfe306722020-03-12 16:32:08 -070060 {
61 if (std::find(headerWhitelist.begin(), headerWhitelist.end(),
62 field.name()) == headerWhitelist.end())
63 {
64 continue;
65 }
66 std::string header;
67 header.reserve(field.name_string().size() + 2 +
68 field.value().size());
69 header += field.name_string();
70 header += ": ";
71 header += field.value();
72 httpHeaders.emplace_back(std::move(header));
73 }
74 }
75 Payload() = delete;
76
77 std::string targetUri;
78 std::string httpOperation;
79 nlohmann::json httpHeaders;
80 nlohmann::json jsonBody;
81};
82
James Feist46229572020-02-19 15:11:58 -080083struct TaskData : std::enable_shared_from_this<TaskData>
84{
85 private:
Patrick Williams59d494e2022-07-22 19:26:55 -050086 TaskData(
87 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
88 const std::shared_ptr<TaskData>&)>&& handler,
89 const std::string& matchIn, size_t idx) :
James Feist46229572020-02-19 15:11:58 -080090 callback(std::move(handler)),
Ed Tanous23a21a12020-07-25 04:45:05 +000091 matchStr(matchIn), index(idx),
James Feist46229572020-02-19 15:11:58 -080092 startTime(std::chrono::system_clock::to_time_t(
93 std::chrono::system_clock::now())),
94 status("OK"), state("Running"), messages(nlohmann::json::array()),
95 timer(crow::connections::systemBus->get_io_context())
96
Gunnar Mills1214b7e2020-06-04 10:11:30 -050097 {}
James Feist46229572020-02-19 15:11:58 -080098
99 public:
Ed Tanousd609fd62020-09-28 19:08:03 -0700100 TaskData() = delete;
101
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500102 static std::shared_ptr<TaskData>& createTask(
Patrick Williams59d494e2022-07-22 19:26:55 -0500103 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500104 const std::shared_ptr<TaskData>&)>&& handler,
105 const std::string& match)
James Feist46229572020-02-19 15:11:58 -0800106 {
107 static size_t lastTask = 0;
108 struct MakeSharedHelper : public TaskData
109 {
110 MakeSharedHelper(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500111 std::function<bool(boost::system::error_code,
Patrick Williams59d494e2022-07-22 19:26:55 -0500112 sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500113 const std::shared_ptr<TaskData>&)>&& handler,
Ed Tanous23a21a12020-07-25 04:45:05 +0000114 const std::string& match2, size_t idx) :
115 TaskData(std::move(handler), match2, idx)
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500116 {}
James Feist46229572020-02-19 15:11:58 -0800117 };
118
119 if (tasks.size() >= maxTaskCount)
120 {
Ed Tanous02cad962022-06-30 16:50:15 -0700121 const auto& last = tasks.front();
James Feist46229572020-02-19 15:11:58 -0800122
123 // destroy all references
124 last->timer.cancel();
125 last->match.reset();
126 tasks.pop_front();
127 }
128
129 return tasks.emplace_back(std::make_shared<MakeSharedHelper>(
130 std::move(handler), match, lastTask++));
131 }
132
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500133 void populateResp(crow::Response& res, size_t retryAfterSeconds = 30)
James Feist46229572020-02-19 15:11:58 -0800134 {
135 if (!endTime)
136 {
137 res.result(boost::beast::http::status::accepted);
138 std::string strIdx = std::to_string(index);
139 std::string uri = "/redfish/v1/TaskService/Tasks/" + strIdx;
Ed Tanous14766872022-03-15 10:44:42 -0700140
141 res.jsonValue["@odata.id"] = uri;
142 res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
143 res.jsonValue["Id"] = strIdx;
144 res.jsonValue["TaskState"] = state;
145 res.jsonValue["TaskStatus"] = status;
146
James Feist46229572020-02-19 15:11:58 -0800147 res.addHeader(boost::beast::http::field::location,
148 uri + "/Monitor");
149 res.addHeader(boost::beast::http::field::retry_after,
150 std::to_string(retryAfterSeconds));
151 }
152 else if (!gave204)
153 {
154 res.result(boost::beast::http::status::no_content);
155 gave204 = true;
156 }
157 }
158
Ed Tanousd609fd62020-09-28 19:08:03 -0700159 void finishTask()
James Feist46229572020-02-19 15:11:58 -0800160 {
161 endTime = std::chrono::system_clock::to_time_t(
162 std::chrono::system_clock::now());
163 }
164
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500165 void extendTimer(const std::chrono::seconds& timeout)
James Feist46229572020-02-19 15:11:58 -0800166 {
James Feist46229572020-02-19 15:11:58 -0800167 timer.expires_after(timeout);
168 timer.async_wait(
169 [self = shared_from_this()](boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700170 if (ec == boost::asio::error::operation_aborted)
171 {
172 return; // completed successfully
173 }
174 if (!ec)
175 {
176 // change ec to error as timer expired
177 ec = boost::asio::error::operation_aborted;
178 }
179 self->match.reset();
Patrick Williams59d494e2022-07-22 19:26:55 -0500180 sdbusplus::message_t msg;
Ed Tanous002d39b2022-05-31 08:59:27 -0700181 self->finishTask();
182 self->state = "Cancelled";
183 self->status = "Warning";
184 self->messages.emplace_back(
185 messages::taskAborted(std::to_string(self->index)));
186 // Send event :TaskAborted
187 self->sendTaskEvent(self->state, self->index);
188 self->callback(ec, msg, self);
189 });
James Feistfd9ab9e2020-05-19 13:48:07 -0700190 }
191
Ed Tanous56d23962022-02-14 20:42:02 -0800192 static void sendTaskEvent(const std::string_view state, size_t index)
Sunitha Harishe7686572020-07-15 02:32:44 -0500193 {
194 std::string origin =
195 "/redfish/v1/TaskService/Tasks/" + std::to_string(index);
196 std::string resType = "Task";
197 // TaskState enums which should send out an event are:
198 // "Starting" = taskResumed
199 // "Running" = taskStarted
200 // "Suspended" = taskPaused
201 // "Interrupted" = taskPaused
202 // "Pending" = taskPaused
203 // "Stopping" = taskAborted
204 // "Completed" = taskCompletedOK
205 // "Killed" = taskRemoved
206 // "Exception" = taskCompletedWarning
207 // "Cancelled" = taskCancelled
208 if (state == "Starting")
209 {
210 redfish::EventServiceManager::getInstance().sendEvent(
211 redfish::messages::taskResumed(std::to_string(index)), origin,
212 resType);
213 }
214 else if (state == "Running")
215 {
216 redfish::EventServiceManager::getInstance().sendEvent(
217 redfish::messages::taskStarted(std::to_string(index)), origin,
218 resType);
219 }
220 else if ((state == "Suspended") || (state == "Interrupted") ||
221 (state == "Pending"))
222 {
223 redfish::EventServiceManager::getInstance().sendEvent(
224 redfish::messages::taskPaused(std::to_string(index)), origin,
225 resType);
226 }
227 else if (state == "Stopping")
228 {
229 redfish::EventServiceManager::getInstance().sendEvent(
230 redfish::messages::taskAborted(std::to_string(index)), origin,
231 resType);
232 }
233 else if (state == "Completed")
234 {
235 redfish::EventServiceManager::getInstance().sendEvent(
236 redfish::messages::taskCompletedOK(std::to_string(index)),
237 origin, resType);
238 }
239 else if (state == "Killed")
240 {
241 redfish::EventServiceManager::getInstance().sendEvent(
242 redfish::messages::taskRemoved(std::to_string(index)), origin,
243 resType);
244 }
245 else if (state == "Exception")
246 {
247 redfish::EventServiceManager::getInstance().sendEvent(
248 redfish::messages::taskCompletedWarning(std::to_string(index)),
249 origin, resType);
250 }
251 else if (state == "Cancelled")
252 {
253 redfish::EventServiceManager::getInstance().sendEvent(
254 redfish::messages::taskCancelled(std::to_string(index)), origin,
255 resType);
256 }
257 else
258 {
259 BMCWEB_LOG_INFO << "sendTaskEvent: No events to send";
260 }
261 }
262
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500263 void startTimer(const std::chrono::seconds& timeout)
James Feistfd9ab9e2020-05-19 13:48:07 -0700264 {
265 if (match)
266 {
267 return;
268 }
Patrick Williams59d494e2022-07-22 19:26:55 -0500269 match = std::make_unique<sdbusplus::bus::match_t>(
270 static_cast<sdbusplus::bus_t&>(*crow::connections::systemBus),
James Feistfd9ab9e2020-05-19 13:48:07 -0700271 matchStr,
Patrick Williams59d494e2022-07-22 19:26:55 -0500272 [self = shared_from_this()](sdbusplus::message_t& message) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700273 boost::system::error_code ec;
James Feistfd9ab9e2020-05-19 13:48:07 -0700274
Ed Tanous002d39b2022-05-31 08:59:27 -0700275 // callback to return True if callback is done, callback needs
276 // to update status itself if needed
277 if (self->callback(ec, message, self) == task::completed)
278 {
279 self->timer.cancel();
280 self->finishTask();
James Feistfd9ab9e2020-05-19 13:48:07 -0700281
Ed Tanous002d39b2022-05-31 08:59:27 -0700282 // Send event
283 self->sendTaskEvent(self->state, self->index);
Sunitha Harishe7686572020-07-15 02:32:44 -0500284
Ed Tanous002d39b2022-05-31 08:59:27 -0700285 // reset the match after the callback was successful
286 boost::asio::post(
287 crow::connections::systemBus->get_io_context(),
288 [self] { self->match.reset(); });
289 return;
290 }
James Feistfd9ab9e2020-05-19 13:48:07 -0700291 });
292
293 extendTimer(timeout);
James Feiste5d50062020-05-11 17:29:00 -0700294 messages.emplace_back(messages::taskStarted(std::to_string(index)));
Sunitha Harishe7686572020-07-15 02:32:44 -0500295 // Send event : TaskStarted
296 sendTaskEvent(state, index);
James Feist46229572020-02-19 15:11:58 -0800297 }
298
Patrick Williams59d494e2022-07-22 19:26:55 -0500299 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500300 const std::shared_ptr<TaskData>&)>
James Feist46229572020-02-19 15:11:58 -0800301 callback;
302 std::string matchStr;
303 size_t index;
304 time_t startTime;
305 std::string status;
306 std::string state;
307 nlohmann::json messages;
308 boost::asio::steady_timer timer;
Patrick Williams59d494e2022-07-22 19:26:55 -0500309 std::unique_ptr<sdbusplus::bus::match_t> match;
James Feist46229572020-02-19 15:11:58 -0800310 std::optional<time_t> endTime;
James Feistfe306722020-03-12 16:32:08 -0700311 std::optional<Payload> payload;
James Feist46229572020-02-19 15:11:58 -0800312 bool gave204 = false;
George Liu6868ff52021-01-02 11:37:41 +0800313 int percentComplete = 0;
James Feist46229572020-02-19 15:11:58 -0800314};
315
316} // namespace task
317
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700318inline void requestRoutesTaskMonitor(App& app)
James Feist46229572020-02-19 15:11:58 -0800319{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700320 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/Monitor/")
Ed Tanoused398212021-06-09 17:05:54 -0700321 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700322 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700323 [&app](const crow::Request& req,
324 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
325 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000326 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700327 {
328 return;
329 }
330 auto find = std::find_if(
331 task::tasks.begin(), task::tasks.end(),
332 [&strParam](const std::shared_ptr<task::TaskData>& task) {
333 if (!task)
334 {
335 return false;
336 }
James Feist46229572020-02-19 15:11:58 -0800337
Ed Tanous002d39b2022-05-31 08:59:27 -0700338 // we compare against the string version as on failure
339 // strtoul returns 0
340 return std::to_string(task->index) == strParam;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700341 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700342
343 if (find == task::tasks.end())
344 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800345 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700346 return;
347 }
348 std::shared_ptr<task::TaskData>& ptr = *find;
349 // monitor expires after 204
350 if (ptr->gave204)
351 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800352 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700353 return;
354 }
355 ptr->populateResp(asyncResp->res);
356 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700357}
358
359inline void requestRoutesTask(App& app)
360{
361 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700362 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700363 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700364 [&app](const crow::Request& req,
365 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
366 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000367 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700368 {
369 return;
370 }
371 auto find = std::find_if(
372 task::tasks.begin(), task::tasks.end(),
373 [&strParam](const std::shared_ptr<task::TaskData>& task) {
374 if (!task)
375 {
376 return false;
377 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700378
Ed Tanous002d39b2022-05-31 08:59:27 -0700379 // we compare against the string version as on failure
380 // strtoul returns 0
381 return std::to_string(task->index) == strParam;
James Feist46229572020-02-19 15:11:58 -0800382 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700383
384 if (find == task::tasks.end())
385 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800386 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700387 return;
388 }
389
Ed Tanous02cad962022-06-30 16:50:15 -0700390 const std::shared_ptr<task::TaskData>& ptr = *find;
Ed Tanous002d39b2022-05-31 08:59:27 -0700391
392 asyncResp->res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
393 asyncResp->res.jsonValue["Id"] = strParam;
394 asyncResp->res.jsonValue["Name"] = "Task " + strParam;
395 asyncResp->res.jsonValue["TaskState"] = ptr->state;
396 asyncResp->res.jsonValue["StartTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700397 redfish::time_utils::getDateTimeStdtime(ptr->startTime);
Ed Tanous002d39b2022-05-31 08:59:27 -0700398 if (ptr->endTime)
399 {
400 asyncResp->res.jsonValue["EndTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700401 redfish::time_utils::getDateTimeStdtime(*(ptr->endTime));
Ed Tanous002d39b2022-05-31 08:59:27 -0700402 }
403 asyncResp->res.jsonValue["TaskStatus"] = ptr->status;
404 asyncResp->res.jsonValue["Messages"] = ptr->messages;
405 asyncResp->res.jsonValue["@odata.id"] =
406 "/redfish/v1/TaskService/Tasks/" + strParam;
407 if (!ptr->gave204)
408 {
409 asyncResp->res.jsonValue["TaskMonitor"] =
410 "/redfish/v1/TaskService/Tasks/" + strParam + "/Monitor";
411 }
412 if (ptr->payload)
413 {
414 const task::Payload& p = *(ptr->payload);
415 asyncResp->res.jsonValue["Payload"]["TargetUri"] = p.targetUri;
416 asyncResp->res.jsonValue["Payload"]["HttpOperation"] =
417 p.httpOperation;
418 asyncResp->res.jsonValue["Payload"]["HttpHeaders"] = p.httpHeaders;
419 asyncResp->res.jsonValue["Payload"]["JsonBody"] = p.jsonBody.dump(
420 2, ' ', true, nlohmann::json::error_handler_t::replace);
421 }
422 asyncResp->res.jsonValue["PercentComplete"] = ptr->percentComplete;
423 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700424}
James Feist46229572020-02-19 15:11:58 -0800425
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700426inline void requestRoutesTaskCollection(App& app)
James Feist46229572020-02-19 15:11:58 -0800427{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700428 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/")
Ed Tanoused398212021-06-09 17:05:54 -0700429 .privileges(redfish::privileges::getTaskCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700430 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700431 [&app](const crow::Request& req,
432 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000433 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700434 {
435 return;
436 }
437 asyncResp->res.jsonValue["@odata.type"] =
438 "#TaskCollection.TaskCollection";
439 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService/Tasks";
440 asyncResp->res.jsonValue["Name"] = "Task Collection";
441 asyncResp->res.jsonValue["Members@odata.count"] = task::tasks.size();
442 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
443 members = nlohmann::json::array();
James Feist46229572020-02-19 15:11:58 -0800444
Ed Tanous002d39b2022-05-31 08:59:27 -0700445 for (const std::shared_ptr<task::TaskData>& task : task::tasks)
446 {
447 if (task == nullptr)
448 {
449 continue; // shouldn't be possible
450 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700451 nlohmann::json::object_t member;
452 member["@odata.id"] =
453 "redfish/v1/TaskService/Tasks/" + std::to_string(task->index);
454 members.emplace_back(std::move(member));
Ed Tanous002d39b2022-05-31 08:59:27 -0700455 }
456 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700457}
zhanghch058d1b46d2021-04-01 11:18:24 +0800458
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700459inline void requestRoutesTaskService(App& app)
James Feist46229572020-02-19 15:11:58 -0800460{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700461 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/")
Ed Tanoused398212021-06-09 17:05:54 -0700462 .privileges(redfish::privileges::getTaskService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700463 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700464 [&app](const crow::Request& req,
465 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000466 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700467 {
468 return;
469 }
470 asyncResp->res.jsonValue["@odata.type"] =
471 "#TaskService.v1_1_4.TaskService";
472 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService";
473 asyncResp->res.jsonValue["Name"] = "Task Service";
474 asyncResp->res.jsonValue["Id"] = "TaskService";
475 asyncResp->res.jsonValue["DateTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700476 redfish::time_utils::getDateTimeOffsetNow().first;
Ed Tanous002d39b2022-05-31 08:59:27 -0700477 asyncResp->res.jsonValue["CompletedTaskOverWritePolicy"] = "Oldest";
James Feist46229572020-02-19 15:11:58 -0800478
Ed Tanous002d39b2022-05-31 08:59:27 -0700479 asyncResp->res.jsonValue["LifeCycleEventOnTaskStateChange"] = true;
James Feist46229572020-02-19 15:11:58 -0800480
Ed Tanous002d39b2022-05-31 08:59:27 -0700481 auto health = std::make_shared<HealthPopulate>(asyncResp);
482 health->populate();
483 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
484 asyncResp->res.jsonValue["ServiceEnabled"] = true;
485 asyncResp->res.jsonValue["Tasks"]["@odata.id"] =
486 "/redfish/v1/TaskService/Tasks";
487 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700488}
James Feist46229572020-02-19 15:11:58 -0800489
490} // namespace redfish