PEL: Manager: Implemented the GetPELIdFromBMCLogId dbus method

In OpenPOWER based system, the application may need to get
the PEL id (aka Entry ID (EID) which is a unique id in the PEL) by using
OpenBMC event log id so added the interface for the same.

Tested:
- Tested by below unit test cases.
 - With valid OpenBMC Event Log ID
 - With invalid OpenBMC Event Log ID

- Tested by using busctl command
 - With valid OpenBMC Event Log ID
```
   busctl call xyz.openbmc_project.Logging \
   /xyz/openbmc_project/logging org.open_power.Logging.PEL \
   GetPELIdFromBMCLogId u 4534
   >>> u 1342211909
```
 - With invalid OpenBMC Event Log ID
```
   busctl call xyz.openbmc_project.Logging \
   /xyz/openbmc_project/logging org.open_power.Logging.PEL \
   GetPELIdFromBMCLogId u 0xFFFFFFFF
   >>> Call failed: Invalid argument was given.
```

DBus interface:
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-dbus-interfaces/+/44420

Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
Change-Id: I60ff5b86bb82cef2c2d3ceab74c49de5b6f6f99d
diff --git a/extensions/openpower-pels/manager.cpp b/extensions/openpower-pels/manager.cpp
index cedb787..0aa2988 100644
--- a/extensions/openpower-pels/manager.cpp
+++ b/extensions/openpower-pels/manager.cpp
@@ -701,5 +701,18 @@
     }
 }
 
+uint32_t Manager::getPELIdFromBMCLogId(uint32_t bmcLogId)
+{
+    Repository::LogID id{Repository::LogID::Obmc(bmcLogId)};
+    if (auto logId = _repo.getLogID(id); !logId.has_value())
+    {
+        throw common_error::InvalidArgument();
+    }
+    else
+    {
+        return logId->pelID.id;
+    }
+}
+
 } // namespace pels
 } // namespace openpower
diff --git a/extensions/openpower-pels/manager.hpp b/extensions/openpower-pels/manager.hpp
index b2224cf..42aae88 100644
--- a/extensions/openpower-pels/manager.hpp
+++ b/extensions/openpower-pels/manager.hpp
@@ -218,6 +218,19 @@
      */
     std::string getEventId(const openpower::pels::PEL& pel) const;
 
+    /** @brief Implementation for GetPELIdFromBMCLogId
+     *
+     *  Returns the PEL Id (aka Entry ID (EID)) based on the given
+     *  BMC event log id.
+     *
+     *  @param[in] bmcLogId - The BMC event log id of the PEL to retrieve
+     *                        the PEL id.
+     *
+     *  @return uint32_t - The Id of the PEL.
+     *                     Throw "InvalidArgument" if not found.
+     */
+    uint32_t getPELIdFromBMCLogId(uint32_t bmcLogId) override;
+
   private:
     /**
      * @brief Adds a received raw PEL to the PEL repository
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index cd940ff..7c9c3ae 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -453,6 +453,12 @@
         sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
 
     fs::remove_all(pelFilename.parent_path());
+
+    // GetPELIdFromBMCLogId
+    EXPECT_EQ(pel.id(), manager.getPELIdFromBMCLogId(pel.obmcLogID()));
+    EXPECT_THROW(
+        manager.getPELIdFromBMCLogId(pel.obmcLogID() + 1),
+        sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
 }
 
 // An ESEL from the wild