Apache Mesos
checker_process.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 __CHECKER_PROCESS_HPP__
18 #define __CHECKER_PROCESS_HPP__
19 
20 #include <memory>
21 #include <string>
22 #include <tuple>
23 #include <vector>
24 
25 #include <mesos/mesos.hpp>
26 
27 #include <process/future.hpp>
28 #include <process/http.hpp>
29 #include <process/protobuf.hpp>
30 
31 #include <stout/duration.hpp>
32 #include <stout/option.hpp>
33 #include <stout/stopwatch.hpp>
34 #include <stout/try.hpp>
35 
36 namespace mesos {
37 namespace internal {
38 namespace checks {
39 
40 class CheckerProcess : public ProtobufProcess<CheckerProcess>
41 {
42 public:
43  // TODO(gkleiman): Instead of passing an optional scheme as a parameter,
44  // consider introducing a global `TLSInfo` protobuf and using it in HTTP
45  // checks. See MESOS-7356.
47  const CheckInfo& _check,
48  const std::string& _launcherDir,
49  const lambda::function<void(const Try<CheckStatusInfo>&)>& _callback,
50  const TaskID& _taskId,
51  const Option<pid_t>& _taskPid,
52  const std::vector<std::string>& _namespaces,
53  const Option<ContainerID>& _taskContainerId,
54  const Option<process::http::URL>& _agentURL,
55  const Option<std::string>& _authorizationHeader,
56  const Option<std::string>& _scheme,
57  const std::string& _name,
58  bool _commandCheckViaAgent,
59  bool _ipv6 = false);
60 
61  void pause();
62  void resume();
63 
64  virtual ~CheckerProcess() {}
65 
66 protected:
67  void initialize() override;
68  void finalize() override;
69 
70 private:
71  void performCheck();
72  void scheduleNext(const Duration& duration);
73  void processCheckResult(
74  const Stopwatch& stopwatch,
75  const Result<CheckStatusInfo>& result);
76 
77  process::Future<int> commandCheck();
78 
79  process::Future<int> nestedCommandCheck();
80  void _nestedCommandCheck(std::shared_ptr<process::Promise<int>> promise);
81  void __nestedCommandCheck(
82  std::shared_ptr<process::Promise<int>> promise,
83  process::http::Connection connection);
84  void ___nestedCommandCheck(
85  std::shared_ptr<process::Promise<int>> promise,
86  const ContainerID& checkContainerId,
87  const process::http::Response& launchResponse);
88 
89  void nestedCommandCheckFailure(
90  std::shared_ptr<process::Promise<int>> promise,
91  process::http::Connection connection,
92  const ContainerID& checkContainerId,
93  std::shared_ptr<bool> checkTimedOut,
94  const std::string& failure);
95 
96  process::Future<Option<int>> waitNestedContainer(
97  const ContainerID& containerId);
98  process::Future<Option<int>> _waitNestedContainer(
99  const ContainerID& containerId,
100  const process::http::Response& httpResponse);
101 
102  void processCommandCheckResult(
103  const Stopwatch& stopwatch,
104  const process::Future<int>& future);
105 
106  process::Future<int> httpCheck();
107  process::Future<int> _httpCheck(
108  const std::tuple<process::Future<Option<int>>,
111  void processHttpCheckResult(
112  const Stopwatch& stopwatch,
113  const process::Future<int>& future);
114 
115  process::Future<bool> tcpCheck();
116  process::Future<bool> _tcpCheck(
117  const std::tuple<process::Future<Option<int>>,
120  void processTcpCheckResult(
121  const Stopwatch& stopwatch,
122  const process::Future<bool>& future);
123 
124  const CheckInfo check;
125  Duration checkDelay;
126  Duration checkInterval;
127  Duration checkTimeout;
128 
129  // Contains the binary for TCP checks.
130  const std::string launcherDir;
131 
132  const lambda::function<void(const Try<CheckStatusInfo>&)> updateCallback;
133  const TaskID taskId;
134  const Option<pid_t> taskPid;
135  const std::vector<std::string> namespaces;
136  const Option<ContainerID> taskContainerId;
137  const Option<process::http::URL> agentURL;
138  const Option<std::string> authorizationHeader;
139  const Option<std::string> scheme;
140  const std::string name;
141  const bool commandCheckViaAgent;
142 
143  // If set to true, the TCP/HTTP(S) check will be performed over IPv6,
144  // otherwise, it will be performed over IPv4.
145  //
146  // TODO(qianzhang): Once we figure out how the IPv4/IPv6 should be supported
147  // in the health check API (i.e., the `CheckInfo` protobuf message), we may
148  // consider to remove this field which is a temporary solution for now.
149  const bool ipv6;
150 
152 
153  bool paused;
154 
155  // Contains the ID of the most recently terminated nested container
156  // that was used to perform a COMMAND check.
157  Option<ContainerID> previousCheckContainerId;
158 };
159 
160 } // namespace checks {
161 } // namespace internal {
162 } // namespace mesos {
163 
164 #endif // __CHECKER_PROCESS_HPP__
Definition: try.hpp:34
CheckerProcess(const CheckInfo &_check, const std::string &_launcherDir, const lambda::function< void(const Try< CheckStatusInfo > &)> &_callback, const TaskID &_taskId, const Option< pid_t > &_taskPid, const std::vector< std::string > &_namespaces, const Option< ContainerID > &_taskContainerId, const Option< process::http::URL > &_agentURL, const Option< std::string > &_authorizationHeader, const Option< std::string > &_scheme, const std::string &_name, bool _commandCheckViaAgent, bool _ipv6=false)
virtual ~CheckerProcess()
Definition: checker_process.hpp:64
Definition: stopwatch.hpp:30
Definition: duration.hpp:32
Definition: result.hpp:40
Definition: future.hpp:73
Protocol< PromiseRequest, PromiseResponse > promise
Definition: protobuf.hpp:100
void finalize() override
Invoked when a process is terminated.
Definition: http.hpp:595
void initialize() override
Invoked when a process gets spawned.
Definition: checker_process.hpp:40
Represents a connection to an HTTP server.
Definition: http.hpp:945
Definition: future.hpp:57