13#ifndef RTCTK_REUSABLECOMPONENT_DEPLOYMENT_DAEMON_LIFE_CYCLE_HPP
14#define RTCTK_REUSABLECOMPONENT_DEPLOYMENT_DAEMON_LIFE_CYCLE_HPP
52 : rtctkif::DeploymentException(
"Request aborted.",
ERROR_CODE) {
64 NoDeployment(std::string
const& request_id, std::string
const& state_id)
65 : rtctkif::DeploymentException(
66 "No active deployment. (Request " + request_id +
" rejected in state " + state_id,
80 : rtctkif::DeploymentException(
"Active deployment already exists. (Request " + request_id +
81 " rejected in state " + state_id,
97 : rtctkif::DeploymentException(
"Request " + request_id +
" rejected in state " + state_id,
113 : rtctkif::DeploymentException(message,
ERROR_CODE) {
193 "ActionDeployEntry", [
this](
auto const& ev) {
199 "ActionDeployDone", [
this](
auto const&) {
205 "ActionDeployFailed", [
this](
auto const& ev) {
206 auto const& eptr = ev.GetPayload();
214 "ActionUndeployEntry", [
this](
auto const& ev) {
220 "ActionUndeployDone", [
this](
auto const&) {
227 "ActionUndeployFailed", [
this](
auto const& ev) {
228 auto const& eptr = ev.GetPayload();
248 "ActivityUndeploying",
258 m_tmp_request = GetPayloadNothrow<deployment_daemon_events::Reset>(c);
271 auto req = GetPayloadNothrow<deployment_daemon_events::Exit>(c);
272 if (req ==
nullptr) {
283 auto req = GetPayloadNothrow<deployment_daemon_events::GetState>(c);
284 if (req ==
nullptr) {
294 auto req = GetPayloadNothrow<deployment_daemon_events::SetLogLevel>(c);
295 if (req ==
nullptr) {
299 auto loginfo = req->GetRequestPayload();
300 auto selected_logger = loginfo->getLogger();
301 auto& logger =
GetLogger(selected_logger);
302 log4cplus::LogLevelManager llm;
303 auto selected_ll = llm.fromString(loginfo->getLevel());
304 if (selected_ll == log4cplus::NOT_SET_LOG_LEVEL) {
307 logger.setLogLevel(selected_ll);
309 "Log Level of logger '" << loginfo->getLogger() <<
"' set to '"
310 << llm.toString(logger.getLogLevel())
316 engine.
RegisterAction(
"ActionGetActiveDeployment", [
this](
auto c) {
317 auto req = GetPayloadNothrow<deployment_daemon_events::GetActiveDeployment>(c);
318 if (req ==
nullptr) {
327 auto req = GetPayloadNothrow<deployment_daemon_events::GetDescription>(c);
328 if (req ==
nullptr) {
332 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetDescription());
336 auto req = GetPayloadNothrow<deployment_daemon_events::StartComponent>(c);
337 if (req ==
nullptr) {
341 std::string arg = req->GetRequestPayload();
345 }
catch (
const std::exception& eptr) {
346 req->SetException(rtctkif::DeploymentException(
347 "ActionStartComponent failed: " + std::string(eptr.what()), 601));
352 auto req = GetPayloadNothrow<deployment_daemon_events::StopComponent>(c);
353 if (req ==
nullptr) {
357 std::string arg = req->GetRequestPayload();
361 }
catch (
const std::exception& eptr) {
362 req->SetException(rtctkif::DeploymentException(
363 "ActionStopComponent failed: " + std::string(eptr.what()), 602));
368 auto req = GetPayloadNothrow<deployment_daemon_events::GetDeploymentSets>(c);
369 if (req ==
nullptr) {
378 auto req = GetPayloadNothrow<deployment_daemon_events::GetComponents>(c);
379 if (req ==
nullptr) {
383 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetComponents());
386 engine.
RegisterAction(
"ActionGetActiveComponents", [
this](
auto c) {
387 auto req = GetPayloadNothrow<deployment_daemon_events::GetActiveComponents>(c);
388 if (req ==
nullptr) {
426 mm.
AddState(
Simple,
"On::Starting",
"On",
"ActivityStarting",
"ActionStartingEntry");
429 mm.
AddState(
Simple,
"On::Deploying",
"On",
"ActivityDeploying",
"ActionDeployEntry");
430 mm.
AddState(
Simple,
"On::Undeploying",
"On",
"ActivityUndeploying",
"ActionUndeployEntry");
433 mm.
AddTrans(
"On",
"Off",
"deployment_daemon_events.Exit",
"",
"ActionExit");
434 mm.
AddTrans(
"On",
"On",
"deployment_daemon_events.Reset");
435 mm.
AddTrans(
"On",
"",
"deployment_daemon_events.GetState",
"",
"ActionGetState");
436 mm.
AddTrans(
"On",
"",
"deployment_daemon_events.SetLogLevel",
"",
"ActionSetLogLevel");
439 mm.
AddTrans(
"On::Starting",
"On::NotDeployed",
"deployment_daemon_events.Done",
"",
"ActionStartingDone");
440 mm.
AddTrans(
"On::NotDeployed",
"On::Deploying",
"deployment_daemon_events.Deploy",
"",
"");
441 mm.
AddTrans(
"On::Deploying",
"On::Deployed",
"deployment_daemon_events.Done",
"",
"ActionDeployDone");
442 mm.
AddTrans(
"On::Deploying",
"On::NotDeployed",
"deployment_daemon_events.Error",
"",
"ActionDeployFailed");
443 mm.
AddTrans(
"On::Deployed",
"On::Undeploying",
"deployment_daemon_events.Undeploy",
"",
"");
444 mm.
AddTrans(
"On::Undeploying",
"On::NotDeployed",
"deployment_daemon_events.Done",
"",
"ActionUndeployDone");
445 mm.
AddTrans(
"On::Undeploying",
"On::NotDeployed",
"deployment_daemon_events.Error",
"",
"ActionUndeployFailed");
447 mm.
AddTrans(
"On",
"",
"deployment_daemon_events.GetDeploymentSets",
"",
"ActionGetDeploymentSets");
448 mm.
AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveDeployment",
"",
"ActionGetActiveDeployment");
449 mm.
AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetDescription",
"",
"ActionGetDescription");
450 mm.
AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetComponents",
"",
"ActionGetComponents");
451 mm.
AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.GetActiveComponents",
"",
"ActionGetActiveComponents");
452 mm.
AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.StartComponent",
"",
"ActionStartComponent");
453 mm.
AddTrans(
"On::Deployed",
"",
"deployment_daemon_events.StopComponent",
"",
"ActionStopComponent");
Class that handles reception of commands using MAL.
Definition: commandReplier.hpp:29
Base class of the ModelBuilder.
Definition: modelBuilderBase.hpp:35
ModelManipulator mm
Definition: modelBuilderBase.hpp:79
void AddTrans(std::string const &source_id, std::string const &target_id, std::string const &event_id="", std::string const &guard_id="", std::string const &action_id="")
Adds a new transition.
Definition: modelManipulator.cpp:229
void AddState(StateType type, std::string const &id, std::string const &parent_id="", std::string const &activity_id="", std::string const &entry_action_id="", std::string const &exit_action_id="")
Adds a new state.
Definition: modelManipulator.cpp:30
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition: exceptions.hpp:185
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition: exceptions.hpp:203
Definition: stateMachineEngine.hpp:35
void RegisterRejectHandler(std::string const &id, RejectMethod reject)
Register reject handler.
Definition: stateMachineEngine.cpp:131
void RegisterActivity(std::string const &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition: stateMachineEngine.cpp:123
void RegisterExitEvent(rad::UniqueEvent exit_event)
Register an exit event.
Definition: stateMachineEngine.cpp:69
std::string GetState()
Queries the current state.
Definition: stateMachineEngine.cpp:153
void RegisterAction(std::string const &id, ActionMethod action)
Register action.
Definition: stateMachineEngine.cpp:86
void RegisterActionStatic(std::string const &id, std::function< void(Event const &)> action)
Register action for statically known event type.
Definition: stateMachineEngine.hpp:93
void Stop()
Stops execution of the state machine event loop.
Definition: stateMachineEngine.cpp:191
void PostEvent(rad::SharedEvent s)
Injects a new event into the state machine engine.
Definition: stateMachineEngine.cpp:148
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(std::string const &request_id, std::string const &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 void ActivityUndeploying(cfw::StopToken st)=0
virtual std::vector< std::string > ActionGetActiveComponents()=0
virtual std::vector< std::string > ActionGetComponents()=0
virtual void ActionStartComponent(std::string args)=0
Definition: deploymentDaemonLifeCycle.hpp:418
ModelBuilder(StateMachineEngine &engine)
Definition: deploymentDaemonLifeCycle.hpp:420
Definition: deploymentDaemonLifeCycle.hpp:162
std::function< void()> m_custom_success_handler
Definition: deploymentDaemonLifeCycle.hpp:414
std::optional< rad::cii::Request< std::string > > m_tmp_undeploy_request
Definition: deploymentDaemonLifeCycle.hpp:410
std::optional< rad::cii::Request< std::string, std::string > > m_tmp_deploy_request
Definition: deploymentDaemonLifeCycle.hpp:411
std::shared_ptr< rad::cii::Request< std::string, void > > m_tmp_request
Definition: deploymentDaemonLifeCycle.hpp:413
virtual ~OutputStage()=default
std::function< void(std::exception_ptr)> m_custom_error_handler
Definition: deploymentDaemonLifeCycle.hpp:415
StateMachineEngine & m_engine
Definition: deploymentDaemonLifeCycle.hpp:408
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition: deploymentDaemonLifeCycle.hpp:164
BizLogicIf & m_logic
Definition: deploymentDaemonLifeCycle.hpp:409
Thrown if somebody sent a stop or abort command.
Definition: deploymentDaemonLifeCycle.hpp:48
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
DeploymentDaemonRequestFailed(std::string const &message)
Definition: deploymentDaemonLifeCycle.hpp:112
static constexpr int32_t ERROR_CODE
Definition: deploymentDaemonLifeCycle.hpp:111
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(std::string const &request_id, std::string const &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
static constexpr int32_t ERROR_CODE
Definition: deploymentDaemonLifeCycle.hpp:63
NoDeployment(std::string const &request_id, std::string const &state_id)
Definition: deploymentDaemonLifeCycle.hpp:64
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.
Definition: commandReplier.cpp:22
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:180
rad::StopToken StopToken
Definition: stopToken.hpp:20
@ Simple
Definition: model.hpp:22
@ Composite
Definition: model.hpp:22
@ Final
Definition: model.hpp:22
@ Initial
Definition: model.hpp:22
Definition: deploymentDaemonBusinessLogic.cpp:30
A container that can hold any type of service.
Wrapper around the SCXML State Machine Engine.
Life cycle for DeploymentDaemonComponent.
Definition: deploymentDaemonLifeCycle.hpp:122