Apache Mesos
http.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_HTTP_HPP__
18 #define __SLAVE_HTTP_HPP__
19 
21 #include <process/http.hpp>
22 #include <process/future.hpp>
23 #include <process/owned.hpp>
24 #include <process/limiter.hpp>
25 
26 #include <stout/json.hpp>
27 #include <stout/option.hpp>
28 
30 
31 #include "common/http.hpp"
32 
33 namespace mesos {
34 namespace internal {
35 namespace slave {
36 
37 // Forward declarations.
38 class Slave;
39 
40 
41 // HTTP route handlers.
42 class Http
43 {
44 public:
45  explicit Http(Slave* _slave)
46  : slave(_slave),
47  statisticsLimiter(new process::RateLimiter(2, Seconds(1))) {}
48 
49  // /api/v1
53 
54  // /api/v1/executor
58 
59  // /slave/flags
63 
64  // /slave/health
66  const process::http::Request& request) const;
67 
68  // /slave/state
72 
73  // /slave/monitor/statistics
74  // /slave/monitor/statistics.json
78 
79  // /slave/containers
83 
84  static std::string API_HELP();
85  static std::string EXECUTOR_HELP();
86  static std::string RESOURCE_PROVIDER_HELP();
87  static std::string FLAGS_HELP();
88  static std::string HEALTH_HELP();
89  static std::string STATE_HELP();
90  static std::string STATISTICS_HELP();
91  static std::string CONTAINERS_HELP();
92 
93 private:
94  JSON::Object _flags() const;
95 
96  // Continuation for `/api` endpoint that handles streaming and non-streaming
97  // requests. In case of a streaming request, `call` would be the first
98  // record and additional records can be read using the `reader`. For
99  // non-streaming requests, `reader` would be set to `None()`.
101  const agent::Call& call,
103  const RequestMediaTypes& mediaTypes,
104  const Option<process::http::authentication::Principal>& principal) const;
105 
106  // Make continuation for `statistics` `static` as it might
107  // execute when the invoking `Http` is already destructed.
108  process::http::Response _statistics(
109  const ResourceUsage& usage,
110  const process::http::Request& request) const;
111 
112  // Continuation for `/containers` endpoint
115  const Option<process::http::authentication::Principal>& principal) const;
116 
117  // Helper function to collect containers status and resource statistics.
118  process::Future<JSON::Array> __containers(
119  process::Owned<AuthorizationAcceptor> authorizeContainer,
120  process::Owned<AuthorizationAcceptor> authorizeStandaloneContainer,
121  Option<IDAcceptor<ContainerID>> selectContainerId,
122  bool showNestedContainers,
123  bool showStandaloneContainers) const;
124 
125  // Helper routines for endpoint authorization.
126  Try<std::string> extractEndpoint(const process::http::URL& url) const;
127 
128  // Agent API handlers.
130  const mesos::agent::Call& call,
131  ContentType acceptType,
132  const Option<process::http::authentication::Principal>& principal) const;
133 
135  const mesos::agent::Call& call,
136  ContentType acceptType,
137  const Option<process::http::authentication::Principal>& principal) const;
138 
140  const mesos::agent::Call& call,
141  ContentType acceptType,
142  const Option<process::http::authentication::Principal>& principal) const;
143 
145  const mesos::agent::Call& call,
146  ContentType acceptType,
147  const Option<process::http::authentication::Principal>& principal) const;
148 
150  const mesos::agent::Call& call,
151  ContentType acceptType,
152  const Option<process::http::authentication::Principal>& principal) const;
153 
155  const mesos::agent::Call& call,
156  ContentType acceptType,
157  const Option<process::http::authentication::Principal>& principal) const;
158 
160  const mesos::agent::Call& call,
161  ContentType acceptType,
162  const Option<process::http::authentication::Principal>& principal) const;
163 
165  const mesos::agent::Call& call,
166  ContentType acceptType,
167  const Option<process::http::authentication::Principal>& principal) const;
168 
170  const mesos::agent::Call& call,
171  ContentType acceptType,
172  const Option<process::http::authentication::Principal>& principal) const;
173 
175  const mesos::agent::Call& call,
176  ContentType acceptType,
177  const Option<process::http::authentication::Principal>& principal) const;
178 
179  mesos::agent::Response::GetFrameworks _getFrameworks(
180  const process::Owned<ObjectApprover>& frameworksApprover) const;
181 
183  const mesos::agent::Call& call,
184  ContentType acceptType,
185  const Option<process::http::authentication::Principal>& principal) const;
186 
187  mesos::agent::Response::GetExecutors _getExecutors(
188  const process::Owned<ObjectApprover>& frameworksApprover,
189  const process::Owned<ObjectApprover>& executorsApprover) const;
190 
192  const mesos::agent::Call& call,
193  ContentType acceptType,
194  const Option<process::http::authentication::Principal>& principal) const;
195 
196  mesos::agent::Response::GetTasks _getTasks(
197  const process::Owned<ObjectApprover>& frameworksApprover,
198  const process::Owned<ObjectApprover>& tasksApprover,
199  const process::Owned<ObjectApprover>& executorsApprover) const;
200 
202  const mesos::agent::Call& call,
203  ContentType acceptType,
204  const Option<process::http::authentication::Principal>& principal) const;
205 
206  process::Future<process::http::Response> getResourceProviders(
207  const mesos::agent::Call& call,
208  ContentType acceptType,
209  const Option<process::http::authentication::Principal>& principal) const;
210 
212  const mesos::agent::Call& call,
213  ContentType acceptType,
214  const Option<process::http::authentication::Principal>& principal) const;
215 
216  mesos::agent::Response::GetState _getState(
217  const process::Owned<ObjectApprover>& frameworksApprover,
218  const process::Owned<ObjectApprover>& taskApprover,
219  const process::Owned<ObjectApprover>& executorsApprover) const;
220 
221  process::Future<process::http::Response> launchNestedContainer(
222  const mesos::agent::Call& call,
223  ContentType acceptType,
224  const Option<process::http::authentication::Principal>& principal) const;
225 
227  const mesos::agent::Call& call,
228  ContentType acceptType,
229  const Option<process::http::authentication::Principal>& principal) const;
230 
232  const ContainerID& containerId,
233  const CommandInfo& commandInfo,
234  const Option<Resources>& resources,
235  const Option<ContainerInfo>& containerInfo,
236  const Option<mesos::slave::ContainerClass>& containerClass,
237  ContentType acceptType,
238  const process::Owned<AuthorizationAcceptor>& authorizer) const;
239 
240  process::Future<process::http::Response> waitNestedContainer(
241  const mesos::agent::Call& call,
242  ContentType acceptType,
243  const Option<process::http::authentication::Principal>& principal) const;
244 
246  const mesos::agent::Call& call,
247  ContentType acceptType,
248  const Option<process::http::authentication::Principal>& principal) const;
249 
251  const ContainerID& containerId,
252  ContentType acceptType,
253  const process::Owned<AuthorizationAcceptor>& authorizer,
254  const bool deprecated) const;
255 
256  process::Future<process::http::Response> killNestedContainer(
257  const mesos::agent::Call& call,
258  ContentType acceptType,
259  const Option<process::http::authentication::Principal>& principal) const;
260 
262  const mesos::agent::Call& call,
263  ContentType acceptType,
264  const Option<process::http::authentication::Principal>& principal) const;
265 
267  const ContainerID& containerId,
268  const int signal,
269  ContentType acceptType,
270  const process::Owned<AuthorizationAcceptor>& authorizer) const;
271 
272  process::Future<process::http::Response> removeNestedContainer(
273  const mesos::agent::Call& call,
274  ContentType acceptType,
275  const Option<process::http::authentication::Principal>& principal) const;
276 
278  const mesos::agent::Call& call,
279  ContentType acceptType,
280  const Option<process::http::authentication::Principal>& principal) const;
281 
283  const ContainerID& containerId,
284  ContentType acceptType,
285  const process::Owned<AuthorizationAcceptor>& authorizer) const;
286 
287  process::Future<process::http::Response> launchNestedContainerSession(
288  const mesos::agent::Call& call,
289  const RequestMediaTypes& mediaTypes,
290  const Option<process::http::authentication::Principal>& principal) const;
291 
292  process::Future<process::http::Response> attachContainerInput(
293  const mesos::agent::Call& call,
295  const RequestMediaTypes& mediaTypes,
296  const Option<process::http::authentication::Principal>& principal) const;
297 
298  process::Future<process::http::Response> _attachContainerInput(
299  const mesos::agent::Call& call,
301  const RequestMediaTypes& mediaTypes) const;
302 
303  process::Future<process::http::Response> attachContainerOutput(
304  const mesos::agent::Call& call,
305  const RequestMediaTypes& mediaTypes,
306  const Option<process::http::authentication::Principal>& principal) const;
307 
308  process::Future<process::http::Response> _attachContainerOutput(
309  const mesos::agent::Call& call,
310  const RequestMediaTypes& mediaTypes) const;
311 
312  process::Future<process::http::Response> addResourceProviderConfig(
313  const mesos::agent::Call& call,
314  const Option<process::http::authentication::Principal>& principal) const;
315 
316  process::Future<process::http::Response> updateResourceProviderConfig(
317  const mesos::agent::Call& call,
318  const Option<process::http::authentication::Principal>& principal) const;
319 
320  process::Future<process::http::Response> removeResourceProviderConfig(
321  const mesos::agent::Call& call,
322  const Option<process::http::authentication::Principal>& principal) const;
323 
325  const mesos::agent::Call& call,
326  ContentType acceptType,
328  principal) const;
329 
330  Slave* slave;
331 
332  // Used to rate limit the statistics endpoint.
333  process::Shared<process::RateLimiter> statisticsLimiter;
334 };
335 
336 } // namespace slave {
337 } // namespace internal {
338 } // namespace mesos {
339 
340 #endif // __SLAVE_HTTP_HPP__
ContentType
Definition: http.hpp:43
Definition: http.hpp:42
process::Future< process::http::Response > statistics(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
Definition: try.hpp:34
process::Future< process::http::Response > state(const process::http::Request &request, const Option< process::http::authentication::Principal > &) const
mesos::v1::scheduler::Call Call
Definition: mesos.hpp:2583
static std::string STATISTICS_HELP()
Definition: http.hpp:518
static std::string STATE_HELP()
Definition: json.hpp:154
static std::string HEALTH_HELP()
Try< ResourceStatistics > usage(pid_t pid, bool mem=true, bool cpus=true)
Provides RecordIO decoding on top of an http::Pipe::Reader.
Definition: recordio.hpp:62
static std::string API_HELP()
Used to filter results for API handlers.
Definition: http.hpp:206
Definition: slave.hpp:115
Definition: http.hpp:129
Definition: http.hpp:63
Definition: duration.hpp:259
static std::string CONTAINERS_HELP()
process::Future< process::http::Response > api(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
static std::string EXECUTOR_HELP()
process::Future< process::http::Response > executor(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
process::Future< process::http::Response > health(const process::http::Request &request) const
Definition: http.hpp:595
static std::string FLAGS_HELP()
static std::string RESOURCE_PROVIDER_HELP()
process::Future< process::http::Response > containers(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
Http(Slave *_slave)
Definition: http.hpp:45
Definition: owned.hpp:35
process::Future< process::http::Response > flags(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
Definition: future.hpp:57