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_METHOD3(
101  update,
103  const ContainerID&,
104  const Resources&,
105  const google::protobuf::Map<std::string, Value::Scalar>&));
106 
107  MOCK_METHOD1(
108  usage,
109  process::Future<ResourceStatistics>(const ContainerID&));
110 
111  MOCK_METHOD1(
112  status,
113  process::Future<ContainerStatus>(const ContainerID&));
114 
115  MOCK_METHOD1(
116  wait,
118  const ContainerID&));
119 
120  MOCK_METHOD1(
121  destroy,
123  const ContainerID&));
124 
125  MOCK_METHOD2(
126  kill,
127  process::Future<bool>(const ContainerID&, int));
128 
129  MOCK_METHOD1(
130  pruneImages,
131  process::Future<Nothing>(const std::vector<Image>&));
132 
133  // Additional destroy method for testing because we won't know the
134  // ContainerID created for each container.
136  const FrameworkID& frameworkId,
137  const ExecutorID& executorId);
138 
139 private:
140  void setup();
141 
142  // The following functions act as a level of indirection to
143  // perform the dispatch while still allowing the above to be
144  // mock functions.
145 
146  process::Future<Nothing> _recover(
147  const Option<slave::state::SlaveState>& state);
148 
150  const ContainerID& containerId,
151  const mesos::slave::ContainerConfig& containerConfig,
152  const std::map<std::string, std::string>& environment,
153  const Option<std::string>& pidCheckpointPath);
154 
156  const ContainerID& containerId);
157 
158  process::Future<Nothing> _update(
159  const ContainerID& containerId,
160  const Resources& resourceRequests,
161  const google::protobuf::Map<std::string, Value::Scalar>& resourceLimits);
162 
164  const ContainerID& containerId);
165 
167  const ContainerID& containerId);
168 
170  const ContainerID& containerId);
171 
173  const ContainerID& containerId);
174 
175  process::Future<bool> _kill(
176  const ContainerID& containerId,
177  int status);
178 
179  process::Future<Nothing> _pruneImages(
180  const std::vector<Image>& excludedImages);
181 
183 };
184 
185 } // namespace tests {
186 } // namespace internal {
187 } // namespace mesos {
188 
189 #endif // __TEST_CONTAINERIZER_HPP__
virtual process::Future< Nothing > update(const ContainerID &containerId, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={})=0
MOCK_METHOD1(recover, process::Future< Nothing >(const Option< slave::state::SlaveState > &))
Definition: option.hpp:29
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)
Definition: containerizer.hpp:136
Definition: resources.hpp:83
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
MOCK_METHOD3(update, process::Future< Nothing >(const ContainerID &, const Resources &, const google::protobuf::Map< std::string, Value::Scalar > &))
virtual process::Future< Nothing > recover(const Option< state::SlaveState > &state)=0
Definition: containerizer.hpp:64
Definition: containerizer.hpp:62
Definition: agent.hpp:25
virtual process::Future< process::http::Connection > attach(const ContainerID &containerId)
Definition: containerizer.hpp:115
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:162
Definition: attributes.hpp:24
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId)=0
Definition: executor.hpp:48
MOCK_METHOD2(kill, process::Future< bool >(const ContainerID &, int))
Definition: mesos.hpp:2636
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