Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDKVREFPLT-1727 - [BCM][Memcr][RDKVREL-279] OCIContainer support #5362

Merged
merged 10 commits into from
Jun 14, 2024
4 changes: 4 additions & 0 deletions OCIContainer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(PLUGIN_NAME OCIContainer)
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})

set(PLUGIN_OCICONTAINER_STARTUPORDER "" CACHE STRING "To configure startup order of OCIContainer plugin")
option(PLUGIN_HIBERNATESUPPORT "Include hibernate support in the build." OFF)

find_package(PkgConfig)
find_package(${NAMESPACE}Plugins REQUIRED)
Expand Down Expand Up @@ -45,6 +46,9 @@ find_package_handle_standard_args(
SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS
)

if(PLUGIN_HIBERNATESUPPORT)
target_compile_definitions(${MODULE_NAME} PRIVATE HIBERNATE_SUPPORT_ENABLED=1)
endif()

target_include_directories(${MODULE_NAME}
PRIVATE
Expand Down
121 changes: 121 additions & 0 deletions OCIContainer/OCIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ uint32_t OCIContainer::getContainerState(const JsonObject &parameters, JsonObjec
case IDobbyProxyEvents::ContainerState::Stopped:
containerState = "Stopped";
break;
#ifdef HIBERNATE_SUPPORT_ENABLED
case IDobbyProxyEvents::ContainerState::Hibernating:
containerState = "Hibernating";
break;
case IDobbyProxyEvents::ContainerState::Hibernated:
containerState = "Hibernated";
break;
case IDobbyProxyEvents::ContainerState::Awakening:
containerState = "Awakening";
break;
#endif
default:
containerState = "Unknown";
break;
Expand Down Expand Up @@ -529,6 +540,76 @@ uint32_t OCIContainer::resumeContainer(const JsonObject &parameters, JsonObject
returnResponse(true);
}

#ifdef HIBERNATE_SUPPORT_ENABLED
/**
* @brief Hibernate a container
*
* @param[in] parameters Must include 'containerId' of container to resume.
* @param[out] response Success.
*
* @return A code indicating success.
*/
uint32_t OCIContainer::hibernateContainer(const JsonObject &parameters, JsonObject &response)
{
LOGINFO("Hibernate container");

// Need to have an ID to hibernate
returnIfStringParamNotFound(parameters, "containerId");
std::string id = parameters["containerId"].String();
std::string options;

int cd = GetContainerDescriptorFromId(id);
if (cd < 0)
{
returnResponse(false);
}

bool offloadSuccessfully = mDobbyProxy->hibernateContainer(cd,options);

if (!offloadSuccessfully)
{
LOGERR("Failed to Hibernate container - internal Dobby error.");
returnResponse(false);
}

returnResponse(true);

}
/**
* @brief Wakeup a container
*
* @param[in] parameters Must include 'containerId' of container to resume.
* @param[out] response Success.
*
* @return A code indicating success.
*/
uint32_t OCIContainer::wakeupContainer(const JsonObject &parameters, JsonObject &response)
{
LOGINFO("Wakeup Container");

// Need to have an ID to wakeup
returnIfStringParamNotFound(parameters, "containerId");
std::string id = parameters["containerId"].String();

int cd = GetContainerDescriptorFromId(id);
if (cd < 0)
{
returnResponse(false);
}

bool wokeSuccessfully = mDobbyProxy->wakeupContainer(cd);

if (!wokeSuccessfully)
{
LOGERR("Failed to Wake up container - internal Dobby error.");
returnResponse(false);
}

returnResponse(true);

}
#endif

/**
* @brief Execute a command in a container.
*
Expand Down Expand Up @@ -568,6 +649,36 @@ uint32_t OCIContainer::executeCommand(const JsonObject &parameters, JsonObject &
returnResponse(true);
}

#ifdef HIBERNATE_SUPPORT_ENABLED
/**
* @brief Send an event notifying that a container has hibernated.
*
* @param descriptor Container descriptor.
* @param name Container name.
*/
void OCIContainer::onContainerHibernated(int32_t descriptor, const std::string& name)
{
JsonObject params;
params["descriptor"] = std::to_string(descriptor);
params["name"] = name;
sendNotify("onContainerHibernated", params);
}

/**
* @brief Send an event notifying that a container has Awoken.
*
* @param descriptor Container descriptor.
* @param name Container name.
*/
void OCIContainer::onContainerAwoken(int32_t descriptor, const std::string& name)
{
JsonObject params;
params["descriptor"] = std::to_string(descriptor);
params["name"] = name;
sendNotify("onContainerAwoken", params);
}
#endif


/**
* @brief Send an event notifying that a container has started.
Expand Down Expand Up @@ -666,6 +777,16 @@ const void OCIContainer::stateListener(int32_t descriptor, const std::string& na
{
__this->onContainerStopped(descriptor, name);
}
#ifdef HIBERNATE_SUPPORT_ENABLED
else if (state == IDobbyProxyEvents::ContainerState::Hibernated)
{
__this->onContainerHibernated(descriptor, name);
DineshkumarJP marked this conversation as resolved.
Show resolved Hide resolved
}
else if (state == IDobbyProxyEvents::ContainerState::Awakening)
{
__this->onContainerAwoken(descriptor, name);
}
#endif
else
{
LOGINFO("Received an unknown state event for container '%s'.", name.c_str());
Expand Down
8 changes: 8 additions & 0 deletions OCIContainer/OCIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ class OCIContainer : public PluginHost::IPlugin, public PluginHost::JSONRPC
uint32_t pauseContainer(const JsonObject &parameters, JsonObject &response);
uint32_t resumeContainer(const JsonObject &parameters, JsonObject &response);
uint32_t executeCommand(const JsonObject &parameters, JsonObject &response);
#ifdef HIBERNATE_SUPPORT_ENABLED
uint32_t hibernateContainer(const JsonObject &parameters, JsonObject &response);
uint32_t wakeupContainer(const JsonObject &parameters, JsonObject &response);
#endif
//End methods

//Begin events
void onContainerStarted(int32_t descriptor, const std::string& name);
void onContainerStopped(int32_t descriptor, const std::string& name);
void onVerityFailed(const std::string& name);
#ifdef HIBERNATE_SUPPORT_ENABLED
void onContainerHibernated(int32_t descriptor, const std::string& name);
void onContainerAwoken(int32_t descriptor, const std::string& name);
#endif
//End events

//Build QueryInterface implementation, specifying all possible interfaces to be returned.
Expand Down
Loading