blob: 563f06f592c4df703ac75245237d9ce4dd2b8637 [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 Tanous3ccb3ad2023-01-13 17:40:03 -080029#include <sdbusplus/bus/match.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050030
31#include <chrono>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080032#include <memory>
James Feist46229572020-02-19 15:11:58 -080033#include <variant>
34
35namespace redfish
36{
37
38namespace task
39{
40constexpr size_t maxTaskCount = 100; // arbitrary limit
41
Ed Tanouscf9e4172022-12-21 09:30:16 -080042// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
James Feist46229572020-02-19 15:11:58 -080043static std::deque<std::shared_ptr<struct TaskData>> tasks;
44
James Feist32898ce2020-03-10 16:16:52 -070045constexpr bool completed = true;
46
James Feistfe306722020-03-12 16:32:08 -070047struct Payload
48{
Ed Tanous4e23a442022-06-06 09:57:26 -070049 explicit Payload(const crow::Request& req) :
James Feistfe306722020-03-12 16:32:08 -070050 targetUri(req.url), httpOperation(req.methodString()),
Ed Tanous1aa0c2b2022-02-08 12:24:30 +010051 httpHeaders(nlohmann::json::array())
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
Ed Tanous1aa0c2b2022-02-08 12:24:30 +010060 JsonParseResult ret = parseRequestAsJson(req, jsonBody);
61 if (ret != JsonParseResult::Success)
James Feistfe306722020-03-12 16:32:08 -070062 {
Ed Tanous1aa0c2b2022-02-08 12:24:30 +010063 return;
James Feistfe306722020-03-12 16:32:08 -070064 }
65
Gunnar Mills1214b7e2020-06-04 10:11:30 -050066 for (const auto& field : req.fields)
James Feistfe306722020-03-12 16:32:08 -070067 {
68 if (std::find(headerWhitelist.begin(), headerWhitelist.end(),
69 field.name()) == headerWhitelist.end())
70 {
71 continue;
72 }
73 std::string header;
74 header.reserve(field.name_string().size() + 2 +
75 field.value().size());
76 header += field.name_string();
77 header += ": ";
78 header += field.value();
79 httpHeaders.emplace_back(std::move(header));
80 }
81 }
82 Payload() = delete;
83
84 std::string targetUri;
85 std::string httpOperation;
86 nlohmann::json httpHeaders;
87 nlohmann::json jsonBody;
88};
89
James Feist46229572020-02-19 15:11:58 -080090struct TaskData : std::enable_shared_from_this<TaskData>
91{
92 private:
Patrick Williams59d494e2022-07-22 19:26:55 -050093 TaskData(
94 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
95 const std::shared_ptr<TaskData>&)>&& handler,
96 const std::string& matchIn, size_t idx) :
James Feist46229572020-02-19 15:11:58 -080097 callback(std::move(handler)),
Ed Tanous23a21a12020-07-25 04:45:05 +000098 matchStr(matchIn), index(idx),
James Feist46229572020-02-19 15:11:58 -080099 startTime(std::chrono::system_clock::to_time_t(
100 std::chrono::system_clock::now())),
101 status("OK"), state("Running"), messages(nlohmann::json::array()),
102 timer(crow::connections::systemBus->get_io_context())
103
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500104 {}
James Feist46229572020-02-19 15:11:58 -0800105
106 public:
Ed Tanousd609fd62020-09-28 19:08:03 -0700107 TaskData() = delete;
108
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500109 static std::shared_ptr<TaskData>& createTask(
Patrick Williams59d494e2022-07-22 19:26:55 -0500110 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500111 const std::shared_ptr<TaskData>&)>&& handler,
112 const std::string& match)
James Feist46229572020-02-19 15:11:58 -0800113 {
114 static size_t lastTask = 0;
115 struct MakeSharedHelper : public TaskData
116 {
117 MakeSharedHelper(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500118 std::function<bool(boost::system::error_code,
Patrick Williams59d494e2022-07-22 19:26:55 -0500119 sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500120 const std::shared_ptr<TaskData>&)>&& handler,
Ed Tanous23a21a12020-07-25 04:45:05 +0000121 const std::string& match2, size_t idx) :
122 TaskData(std::move(handler), match2, idx)
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500123 {}
James Feist46229572020-02-19 15:11:58 -0800124 };
125
126 if (tasks.size() >= maxTaskCount)
127 {
Ed Tanous02cad962022-06-30 16:50:15 -0700128 const auto& last = tasks.front();
James Feist46229572020-02-19 15:11:58 -0800129
130 // destroy all references
131 last->timer.cancel();
132 last->match.reset();
133 tasks.pop_front();
134 }
135
136 return tasks.emplace_back(std::make_shared<MakeSharedHelper>(
137 std::move(handler), match, lastTask++));
138 }
139
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500140 void populateResp(crow::Response& res, size_t retryAfterSeconds = 30)
James Feist46229572020-02-19 15:11:58 -0800141 {
142 if (!endTime)
143 {
144 res.result(boost::beast::http::status::accepted);
145 std::string strIdx = std::to_string(index);
146 std::string uri = "/redfish/v1/TaskService/Tasks/" + strIdx;
Ed Tanous14766872022-03-15 10:44:42 -0700147
148 res.jsonValue["@odata.id"] = uri;
149 res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
150 res.jsonValue["Id"] = strIdx;
151 res.jsonValue["TaskState"] = state;
152 res.jsonValue["TaskStatus"] = status;
153
James Feist46229572020-02-19 15:11:58 -0800154 res.addHeader(boost::beast::http::field::location,
155 uri + "/Monitor");
156 res.addHeader(boost::beast::http::field::retry_after,
157 std::to_string(retryAfterSeconds));
158 }
159 else if (!gave204)
160 {
161 res.result(boost::beast::http::status::no_content);
162 gave204 = true;
163 }
164 }
165
Ed Tanousd609fd62020-09-28 19:08:03 -0700166 void finishTask()
James Feist46229572020-02-19 15:11:58 -0800167 {
168 endTime = std::chrono::system_clock::to_time_t(
169 std::chrono::system_clock::now());
170 }
171
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500172 void extendTimer(const std::chrono::seconds& timeout)
James Feist46229572020-02-19 15:11:58 -0800173 {
James Feist46229572020-02-19 15:11:58 -0800174 timer.expires_after(timeout);
175 timer.async_wait(
176 [self = shared_from_this()](boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700177 if (ec == boost::asio::error::operation_aborted)
178 {
179 return; // completed successfully
180 }
181 if (!ec)
182 {
183 // change ec to error as timer expired
184 ec = boost::asio::error::operation_aborted;
185 }
186 self->match.reset();
Patrick Williams59d494e2022-07-22 19:26:55 -0500187 sdbusplus::message_t msg;
Ed Tanous002d39b2022-05-31 08:59:27 -0700188 self->finishTask();
189 self->state = "Cancelled";
190 self->status = "Warning";
191 self->messages.emplace_back(
192 messages::taskAborted(std::to_string(self->index)));
193 // Send event :TaskAborted
194 self->sendTaskEvent(self->state, self->index);
195 self->callback(ec, msg, self);
196 });
James Feistfd9ab9e2020-05-19 13:48:07 -0700197 }
198
Ed Tanous56d23962022-02-14 20:42:02 -0800199 static void sendTaskEvent(const std::string_view state, size_t index)
Sunitha Harishe7686572020-07-15 02:32:44 -0500200 {
201 std::string origin =
202 "/redfish/v1/TaskService/Tasks/" + std::to_string(index);
203 std::string resType = "Task";
204 // TaskState enums which should send out an event are:
205 // "Starting" = taskResumed
206 // "Running" = taskStarted
207 // "Suspended" = taskPaused
208 // "Interrupted" = taskPaused
209 // "Pending" = taskPaused
210 // "Stopping" = taskAborted
211 // "Completed" = taskCompletedOK
212 // "Killed" = taskRemoved
213 // "Exception" = taskCompletedWarning
214 // "Cancelled" = taskCancelled
215 if (state == "Starting")
216 {
217 redfish::EventServiceManager::getInstance().sendEvent(
218 redfish::messages::taskResumed(std::to_string(index)), origin,
219 resType);
220 }
221 else if (state == "Running")
222 {
223 redfish::EventServiceManager::getInstance().sendEvent(
224 redfish::messages::taskStarted(std::to_string(index)), origin,
225 resType);
226 }
227 else if ((state == "Suspended") || (state == "Interrupted") ||
228 (state == "Pending"))
229 {
230 redfish::EventServiceManager::getInstance().sendEvent(
231 redfish::messages::taskPaused(std::to_string(index)), origin,
232 resType);
233 }
234 else if (state == "Stopping")
235 {
236 redfish::EventServiceManager::getInstance().sendEvent(
237 redfish::messages::taskAborted(std::to_string(index)), origin,
238 resType);
239 }
240 else if (state == "Completed")
241 {
242 redfish::EventServiceManager::getInstance().sendEvent(
243 redfish::messages::taskCompletedOK(std::to_string(index)),
244 origin, resType);
245 }
246 else if (state == "Killed")
247 {
248 redfish::EventServiceManager::getInstance().sendEvent(
249 redfish::messages::taskRemoved(std::to_string(index)), origin,
250 resType);
251 }
252 else if (state == "Exception")
253 {
254 redfish::EventServiceManager::getInstance().sendEvent(
255 redfish::messages::taskCompletedWarning(std::to_string(index)),
256 origin, resType);
257 }
258 else if (state == "Cancelled")
259 {
260 redfish::EventServiceManager::getInstance().sendEvent(
261 redfish::messages::taskCancelled(std::to_string(index)), origin,
262 resType);
263 }
264 else
265 {
266 BMCWEB_LOG_INFO << "sendTaskEvent: No events to send";
267 }
268 }
269
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500270 void startTimer(const std::chrono::seconds& timeout)
James Feistfd9ab9e2020-05-19 13:48:07 -0700271 {
272 if (match)
273 {
274 return;
275 }
Patrick Williams59d494e2022-07-22 19:26:55 -0500276 match = std::make_unique<sdbusplus::bus::match_t>(
277 static_cast<sdbusplus::bus_t&>(*crow::connections::systemBus),
James Feistfd9ab9e2020-05-19 13:48:07 -0700278 matchStr,
Patrick Williams59d494e2022-07-22 19:26:55 -0500279 [self = shared_from_this()](sdbusplus::message_t& message) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700280 boost::system::error_code ec;
James Feistfd9ab9e2020-05-19 13:48:07 -0700281
Ed Tanous002d39b2022-05-31 08:59:27 -0700282 // callback to return True if callback is done, callback needs
283 // to update status itself if needed
284 if (self->callback(ec, message, self) == task::completed)
285 {
286 self->timer.cancel();
287 self->finishTask();
James Feistfd9ab9e2020-05-19 13:48:07 -0700288
Ed Tanous002d39b2022-05-31 08:59:27 -0700289 // Send event
290 self->sendTaskEvent(self->state, self->index);
Sunitha Harishe7686572020-07-15 02:32:44 -0500291
Ed Tanous002d39b2022-05-31 08:59:27 -0700292 // reset the match after the callback was successful
293 boost::asio::post(
294 crow::connections::systemBus->get_io_context(),
295 [self] { self->match.reset(); });
296 return;
297 }
James Feistfd9ab9e2020-05-19 13:48:07 -0700298 });
299
300 extendTimer(timeout);
James Feiste5d50062020-05-11 17:29:00 -0700301 messages.emplace_back(messages::taskStarted(std::to_string(index)));
Sunitha Harishe7686572020-07-15 02:32:44 -0500302 // Send event : TaskStarted
303 sendTaskEvent(state, index);
James Feist46229572020-02-19 15:11:58 -0800304 }
305
Patrick Williams59d494e2022-07-22 19:26:55 -0500306 std::function<bool(boost::system::error_code, sdbusplus::message_t&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500307 const std::shared_ptr<TaskData>&)>
James Feist46229572020-02-19 15:11:58 -0800308 callback;
309 std::string matchStr;
310 size_t index;
311 time_t startTime;
312 std::string status;
313 std::string state;
314 nlohmann::json messages;
315 boost::asio::steady_timer timer;
Patrick Williams59d494e2022-07-22 19:26:55 -0500316 std::unique_ptr<sdbusplus::bus::match_t> match;
James Feist46229572020-02-19 15:11:58 -0800317 std::optional<time_t> endTime;
James Feistfe306722020-03-12 16:32:08 -0700318 std::optional<Payload> payload;
James Feist46229572020-02-19 15:11:58 -0800319 bool gave204 = false;
George Liu6868ff52021-01-02 11:37:41 +0800320 int percentComplete = 0;
James Feist46229572020-02-19 15:11:58 -0800321};
322
323} // namespace task
324
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700325inline void requestRoutesTaskMonitor(App& app)
James Feist46229572020-02-19 15:11:58 -0800326{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700327 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/Monitor/")
Ed Tanoused398212021-06-09 17:05:54 -0700328 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700329 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700330 [&app](const crow::Request& req,
331 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
332 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000333 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700334 {
335 return;
336 }
337 auto find = std::find_if(
338 task::tasks.begin(), task::tasks.end(),
339 [&strParam](const std::shared_ptr<task::TaskData>& task) {
340 if (!task)
341 {
342 return false;
343 }
James Feist46229572020-02-19 15:11:58 -0800344
Ed Tanous002d39b2022-05-31 08:59:27 -0700345 // we compare against the string version as on failure
346 // strtoul returns 0
347 return std::to_string(task->index) == strParam;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700348 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700349
350 if (find == task::tasks.end())
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 std::shared_ptr<task::TaskData>& ptr = *find;
356 // monitor expires after 204
357 if (ptr->gave204)
358 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800359 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700360 return;
361 }
362 ptr->populateResp(asyncResp->res);
363 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700364}
365
366inline void requestRoutesTask(App& app)
367{
368 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700369 .privileges(redfish::privileges::getTask)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700370 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700371 [&app](const crow::Request& req,
372 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
373 const std::string& strParam) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000374 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700375 {
376 return;
377 }
378 auto find = std::find_if(
379 task::tasks.begin(), task::tasks.end(),
380 [&strParam](const std::shared_ptr<task::TaskData>& task) {
381 if (!task)
382 {
383 return false;
384 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700385
Ed Tanous002d39b2022-05-31 08:59:27 -0700386 // we compare against the string version as on failure
387 // strtoul returns 0
388 return std::to_string(task->index) == strParam;
James Feist46229572020-02-19 15:11:58 -0800389 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700390
391 if (find == task::tasks.end())
392 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800393 messages::resourceNotFound(asyncResp->res, "Task", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700394 return;
395 }
396
Ed Tanous02cad962022-06-30 16:50:15 -0700397 const std::shared_ptr<task::TaskData>& ptr = *find;
Ed Tanous002d39b2022-05-31 08:59:27 -0700398
399 asyncResp->res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
400 asyncResp->res.jsonValue["Id"] = strParam;
401 asyncResp->res.jsonValue["Name"] = "Task " + strParam;
402 asyncResp->res.jsonValue["TaskState"] = ptr->state;
403 asyncResp->res.jsonValue["StartTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700404 redfish::time_utils::getDateTimeStdtime(ptr->startTime);
Ed Tanous002d39b2022-05-31 08:59:27 -0700405 if (ptr->endTime)
406 {
407 asyncResp->res.jsonValue["EndTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700408 redfish::time_utils::getDateTimeStdtime(*(ptr->endTime));
Ed Tanous002d39b2022-05-31 08:59:27 -0700409 }
410 asyncResp->res.jsonValue["TaskStatus"] = ptr->status;
411 asyncResp->res.jsonValue["Messages"] = ptr->messages;
Willy Tueddfc432022-09-26 16:46:38 +0000412 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
413 "redfish", "v1", "TaskService", "Tasks", strParam);
Ed Tanous002d39b2022-05-31 08:59:27 -0700414 if (!ptr->gave204)
415 {
416 asyncResp->res.jsonValue["TaskMonitor"] =
417 "/redfish/v1/TaskService/Tasks/" + strParam + "/Monitor";
418 }
419 if (ptr->payload)
420 {
421 const task::Payload& p = *(ptr->payload);
422 asyncResp->res.jsonValue["Payload"]["TargetUri"] = p.targetUri;
423 asyncResp->res.jsonValue["Payload"]["HttpOperation"] =
424 p.httpOperation;
425 asyncResp->res.jsonValue["Payload"]["HttpHeaders"] = p.httpHeaders;
426 asyncResp->res.jsonValue["Payload"]["JsonBody"] = p.jsonBody.dump(
427 2, ' ', true, nlohmann::json::error_handler_t::replace);
428 }
429 asyncResp->res.jsonValue["PercentComplete"] = ptr->percentComplete;
430 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700431}
James Feist46229572020-02-19 15:11:58 -0800432
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700433inline void requestRoutesTaskCollection(App& app)
James Feist46229572020-02-19 15:11:58 -0800434{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700435 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/")
Ed Tanoused398212021-06-09 17:05:54 -0700436 .privileges(redfish::privileges::getTaskCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700437 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700438 [&app](const crow::Request& req,
439 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000440 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700441 {
442 return;
443 }
444 asyncResp->res.jsonValue["@odata.type"] =
445 "#TaskCollection.TaskCollection";
446 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService/Tasks";
447 asyncResp->res.jsonValue["Name"] = "Task Collection";
448 asyncResp->res.jsonValue["Members@odata.count"] = task::tasks.size();
449 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
450 members = nlohmann::json::array();
James Feist46229572020-02-19 15:11:58 -0800451
Ed Tanous002d39b2022-05-31 08:59:27 -0700452 for (const std::shared_ptr<task::TaskData>& task : task::tasks)
453 {
454 if (task == nullptr)
455 {
456 continue; // shouldn't be possible
457 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700458 nlohmann::json::object_t member;
Willy Tueddfc432022-09-26 16:46:38 +0000459 member["@odata.id"] = crow::utility::urlFromPieces(
460 "redfish", "v1", "TaskService", "Tasks",
461 std::to_string(task->index));
Ed Tanous613dabe2022-07-09 11:17:36 -0700462 members.emplace_back(std::move(member));
Ed Tanous002d39b2022-05-31 08:59:27 -0700463 }
464 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700465}
zhanghch058d1b46d2021-04-01 11:18:24 +0800466
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700467inline void requestRoutesTaskService(App& app)
James Feist46229572020-02-19 15:11:58 -0800468{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700469 BMCWEB_ROUTE(app, "/redfish/v1/TaskService/")
Ed Tanoused398212021-06-09 17:05:54 -0700470 .privileges(redfish::privileges::getTaskService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700471 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700472 [&app](const crow::Request& req,
473 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000474 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700475 {
476 return;
477 }
478 asyncResp->res.jsonValue["@odata.type"] =
479 "#TaskService.v1_1_4.TaskService";
480 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TaskService";
481 asyncResp->res.jsonValue["Name"] = "Task Service";
482 asyncResp->res.jsonValue["Id"] = "TaskService";
483 asyncResp->res.jsonValue["DateTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -0700484 redfish::time_utils::getDateTimeOffsetNow().first;
Ed Tanous002d39b2022-05-31 08:59:27 -0700485 asyncResp->res.jsonValue["CompletedTaskOverWritePolicy"] = "Oldest";
James Feist46229572020-02-19 15:11:58 -0800486
Ed Tanous002d39b2022-05-31 08:59:27 -0700487 asyncResp->res.jsonValue["LifeCycleEventOnTaskStateChange"] = true;
James Feist46229572020-02-19 15:11:58 -0800488
Ed Tanous002d39b2022-05-31 08:59:27 -0700489 auto health = std::make_shared<HealthPopulate>(asyncResp);
490 health->populate();
491 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
492 asyncResp->res.jsonValue["ServiceEnabled"] = true;
493 asyncResp->res.jsonValue["Tasks"]["@odata.id"] =
494 "/redfish/v1/TaskService/Tasks";
495 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700496}
James Feist46229572020-02-19 15:11:58 -0800497
498} // namespace redfish