Apache Mesos
launcher.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. 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 #ifndef __LAUNCHER_HPP__
18 #define __LAUNCHER_HPP__
19 
20 #include <sys/types.h>
21 
22 #include <list>
23 #include <map>
24 #include <string>
25 
26 #include <mesos/mesos.hpp>
27 
28 #include <mesos/slave/isolator.hpp>
29 
30 #include <process/future.hpp>
31 #include <process/subprocess.hpp>
32 
33 #include <stout/flags.hpp>
34 #include <stout/hashmap.hpp>
35 #include <stout/hashset.hpp>
36 #include <stout/lambda.hpp>
37 #include <stout/option.hpp>
38 #include <stout/try.hpp>
39 
40 #include "slave/flags.hpp"
41 
42 namespace mesos {
43 namespace internal {
44 namespace slave {
45 
46 class Launcher
47 {
48 public:
49  virtual ~Launcher() {}
50 
51  // Recover the necessary state for each container listed in state.
52  // Return the set of containers that are known to the launcher but
53  // not known to the slave (a.k.a. orphans).
55  const std::list<mesos::slave::ContainerState>& states) = 0;
56 
57  // Fork a new process in the containerized context. The child will
58  // exec the binary at the given path with the given argv, flags and
59  // environment. The I/O of the child will be redirected according to
60  // the specified I/O descriptors. The parentHooks will be executed
61  // in the parent process before the child execs. The parent will return
62  // the child's pid if the fork is successful.
63  virtual Try<pid_t> fork(
64  const ContainerID& containerId,
65  const std::string& path,
66  const std::vector<std::string>& argv,
67  const process::Subprocess::IO& in,
68  const process::Subprocess::IO& out,
69  const process::Subprocess::IO& err,
70  const flags::FlagsBase* flags,
71  const Option<std::map<std::string, std::string>>& environment,
72  const Option<int>& enterNamespaces,
73  const Option<int>& cloneNamespaces) = 0;
74 
75  // Kill all processes in the containerized context.
76  virtual process::Future<Nothing> destroy(const ContainerID& containerId) = 0;
77 
78  // Return ContainerStatus information about container.
79  // Currently only returns Executor PID info.
81  const ContainerID& containerId) = 0;
82 };
83 
84 
85 // Launcher suitable for any POSIX compliant system. Uses process
86 // groups and sessions to track processes in a container. POSIX states
87 // that process groups cannot migrate between sessions so all
88 // processes for a container will be contained in a session.
89 // Also suitable for Windows, which uses job objects to obtain the
90 // same functionality. Everything is coordinated through `Subprocess`.
92 {
93 public:
94  static Try<Launcher*> create(const Flags& flags);
95 
96  virtual ~SubprocessLauncher() {}
97 
99  const std::list<mesos::slave::ContainerState>& states);
100 
101  virtual Try<pid_t> fork(
102  const ContainerID& containerId,
103  const std::string& path,
104  const std::vector<std::string>& argv,
105  const process::Subprocess::IO& in,
106  const process::Subprocess::IO& out,
107  const process::Subprocess::IO& err,
108  const flags::FlagsBase* flags,
109  const Option<std::map<std::string, std::string>>& environment,
110  const Option<int>& enterNamespaces,
111  const Option<int>& cloneNamespaces);
112 
113  virtual process::Future<Nothing> destroy(const ContainerID& containerId);
114 
116  const ContainerID& containerId);
117 
118 protected:
120 
121  // The 'pid' is the process id of the first process and also the
122  // process group id and session id.
124 };
125 
126 
127 } // namespace slave {
128 } // namespace internal {
129 } // namespace mesos {
130 
131 #endif // __LAUNCHER_HPP__
Definition: launcher.hpp:46
Definition: option.hpp:28
Definition: try.hpp:34
SubprocessLauncher()
Definition: launcher.hpp:119
static Try< Launcher * > create(const Flags &flags)
Definition: flags.hpp:39
Environment * environment
virtual ~SubprocessLauncher()
Definition: launcher.hpp:96
virtual process::Future< Nothing > destroy(const ContainerID &containerId)=0
Describes how the I/O is redirected for stdin/stdout/stderr.
Definition: subprocess.hpp:61
Definition: flags.hpp:44
#define flags
Definition: decoder.hpp:18
virtual process::Future< hashset< ContainerID > > recover(const std::list< mesos::slave::ContainerState > &states)=0
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)=0
virtual ~Launcher()
Definition: launcher.hpp:49
virtual process::Future< Nothing > destroy(const ContainerID &containerId)
virtual process::Future< hashset< ContainerID > > recover(const std::list< mesos::slave::ContainerState > &states)
virtual Try< pid_t > fork(const ContainerID &containerId, const std::string &path, const std::vector< std::string > &argv, const process::Subprocess::IO &in, const process::Subprocess::IO &out, const process::Subprocess::IO &err, const flags::FlagsBase *flags, const Option< std::map< std::string, std::string >> &environment, const Option< int > &enterNamespaces, const Option< int > &cloneNamespaces)=0
virtual Try< pid_t > fork(const ContainerID &containerId, const std::string &path, const std::vector< std::string > &argv, const process::Subprocess::IO &in, const process::Subprocess::IO &out, const process::Subprocess::IO &err, const flags::FlagsBase *flags, const Option< std::map< std::string, std::string >> &environment, const Option< int > &enterNamespaces, const Option< int > &cloneNamespaces)
hashmap< ContainerID, pid_t > pids
Definition: launcher.hpp:123
Definition: future.hpp:57