Update Crashdump to the latest LogService and LogEntry schemas

This updates Crashdump to the latest LogService schema which now
has a "CollectDiagnosticData" Action that replaces the OEM actions.

It also updates to the latest LogEntry to use the new
"AdditionalDataURI" property to provide the Crashdump file URI.

Tested:
Confirmed that the Crashdump LogEntries are displayed and can
be collected correctly.

Confirmed that the schema changes pass the Redfish Service Validator.

Change-Id: I34f533b78441269a66201a13e990dba18745c7ba
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp
index aad28ac..a9832f1 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -141,8 +141,7 @@
         nodes.emplace_back(std::make_unique<CrashdumpEntry>(app));
         nodes.emplace_back(std::make_unique<CrashdumpFile>(app));
         nodes.emplace_back(std::make_unique<CrashdumpClear>(app));
-        nodes.emplace_back(std::make_unique<OnDemandCrashdump>(app));
-        nodes.emplace_back(std::make_unique<TelemetryCrashdump>(app));
+        nodes.emplace_back(std::make_unique<CrashdumpCollect>(app));
 #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
         nodes.emplace_back(std::make_unique<SendRawPECI>(app));
 #endif // BMCWEB_ENABLE_REDFISH_RAW_PECI
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 255c24e..47d61c0 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -2418,7 +2418,7 @@
         asyncResp->res.jsonValue["@odata.id"] =
             "/redfish/v1/Systems/system/LogServices/Crashdump";
         asyncResp->res.jsonValue["@odata.type"] =
-            "#LogService.v1_1_0.LogService";
+            "#LogService.v1_2_0.LogService";
         asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
         asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
         asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
@@ -2431,19 +2431,15 @@
             {"#LogService.ClearLog",
              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
                          "Actions/LogService.ClearLog"}}},
-            {"Oem",
-             {{"#Crashdump.OnDemand",
-               {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
-                           "Actions/Oem/Crashdump.OnDemand"}}},
-              {"#Crashdump.Telemetry",
-               {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
-                           "Actions/Oem/Crashdump.Telemetry"}}}}}};
+            {"#LogService.CollectDiagnosticData",
+             {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
+                         "Actions/LogService.CollectDiagnosticData"}}}};
 
 #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
-        asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
+        asyncResp->res.jsonValue["Actions"]["Oem"] = {
             {"#Crashdump.SendRawPeci",
              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
-                         "Actions/Oem/Crashdump.SendRawPeci"}}});
+                         "Actions/Oem/Crashdump.SendRawPeci"}}}};
 #endif
     }
 };
@@ -2524,15 +2520,16 @@
             std::string crashdumpURI =
                 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
                 logID + "/" + filename;
-            logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
+            logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"},
                             {"@odata.id", "/redfish/v1/Systems/system/"
                                           "LogServices/Crashdump/Entries/" +
                                               logID},
                             {"Name", "CPU Crashdump"},
                             {"Id", logID},
                             {"EntryType", "Oem"},
-                            {"OemRecordFormat", "Crashdump URI"},
-                            {"Message", std::move(crashdumpURI)},
+                            {"AdditionalDataURI", std::move(crashdumpURI)},
+                            {"DiagnosticDataType", "OEM"},
+                            {"OEMDiagnosticDataType", "PECICrashdump"},
                             {"Created", std::move(timestamp)}};
         };
     crow::connections::systemBus->async_method_call(
@@ -2763,13 +2760,12 @@
     }
 };
 
