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 <map>
23 #include <string>
24 #include <vector>
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"
42 
43 namespace mesos {
44 namespace internal {
45 namespace slave {
46 
47 class Launcher
48 {
49 public:
50  virtual ~Launcher() {}
51 
52  // Recover the necessary state for each container listed in state.
53  // Return the set of containers that are known to the launcher but
54  // not known to the slave (a.k.a. orphans).
56  const std::vector<mesos::slave::ContainerState>& states) = 0;
57 
58  // Fork a new process in the containerized context. The child will
59  // exec the binary at the given path with the given argv, flags and
60  // environment. The I/O of the child will be redirected according to
61  // the specified I/O descriptors. The parentHooks will be executed
62  // in the parent process before the child execs. The parent will return
63  // the child's pid if the fork is successful.
64  virtual Try<pid_t> fork(
65  const ContainerID& containerId,
66  const std::string& path,
67  const std::vector<std::string>& argv,
68  const mesos::slave::ContainerIO& containerIO,
69  const flags::FlagsBase* flags,
70  const Option<std::map<std::string, std::string>>& environment,
71  const Option<int>& enterNamespaces,
72  const Option<int>& cloneNamespaces,
73  const std::vector<int_fd>& whitelistFds) = 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  ~SubprocessLauncher() override {}
97 
99  const std::vector<mesos::slave::ContainerState>& states) override;
100 
102  const ContainerID& containerId,
103  const std::string& path,
104  const std::vector<std::string>& argv,
105  const mesos::slave::ContainerIO& containerIO,
106  const flags::FlagsBase* flags,
107  const Option<std::map<std::string, std::string>>& environment,
108  const Option<int>& enterNamespaces,
109  const Option<int>& cloneNamespaces,
110  const std::vector<int_fd>& whitelistFds) override;
111 
112  process::Future<Nothing> destroy(const ContainerID& containerId) override;
113 
115  const ContainerID& containerId) override;
116 
117 protected:
119 
120  // The 'pid' is the process id of the first process and also the
121  // process group id and session id.
123 };
124 
125 
126 } // namespace slave {
127 } // namespace internal {
128 } // namespace mesos {
129 
130 #endif // __LAUNCHER_HPP__
Definition: path.hpp:29
Definition: launcher.hpp:47
Definition: option.hpp:29
virtual process::Future< hashset< ContainerID > > recover(const std::vector< mesos::slave::ContainerState > &states)=0
Definition: check.hpp:33
~SubprocessLauncher() override
Definition: launcher.hpp:96
virtual Try< pid_t > fork(const ContainerID &containerId, const std::string &path, const std::vector< std::string > &argv, const mesos::slave::ContainerIO &containerIO, const flags::FlagsBase *flags, const Option< std::map< std::string, std::string >> &environment, const Option< int > &enterNamespaces, const Option< int > &cloneNamespaces, const std::vector< int_fd > &whitelistFds)=0
SubprocessLauncher()
Definition: launcher.hpp:118
An abstraction around the IO classes used to redirect stdin/stdout/stderr to/from a container by the ...
Definition: containerizer.hpp:37
Definition: flags.hpp:39
Environment * environment
virtual process::Future< Nothing > destroy(const ContainerID &containerId)=0
Definition: flags.hpp:44
Definition: agent.hpp:25
Definition: attributes.hpp:24
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)=0
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
virtual ~Launcher()
Definition: launcher.hpp:50
Definition: parse.hpp:33
hashmap< ContainerID, pid_t > pids
Definition: launcher.hpp:122
Definition: future.hpp:58