NRP Core  1.4.1
docker_launcher.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef DOCKER_LAUNCHER_H
23 #define DOCKER_LAUNCHER_H
24 
25 #include "nrp_general_library/config/cmake_constants.h"
27 #include <iostream>
28 
29 #include <boost/python.hpp>
30 
31 namespace bpy = boost::python;
32 
33 inline const char LAUNCH_DOCKER_COMMAND[] = "DockerLauncher";
34 
36  : public LaunchCommand<LAUNCH_DOCKER_COMMAND>
37 {
38  public:
39  ~DockerLauncher() override;
40 
41  pid_t launchProcess(const nlohmann::json &launcherConfig, const std::string& procCmd,
42  const std::vector<std::string> &envParams,
43  const std::vector<std::string> &startParams, bool appendParentEnv = true,
44  int logFD = -1) override;
45 
46  pid_t stopProcess(unsigned int killWait) override;
47 
49 
50  private:
51 
53  pid_t _enginePID = 0;
55  bpy::object _dockerHandle;
57  std::string _procCmd;
59  bool _printLogs = true;
61  std::string getDockerLogs();
62 };
63 
64 #endif // DOCKER_LAUNCHER_H
DockerLauncher::stopProcess
pid_t stopProcess(unsigned int killWait) override
Stop a running engine process.
Definition: docker_launcher.cpp:85
launch_command.h
DockerLauncher::launchProcess
pid_t launchProcess(const nlohmann::json &launcherConfig, const std::string &procCmd, const std::vector< std::string > &envParams, const std::vector< std::string > &startParams, bool appendParentEnv=true, int logFD=-1) override
Fork a new process for the given engine. Will read environment variables and start params from engine...
Definition: docker_launcher.cpp:38
DockerLauncher
Definition: docker_launcher.h:35
LaunchCommand
Class for launch commands. Must be specialized further.
Definition: launch_command.h:93
LAUNCH_DOCKER_COMMAND
const char LAUNCH_DOCKER_COMMAND[]
Definition: docker_launcher.h:33
DockerLauncher::~DockerLauncher
~DockerLauncher() override
Definition: docker_launcher.cpp:30
LaunchCommandInterface::ENGINE_RUNNING_STATUS
ENGINE_RUNNING_STATUS
Engine Process status.
Definition: launch_command.h:39
DockerLauncher::getProcessStatus
ENGINE_RUNNING_STATUS getProcessStatus() override
Get the current engine process status. If status cannot be retrieved, return ENGINE_RUNNING_STATUS::U...
Definition: docker_launcher.cpp:109
json
nlohmann::json json
Definition: engine_json_server.cpp:31