56 std::lock_guard<std::mutex> guard(lifecyclesMutex);
61 lifecycle = std::make_shared<ApplicationLifecycle>(application, statusManager);
69 const std::string& commandLineParameters)
72 lifecycleFor(application)
76 commandLineParameters,
84 lifecycleFor(application)
92 lifecycleFor(application)
103 lifecycleFor(application)->wait();
124 return getStarter(application->getScenario())->getStatus(application, statusManager);
130 const std::string& commandLineParameters,
139 lifecycleFor(application)
141 getStarter(scenario),
142 getStopStrategy(scenario),
143 commandLineParameters,
151 const std::string& commandLineParameters)
170 const std::filesystem::path& xmlFilePath)
180 const std::string executable = application->getExecutableAbsPath();
181 const std::string commandLine = executable +
" -p -f xml -o " + xmlFilePath.string();
184 using namespace boost::process::initializers;
189 child
c = execute(run_exe(executable), set_cmd_line(commandLine), inherit_env());
192 catch (
const std::exception& e)
194 ARMARX_WARNING <<
"Failed to generate properties xml for " << application->getName()
195 <<
": " << e.what() <<
"\nCommand was: " << commandLine;
201 ARMARX_WARNING <<
"Generating the properties xml for " << application->getName()
202 <<
" did not finish within " << PropertyGenerationTimeout.count()
203 <<
" ms, giving up on it.\nCommand was: " << commandLine;
204 ::kill(pid, SIGKILL);
209 if (!std::filesystem::exists(xmlFilePath, ec) ||
210 std::filesystem::file_size(xmlFilePath, ec) == 0)
212 ARMARX_WARNING <<
"Failed to generate properties xml for " << application->getName()
213 <<
"\nCommand was: " << commandLine;
223 std::filesystem::path xmlFilePath =
224 std::filesystem::path(path) / std::filesystem::path(application->getPackageName() +
"." +
225 application->getName() +
".xml");
227 if (reload || !std::filesystem::exists(xmlFilePath))
232 application->updateFound();
233 if (!application->getFound())
235 ARMARX_WARNING <<
"Cannot generate the properties xml for " << application->getName()
236 <<
": the binary is missing at " << application->getExecutableAbsPath();
240 std::filesystem::create_directories(path);
241 generatePropertiesXml(application, xmlFilePath);
245 application->updateFound();
246 if (!application->getFound())
251 auto xmlDate = (std::filesystem::last_write_time(xmlFilePath));
254 std::filesystem::last_write_time(application->getPathToExecutable().append(
"/").append(
255 application->getExecutableName()));
257 if (execDate > xmlDate)
267 application->setProperties(parser.loadFromXml(xmlFilePath.string()));
274 defaultStopStrategy = strategy;
280 defaultStartStrategy = appStarter;
286 this->stopStrategy[scenario] = strategy;
292 this->starter[scenario] = appStarter;
298 if (starter.count(scenario) == 0)
300 return defaultStartStrategy;
302 return starter[scenario];
308 if (stopStrategy.count(scenario) == 0)
310 return defaultStopStrategy;
312 return stopStrategy[scenario];
318 return defaultStopStrategy;
std::shared_ptr< ScenarioManager::Data_Structure::ApplicationInstance > ApplicationInstancePtr
StopStrategyPtr getStopStrategy(Data_Structure::ScenarioPtr scenario)
void restartScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false)
Restarts a scenario.
void setDefaultStarter(ApplicationStarterPtr appStarter)
Sets the appStarter this Executor uses to start applications and request statuses.
static 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.
std::string getApplicationStatus(Data_Structure::ApplicationInstancePtr application)
Returns the status of an application.
void waitForScenario(const Data_Structure::ScenarioPtr &scenario)
Blocks until no application of the scenario has an operation requested or running.
void restartApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false)
Requests that an application be restarted.
void startScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false, const std::string &commandLineParameters="")
Starts a scenario.
Executor(StopStrategyPtr strategy, ApplicationStarterPtr starter)
Constructor that sets StopStrategy and ApplicationStarter.
void stopScenario(Data_Structure::ScenarioPtr scenario)
Stops a scenario.
void setDefaultStopStrategy(StopStrategyPtr strategy)
Sets the strategy this Executor uses to stop applications.
void startApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false, const std::string &commandLineParameters="")
Requests that an application be started.
void stopApplication(Data_Structure::ApplicationInstancePtr application)
Requests that an application be stopped.
StopStrategyPtr getDefaultStopStrategy()
void setStarter(ApplicationStarterPtr appStarter, Data_Structure::ScenarioPtr scenario)
ApplicationStarterPtr getStarter(Data_Structure::ScenarioPtr scenario)
void setStopStrategy(StopStrategyPtr strategy, Data_Structure::ScenarioPtr scenario)
void waitForApplication(const Data_Structure::ApplicationInstancePtr &application)
Blocks until the application has no operation requested or running any more.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< Scenario > ScenarioPtr
Intent
What the ScenarioManager is currently trying to do with an application.
std::shared_ptr< Application > ApplicationPtr
bool WaitForExit(int pid, std::chrono::milliseconds timeout, std::chrono::milliseconds pollInterval)
Blocks until the process with the given pid has disappeared, at most for timeout.
std::shared_ptr< StopStrategy > StopStrategyPtr
std::shared_ptr< ApplicationStarter > ApplicationStarterPtr
std::shared_ptr< ApplicationLifecycle > ApplicationLifecyclePtr
Convenience header which includes all public Boost.Process header files.
static const std::string Waiting