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) {
65 : rtctkif::DeploymentException(
80 : rtctkif::DeploymentException(
"Active deployment already exists. (Request " +
request_id +
97 : rtctkif::DeploymentException(
"Request " +
request_id +
" rejected in state " +
state_id,
177 engine.RegisterRejectHandler<deployment_daemon_events::GetActiveDeployment,
NoDeployment>();
178 engine.RegisterRejectHandler<deployment_daemon_events::GetDescription,
NoDeployment>();
179 engine.RegisterRejectHandler<deployment_daemon_events::GetDeploymentSets,
NoDeployment>();
180 engine.RegisterRejectHandler<deployment_daemon_events::GetComponents,
NoDeployment>();
181 engine.RegisterRejectHandler<deployment_daemon_events::GetActiveComponents,
NoDeployment>();
183 engine.RegisterRejectHandler<deployment_daemon_events::StartComponent,
NoDeployment>();
184 engine.RegisterRejectHandler<deployment_daemon_events::StopComponent,
NoDeployment>();
187 engine.RegisterRejectHandler<deployment_daemon_events::GetActiveServices,
NoDeployment>();
198 engine.RegisterActionStatic<deployment_daemon_events::Deploy>(
199 "ActionDeployEntry", [
this](
const auto&
ev) {
204 engine.RegisterActionStatic<deployment_daemon_events::Done>(
205 "ActionDeployDone", [
this](
const auto&) {
210 engine.RegisterActionStatic<deployment_daemon_events::Error>(
211 "ActionDeployFailed", [
this](
const auto&
ev) {
212 const auto&
eptr =
ev.GetPayload();
219 engine.RegisterActionStatic<deployment_daemon_events::Undeploy>(
220 "ActionUndeployEntry", [
this](
const auto&
ev) {
225 engine.RegisterActionStatic<deployment_daemon_events::Done>(
226 "ActionUndeployDone", [
this](
const auto&) {
232 engine.RegisterActionStatic<deployment_daemon_events::Error>(
233 "ActionUndeployFailed", [
this](
const auto&
ev) {
234 const auto&
eptr =
ev.GetPayload();
254 "ActivityUndeploying",
263 engine.RegisterAction(
"ActionStartingEntry", [
this](
auto c) {
267 engine.RegisterAction(
"ActionStartingDone", [
this](
auto c) {
276 engine.RegisterAction(
"ActionExit", [
this](
auto c) {
278 if (req ==
nullptr) {
288 engine.RegisterAction(
"ActionGetState", [
this](
auto c) {
290 if (req ==
nullptr) {
299 engine.RegisterAction(
"ActionSetLogLevel", [
this](
auto c) {
301 if (req ==
nullptr) {
305 auto loginfo = req->GetRequestPayload();
308 log4cplus::LogLevelManager
llm;
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) {
332 engine.RegisterAction(
"ActionGetDescription", [
this](
auto c) {
334 if (req ==
nullptr) {
338 req->SetReplyValue(
static_cast<BizLogicIf&
>(this->
m_logic).ActionGetDescription());
341 engine.RegisterAction(
"ActionStartComponent", [
this](
auto c) {
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));
357 engine.RegisterAction(
"ActionStopComponent", [
this](
auto c) {
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));
373 engine.RegisterAction(
"ActionGetDeploymentSets", [
this](
auto c) {
375 if (req ==
nullptr) {
383 engine.RegisterAction(
"ActionGetComponents", [
this](
auto c) {
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) {
402 engine.RegisterAction(
"ActionGetServices", [
this](
auto c) {
404 if (req ==
nullptr) {
411 engine.RegisterAction(
"ActionGetActiveServices", [
this](
auto c) {
413 if (req ==
nullptr) {
450 mm.
AddState(
Simple,
"On::Starting",
"On",
"ActivityStarting",
"ActionStartingEntry");
453 mm.
AddState(
Simple,
"On::Deploying",
"On",
"ActivityDeploying",
"ActionDeployEntry");
454 mm.
AddState(
Simple,
"On::Undeploying",
"On",
"ActivityUndeploying",
"ActionUndeployEntry");
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");
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
Base class of the ModelBuilder.
Definition modelBuilderBase.hpp:35
ModelManipulator mm
Definition modelBuilderBase.hpp:79
void AddState(StateType type, const std::string &id, const std::string &parent_id="", const std::string &activity_id="", const std::string &entry_action_id="", const std::string &exit_action_id="")
Adds a new state.
Definition modelManipulator.cpp:30
void AddTrans(const std::string &source_id, const std::string &target_id, const std::string &event_id="", const std::string &guard_id="", const std::string &action_id="")
Adds a new transition.
Definition modelManipulator.cpp:229
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition exceptions.hpp:159
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition exceptions.hpp:177
Definition stateMachineEngine.hpp:35
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 Stop()
Stops execution of the state machine event loop.
Definition stateMachineEngine.cpp:191
void RegisterActivity(const std::string &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition stateMachineEngine.cpp:123
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(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
Definition deploymentDaemonLifeCycle.hpp:442
ModelBuilder(StateMachineEngine &engine)
Definition deploymentDaemonLifeCycle.hpp:444
Definition deploymentDaemonLifeCycle.hpp:165
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
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
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.
Definition commandReplier.cpp:22
@ 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
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:193
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition deploymentDaemonBusinessLogic.cpp:33
A container that can hold any type of service.
Wrapper around the SCXML State Machine Engine.
Life cycle for DeploymentDaemonComponent.
Definition deploymentDaemonLifeCycle.hpp:122