-class OnDemandCrashdump : public Node
+class CrashdumpCollect : public Node
 {
   public:
-    OnDemandCrashdump(App& app) :
-        Node(app,
-             "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
-             "Crashdump.OnDemand/")
+    CrashdumpCollect(App& app) :
+        Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
+                  "LogService.CollectDiagnosticData/")
     {
         // Note: Deviated from redfish privilege registry for GET & HEAD
         // method for security reasons.
@@ -2788,10 +2784,28 @@
     {
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
 
-        auto generateonDemandLogCallback = [asyncResp,
-                                            req](const boost::system::error_code
-                                                     ec,
-                                                 const std::string&) {
+        std::string diagnosticDataType;
+        std::string oemDiagnosticDataType;
+        if (!redfish::json_util::readJson(
+                req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
+                "OEMDiagnosticDataType", oemDiagnosticDataType))
+        {
+            return;
+        }
+
+        if (diagnosticDataType != "OEM")
+        {
+            BMCWEB_LOG_ERROR
+                << "Only OEM DiagnosticDataType supported for Crashdump";
+            messages::actionParameterValueFormatError(
+                asyncResp->res, diagnosticDataType, "DiagnosticDataType",
+                "CollectDiagnosticData");
+            return;
+        }
+
+        auto collectCrashdumpCallback = [asyncResp, req](
+                                            const boost::system::error_code ec,
+                                            const std::string&) {
             if (ec)
             {
                 if (ec.value() == boost::system::errc::operation_not_supported)
@@ -2829,81 +2843,30 @@
             task->populateResp(asyncResp->res);
             task->payload.emplace(req);
         };
-        crow::connections::systemBus->async_method_call(
-            std::move(generateonDemandLogCallback), crashdumpObject,
-            crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
-    }
-};
 
-class TelemetryCrashdump : public Node
-{
-  public:
-    TelemetryCrashdump(App& app) :
-        Node(app,
-             "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
-             "Crashdump.Telemetry/")
-    {
-        // Note: Deviated from redfish privilege registry for GET & HEAD
-        // method for security reasons.
-        entityPrivileges = {
-            {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
-            {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
-            {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
-            {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
-            {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
-            {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
-    }
-
-  private:
-    void doPost(crow::Response& res, const crow::Request& req,
-                const std::vector<std::string>&) override
-    {
-        std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
-
-        auto generateTelemetryLogCallback = [asyncResp, req](
-                                                const boost::system::error_code
-                                                    ec,
-                                                const std::string&) {
-            if (ec)
-            {
-                if (ec.value() == boost::system::errc::operation_not_supported)
-                {
-                    messages::resourceInStandby(asyncResp->res);
-                }
-                else if (ec.value() ==
-                         boost::system::errc::device_or_resource_busy)
-                {
-                    messages::serviceTemporarilyUnavailable(asyncResp->res,
-                                                            "60");
-                }
-                else
-                {
-                    messages::internalError(asyncResp->res);
-                }
-                return;
-            }
-            std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
-                [](boost::system::error_code err, sdbusplus::message::message&,
-                   const std::shared_ptr<task::TaskData>& taskData) {
-                    if (!err)
-                    {
-                        taskData->messages.emplace_back(
-                            messages::taskCompletedOK(
-                                std::to_string(taskData->index)));
-                        taskData->state = "Completed";
-                    }
-                    return task::completed;
-                },
-                "type='signal',interface='org.freedesktop.DBus.Properties',"
-                "member='PropertiesChanged',arg0namespace='com.intel."
-                "crashdump'");
-            task->startTimer(std::chrono::minutes(5));
-            task->populateResp(asyncResp->res);
-            task->payload.emplace(req);
-        };
-        crow::connections::systemBus->async_method_call(
-            std::move(generateTelemetryLogCallback), crashdumpObject,
-            crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
+        if (oemDiagnosticDataType == "OnDemand")
+        {
+            crow::connections::systemBus->async_method_call(
+                std::move(collectCrashdumpCallback), crashdumpObject,
+                crashdumpPath, crashdumpOnDemandInterface,
+                "GenerateOnDemandLog");
+        }
+        else if (oemDiagnosticDataType == "Telemetry")
+        {
+            crow::connections::systemBus->async_method_call(
+                std::move(collectCrashdumpCallback), crashdumpObject,
+                crashdumpPath, crashdumpTelemetryInterface,
+                "GenerateTelemetryLog");
+        }
+        else
+        {
+            BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: "
+                             << oemDiagnosticDataType;
+            messages::actionParameterValueFormatError(
+                asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
+                "CollectDiagnosticData");
+            return;
+        }
     }
 };