Executor.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Nicola Miskowiec
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #pragma once
27 
28 #include "ApplicationStarter.h"
29 #include "../parser/StatusManager.h"
30 #include "../data_structure/ApplicationInstance.h"
31 #include "../data_structure/Scenario.h"
32 #include "StopStrategy.h"
33 #include "ApplicationStarter.h"
34 #include <memory>
35 #include <future>
36 #include <map>
37 
38 namespace ScenarioManager
39 {
40  class StatusManager;
41 }
42 
43 namespace ScenarioManager::Exec
44 {
45  class StopStrategy;
46  using StopStrategyPtr = std::shared_ptr<StopStrategy>;
47 
48  /**
49  * @class Executor
50  * @ingroup exec
51  * @brief Starts, stops and restarts applications and scenarios.
52  * Can also be used to request the status of an application. The proper system-specific stopstrategy and starter have to be set in the constructor.
53  */
54  class Executor
55  {
56 
57  private:
58  StopStrategyPtr defaultStopStrategy;
59  ApplicationStarterPtr defaultStartStrategy;
60  std::map<Data_Structure::ScenarioPtr, StopStrategyPtr> stopStrategy;
61  std::map<Data_Structure::ScenarioPtr, ApplicationStarterPtr> starter;
62  StatusManager statusManager;
63 
64 
65  void asyncApplicationRestart(Data_Structure::ApplicationInstancePtr application, bool printOnly);
66 
67  void asyncScenarioStop(Data_Structure::ScenarioPtr scenario);
68  std::string asyncGetScenarioStatus(Data_Structure::ScenarioPtr scenario);
69  void asyncScenarioRestart(Data_Structure::ScenarioPtr scenario, bool printOnly);
70 
71  public:
72  /**
73  * Constructor that sets StopStrategy and ApplicationStarter.
74  * @param strategy Strategy used to stop applications.
75  * @param starter Starter used to start applications and request their status.
76  */
78 
79  /**
80  * Starts an application.
81  * @param application application to be started.
82  * @return {@code true} if the application was successfully started
83  */
84  std::future<void> startApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly = false, const std::string& commandLineParameters = "");
85  std::future<void> deployApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly = false, const std::string& commandLineParameters = "");
86 
87  /**
88  * Stops an application
89  * @param application application to be stopped
90  * @return {@code true} if the application was successfully stopped
91  */
92  std::future<void> stopApplication(Data_Structure::ApplicationInstancePtr application);
93  std::future<void> removeApplication(Data_Structure::ApplicationInstancePtr application);
94 
95  /**
96  * Restarts an application. Stops and starts an application.
97  * @param application application to be restarted
98  * @return {@code true} if the application was successfully restarted. Successfull restart requires successfull stop and successfull start.
99  * An already stopped application also counts as successfully restarted, if successfully started.
100  */
101  std::future<void> restartApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly = false);
102 
103  /**
104  * Returns the status of an application. Uses the ApplicationStarter to request the status, therefore the proper
105  * system-specific starter has to be set, even to use this method.
106  * @param application application whose status is returned
107  * @return status of the application
108  */
110 
111  /**
112  * Starts a scenario. Iterates over the applications in the scenario and starts them.
113  * @param scenario scenario to be started
114  * @return {@code true} if all applications were successfully started
115  */
116  std::future<void> startScenario(Data_Structure::ScenarioPtr scenario, bool printOnly = false, const std::string& commandLineParameters = "");
117  std::future<void> deployScenario(Data_Structure::ScenarioPtr scenario, bool printOnly = false, const std::string& commandLineParameters = "");
118 
119  /**
120  * Stops a scenario. Iterates over the applications in the scenario and stops them.
121  * @param scenario scenario to be stopped
122  * @return {@code true} if all applications were successfully stopped
123  */
124  std::future<void> stopScenario(Data_Structure::ScenarioPtr scenario);
125  std::future<void> removeScenario(Data_Structure::ScenarioPtr scenario);
126 
127  /**
128  * Restarts a scenario. Iterates over the applications in the scenario and restarts them.
129  * @param scenario scenario to be restarted
130  * @return {@code true} if all applications were successfully restarted
131  */
132  std::future<void> restartScenario(Data_Structure::ScenarioPtr scenario, bool printOnly = false);
133 
134  /**
135  * Generates an XML file of the given application and saves it in the specified path.
136  * If there already is an XML file at that location it only reloads the file if the executable is more recently changed
137  * than the Xml file
138  * @param application Application whose XML file is to be generate
139  * @param path location to save the XML, must be a folder
140  * @param reload forces to reload the cached XML
141  * @param set if true the newly Cached Xml gets loaded into the Application (Warning: If you load an ApplicationInstance the cfg parameter have to be reloaded)
142  */
143  void loadAndSetCachedProperties(Data_Structure::ApplicationPtr application, std::string path, bool reload = false, bool set = true);
144 
145  /**
146  * Sets the strategy this Executor uses to stop applications. Needs to be system specific.
147  * Use the Factory-Classes to get the proper strategy for your system.
148  * @param strategy strategy to be set
149  * @see StopStrategyFactory
150  */
153 
156 
157  /**
158  * Sets the starter this Executor uses to start applications and request statuses. Needs to be system specific.
159  * Use the Factory-Classes to get the proper starter for your system.
160  * @param starter starter to be set
161  * @see StarterFactory
162  * @see StarterFactoryLinux
163  */
166 
170  };
171  using ExecutorPtr = std::shared_ptr<Executor>;
172 }
ScenarioManager::Exec::Executor::setStopStrategy
void setStopStrategy(StopStrategyPtr strategy, Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:329
ScenarioManager::Exec::Executor::setDefaultStopStrategy
void setDefaultStopStrategy(StopStrategyPtr strategy)
Sets the strategy this Executor uses to stop applications.
Definition: Executor.cpp:320
ScenarioManager::Exec::Executor
Starts, stops and restarts applications and scenarios. Can also be used to request the status of an a...
Definition: Executor.h:54
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioManager::Exec::Executor::removeApplication
std::future< void > removeApplication(Data_Structure::ApplicationInstancePtr application)
Definition: Executor.cpp:103
ScenarioManager::Exec::Executor::getStarter
ApplicationStarterPtr getStarter(Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:339
ScenarioManager::Exec::Executor::restartApplication
std::future< void > restartApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false)
Restarts an application.
Definition: Executor.cpp:143
ScenarioManager::Exec
Definition: ApplicationStarter.h:35
ScenarioManager::Data_Structure::ApplicationPtr
std::shared_ptr< Application > ApplicationPtr
Definition: Application.h:119
ScenarioManager::Exec::Executor::stopApplication
std::future< void > stopApplication(Data_Structure::ApplicationInstancePtr application)
Stops an application.
Definition: Executor.cpp:88
ScenarioManager::Exec::Executor::setStarter
void setStarter(ApplicationStarterPtr starter, Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:334
ScenarioManager::Exec::StopStrategyPtr
std::shared_ptr< StopStrategy > StopStrategyPtr
Definition: Executor.h:46
ScenarioManager::Exec::Executor::setDefaultStarter
void setDefaultStarter(ApplicationStarterPtr starter)
Sets the starter this Executor uses to start applications and request statuses.
Definition: Executor.cpp:324
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:171
ScenarioManager::Exec::Executor::startApplication
std::future< void > startApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false, const std::string &commandLineParameters="")
Starts an application.
Definition: Executor.cpp:46
ScenarioManager::Exec::Executor::getApplicationStatus
std::string getApplicationStatus(Data_Structure::ApplicationInstancePtr application)
Returns the status of an application.
Definition: Executor.cpp:160
ScenarioManager::Exec::Executor::stopScenario
std::future< void > stopScenario(Data_Structure::ScenarioPtr scenario)
Stops a scenario.
Definition: Executor.cpp:232
StopStrategy.h
ScenarioManager::Exec::Executor::getStopStrategy
StopStrategyPtr getStopStrategy(Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:348
ScenarioManager::Exec::Executor::isScenarioDeployed
bool isScenarioDeployed(Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:362
ScenarioManager::StatusManager
Definition: StatusManager.h:7
ScenarioManager::Exec::ApplicationStarterPtr
std::shared_ptr< ApplicationStarter > ApplicationStarterPtr
Definition: ApplicationStarter.h:70
ScenarioManager::Exec::Executor::deployScenario
std::future< void > deployScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false, const std::string &commandLineParameters="")
Definition: Executor.cpp:192
ScenarioManager
Definition: Application.cpp:166
ScenarioManager::Exec::Executor::removeScenario
std::future< void > removeScenario(Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:241
set
set(LIBS ArmarXCoreInterfaces ${CMAKE_THREAD_LIBS_INIT} ${dl_LIBRARIES} ${rt_LIBRARIES} ${QT_LIBRARIES} ${Boost_LIBRARIES} BoostAssertionHandler ArmarXCPPUtility SimoxUtility) set(LIB_FILES ArmarXManager.cpp ArmarXMultipleObjectsScheduler.cpp ArmarXObjectScheduler.cpp ManagedIceObject.cpp ManagedIceObjectPlugin.cpp Component.cpp ComponentPlugin.cpp IceGridAdmin.cpp ArmarXObjectObserver.cpp IceManager.cpp PackagePath.cpp RemoteReferenceCount.cpp logging/LoggingUtil.cpp logging/Logging.cpp logging/LogSender.cpp logging/ArmarXLogBuf.cpp system/ArmarXDataPath.cpp system/DynamicLibrary.cpp system/ProcessWatcher.cpp system/FactoryCollectionBase.cpp system/cmake/CMakePackageFinder.cpp system/cmake/CMakePackageFinderCache.cpp system/cmake/ArmarXPackageToolInterface.cpp system/RemoteObjectNode.cpp services/sharedmemory/HardwareId.cpp services/tasks/RunningTask.cpp services/tasks/ThreadList.cpp services/tasks/ThreadPool.cpp services/profiler/Profiler.cpp services/profiler/FileLoggingStrategy.cpp services/profiler/IceLoggingStrategy.cpp application/Application.cpp application/ApplicationOptions.cpp application/ApplicationProcessFacet.cpp application/ApplicationNetworkStats.cpp application/properties/PropertyUser.cpp application/properties/Property.cpp application/properties/PropertyDefinition.cpp application/properties/PropertyDefinitionContainer.cpp application/properties/PropertyDefinitionHelpFormatter.cpp application/properties/PropertyDefinitionConfigFormatter.cpp application/properties/PropertyDefinitionBriefHelpFormatter.cpp application/properties/PropertyDefinitionXmlFormatter.cpp application/properties/PropertyDefinitionDoxygenFormatter.cpp application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.cpp application/properties/PropertyDefinitionContainerBriefHelpFormatter.cpp application/properties/IceProperties.cpp exceptions/Exception.cpp exceptions/local/UnexpectedEnumValueException.cpp util/FileSystemPathBuilder.cpp util/StringHelpers.cpp util/IceReportSkipper.cpp util/Throttler.cpp util/distributed/AMDCallbackCollection.cpp util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.cpp util/distributed/RemoteHandle/RemoteHandle.cpp util/distributed/RemoteHandle/RemoteHandleControlBlock.cpp time/ice_conversions.cpp time/json_conversions.cpp time/CallbackWaitLock.cpp time/Clock.cpp time/ClockType.cpp time/ClockTypeNames.cpp time/CycleUtil.cpp time/DateTime.cpp time/Duration.cpp time/Frequency.cpp time/LocalTimeServer.cpp time/Metronome.cpp time/ScopedStopWatch.cpp time/StopWatch.cpp time/Timer.cpp time/TimeKeeper.cpp time/TimeUtil.cpp csv/CsvWriter.cpp csv/CsvReader.cpp eigen/conversions.cpp eigen/ice_conversions.cpp) set(LIB_HEADERS ArmarXManager.h ArmarXDummyManager.h ArmarXMultipleObjectsScheduler.h ArmarXObjectObserver.h ArmarXObjectScheduler.h ArmarXFwd.h Component.h ComponentPlugin.h ComponentFactories.h CoreObjectFactories.h IceGridAdmin.h IceManager.h IceManagerImpl.h json_conversions.h ManagedIceObject.h ManagedIceObjectPlugin.h ManagedIceObjectImpl.h ManagedIceObjectDependency.h ManagedIceObjectRegistryInterface.h PackagePath.h RemoteReferenceCount.h system/ImportExport.h system/ImportExportComponent.h system/AbstractFactoryMethod.h system/FactoryCollectionBase.h system/Synchronization.h system/ArmarXDataPath.h system/DynamicLibrary.h system/ProcessWatcher.h system/ConditionSynchronization.h system/cmake/CMakePackageFinder.h system/cmake/CMakePackageFinderCache.h system/cmake/FindPackageX.cmake system/cmake/ArmarXPackageToolInterface.h system/RemoteObjectNode.h logging/LoggingUtil.h logging/LogSender.h logging/Logging.h logging/ArmarXLogBuf.h logging/SpamFilterData.h services/tasks/RunningTask.h services/tasks/PeriodicTask.h services/tasks/ThreadList.h services/tasks/TaskUtil.h services/tasks/ThreadPool.h services/sharedmemory/SharedMemoryProvider.h services/sharedmemory/SharedMemoryConsumer.h services/sharedmemory/IceSharedMemoryProvider.h services/sharedmemory/IceSharedMemoryConsumer.h services/sharedmemory/HardwareIdentifierProvider.h services/sharedmemory/HardwareId.h services/sharedmemory/exceptions/SharedMemoryExceptions.h services/profiler/Profiler.h services/profiler/LoggingStrategy.h services/profiler/FileLoggingStrategy.h services/profiler/IceLoggingStrategy.h application/Application.h application/ApplicationOptions.h application/ApplicationProcessFacet.h application/ApplicationNetworkStats.h application/properties/forward_declarations.h application/properties/Properties.h application/properties/Property.h application/properties/PluginEigen.h application/properties/PluginEnumNames.h application/properties/PluginCfgStruct.h application/properties/PluginAll.h application/properties/PropertyUser.h application/properties/PropertyDefinition.h application/properties/PropertyDefinition.hpp application/properties/PropertyDefinitionInterface.h application/properties/PropertyDefinitionContainer.h application/properties/PropertyDefinitionFormatter.h application/properties/PropertyDefinitionContainerFormatter.h application/properties/PropertyDefinitionConfigFormatter.h application/properties/PropertyDefinitionHelpFormatter.h application/properties/PropertyDefinitionBriefHelpFormatter.h application/properties/PropertyDefinitionXmlFormatter.h application/properties/PropertyDefinitionDoxygenFormatter.h application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.h application/properties/PropertyDefinitionContainerBriefHelpFormatter.h application/properties/ProxyPropertyDefinition.h application/properties/IceProperties.h exceptions/Exception.h exceptions/LocalException.h exceptions/local/DynamicLibraryException.h exceptions/local/ExpressionException.h exceptions/local/FileIOException.h exceptions/local/InvalidPropertyValueException.h exceptions/local/MissingRequiredPropertyException.h exceptions/local/PropertyInheritanceCycleException.h exceptions/local/ProxyNotInitializedException.h exceptions/local/UnexpectedEnumValueException.h exceptions/local/UnmappedValueException.h exceptions/local/ValueRangeExceededException.h exceptions/user/NotImplementedYetException.h rapidxml/rapidxml.hpp rapidxml/rapidxml_print.hpp rapidxml/rapidxml_iterators.hpp rapidxml/rapidxml_utils.hpp rapidxml/wrapper/RapidXmlReader.h rapidxml/wrapper/RapidXmlWriter.h rapidxml/wrapper/DefaultRapidXmlReader.h rapidxml/wrapper/MultiNodeRapidXMLReader.h util/IceBlobToObject.h util/ObjectToIceBlob.h util/FileSystemPathBuilder.h util/FiniteStateMachine.h util/StringHelpers.h util/StringHelperTemplates.h util/algorithm.h util/OnScopeExit.h util/Predicates.h util/Preprocessor.h util/PropagateConst.h util/Registrar.h util/TemplateMetaProgramming.h util/TripleBuffer.h util/IceReportSkipper.h util/Throttler.h util/distributed/AMDCallbackCollection.h util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h util/distributed/RemoteHandle/RemoteHandle.h util/distributed/RemoteHandle/RemoteHandleControlBlock.h util/SimpleStatemachine.h time.h time_minimal.h time/forward_declarations.h time/ice_conversions.h time/json_conversions.h time/CallbackWaitLock.h time/Clock.h time/ClockType.h time/ClockTypeNames.h time/CycleUtil.h time/DateTime.h time/Duration.h time/Frequency.h time/LocalTimeServer.h time/Metronome.h time/ScopedStopWatch.h time/StopWatch.h time/Timer.h time/TimeUtil.h time/TimeKeeper.h csv/CsvWriter.h csv/CsvReader.h eigen/conversions.h eigen/ice_conversions.h ice_conversions.h ice_conversions/ice_conversions_boost_templates.h ice_conversions/ice_conversions_templates.h ice_conversions/ice_conversions_templates.tpp $
Definition: CMakeLists.txt:12
ApplicationStarter.h
ScenarioManager::Exec::Executor::deployApplication
std::future< void > deployApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false, const std::string &commandLineParameters="")
Definition: Executor.cpp:69
ScenarioManager::Exec::Executor::isApplicationDeployed
bool isApplicationDeployed(Data_Structure::ApplicationInstancePtr application)
Definition: Executor.cpp:357
ScenarioManager::Exec::Executor::Executor
Executor(StopStrategyPtr strategy, ApplicationStarterPtr starter)
Constructor that sets StopStrategy and ApplicationStarter.
Definition: Executor.cpp:40
ScenarioManager::Exec::Executor::getDefaultStopStrategy
StopStrategyPtr getDefaultStopStrategy()
Definition: Executor.cpp:367
ScenarioManager::Exec::Executor::restartScenario
std::future< void > restartScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false)
Restarts a scenario.
Definition: Executor.cpp:270
ScenarioManager::Exec::Executor::loadAndSetCachedProperties
void loadAndSetCachedProperties(Data_Structure::ApplicationPtr application, std::string path, bool reload=false, bool set=true)
Generates an XML file of the given application and saves it in the specified path.
Definition: Executor.cpp:279
ScenarioManager::Exec::Executor::startScenario
std::future< void > startScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false, const std::string &commandLineParameters="")
Starts a scenario.
Definition: Executor.cpp:169