Apache Mesos
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 __CHECKER_HPP__
18 #define __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 #include <stout/try.hpp>
32 
33 namespace mesos {
34 namespace internal {
35 namespace checks {
36 
37 class CheckerProcess;
38 
39 
40 class Checker
41 {
42 public:
65  const CheckInfo& check,
66  const std::string& launcherDir,
67  const lambda::function<void(const CheckStatusInfo&)>& callback,
68  const TaskID& taskId,
69  const Option<pid_t>& taskPid,
70  const std::vector<std::string>& namespaces);
71 
96  const CheckInfo& check,
97  const std::string& launcherDir,
98  const lambda::function<void(const CheckStatusInfo&)>& callback,
99  const TaskID& taskId,
100  const ContainerID& taskContainerId,
101  const process::http::URL& agentURL,
102  const Option<std::string>& authorizationHeader);
103 
104  ~Checker();
105 
106  // Not copyable, not assignable.
107  Checker(const Checker&) = delete;
108  Checker& operator=(const Checker&) = delete;
109 
110  // Idempotent helpers for pausing and resuming checking.
111  void pause();
112  void resume();
113 
114 private:
115  Checker(
116  const CheckInfo& _check,
117  const std::string& _launcherDir,
118  const lambda::function<void(const CheckStatusInfo&)>& _callback,
119  const TaskID& _taskId,
120  const Option<pid_t>& taskPid,
121  const std::vector<std::string>& _namespaces,
122  const Option<ContainerID>& _taskContainerId,
123  const Option<process::http::URL>& _agentURL,
124  const Option<std::string>& _authorizationHeader,
125  bool _commandCheckViaAgent);
126 
127  void processCheckResult(const Try<CheckStatusInfo>& result);
128 
129  const CheckInfo check;
130  const lambda::function<void(const CheckStatusInfo&)> callback;
131  const std::string name;
132  const TaskID taskId;
133 
134  CheckStatusInfo previousCheckStatus;
136 };
137 
138 namespace validation {
139 
140 // TODO(alexr): A better place for these functions would be something like
141 // "mesos_validation.cpp", since they validate API protobufs which are not
142 // solely related to this library.
143 Option<Error> checkInfo(const CheckInfo& checkInfo);
144 Option<Error> checkStatusInfo(const CheckStatusInfo& checkStatusInfo);
145 
146 } // namespace validation {
147 
148 } // namespace checks {
149 } // namespace internal {
150 } // namespace mesos {
151 
152 #endif // __CHECKER_HPP__
Definition: checker.hpp:40
Definition: try.hpp:34
Checker & operator=(const Checker &)=delete
Definition: http.hpp:129
Option< Error > checkInfo(const CheckInfo &checkInfo)
Checker(const Checker &)=delete
std::set< std::string > namespaces()
static Try< process::Owned< Checker > > create(const CheckInfo &check, const std::string &launcherDir, const lambda::function< void(const CheckStatusInfo &)> &callback, const TaskID &taskId, const Option< pid_t > &taskPid, const std::vector< std::string > &namespaces)
Attempts to create a Checker object.
Definition: checker_process.hpp:40
Definition: owned.hpp:35
Option< Error > checkStatusInfo(const CheckStatusInfo &checkStatusInfo)