Apache Mesos
containerizer.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 __CONTAINERIZER_HPP__
18 #define __CONTAINERIZER_HPP__
19 
20 #include <map>
21 
22 #include <mesos/mesos.hpp>
23 #include <mesos/resources.hpp>
24 
26 
28 
29 #include <process/future.hpp>
30 #include <process/http.hpp>
31 #include <process/owned.hpp>
32 #include <process/process.hpp>
33 
34 #include <stout/duration.hpp>
35 #include <stout/hashset.hpp>
36 #include <stout/option.hpp>
37 #include <stout/try.hpp>
38 
40 
41 namespace mesos {
42 namespace internal {
43 namespace slave {
44 
45 // Forward declaration.
46 class Slave;
47 class Flags;
48 
49 namespace state {
50 // Forward declaration.
51 struct SlaveState;
52 } // namespace state {
53 
54 
55 // An abstraction of a Containerizer that will contain an executor and
56 // its tasks.
58 {
59 public:
60  enum class LaunchResult {
61  SUCCESS,
64  };
65 
66  // Attempts to create a containerizer as specified by 'isolation' in
67  // flags.
69  const Flags& flags,
70  bool local,
71  Fetcher* fetcher,
72  SecretResolver* secretResolver = nullptr);
73 
74  // Determine slave resources from flags, probing the system or
75  // querying a delegate.
76  // TODO(idownes): Consider making this non-static and moving to
77  // containerizer implementations to enable a containerizer to best
78  // determine the resources, particularly if containerizeration is
79  // delegated.
80  static Try<Resources> resources(const Flags& flags);
81 
82  virtual ~Containerizer() {}
83 
84  // Recover all containerized executors specified in state. Any
85  // containerized executors present on the system but not included in
86  // state (or state is None) will be terminated and cleaned up.
88  const Option<state::SlaveState>& state) = 0;
89 
90  // Launch a container with the specified ContainerConfig.
91  //
92  // If the ContainerID has a parent, this will attempt to launch
93  // a nested container.
94  // NOTE: For nested containers, the required `directory` field of
95  // the ContainerConfig will be determined by the containerizer.
97  const ContainerID& containerId,
98  const mesos::slave::ContainerConfig& containerConfig,
99  const std::map<std::string, std::string>& environment,
100  const Option<std::string>& pidCheckpointPath) = 0;
101 
102  // Create an HTTP connection that can be used to "attach" (i.e.,
103  // stream input to or stream output from) a container.
105  const ContainerID& containerId)
106  {
107  return process::Failure("Unsupported");
108  }
109 
110  // Update the resources for a container.
112  const ContainerID& containerId,
113  const Resources& resources) = 0;
114 
115  // Get resource usage statistics on the container.
117  const ContainerID& containerId) = 0;
118 
119  // Retrieve the run-time state of various isolator properties
120  // associated with the container. Unlike other methods in this class
121  // we are not making this pure virtual, since a `Containerizer`
122  // doesn't necessarily need to return the status of a container.
124  const ContainerID &containerId)
125  {
126  return ContainerStatus();
127  }
128 
129  // Wait on the 'ContainerTermination'. If the executor terminates,
130  // the containerizer should also destroy the containerized context.
131  // Returns None if the container cannot be found.
132  // The future may be failed if an error occurs during termination of
133  // the executor or destruction of the container.
135  const ContainerID& containerId) = 0;
136 
137  // Destroy a running container, killing all processes and releasing
138  // all resources. Returns false when the container cannot be found,
139  // or a failure if something went wrong.
140  //
141  // NOTE: You cannot wait() on containers that have been destroyed,
142  // so you should always call wait() before destroy().
143  virtual process::Future<bool> destroy(const ContainerID& containerId) = 0;
144 
145  // Sends a signal to a running container. Returns false when the container
146  // cannot be found. The future may be failed if an error occurs in sending
147  // the signal to the running container.
149  const ContainerID& containerId,
150  int signal)
151  {
152  return process::Failure("Unsupported");
153  };
154 
156 
157  // Remove a nested container, including its sandbox and runtime directories.
158  //
159  // NOTE: You can only remove a a nested container that has been fully
160  // destroyed and whose parent has not been destroyed yet. If the parent has
161  // already been destroyed, then the sandbox and runtime directories will be
162  // eventually garbage collected. The caller is responsible for ensuring that
163  // `containerId` belongs to a nested container.
164  virtual process::Future<Nothing> remove(const ContainerID& containerId)
165  {
166  return process::Failure("Unsupported");
167  }
168 
169  // Prune unused images from supported image stores.
171  const std::vector<Image>& excludedImages) = 0;
172 };
173 
174 } // namespace slave {
175 } // namespace internal {
176 } // namespace mesos {
177 
178 #endif // __CONTAINERIZER_HPP__
Definition: option.hpp:28
LaunchResult
Definition: containerizer.hpp:60
Definition: fetcher.hpp:49
Definition: try.hpp:34
Definition: future.hpp:664
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)
Definition: containerizer.hpp:123
static Try< Containerizer * > create(const Flags &flags, bool local, Fetcher *fetcher, SecretResolver *secretResolver=nullptr)
Definition: resources.hpp:79
virtual process::Future< Nothing > update(const ContainerID &containerId, const Resources &resources)=0
virtual process::Future< LaunchResult > launch(const ContainerID &containerId, const mesos::slave::ContainerConfig &containerConfig, const std::map< std::string, std::string > &environment, const Option< std::string > &pidCheckpointPath)=0
Definition: flags.hpp:39
Environment * environment
virtual process::Future< Nothing > recover(const Option< state::SlaveState > &state)=0
Definition: containerizer.hpp:57
virtual process::Future< process::http::Connection > attach(const ContainerID &containerId)
Definition: containerizer.hpp:104
virtual ~Containerizer()
Definition: containerizer.hpp:82
virtual process::Future< bool > kill(const ContainerID &containerId, int signal)
Definition: containerizer.hpp:148
virtual process::Future< bool > destroy(const ContainerID &containerId)=0
#define flags
Definition: decoder.hpp:18
virtual process::Future< hashset< ContainerID > > containers()=0
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId)=0
static Try< Resources > resources(const Flags &flags)
Definition: resolver.hpp:34
virtual process::Future< Option< mesos::slave::ContainerTermination > > wait(const ContainerID &containerId)=0
virtual process::Future< Nothing > pruneImages(const std::vector< Image > &excludedImages)=0