13#ifndef RTCTK_REUSABLECOMPONENT_DEPLOYMENT_DAEMON_LIFE_CYCLE_HPP
14#define RTCTK_REUSABLECOMPONENT_DEPLOYMENT_DAEMON_LIFE_CYCLE_HPP
33using namespace rtctk::componentFramework;
52 : rtctkif::DeploymentException(
"Request aborted.",
ERROR_CODE) {
64 NoDeployment(
const std::string& request_id,
const std::string& state_id)
65 : rtctkif::DeploymentException(
"No active deployment. (Request " + request_id +
66 " rejected in state " + state_id +
")",
80 : rtctkif::DeploymentException(
"Active deployment already exists. (Request " + request_id +
81 " rejected in state " + state_id +
")",
97 : rtctkif::DeploymentException(
98 "Request " + request_id +
" rejected in state " + state_id +
")",
ERROR_CODE) {
113 : rtctkif::DeploymentException(message,
ERROR_CODE) {
155 m_engine.RegisterExitEvent(std::make_unique<deployment_daemon_events::Exit>());
191 m_engine.PostEvent(std::make_unique<deployment_daemon_events::Done>());
195 m_engine.PostEvent(std::make_unique<deployment_daemon_events::Error>(eptr));
199 "ActionDeployEntry", [
this](
const auto& ev) {
205 "ActionDeployDone", [
this](
const auto&) {
211 "ActionDeployFailed", [
this](
const auto& ev) {
212 const auto& eptr = ev.GetPayload();
220 "ActionUndeployEntry", [
this](
const auto& ev) {
226 "ActionUndeployDone", [
this](
const auto&) {
233 "ActionUndeployFailed", [
this](
const auto& ev) {
234 const auto& eptr = ev.GetPayload();
254 "ActivityUndeploying",
278 if (req ==
nullptr) {
290 if (req ==
nullptr) {
294 req->SetReplyValue(
m_engine.GetState());
301 if (req ==
nullptr) {
305 auto loginfo = req->GetRequestPayload();
306 auto selected_logger = loginfo->getLogger();
307 auto& logger =
GetLogger(selected_logger);
308 log4cplus::LogLevelManager llm;
309 auto selected_ll = llm.fromString(loginfo->getLevel());
310 if (selected_ll == log4cplus::NOT_SET_LOG_LEVEL) {
313 logger.setLogLevel(selected_ll);
315 "Log Level of logger '" << loginfo->getLogger() <<
"' set to '"
316 << llm.toString(logger.getLogLevel())
322 engine.
RegisterAction(
"ActionGetActiveDeployment", [
this](
auto c) {
324 if (req ==
nullptr) {
334 if (req ==
nullptr) {
338 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetDescription());
343 if (req ==
nullptr) {
347 std::string arg = req->GetRequestPayload();
351 }
catch (
const std::exception& eptr) {
352 req->SetException(rtctkif::DeploymentException(
353 "ActionStartComponent failed: " + std::string(eptr.what()), 601));
359 if (req ==
nullptr) {
363 std::string arg = req->GetRequestPayload();
367 }
catch (
const std::exception& eptr) {
368 req->SetException(rtctkif::DeploymentException(
369 "ActionStopComponent failed: " + std::string(eptr.what()), 602));
375 if (req ==
nullptr) {
385 if (req ==
nullptr) {
389 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetComponents());
392 engine.
RegisterAction(
"ActionGetActiveComponents", [
this](
auto c) {
394 if (req ==
nullptr) {
404 if (req ==
nullptr) {
413 if (req ==
nullptr) {
449 mm.AddState(
Initial,
"On::Initial",
"On");
450 mm.AddState(
Simple,
"On::Starting",
"On",
"ActivityStarting",
"ActionStartingEntry");
451 mm.AddState(
Simple,
"On::NotDeployed",
"On");
452 mm.AddState(
Simple,
"On::Deployed",
"On");
453 mm.AddState(
Simple,
"On::Deploying",
"On",
"ActivityDeploying",
"ActionDeployEntry");
454 mm.AddState(
Simple,
"On::Undeploying",
"On",
"ActivityUndeploying",
"ActionUndeployEntry");
456 mm.AddTrans(
"Initial",
"On");
457 mm.AddTrans(
"On",
"Off",
"deployment_daemon_events.Exit",
"",
"ActionExit");
458 mm.AddTrans(
"On",
"On",
"deployment_daemon_events.Reset");
459 mm.AddTrans(
"On",
"",
"deployment_daemon_events.GetState",
"",
"ActionGetState");
460 mm.AddTrans(
"On",
"",
"deployment_daemon_events.SetLogLevel",
"",
"ActionSetLogLevel");
462 mm.AddTrans(
"On::Initial",
"On::Starting");
463 mm.AddTrans(
"On::Starting",
"On::NotDeployed",
"deployment_daemon_events.Done",
"",
"ActionStartingDone");
464 mm.AddTrans(
"On::NotDeployed",
"On::Deploying",
"deployment_daemon_events.Deploy",
"",
"");
465 mm.AddTrans(
"On::Deploying",
"On::Deployed",
"deployment_daemon_events.Done",
"",
"ActionDeployDone");
466 mm.AddTrans(
"On::Deploying",
"On::NotDeployed",
"deployment_daemon_events.Error",
"",
"ActionDeployFailed");
467 mm.AddTrans(
"On::Deployed",
"On::Undeploying",
"deployment_daemon_events.Undeploy",
"",
"");
468 mm.AddTrans(
"On::Undeploying",
"On::NotDeployed",
"deployment_daemon_events.Done",
"",
"ActionUndeployDone");
469 mm.AddTrans(
"On::Undeploying",
"On::NotDeployed",
"deployment_daemon_events.Error",
"",
"ActionUndeployFailed");
471 mm.AddTrans(
"On",
"",
"deployment_daemon_events.GetDeploymentSets",
"",
"ActionGetDeploymentSets");
472 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveDeployment",
"",
"ActionGetActiveDeployment");
473 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetDescription",
"",
"ActionGetDescription");
474 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetComponents",
"",
"ActionGetComponents");
475 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveComponents",
"",
"ActionGetActiveComponents");
476 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.StartComponent",
"",
"ActionStartComponent");
477 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.StopComponent",
"",
"ActionStopComponent");
478 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetServices",
"",
"ActionGetServices");
479 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveServices",
"",
"ActionGetActiveServices");
Class that handles reception of commands using MAL.
Definition commandReplier.hpp:30
ModelBuilderBase(StateMachineEngine &engine)
Definition modelBuilderBase.hpp:37
ModelManipulator mm
Definition modelBuilderBase.hpp:79
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition exceptions.hpp:161
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition exceptions.hpp:179
Definition stateMachineEngine.hpp:35
void RegisterAction(const std::string &id, ActionMethod action)
Register action.
Definition stateMachineEngine.cpp:86
void RegisterRejectHandler(const std::string &id, RejectMethod reject)
Register reject handler.
Definition stateMachineEngine.cpp:129
void RegisterActivity(const std::string &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition stateMachineEngine.cpp:121
void RegisterActionStatic(const std::string &id, std::function< void(const Event &)> action)
Register action for statically known event type.
Definition stateMachineEngine.hpp:93
Thrown if the command is not allowed because there is already deployment (= in Deployment State)
Definition deploymentDaemonLifeCycle.hpp:76
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:78
DeploymentAlreadyExists(const std::string &request_id, const std::string &state_id)
Definition deploymentDaemonLifeCycle.hpp:79
static void Register(cfw::CommandReplier &replier, cfw::StateMachineEngine &engine)
Definition deploymentDaemonCmdsImpl.hpp:38
Definition deploymentDaemonLifeCycle.hpp:123
virtual void ActivityStarting(cfw::StopToken st)=0
virtual void ActivityDeploying(cfw::StopToken st, std::string args)=0
virtual std::string ActionGetDescription()=0
virtual void ActionStopComponent(std::string args)=0
virtual std::vector< std::string > ActionGetDeploymentSets()=0
virtual std::string ActionGetActiveDeployment()=0
virtual std::vector< std::string > ActionGetActiveServices()=0
virtual void ActivityUndeploying(cfw::StopToken st)=0
virtual std::vector< std::string > ActionGetServices()=0
virtual std::vector< std::string > ActionGetActiveComponents()=0
virtual std::vector< std::string > ActionGetComponents()=0
virtual void ActionStartComponent(std::string args)=0
ModelBuilder(StateMachineEngine &engine)
Definition deploymentDaemonLifeCycle.hpp:444
std::function< void()> m_custom_success_handler
Definition deploymentDaemonLifeCycle.hpp:438
std::optional< rad::cii::Request< std::string > > m_tmp_undeploy_request
Definition deploymentDaemonLifeCycle.hpp:434
std::optional< rad::cii::Request< std::string, std::string > > m_tmp_deploy_request
Definition deploymentDaemonLifeCycle.hpp:435
std::shared_ptr< rad::cii::Request< std::string, void > > m_tmp_request
Definition deploymentDaemonLifeCycle.hpp:437
virtual ~OutputStage()=default
std::function< void(std::exception_ptr)> m_custom_error_handler
Definition deploymentDaemonLifeCycle.hpp:439
StateMachineEngine & m_engine
Definition deploymentDaemonLifeCycle.hpp:432
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition deploymentDaemonLifeCycle.hpp:167
BizLogicIf & m_logic
Definition deploymentDaemonLifeCycle.hpp:433
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:50
DeploymentDaemonRequestAborted()
Definition deploymentDaemonLifeCycle.hpp:51
Thrown if the command was accepted but the task to run failed.
Definition deploymentDaemonLifeCycle.hpp:106
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:111
DeploymentDaemonRequestFailed(const std::string &message)
Definition deploymentDaemonLifeCycle.hpp:112
Thrown if the command is not allowed in current state.
Definition deploymentDaemonLifeCycle.hpp:90
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:95
DeploymentDaemonRequestRejected(const std::string &request_id, const std::string &state_id)
Definition deploymentDaemonLifeCycle.hpp:96
Thrown if the command is not allowed because there is no deployment (=not in Deployment State)
Definition deploymentDaemonLifeCycle.hpp:61
NoDeployment(const std::string &request_id, const std::string &state_id)
Definition deploymentDaemonLifeCycle.hpp:64
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:63
Receive commands via MAL.
Implementation of MAL commands for layer 'DeploymentDaemonComponent'.
Provides macros and utilities for exception handling.
Logging Support Library based on log4cplus.
Base class of the ModelBuilder.
@ Simple
Definition model.hpp:23
@ Composite
Definition model.hpp:23
@ Final
Definition model.hpp:23
@ Initial
Definition model.hpp:23
rad::StopToken StopToken
Definition stopToken.hpp:20
std::shared_ptr< typename EVENT::payload_t > GetPayloadNothrow(scxml4cpp::Context *c)
Definition stateMachineEngine.hpp:256
const std::string STD_OK_REPLY
Definition stdComponent.hpp:86
log4cplus::Logger & GetLogger(const std::string &name="app")
Get handle to a specific logger.
Definition logger.cpp:192
Definition deploymentDaemonBusinessLogic.cpp:35
A container that can hold any type of service.
Wrapper around the SCXML State Machine Engine.
Life cycle for DeploymentDaemonComponent.
Definition deploymentDaemonLifeCycle.hpp:122