Apache Mesos
container_daemon.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 __SLAVE_CONTAINER_DAEMON_HPP__
18 #define __SLAVE_CONTAINER_DAEMON_HPP__
19 
20 #include <functional>
21 
22 #include <mesos/mesos.hpp>
23 #include <mesos/resources.hpp>
24 
25 #include <process/future.hpp>
26 #include <process/http.hpp>
27 #include <process/owned.hpp>
28 
29 #include <stout/duration.hpp>
30 #include <stout/option.hpp>
31 #include <stout/try.hpp>
32 
33 namespace mesos {
34 namespace internal {
35 namespace slave {
36 
37 // Forward declarations.
38 class ContainerDaemonProcess;
39 
40 
41 // A daemon that launches and monitors a service running in a standalone
42 // container, and automatically restarts the container when it exits.
43 //
44 // NOTE: The `ContainerDaemon` itself is not responsible to manage the
45 // lifecycle of the service container it monitors.
47 {
48 public:
49  // Creates a container daemon that idempotently launches the container
50  // and then run the `postStartHook` function. Upon container exits, it
51  // executes the `postStopHook` function, then restarts the launch
52  // cycle again. Any failed or discarded future returned by the hook
53  // functions will be reflected by the `wait()` method.
55  const process::http::URL& agentUrl,
56  const Option<std::string>& authToken,
57  const ContainerID& containerId,
58  const Option<CommandInfo>& commandInfo,
59  const Option<Resources>& resources,
60  const Option<ContainerInfo>& containerInfo,
61  const Option<std::function<process::Future<Nothing>()>>& postStartHook =
62  None(),
63  const Option<std::function<process::Future<Nothing>()>>& postStopHook =
64  None());
65 
67 
68  // Returns a future that only reaches a terminal state when a failure
69  // or a discarded future occurs during the launch cycle. This is
70  // intended to capture any loop-breaking error, and the caller should
71  // reconstruct a new daemon instance if they want to retry.
73 
74 private:
75  explicit ContainerDaemon(
76  const process::http::URL& agentUrl,
77  const Option<std::string>& authToken,
78  const ContainerID& containerId,
79  const Option<CommandInfo>& commandInfo,
80  const Option<Resources>& resources,
81  const Option<ContainerInfo>& containerInfo,
82  const Option<std::function<process::Future<Nothing>()>>& postStartHook,
83  const Option<std::function<process::Future<Nothing>()>>& postStopHook);
84 
86 };
87 
88 } // namespace slave {
89 } // namespace internal {
90 } // namespace mesos {
91 
92 #endif // __SLAVE_CONTAINER_DAEMON_HPP__
Definition: check.hpp:33
static Try< process::Owned< ContainerDaemon > > create(const process::http::URL &agentUrl, const Option< std::string > &authToken, const ContainerID &containerId, const Option< CommandInfo > &commandInfo, const Option< Resources > &resources, const Option< ContainerInfo > &containerInfo, const Option< std::function< process::Future< Nothing >()>> &postStartHook=None(), const Option< std::function< process::Future< Nothing >()>> &postStopHook=None())
process::Future< Nothing > wait()
Definition: container_daemon.hpp:46
Definition: http.hpp:130
Definition: agent.hpp:25
Definition: none.hpp:27
Definition: attributes.hpp:24
Definition: executor.hpp:48
Definition: owned.hpp:36