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 __TEST_CONTAINERIZER_HPP__
18 #define __TEST_CONTAINERIZER_HPP__
19 
20 #ifndef __WINDOWS__
21 #include <unistd.h>
22 #endif // __WINDOWS__
23 
24 #include <map>
25 #include <memory>
26 #include <string>
27 
28 #include <mesos/executor.hpp>
29 #include <mesos/mesos.hpp>
30 #include <mesos/resources.hpp>
31 #include <mesos/type_utils.hpp>
32 
33 #include <mesos/v1/executor.hpp>
34 
35 #include <process/dispatch.hpp>
36 #include <process/future.hpp>
37 #include <process/gmock.hpp>
38 #include <process/http.hpp>
39 #include <process/pid.hpp>
40 
41 #include <stout/hashmap.hpp>
42 #include <stout/os.hpp>
43 #include <stout/try.hpp>
44 #include <stout/uuid.hpp>
45 
47 
48 #include "slave/slave.hpp"
49 #include "slave/state.hpp"
50 
51 #include "tests/mesos.hpp"
52 
53 namespace mesos {
54 namespace internal {
55 namespace tests {
56 
57 // Forward declaration.
58 class MockExecutor;
59 class TestContainerizerProcess;
60 
61 
63 {
64 public:
65  // TODO(bmahler): These constructors assume that ExecutorIDs are
66  // unique across FrameworkIDs, which is not the case.
68  const ExecutorID& executorId,
69  const std::shared_ptr<v1::MockHTTPExecutor>& executor);
70 
72 
73  TestContainerizer(const ExecutorID& executorId, Executor* executor);
74 
75  explicit TestContainerizer(MockExecutor* executor);
76 
78 
79  ~TestContainerizer() override;
80 
82 
84  recover,
86 
88  launch,
90  const ContainerID&,
91  const mesos::slave::ContainerConfig&,
92  const std::map<std::string, std::string>&,
93  const Option<std::string>&));
94 
96  attach,
98  const ContainerID& containerId));
99 
100  MOCK_METHOD2(
101  update,
102  process::Future<Nothing>(const ContainerID&, const Resources&));
103 
104  MOCK_METHOD1(
105  usage,
106  process::Future<ResourceStatistics>(const ContainerID&));
107 
108  MOCK_METHOD1(
109  status,
110  process::Future<ContainerStatus>(const ContainerID&));
111 
112  MOCK_METHOD1(
113  wait,
115  const ContainerID&));
116 
117  MOCK_METHOD1(
118  destroy,
120  const ContainerID&));
121 
122  MOCK_METHOD2(
123  kill,
124  process::Future<bool>(const ContainerID&, int));
125 
126  MOCK_METHOD1(
127  pruneImages,
128  process::Future<Nothing>(const std::vector<Image>&));
129 
130  // Additional destroy method for testing because we won't know the
131  // ContainerID created for each container.
133  const FrameworkID& frameworkId,
134  const ExecutorID& executorId);
135 
136 private:
137  void setup();
138 
139  // The following functions act as a level of indirection to
140  // perform the dispatch while still allowing the above to be
141  // mock functions.
142 
143  process::Future<Nothing> _recover(
144  const Option<slave::state::SlaveState>& state);
145 
147  const ContainerID& containerId,
148  const mesos::slave::ContainerConfig& containerConfig,
149  const std::map<std::string, std::string>& environment,
150  const Option<std::string>& pidCheckpointPath);
151 
153  const ContainerID& containerId);
154 
155  process::Future<Nothing> _update(
156  const ContainerID& containerId,
157  const Resources& resources);
158 
160  const ContainerID& containerId);
161 
163  const ContainerID& containerId);
164 
166  const ContainerID& containerId);
167 
169  const ContainerID& containerId);
170 
171  process::Future<bool> _kill(
172  const ContainerID& containerId,
173  int status);
174 
175  process::Future<Nothing> _pruneImages(
176  const std::vector<Image>& excludedImages);
177 
179 };
180 
181 } // namespace tests {
182 } // namespace internal {
183 } // namespace mesos {
184 
185 #endif // __TEST_CONTAINERIZER_HPP__
MOCK_METHOD1(recover, process::Future< Nothing >(const Option< slave::state::SlaveState > &))
Definition: option.hpp:28
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)
Definition: containerizer.hpp:123
Definition: resources.hpp:79
MOCK_METHOD2(update, process::Future< Nothing >(const ContainerID &, const Resources &))
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: hashmap.hpp:38
process::Future< Option< mesos::slave::ContainerTermination > > destroy(const FrameworkID &frameworkId, const ExecutorID &executorId)
process::Future< hashset< ContainerID > > containers() override
Environment * environment
virtual process::Future< Nothing > recover(const Option< state::SlaveState > &state)=0
Definition: containerizer.hpp:57
Definition: containerizer.hpp:62
Definition: spec.hpp:30
virtual process::Future< process::http::Connection > attach(const ContainerID &containerId)
Definition: containerizer.hpp:104
MOCK_METHOD4(launch, process::Future< slave::Containerizer::LaunchResult >(const ContainerID &, const mesos::slave::ContainerConfig &, const std::map< std::string, std::string > &, const Option< std::string > &))
Definition: executor.hpp:75
virtual process::Future< bool > kill(const ContainerID &containerId, int signal)
Definition: containerizer.hpp:149
Definition: attributes.hpp:24
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId)=0
Definition: executor.hpp:48
static Try< Resources > resources(const Flags &flags)
Definition: mesos.hpp:2397
virtual process::Future< Option< mesos::slave::ContainerTermination > > wait(const ContainerID &containerId)=0
virtual process::Future< Nothing > pruneImages(const std::vector< Image > &excludedImages)=0
Definition: future.hpp:58