Apache Mesos
isolator.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 __MESOS_SLAVE_ISOLATOR_HPP__
18 #define __MESOS_SLAVE_ISOLATOR_HPP__
19 
20 #include <string>
21 #include <vector>
22 
23 #include <mesos/resources.hpp>
24 
26 
27 #include <process/dispatch.hpp>
28 #include <process/future.hpp>
29 #include <process/owned.hpp>
30 #include <process/process.hpp>
31 
32 #include <stout/hashset.hpp>
33 #include <stout/option.hpp>
34 #include <stout/try.hpp>
35 
36 namespace mesos {
37 namespace slave {
38 
39 class Isolator
40 {
41 public:
42  virtual ~Isolator() {}
43 
44  // Returns true if this isolator supports nested containers. This
45  // method is designed to allow isolators to opt-in to support nested
46  // containers.
47  virtual bool supportsNesting()
48  {
49  return false;
50  }
51 
52  virtual bool supportsStandalone()
53  {
54  return false;
55  }
56 
57  // Recover containers from the run states and the orphan containers
58  // (known to the launcher but not known to the slave) detected by
59  // the launcher.
61  const std::vector<ContainerState>& states,
62  const hashset<ContainerID>& orphans)
63  {
64  return Nothing();
65  }
66 
67  // Prepare for isolation of the executor. Any steps that require
68  // execution in the containerized context (e.g. inside a network
69  // namespace) can be returned in the optional CommandInfo and they
70  // will be run by the Launcher.
71  // TODO(idownes): Any URIs or Environment in the CommandInfo will be
72  // ignored; only the command value is used.
74  const ContainerID& containerId,
75  const ContainerConfig& containerConfig)
76  {
77  return None();
78  }
79 
80  // Isolate the executor.
82  const ContainerID& containerId,
83  pid_t pid)
84  {
85  return Nothing();
86  }
87 
88  // Watch the containerized executor and report if any resource
89  // constraint impacts the container, e.g., the kernel killing some
90  // processes.
92  const ContainerID& containerId)
93  {
95  }
96 
97  // Update the resources allocated to the container.
99  const ContainerID& containerId,
100  const Resources& resourceRequests,
101  const google::protobuf::Map<
102  std::string, Value::Scalar>& resourceLimits = {})
103  {
104  return Nothing();
105  }
106 
107  // Gather resource usage statistics for the container.
109  const ContainerID& containerId)
110  {
111  return ResourceStatistics();
112  }
113 
114  // Get the run-time status of isolator specific properties
115  // associated with the container.
117  const ContainerID& containerId)
118  {
119  return ContainerStatus();
120  }
121 
122  // Clean up a terminated container. This is called after the
123  // executor and all processes in the container have terminated.
124  // It's likely that isolator `cleanup` is called for an unknown
125  // container (see MESOS-6059). Therefore, the isolator should ignore
126  // the cleanup is the container is unknown to it. In any case, the
127  // `cleanup` won't be called multiple times for a container. Also,
128  // if `prepare` is called, the cleanup is guaranteed to be called
129  // after `prepare` finishes (or fails).
131  const ContainerID& containerId)
132  {
133  return Nothing();
134  }
135 };
136 
137 } // namespace slave {
138 } // namespace mesos {
139 
140 #endif // __MESOS_SLAVE_ISOLATOR_HPP__
Definition: nothing.hpp:16
virtual bool supportsNesting()
Definition: isolator.hpp:47
Definition: resources.hpp:83
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)
Definition: isolator.hpp:116
virtual process::Future< Nothing > cleanup(const ContainerID &containerId)
Definition: isolator.hpp:130
virtual ~Isolator()
Definition: isolator.hpp:42
DWORD pid_t
Definition: windows.hpp:181
virtual process::Future< Nothing > recover(const std::vector< ContainerState > &states, const hashset< ContainerID > &orphans)
Definition: isolator.hpp:60
Definition: agent.hpp:25
virtual process::Future< Nothing > update(const ContainerID &containerId, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={})
Definition: isolator.hpp:98
Definition: none.hpp:27
virtual bool supportsStandalone()
Definition: isolator.hpp:52
virtual process::Future< ContainerLimitation > watch(const ContainerID &containerId)
Definition: isolator.hpp:91
virtual process::Future< Nothing > isolate(const ContainerID &containerId, pid_t pid)
Definition: isolator.hpp:81
virtual process::Future< Option< ContainerLaunchInfo > > prepare(const ContainerID &containerId, const ContainerConfig &containerConfig)
Definition: isolator.hpp:73
Definition: isolator.hpp:39
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId)
Definition: isolator.hpp:108