12#ifndef RTCTK_REUSABLECOMPONENT_DEPLOYMENT_DAEMON_LIFE_CYCLE_HPP
13#define RTCTK_REUSABLECOMPONENT_DEPLOYMENT_DAEMON_LIFE_CYCLE_HPP
32using namespace rtctk::componentFramework;
51 : rtctkif::DeploymentException(
"Request aborted.",
ERROR_CODE) {
63 NoDeployment(
const std::string& request_id,
const std::string& state_id)
64 : rtctkif::DeploymentException(
"No active deployment. (Request " + request_id +
65 " rejected in state " + state_id +
")",
79 : rtctkif::DeploymentException(
"Active deployment already exists. (Request " + request_id +
80 " rejected in state " + state_id +
")",
96 : rtctkif::DeploymentException(
97 "Request " + request_id +
" rejected in state " + state_id +
")",
ERROR_CODE) {
112 : rtctkif::DeploymentException(message,
ERROR_CODE) {
154 m_engine.RegisterExitEvent(std::make_unique<deployment_daemon_events::Exit>());
190 m_engine.PostEvent(std::make_unique<deployment_daemon_events::Done>());
194 m_engine.PostEvent(std::make_unique<deployment_daemon_events::Error>(eptr));
198 "ActionDeployEntry", [
this](
const auto& ev) {
204 "ActionDeployDone", [
this](
const auto&) {
210 "ActionDeployFailed", [
this](
const auto& ev) {
211 const auto& eptr = ev.GetPayload();
219 "ActionUndeployEntry", [
this](
const auto& ev) {
225 "ActionUndeployDone", [
this](
const auto&) {
232 "ActionUndeployFailed", [
this](
const auto& ev) {
233 const auto& eptr = ev.GetPayload();
253 "ActivityUndeploying",
277 if (req ==
nullptr) {
289 if (req ==
nullptr) {
293 req->SetReplyValue(
m_engine.GetState());
300 if (req ==
nullptr) {
304 auto loginfo = req->GetRequestPayload();
305 auto selected_logger = loginfo->getLogger();
306 auto& logger =
GetLogger(selected_logger);
307 log4cplus::LogLevelManager llm;
308 auto selected_ll = llm.fromString(loginfo->getLevel());
309 if (selected_ll == log4cplus::NOT_SET_LOG_LEVEL) {
312 logger.setLogLevel(selected_ll);
314 "Log Level of logger '" << loginfo->getLogger() <<
"' set to '"
315 << llm.toString(logger.getLogLevel())
321 engine.
RegisterAction(
"ActionGetActiveDeployment", [
this](
auto c) {
323 if (req ==
nullptr) {
333 if (req ==
nullptr) {
337 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetDescription());
342 if (req ==
nullptr) {
346 std::string arg = req->GetRequestPayload();
350 }
catch (
const std::exception& eptr) {
351 req->SetException(rtctkif::DeploymentException(
352 "ActionStartComponent failed: " + std::string(eptr.what()), 601));
358 if (req ==
nullptr) {
362 std::string arg = req->GetRequestPayload();
366 }
catch (
const std::exception& eptr) {
367 req->SetException(rtctkif::DeploymentException(
368 "ActionStopComponent failed: " + std::string(eptr.what()), 602));
374 if (req ==
nullptr) {
384 if (req ==
nullptr) {
388 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetComponents());
391 engine.
RegisterAction(
"ActionGetActiveComponents", [
this](
auto c) {
393 if (req ==
nullptr) {
403 if (req ==
nullptr) {
412 if (req ==
nullptr) {
448 mm.AddState(
Initial,
"On::Initial",
"On");
449 mm.AddState(
Simple,
"On::Starting",
"On",
"ActivityStarting",
"ActionStartingEntry");
450 mm.AddState(
Simple,
"On::NotDeployed",
"On");
451 mm.AddState(
Simple,
"On::Deployed",
"On");
452 mm.AddState(
Simple,
"On::Deploying",
"On",
"ActivityDeploying",
"ActionDeployEntry");
453 mm.AddState(
Simple,
"On::Undeploying",
"On",
"ActivityUndeploying",
"ActionUndeployEntry");
455 mm.AddTrans(
"Initial",
"On");
456 mm.AddTrans(
"On",
"Off",
"deployment_daemon_events.Exit",
"",
"ActionExit");
457 mm.AddTrans(
"On",
"On",
"deployment_daemon_events.Reset");
458 mm.AddTrans(
"On",
"",
"deployment_daemon_events.GetState",
"",
"ActionGetState");
459 mm.AddTrans(
"On",
"",
"deployment_daemon_events.SetLogLevel",
"",
"ActionSetLogLevel");
461 mm.AddTrans(
"On::Initial",
"On::Starting");
462 mm.AddTrans(
"On::Starting",
"On::NotDeployed",
"deployment_daemon_events.Done",
"",
"ActionStartingDone");
463 mm.AddTrans(
"On::NotDeployed",
"On::Deploying",
"deployment_daemon_events.Deploy",
"",
"");
464 mm.AddTrans(
"On::Deploying",
"On::Deployed",
"deployment_daemon_events.Done",
"",
"ActionDeployDone");
465 mm.AddTrans(
"On::Deploying",
"On::NotDeployed",
"deployment_daemon_events.Error",
"",
"ActionDeployFailed");
466 mm.AddTrans(
"On::Deployed",
"On::Undeploying",
"deployment_daemon_events.Undeploy",
"",
"");
467 mm.AddTrans(
"On::Undeploying",
"On::NotDeployed",
"deployment_daemon_events.Done",
"",
"ActionUndeployDone");
468 mm.AddTrans(
"On::Undeploying",
"On::NotDeployed",
"deployment_daemon_events.Error",
"",
"ActionUndeployFailed");
470 mm.AddTrans(
"On",
"",
"deployment_daemon_events.GetDeploymentSets",
"",
"ActionGetDeploymentSets");
471 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveDeployment",
"",
"ActionGetActiveDeployment");
472 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetDescription",
"",
"ActionGetDescription");
473 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetComponents",
"",
"ActionGetComponents");
474 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveComponents",
"",
"ActionGetActiveComponents");
475 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.StartComponent",
"",
"ActionStartComponent");
476 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.StopComponent",
"",
"ActionStopComponent");
477 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetServices",
"",
"ActionGetServices");
478 mm.AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveServices",
"",
"ActionGetActiveServices");
Class that handles reception of commands using MAL.
Definition commandReplier.hpp:29
ModelBuilderBase(StateMachineEngine &engine)
Definition modelBuilderBase.hpp:36
ModelManipulator mm
Definition modelBuilderBase.hpp:78
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition exceptions.hpp:168
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition exceptions.hpp:186
Definition stateMachineEngine.hpp:34
void RegisterAction(const std::string &id, ActionMethod action)
Register action.
Definition stateMachineEngine.cpp:85
void RegisterRejectHandler(const std::string &id, RejectMethod reject)
Register reject handler.
Definition stateMachineEngine.cpp:128
void RegisterActivity(const std::string &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition stateMachineEngine.cpp:120
void RegisterActionStatic(const std::string &id, std::function< void(const Event &)> action)
Register action for statically known event type.
Definition stateMachineEngine.hpp:92
Thrown if the command is not allowed because there is already deployment (= in Deployment State)
Definition deploymentDaemonLifeCycle.hpp:75
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:77
DeploymentAlreadyExists(const std::string &request_id, const std::string &state_id)
Definition deploymentDaemonLifeCycle.hpp:78
static void Register(cfw::CommandReplier &replier, cfw::StateMachineEngine &engine)
Definition deploymentDaemonCmdsImpl.hpp:37
Definition deploymentDaemonLifeCycle.hpp:122
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:443
std::function< void()> m_custom_success_handler
Definition deploymentDaemonLifeCycle.hpp:437
std::optional< rad::cii::Request< std::string > > m_tmp_undeploy_request
Definition deploymentDaemonLifeCycle.hpp:433
std::optional< rad::cii::Request< std::string, std::string > > m_tmp_deploy_request
Definition deploymentDaemonLifeCycle.hpp:434
std::shared_ptr< rad::cii::Request< std::string, void > > m_tmp_request
Definition deploymentDaemonLifeCycle.hpp:436
virtual ~OutputStage()=default
std::function< void(std::exception_ptr)> m_custom_error_handler
Definition deploymentDaemonLifeCycle.hpp:438
StateMachineEngine & m_engine
Definition deploymentDaemonLifeCycle.hpp:431
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition deploymentDaemonLifeCycle.hpp:166
BizLogicIf & m_logic
Definition deploymentDaemonLifeCycle.hpp:432
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:49
DeploymentDaemonRequestAborted()
Definition deploymentDaemonLifeCycle.hpp:50
Thrown if the command was accepted but the task to run failed.
Definition deploymentDaemonLifeCycle.hpp:105
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:110
DeploymentDaemonRequestFailed(const std::string &message)
Definition deploymentDaemonLifeCycle.hpp:111
Thrown if the command is not allowed in current state.
Definition deploymentDaemonLifeCycle.hpp:89
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:94
DeploymentDaemonRequestRejected(const std::string &request_id, const std::string &state_id)
Definition deploymentDaemonLifeCycle.hpp:95
Thrown if the command is not allowed because there is no deployment (=not in Deployment State)
Definition deploymentDaemonLifeCycle.hpp:60
NoDeployment(const std::string &request_id, const std::string &state_id)
Definition deploymentDaemonLifeCycle.hpp:63
static constexpr int32_t ERROR_CODE
Definition deploymentDaemonLifeCycle.hpp:62
Receive commands via MAL.
Implementation of MAL commands for layer 'DeploymentDaemonComponent'.
Provides macros and utilities for exception handling.
log4cplus::Logger & GetLogger(const std::string &name="app")
Get handle to a specific logger.
Definition logger.cpp:191
Logging Support Library based on log4cplus.
Base class of the ModelBuilder.
@ Simple
Definition model.hpp:22
@ Composite
Definition model.hpp:22
@ Final
Definition model.hpp:22
@ Initial
Definition model.hpp:22
rad::StopToken StopToken
Definition stopToken.hpp:19
std::shared_ptr< typename EVENT::payload_t > GetPayloadNothrow(scxml4cpp::Context *c)
Definition stateMachineEngine.hpp:255
const std::string STD_OK_REPLY
Definition stdComponent.hpp:85
Definition deploymentDaemonBusinessLogic.cpp:34
A container that can hold any type of service.
Wrapper around the SCXML State Machine Engine.
Life cycle for DeploymentDaemonComponent.
Definition deploymentDaemonLifeCycle.hpp:121