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
56  const process::http::Request& request,
58 
59  // /slave/flags
61  const process::http::Request& request,
63 
64  // /slave/health
66  const process::http::Request& request) const;
67 
68  // /slave/state
70  const process::http::Request& request,
72 
73  // /slave/monitor/statistics
75  const process::http::Request& request,
77 
78  // /slave/containers
80  const process::http::Request& request,
82 
83  static std::string API_HELP();
84  static std::string EXECUTOR_HELP();
85  static std::string RESOURCE_PROVIDER_HELP();
86  static std::string FLAGS_HELP();
87  static std::string HEALTH_HELP();
88  static std::string STATE_HELP();
89  static std::string STATISTICS_HELP();
90  static std::string CONTAINERS_HELP();
91 
92 private:
93  JSON::Object _flags() const;
94 
95  // Continuation for `/api` endpoint that handles streaming and non-streaming
96  // requests. In case of a streaming request, `call` would be the first
97  // record and additional records can be read using the `reader`. For
98  // non-streaming requests, `reader` would be set to `None()`.
100  const agent::Call& call,
102  const RequestMediaTypes& mediaTypes,
103  const Option<process::http::authentication::Principal>& principal) const;
104 
105  // Make continuation for `statistics` `static` as it might
106  // execute when the invoking `Http` is already destructed.
107  process::http::Response _statistics(
108  const ResourceUsage& usage,
109  const process::http::Request& request) const;
110 
111  // Continuation for `/containers` endpoint
113  const process::http::Request& request,
114  const Option<process::http::authentication::Principal>& principal) const;
115 
116  // Helper function to collect containers status and resource statistics.
117  process::Future<JSON::Array> __containers(
118  const process::Owned<ObjectApprovers>& approvers,
119  Option<IDAcceptor<ContainerID>> selectContainerId,
120  bool showNestedContainers,
121  bool showStandaloneContainers) const;
122 
123  // Helper routines for endpoint authorization.
124  Try<std::string> extractEndpoint(const process::http::URL& url) const;
125 
126  // Agent API handlers.
128  const mesos::agent::Call& call,
129  ContentType acceptType,
130  const Option<process::http::authentication::Principal>& principal) const;
131 
133  const mesos::agent::Call& call,
134  ContentType acceptType,
135  const Option<process::http::authentication::Principal>& principal) const;
136 
138  const mesos::agent::Call& call,
139  ContentType acceptType,
140  const Option<process::http::authentication::Principal>& principal) const;
141 
143  const mesos::agent::Call& call,
144  ContentType acceptType,
145  const Option<process::http::authentication::Principal>& principal) const;
146 
148  const mesos::agent::Call& call,
149  ContentType acceptType,
150  const Option<process::http::authentication::Principal>& principal) const;
151 
153  const mesos::agent::Call& call,
154  ContentType acceptType,
155  const Option<process::http::authentication::Principal>& principal) const;
156 
158  const mesos::agent::Call& call,
159  ContentType acceptType,
160  const Option<process::http::authentication::Principal>& principal) const;
161 
163  const mesos::agent::Call& call,
164  ContentType acceptType,
165  const Option<process::http::authentication::Principal>& principal) const;
166 
168  const mesos::agent::Call& call,
169  ContentType acceptType,
170  const Option<process::http::authentication::Principal>& principal) const;
171 
173  const mesos::agent::Call& call,
174  ContentType acceptType,
175  const Option<process::http::authentication::Principal>& principal) const;
176 
177  mesos::agent::Response::GetFrameworks _getFrameworks(
178  const process::Owned<ObjectApprovers>& approvers ) const;
179 
181  const mesos::agent::Call& call,
182  ContentType acceptType,
183  const Option<process::http::authentication::Principal>& principal) const;
184 
185  mesos::agent::Response::GetExecutors _getExecutors(
186  const process::Owned<ObjectApprovers>& approvers) const;
187 
189  const mesos::agent::Call& call,
190  ContentType acceptType,
191  const Option<process::http::authentication::Principal>& principal) const;
192 
194  const mesos::agent::Call& call,
195  ContentType acceptType,
196  const Option<process::http::authentication::Principal>& principal) const;
197 
198  mesos::agent::Response::GetTasks _getTasks(
199  const process::Owned<ObjectApprovers>& approvers) 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<ObjectApprovers>& approvers) const;
218 
219  process::Future<process::http::Response> launchNestedContainer(
220  const mesos::agent::Call& call,
221  ContentType acceptType,
222  const Option<process::http::authentication::Principal>& principal) const;
223 
225  const mesos::agent::Call& call,
226  ContentType acceptType,
227  const Option<process::http::authentication::Principal>& principal) const;
228 
229  template <mesos::authorization::Action action>
231  const mesos::agent::Call& call,
232  ContentType acceptType,
233  const Option<process::http::authentication::Principal>& principal) const;
234 
235  template <mesos::authorization::Action action>
237  const ContainerID& containerId,
238  const CommandInfo& commandInfo,
239  const Option<Resources>& resources,
240  const Option<ContainerInfo>& containerInfo,
241  const Option<mesos::slave::ContainerClass>& containerClass,
242  ContentType acceptType,
243  const process::Owned<ObjectApprovers>& approvers) const;
244 
245  process::Future<process::http::Response> waitNestedContainer(
246  const mesos::agent::Call& call,
247  ContentType acceptType,
248  const Option<process::http::authentication::Principal>& principal) const;
249 
251  const mesos::agent::Call& call,
252  ContentType acceptType,
253  const Option<process::http::authentication::Principal>& principal) const;
254 
255  template <authorization::Action action>
257  const mesos::agent::Call& call,
258  ContentType acceptType,
259  const Option<process::http::authentication::Principal>& principal) const;
260 
261  template <authorization::Action action>
263  const ContainerID& containerId,
264  ContentType acceptType,
265  const process::Owned<ObjectApprovers>& approvers,
266  const bool deprecated) const;
267 
268  process::Future<process::http::Response> killNestedContainer(
269  const mesos::agent::Call& call,
270  ContentType acceptType,
271  const Option<process::http::authentication::Principal>& principal) const;
272 
274  const mesos::agent::Call& call,
275  ContentType acceptType,
276  const Option<process::http::authentication::Principal>& principal) const;
277 
278  template <mesos::authorization::Action ACTION>
280  const mesos::agent::Call& call,
281  ContentType acceptType,
282  const Option<process::http::authentication::Principal>& principal) const;
283 
284  template <mesos::authorization::Action ACTION>
286  const ContainerID& containerId,
287  const int signal,
288  ContentType acceptType,
289  const process::Owned<ObjectApprovers>& approvers) const;
290 
291  process::Future<process::http::Response> removeNestedContainer(
292  const mesos::agent::Call& call,
293  ContentType acceptType,
294  const Option<process::http::authentication::Principal>& principal) const;
295 
297  const mesos::agent::Call& call,
298  ContentType acceptType,
299  const Option<process::http::authentication::Principal>& principal) const;
300 
301  template <mesos::authorization::Action ACTION>
303  const mesos::agent::Call& call,
304  ContentType acceptType,
305  const Option<process::http::authentication::Principal>& principal) const;
306 
307  template <mesos::authorization::Action ACTION>
309  const ContainerID& containerId,
310  ContentType acceptType,
311  const process::Owned<ObjectApprovers>& approvers) const;
312 
313  process::Future<process::http::Response> launchNestedContainerSession(
314  const mesos::agent::Call& call,
315  const RequestMediaTypes& mediaTypes,
316  const Option<process::http::authentication::Principal>& principal) const;
317 
318  process::Future<process::http::Response> attachContainerInput(
319  const mesos::agent::Call& call,
321  const RequestMediaTypes& mediaTypes,
322  const Option<process::http::authentication::Principal>& principal) const;
323 
324  process::Future<process::http::Response> _attachContainerInput(
325  const mesos::agent::Call& call,
327  const RequestMediaTypes& mediaTypes) const;
328 
329  process::Future<process::http::Response> acknowledgeContainerInputResponse(
330  const ContainerID& containerId) const;
331 
332  process::Future<process::http::Response> attachContainerOutput(
333  const mesos::agent::Call& call,
334  const RequestMediaTypes& mediaTypes,
335  const Option<process::http::authentication::Principal>& principal) const;
336 
337  process::Future<process::http::Response> _attachContainerOutput(
338  const mesos::agent::Call& call,
339  const RequestMediaTypes& mediaTypes) const;
340 
341  process::Future<process::http::Response> addResourceProviderConfig(
342  const mesos::agent::Call& call,
343  const Option<process::http::authentication::Principal>& principal) const;
344 
345  process::Future<process::http::Response> updateResourceProviderConfig(
346  const mesos::agent::Call& call,
347  const Option<process::http::authentication::Principal>& principal) const;
348 
349  process::Future<process::http::Response> removeResourceProviderConfig(
350  const mesos::agent::Call& call,
351  const Option<process::http::authentication::Principal>& principal) const;
352 
354  const mesos::agent::Call& call,
355  ContentType acceptType,
357  principal) const;
358 
359  Slave* slave;
360 
361  // Used to rate limit the statistics endpoint.
362  process::Shared<process::RateLimiter> statisticsLimiter;
363 };
364 
365 } // namespace slave {
366 } // namespace internal {
367 } // namespace mesos {
368 
369 #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: check.hpp:33
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:2616
static std::string STATISTICS_HELP()
Definition: http.hpp:520
static std::string STATE_HELP()
Definition: json.hpp:158
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:285
Definition: slave.hpp:115
Definition: http.hpp:129
Definition: http.hpp:86
Definition: duration.hpp:207
Definition: spec.hpp:26
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
process::Future< process::http::Response > health(const process::http::Request &request) const
Definition: attributes.hpp:24
Definition: executor.hpp:48
Definition: http.hpp:599
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:36
process::Future< process::http::Response > flags(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const