Apache Mesos
executor.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 __DOCKER_EXECUTOR_HPP__
18 #define __DOCKER_EXECUTOR_HPP__
19 
20 #include <stdio.h>
21 
22 #include <map>
23 #include <string>
24 
25 #include <mesos/executor.hpp>
26 
27 #include <process/owned.hpp>
28 #include <process/process.hpp>
29 
30 #include <stout/option.hpp>
31 
32 #include "docker/docker.hpp"
33 
34 #include "logging/flags.hpp"
35 
36 namespace mesos {
37 namespace internal {
38 namespace docker {
39 
40 struct Flags : public virtual mesos::internal::logging::Flags
41 {
42  Flags() {
44  "container",
45  "The name of the docker container to run.");
46 
48  "docker",
49  "The path to the docker executable.");
50 
52  "docker_socket",
53  "Resource used by the agent and the executor to provide CLI access\n"
54  "to the Docker daemon. On Unix, this is typically a path to a\n"
55  "socket, such as '/var/run/docker.sock'. On Windows this must be a\n"
56  "named pipe, such as '//./pipe/docker_engine'.");
57 
59  "sandbox_directory",
60  "The path to the container sandbox holding stdout and stderr files\n"
61  "into which docker container logs will be redirected.");
62 
64  "mapped_directory",
65  "The sandbox directory path that is mapped in the docker container.");
66 
67  // TODO(alexr): Remove this after the deprecation cycle (started in 1.0).
69  "stop_timeout",
70  "The duration for docker to wait after stopping a running container\n"
71  "before it kills that container. This flag is deprecated; use task's\n"
72  "kill policy instead.");
73 
75  "launcher_dir",
76  "Directory path of Mesos binaries. Mesos would find fetcher,\n"
77  "containerizer and executor binary files under this directory.");
78 
80  "task_environment",
81  "A JSON map of environment variables and values that should\n"
82  "be passed into the task launched by this executor.");
83 
85  "default_container_dns",
86  "JSON-formatted default DNS information for container.");
87 
89  "cgroups_enable_cfs",
90  "Cgroups feature flag to enable hard limits on CPU resources\n"
91  "via the CFS bandwidth limiting subfeature.\n",
92  false);
93  }
94 
103 
105 
106  // TODO(alexr): Remove this after the deprecation cycle (started in 1.0).
108 };
109 
110 
111 class DockerExecutorProcess;
112 
113 
114 class DockerExecutor : public Executor
115 {
116 public:
119  const std::string& container,
120  const std::string& sandboxDirectory,
121  const std::string& mappedDirectory,
122  const Duration& shutdownGracePeriod,
123  const std::string& launcherDir,
124  const std::map<std::string, std::string>& taskEnvironment,
125  const Option<ContainerDNSInfo>& defaultContainerDNS,
126  bool cgroupsEnableCfs);
127 
128  ~DockerExecutor() override;
129 
130  void registered(
131  ExecutorDriver* driver,
132  const ExecutorInfo& executorInfo,
133  const FrameworkInfo& frameworkInfo,
134  const SlaveInfo& slaveInfo) override;
135 
136  void reregistered(
137  ExecutorDriver* driver,
138  const SlaveInfo& slaveInfo) override;
139 
140  void disconnected(ExecutorDriver* driver) override;
141 
142  void launchTask(ExecutorDriver* driver, const TaskInfo& task) override;
143 
144  void killTask(ExecutorDriver* driver, const TaskID& taskId) override;
145 
146  void frameworkMessage(
147  ExecutorDriver* driver,
148  const std::string& data) override;
149 
150  void shutdown(ExecutorDriver* driver) override;
151 
152  void error(ExecutorDriver* driver, const std::string& data) override;
153 
154  void killTask(
155  ExecutorDriver* driver,
156  const TaskID& taskId,
157  const Option<KillPolicy>& killPolicyOverride);
158 
159 private:
161 };
162 
163 } // namespace docker {
164 } // namespace internal {
165 } // namespace mesos {
166 
167 #endif // __DOCKER_EXECUTOR_HPP__
Definition: executor.hpp:147
Definition: flags.hpp:29
Definition: executor.hpp:114
Option< std::string > sandbox_directory
Definition: executor.hpp:98
Definition: duration.hpp:32
Option< std::string > docker
Definition: executor.hpp:96
Definition: agent.hpp:25
Option< Duration > stop_timeout
Definition: executor.hpp:107
Definition: executor.hpp:75
Option< std::string > mapped_directory
Definition: executor.hpp:99
Option< std::string > container
Definition: executor.hpp:95
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: attributes.hpp:24
Option< std::string > launcher_dir
Definition: executor.hpp:100
std::string error(const std::string &msg, uint32_t code)
Flags()
Definition: executor.hpp:42
void add(T1 Flags::*t1, const Name &name, const Option< Name > &alias, const std::string &help, const T2 *t2, F validate)
Definition: flags.hpp:333
Option< std::string > task_environment
Definition: executor.hpp:101
Option< std::string > default_container_dns
Definition: executor.hpp:102
Definition: spec.hpp:35
Definition: owned.hpp:36
bool cgroups_enable_cfs
Definition: executor.hpp:104
Definition: executor.hpp:40
Option< std::string > docker_socket
Definition: executor.hpp:97