Apache Mesos
health_checker.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 __HEALTH_CHECKER_HPP__
18 #define __HEALTH_CHECKER_HPP__
19 
20 #include <string>
21 #include <vector>
22 
23 #include <mesos/mesos.hpp>
24 
25 #include <process/http.hpp>
26 #include <process/owned.hpp>
27 
28 #include <stout/error.hpp>
29 #include <stout/lambda.hpp>
30 #include <stout/option.hpp>
31 
32 #include "messages/messages.hpp"
33 
34 namespace mesos {
35 namespace internal {
36 namespace checks {
37 
38 class CheckerProcess;
39 
40 
42 {
43 public:
69  const HealthCheck& healthCheck,
70  const std::string& launcherDir,
71  const lambda::function<void(const TaskHealthStatus&)>& callback,
72  const TaskID& taskId,
73  const Option<pid_t>& taskPid,
74  const std::vector<std::string>& namespaces);
75 
99  const HealthCheck& healthCheck,
100  const std::string& launcherDir,
101  const lambda::function<void(const TaskHealthStatus&)>& callback,
102  const TaskID& taskId,
103  const ContainerID& taskContainerId,
104  const process::http::URL& agentURL,
105  const Option<std::string>& authorizationHeader);
106 
107  ~HealthChecker();
108 
109  // Idempotent helpers for pausing and resuming health checking.
110  void pause();
111  void resume();
112 
113 private:
115  const HealthCheck& _healthCheck,
116  const TaskID& _taskId,
117  const lambda::function<void(const TaskHealthStatus&)>& _callback,
118  const std::string& launcherDir,
119  const Option<pid_t>& taskPid,
120  const std::vector<std::string>& namespaces,
121  const Option<ContainerID>& taskContainerId,
122  const Option<process::http::URL>& agentURL,
123  const Option<std::string>& authorizationHeader,
124  bool commandCheckViaAgent);
125 
126  void processCheckResult(const Try<CheckStatusInfo>& result);
127  void failure();
128  void success();
129 
130  const HealthCheck healthCheck;
131  const lambda::function<void(const TaskHealthStatus&)> callback;
132  const std::string name;
133  const process::Time startTime;
134  const TaskID taskId;
135 
136  Duration checkGracePeriod;
137  uint32_t consecutiveFailures;
138  bool initializing;
139 
141 };
142 
143 
144 namespace validation {
145 
146 // TODO(alexr): A better place for this function would be something like
147 // "mesos_validation.cpp", since it validates API protobuf which is not
148 // solely related to the health checking library.
149 Option<Error> healthCheck(const HealthCheck& check);
150 
151 } // namespace validation {
152 
153 } // namespace checks {
154 } // namespace internal {
155 } // namespace mesos {
156 
157 #endif // __HEALTH_CHECKER_HPP__
Definition: try.hpp:34
Try< Nothing > check()
Definition: duration.hpp:32
Option< Error > healthCheck(const HealthCheck &check)
Definition: http.hpp:129
Definition: time.hpp:23
std::set< std::string > namespaces()
Definition: owned.hpp:35
static Try< process::Owned< HealthChecker > > create(const HealthCheck &healthCheck, const std::string &launcherDir, const lambda::function< void(const TaskHealthStatus &)> &callback, const TaskID &taskId, const Option< pid_t > &taskPid, const std::vector< std::string > &namespaces)
Attempts to create a HealthChecker object.
Definition: health_checker.hpp:41