blob: e0058f52a7d16d7b4479e30906f69386b40cca06 [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 Tanous1aa0c2b2022-02-08 12:24:30 +010022#include "http/parsing.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "query.hpp"
24#include "registries/privilege_registry.hpp"
25#include "task_messages.hpp"
26
Ed Tanousd43cd0c2020-09-30 20:46:53 -070027#include <boost/asio/post.hpp>
28#include <boost/asio/steady_timer.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070029#include <boost/url/format.hpp>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080030#include <sdbusplus/bus/match.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050031
32#include <chrono>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080033#include <memory>
James Feist46229572020-02-19 15:11:58 -080034#include <variant>
35
36namespace redfish
37{
38
39namespace task
40{
41constexpr size_t maxTaskCount = 100; // arbitrary limit
42
Ed Tanouscf9e4172022-12-21 09:30:16 -080043// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
James Feist46229572020-02-19 15:11:58 -080044static std::deque<std::shared_ptr<struct TaskData>> tasks;
45
James Feist32898ce2020-03-10 16:16:52 -070046constexpr bool completed = true;
47
James Feistfe306722020-03-12 16:32:08 -070048struct Payload
49{
Ed Tanous4e23a442022-06-06 09:57:26 -070050 explicit Payload(const crow::Request& req) :
Ed Tanous39662a32023-02-06 15:09:46 -080051 targetUri(req.url().encoded_path()), httpOperation(req.methodString()),
Ed Tanous1aa0c2b2022-02-08 12:24:30 +010052 httpHeaders(nlohmann::json::array())
James Feistfe306722020-03-12 16:32:08 -070053 {
54 using field_ns = boost::beast::http::field;
55 constexpr const std::array<boost::beast::http::field, 7>
56 headerWhitelist = {field_ns::accept, field_ns::accept_encoding,
57 field_ns::user_agent, field_ns::host,
58 field_ns::connection, field_ns::content_length,
59 field_ns::upgrade};
60
Ed Tanous1aa0c2b2022-02-08 12:24:30 +010061 JsonParseResult ret = parseRequestAsJson(req, jsonBody);
62 if (ret != JsonParseResult::Success)
James Feistfe306722020-03-12 16:32:08 -070063 {
Ed Tanous1aa0c2b2022-02-08 12:24:30 +010064 return;
James Feistfe306722020-03-12 16:32:08 -070065 }
66
Ed Tanous98fe7402023-02-14 14:50:33 -080067 for (const auto& field : req.fields())
James Feistfe306722020-03-12 16:32:08 -070068 {
69 if (std::find(headerWhitelist.begin(), headerWhitelist.end(),
70 field.name()) == headerWhitelist.end())
71 {
72 continue;
73 }
74 std::string header;
75 header.reserve(field.name_string().size() + 2 +
76 field.value().size());
77 header += field.name_string();
78 header += ": ";
79 header += field.value();
80 httpHeaders.emplace_back(std::move(header));
81 }
82 }
83 Payload() = delete;
84
85 std::string targetUri;
86 std::string httpOperation;
87 nlohmann::json httpHeaders;
88 nlohmann::json jsonBody;
89};
90
James Feist46229572020-02-19 15:11:58 -080091struct TaskData : std::enable_shared_from_this<TaskData>
92{
93 private:
Patrick Williams59d494e2022-07-22 19:26:55 -050094 TaskData(
95 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
96 const std::shared_ptr<TaskData>&)>&& handler,
97 const std::string& matchIn, size_t idx) :
James Feist46229572020-02-19 15:11:58 -080098 callback(std::move(handler)),
Ed Tanous23a21a12020-07-25 04:45:05 +000099 matchStr(matchIn), index(idx),
James Feist46229572020-02-19 15:11:58 -0800100 startTime(std::chrono::system_clock::to_time_t(
101 std::chrono::system_clock::now())),
102 status("OK"), state("Running"), messages(nlohmann::json::array()),
103 timer(crow::connections::systemBus->get_io_context())
104
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500105 {}
James Feist46229572020-02-19 15:11:58 -0800106
107 public:
Ed Tanousd609fd62020-09-28 19:08:03 -0700108 TaskData() = delete;
109
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500110 static std::shared_ptr<TaskData>& createTask(
Patrick Williams59d494e2022-07-22 19:26:55 -0500111 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500112 const std::shared_ptr<TaskData>&)>&& handler,
113 const std::string& match)
James Feist46229572020-02-19 15:11:58 -0800114 {
115 static size_t lastTask = 0;
116 struct MakeSharedHelper : public TaskData
117 {
118 MakeSharedHelper(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500119 std::function<bool(boost::system::error_code,
Patrick Williams59d494e2022-07-22 19:26:55 -0500120 sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500121 const std::shared_ptr<TaskData>&)>&& handler,
Ed Tanous23a21a12020-07-25 04:45:05 +0000122 const std::string& match2, size_t idx) :
123 TaskData(std::move(handler), match2, idx)
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500124 {}
James Feist46229572020-02-19 15:11:58 -0800125 };
126
127 if (tasks.size() >= maxTaskCount)
128 {
Ed Tanous02cad962022-06-30 16:50:15 -0700129 const auto& last = tasks.front();
James Feist46229572020-02-19 15:11:58 -0800130
131 // destroy all references
132 last->timer.cancel();
133 last->match.reset();
134 tasks.pop_front();
135 }
136
137 return tasks.emplace_back(std::make_shared<MakeSharedHelper>(
138 std::move(handler), match, lastTask++));
139 }
140
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500141 void populateResp(crow::Response& res, size_t retryAfterSeconds = 30)
James Feist46229572020-02-19 15:11:58 -0800142 {
143 if (!endTime)
144 {
145 res.result(boost::beast::http::status::accepted);
146 std::string strIdx = std::to_string(index);
147 std::string uri = "/redfish/v1/TaskService/Tasks/" + strIdx;
Ed Tanous14766872022-03-15 10:44:42 -0700148
149 res.jsonValue["@odata.id"] = uri;
150 res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
151 res.jsonValue["Id"] = strIdx;
152 res.jsonValue["TaskState"] = state;
153 res.jsonValue["TaskStatus"] = status;
154
James Feist46229572020-02-19 15:11:58 -0800155 res.addHeader(boost::beast::http::field::location,
156 uri + "/Monitor");
157 res.addHeader(boost::beast::http::field::retry_after,
158 std::to_string(retryAfterSeconds));
159 }
160 else if (!gave204)
161 {
162 res.result(boost::beast::http::status::no_content);
163 gave204 = true;
164 }
165 }
166
Ed Tanousd609fd62020-09-28 19:08:03 -0700167 void finishTask()
James Feist46229572020-02-19 15:11:58 -0800168 {
169 endTime = std::chrono::system_clock::to_time_t(
170 std::chrono::system_clock::now());
171 }
172
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500173 void extendTimer(const std::chrono::seconds& timeout)
James Feist46229572020-02-19 15:11:58 -0800174 {
James Feist46229572020-02-19 15:11:58 -0800175 timer.expires_after(timeout);
176 timer.async_wait(
177 [self = shared_from_this()](boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700178 if (ec == boost::asio::error::operation_aborted)
179 {
180 return; // completed successfully
181 }
182 if (!ec)
183 {
184 // change ec to error as timer expired
185 ec = boost::asio::error::operation_aborted;
186 }
187 self->match.reset();
Patrick Williams59d494e2022-07-22 19:26:55 -0500188 sdbusplus::message_t msg;
Ed Tanous002d39b2022-05-31 08:59:27 -0700189 self->finishTask();
190 self->state = "Cancelled";
191 self->status = "Warning";
192 self->messages.emplace_back(
193 messages::taskAborted(std::to_string(self->index)));
194 // Send event :TaskAborted
195 self->sendTaskEvent(self->state, self->index);
196 self->callback(ec, msg, self);
197 });
James Feistfd9ab9e2020-05-19 13:48:07 -0700198 }
199
Ed Tanous26ccae32023-02-16 10:28:44 -0800200 static void sendTaskEvent(std::string_view state, size_t index)
Sunitha Harishe7686572020-07-15 02:32:44 -0500201 {
Patrick Williams89492a12023-05-10 07:51:34 -0500202 std::string origin = "/redfish/v1/TaskService/Tasks/" +
203 std::to_string(index);
Sunitha Harishe7686572020-07-15 02:32:44 -0500204 std::string resType = "Task";
205 // TaskState enums which should send out an event are:
206 // "Starting" = taskResumed
207 // "Running" = taskStarted
208 // "Suspended" = taskPaused
209 // "Interrupted" = taskPaused
210 // "Pending" = taskPaused
211 // "Stopping" = taskAborted
212 // "Completed" = taskCompletedOK
213 // "Killed" = taskRemoved
214 // "Exception" = taskCompletedWarning
215 // "Cancelled" = taskCancelled
216 if (state == "Starting")
217 {
218 redfish::EventServiceManager::getInstance().sendEvent(
219 redfish::messages::taskResumed(std::to_string(index)), origin,
220 resType);
221 }
222 else if (state == "Running")
223 {
224 redfish::EventServiceManager::getInstance().sendEvent(
225 redfish::messages::taskStarted(std::to_string(index)), origin,
226 resType);
227 }
228 else if ((state == "Suspended") || (state == "Interrupted") ||
229 (state == "Pending"))
230 {
231 redfish::EventServiceManager::getInstance().sendEvent(
232 redfish::messages::taskPaused(std::to_string(index)), origin,
233 resType);
234 }
235 else if (state == "Stopping")
236 {
237 redfish::EventServiceManager::getInstance().sendEvent(
238 redfish::messages::taskAborted(std::to_string(index)), origin,
239 resType);
240 }
241 else if (state == "Completed")
242 {
243 redfish::EventServiceManager::getInstance().sendEvent(
244 redfish::messages::taskCompletedOK(std::to_string(index)),
245 origin, resType);
246 }
247 else if (state == "Killed")
248 {
249 redfish::EventServiceManager::getInstance().sendEvent(
250 redfish::messages::taskRemoved(std::to_string(index)), origin,
251 resType);
252 }
253 else if (state == "Exception")
254 {
255 redfish::EventServiceManager::getInstance().sendEvent(
256 redfish::messages::taskCompletedWarning(std::to_string(index)),
257 origin, resType);
258 }
259 else if (state == "Cancelled")
260 {
261 redfish::EventServiceManager::getInstance().sendEvent(
262 redfish::messages::taskCancelled(std::to_string(index)), origin,
263 resType);
264 }
265 else
266 {
267 BMCWEB_LOG_INFO << "sendTaskEvent: No events to send";
268 }
269 }
270
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500271 void startTimer(const std::chrono::seconds& timeout)
James Feistfd9ab9e2020-05-19 13:48:07 -0700272 {
273 if (match)
274 {
275 return;
276 }
Patrick Williams59d494e2022-07-22 19:26:55 -0500277 match = std::make_unique<sdbusplus::bus::match_t>(
278 static_cast<sdbusplus::bus_t&>(*crow::connections::systemBus),
James Feistfd9ab9e2020-05-19 13:48:07 -0700279 matchStr,
Patrick Williams59d494e2022-07-22 19:26:55 -0500280 [self = shared_from_this()](sdbusplus::message_t& message) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700281 boost::system::error_code ec;
James Feistfd9ab9e2020-05-19 13:48:07 -0700282
Ed Tanous002d39b2022-05-31 08:59:27 -0700283 // callback to return True if callback is done, callback needs
284 // to update status itself if needed
285 if (self->callback(ec, message, self) == task::completed)
286 {
287 self->timer.cancel();
288 self->finishTask();
James Feistfd9ab9e2020-05-19 13:48:07 -0700289
Ed Tanous002d39b2022-05-31 08:59:27 -0700290 // Send event
291 self->sendTaskEvent(self->state, self->index);
Sunitha Harishe7686572020-07-15 02:32:44 -0500292
Ed Tanous002d39b2022-05-31 08:59:27 -0700293 // reset the match after the callback was successful
294 boost::asio::post(
295 crow::connections::systemBus->get_io_context(),
296 [self] { self->match.reset(); });
297 return;
298 }
James Feistfd9ab9e2020-05-19 13:48:07 -0700299 });
300
301 extendTimer(timeout);
James Feiste5d50062020-05-11 17:29:00 -0700302 messages.emplace_back(messages::taskStarted(std::to_string(index)));
Sunitha Harishe7686572020-07-15 02:32:44 -0500303 // Send event : TaskStarted
304 sendTaskEvent(state, index);
James Feist46229572020-02-19 15:11:58 -0800305 }
306
Patrick Williams59d494e2022-07-22 19:26:55 -0500307 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500308 const std::shared_ptr<TaskData>&)>
James Feist46229572020-02-19 15:11:58 -0800309 callback;
310 std::string matchStr;
311 size_t index;
312 time_t startTime;
313 std::string status;
314 std::string state;
315 nlohmann::json messages;
316 boost::asio::steady_timer timer;
Patrick Williams59d494e2022-07-22 19:26:55 -0500317 std::unique_ptr<sdbusplus::bus::match_t> match;
James Feist46229572020-02-19 15:11:58 -0800318 std::optional<time_t> endTime;
James Feistfe306722020-03-12 16:32:08 -0700319 std::optional<Payload> payload;
James Feist46229572020-02-19 15:11:58 -0800320 bool gave204 = false;
George Liu6868ff52021-01-02 11:37:41 +0800321 int percentComplete = 0;
James Feist46229572020-02-19 15:11:58 -0800322};
323
324} // namespace task
325
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700326inline void requestRoutesTaskMonitor(App& app)
James Feist46229572020-02-19 15:11:58 -0800327{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700328 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/Monitor/")
Ed Tanoused398212021-06-09 17:05:54 -0700329 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700330 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700331 [&app](const crow::Request& req,
332 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
333 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000334 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700335 {
336 return;
337 }
338 auto find = std::find_if(
339 task::tasks.begin(), task::tasks.end(),
340 [&strParam](const std::shared_ptr<task::TaskData>& task) {
341 if (!task)
342 {
343 return false;
344 }
James Feist46229572020-02-19 15:11:58 -0800345
Ed Tanous002d39b2022-05-31 08:59:27 -0700346 // we compare against the string version as on failure
347 // strtoul returns 0
348 return std::to_string(task->index) == strParam;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700349 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700350
351 if (find == task::tasks.end())
352 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800353 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700354 return;
355 }
356 std::shared_ptr<task::TaskData>& ptr = *find;
357 // monitor expires after 204
358 if (ptr->gave204)
359 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800360 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700361 return;
362 }
363 ptr->populateResp(asyncResp->res);
364 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700365}
366
367inline void requestRoutesTask(App& app)
368{
369 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700370 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700371 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700372 [&app](const crow::Request& req,
373 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
374 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000375 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700376 {
377 return;
378 }
379 auto find = std::find_if(
380 task::tasks.begin(), task::tasks.end(),
381 [&strParam](const std::shared_ptr<task::TaskData>& task) {
382 if (!task)
383 {
384 return false;
385 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700386
Ed Tanous002d39b2022-05-31 08:59:27 -0700387 // we compare against the string version as on failure
388 // strtoul returns 0
389 return std::to_string(task->index) == strParam;
James Feist46229572020-02-19 15:11:58 -0800390 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700391
392 if (find == task::tasks.end())
393 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800394 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700395 return;
396 }
397
Ed Tanous02cad962022-06-30 16:50:15 -0700398 const std::shared_ptr<task::TaskData>& ptr = *find;
Ed Tanous002d39b2022-05-31 08:59:27 -0700399
400 asyncResp->res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
401 asyncResp->res.jsonValue["Id"] = strParam;
402 asyncResp->res.jsonValue["Name"] = "Task " + strParam;
403 asyncResp->res.jsonValue["TaskState"] = ptr->state;
404 asyncResp->res.jsonValue["StartTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700405 redfish::time_utils::getDateTimeStdtime(ptr->startTime);
Ed Tanous002d39b2022-05-31 08:59:27 -0700406 if (ptr->endTime)
407 {
408 asyncResp->res.jsonValue["EndTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700409 redfish::time_utils::getDateTimeStdtime(*(ptr->endTime));
Ed Tanous002d39b2022-05-31 08:59:27 -0700410 }
411 asyncResp->res.jsonValue["TaskStatus"] = ptr->status;
412 asyncResp->res.jsonValue["Messages"] = ptr->messages;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700413 asyncResp->res.jsonValue["@odata.id"] =
414 boost::urls::format("/redfish/v1/TaskService/Tasks/{}", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700415 if (!ptr->gave204)
416 {
417 asyncResp->res.jsonValue["TaskMonitor"] =
418 "/redfish/v1/TaskService/Tasks/" + strParam + "/Monitor";
419 }
420 if (ptr->payload)
421 {
422 const task::Payload& p = *(ptr->payload);
423 asyncResp->res.jsonValue["Payload"]["TargetUri"] = p.targetUri;
424 asyncResp->res.jsonValue["Payload"]["HttpOperation"] =
425 p.httpOperation;
426 asyncResp->res.jsonValue["Payload"]["HttpHeaders"] = p.httpHeaders;
427 asyncResp->res.jsonValue["Payload"]["JsonBody"] = p.jsonBody.dump(
428 2, ' ', true, nlohmann::json::error_handler_t::replace);
429 }
430 asyncResp->res.jsonValue["PercentComplete"] = ptr->percentComplete;
431 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700432}
James Feist46229572020-02-19 15:11:58 -0800433
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700434inline void requestRoutesTaskCollection(App& app)
James Feist46229572020-02-19 15:11:58 -0800435{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700436 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/")
Ed Tanoused398212021-06-09 17:05:54 -0700437 .privileges(redfish::privileges::getTaskCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700438 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700439 [&app](const crow::Request& req,
440 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000441 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700442 {
443 return;
444 }
445 asyncResp->res.jsonValue["@odata.type"] =
446 "#TaskCollection.TaskCollection";
447 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService/Tasks";
448 asyncResp->res.jsonValue["Name"] = "Task Collection";
449 asyncResp->res.jsonValue["Members@odata.count"] = task::tasks.size();
450 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
451 members = nlohmann::json::array();
James Feist46229572020-02-19 15:11:58 -0800452
Ed Tanous002d39b2022-05-31 08:59:27 -0700453 for (const std::shared_ptr<task::TaskData>& task : task::tasks)
454 {
455 if (task == nullptr)
456 {
457 continue; // shouldn't be possible
458 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700459 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700460 member["@odata.id"] =
461 boost::urls::format("/redfish/v1/TaskService/Tasks/{}",
462 std::to_string(task->index));
Ed Tanous613dabe2022-07-09 11:17:36 -0700463 members.emplace_back(std::move(member));
Ed Tanous002d39b2022-05-31 08:59:27 -0700464 }
465 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700466}
zhanghch058d1b46d2021-04-01 11:18:24 +0800467
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700468inline void requestRoutesTaskService(App& app)
James Feist46229572020-02-19 15:11:58 -0800469{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700470 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/")
Ed Tanoused398212021-06-09 17:05:54 -0700471 .privileges(redfish::privileges::getTaskService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700472 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700473 [&app](const crow::Request& req,
474 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000475 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700476 {
477 return;
478 }
479 asyncResp->res.jsonValue["@odata.type"] =
480 "#TaskService.v1_1_4.TaskService";
481 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService";
482 asyncResp->res.jsonValue["Name"] = "Task Service";
483 asyncResp->res.jsonValue["Id"] = "TaskService";
484 asyncResp->res.jsonValue["DateTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700485 redfish::time_utils::getDateTimeOffsetNow().first;
Ed Tanous002d39b2022-05-31 08:59:27 -0700486 asyncResp->res.jsonValue["CompletedTaskOverWritePolicy"] = "Oldest";
James Feist46229572020-02-19 15:11:58 -0800487
Ed Tanous002d39b2022-05-31 08:59:27 -0700488 asyncResp->res.jsonValue["LifeCycleEventOnTaskStateChange"] = true;
James Feist46229572020-02-19 15:11:58 -0800489
Ed Tanous002d39b2022-05-31 08:59:27 -0700490 auto health = std::make_shared<HealthPopulate>(asyncResp);
491 health->populate();
492 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
493 asyncResp->res.jsonValue["ServiceEnabled"] = true;
494 asyncResp->res.jsonValue["Tasks"]["@odata.id"] =
495 "/redfish/v1/TaskService/Tasks";
496 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700497}
James Feist46229572020-02-19 15:11:58 -0800498
499} // namespace redfish