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
74  // /slave/monitor/statistics.json
76  const process::http::Request& request,
78 
79  // /slave/containers
81  const process::http::Request& request,
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
114  const process::http::Request& request,
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  const process::Owned<ObjectApprovers>& approvers,
120  Option<IDAcceptor<ContainerID>> selectContainerId,
121  bool showNestedContainers,
122  bool showStandaloneContainers) const;
123 
124  // Helper routines for endpoint authorization.
125  Try<std::string> extractEndpoint(const process::http::URL& url) const;
126 
127  // Agent API handlers.
129  const mesos::agent::Call& call,
130  ContentType acceptType,
131  const Option<process::http::authentication::Principal>& principal) const;
132 
134  const mesos::agent::Call& call,
135  ContentType acceptType,
136  const Option<process::http::authentication::Principal>& principal) const;
137 
139  const mesos::agent::Call& call,
140  ContentType acceptType,
141  const Option<process::http::authentication::Principal>& principal) const;
142 
144  const mesos::agent::Call& call,
145  ContentType acceptType,
146  const Option<process::http::authentication::Principal>& principal) const;
147 
149  const mesos::agent::Call& call,
150  ContentType acceptType,
151  const Option<process::http::authentication::Principal>& principal) const;
152 
154  const mesos::agent::Call& call,
155  ContentType acceptType,
156  const Option<process::http::authentication::Principal>& principal) const;
157 
159  const mesos::agent::Call& call,
160  ContentType acceptType,
161  const Option<process::http::authentication::Principal>& principal) const;
162 
164  const mesos::agent::Call& call,
165  ContentType acceptType,
166  const Option<process::http::authentication::Principal>& principal) const;
167 
169  const mesos::agent::Call& call,
170  ContentType acceptType,
171  const Option<process::http::authentication::Principal>& principal) const;
172 
174  const mesos::agent::Call& call,
175  ContentType acceptType,
176  const Option<process::http::authentication::Principal>& principal) const;
177 
178  mesos::agent::Response::GetFrameworks _getFrameworks(
179  const process::Owned<ObjectApprovers>& approvers ) const;
180 
182  const mesos::agent::Call& call,
183  ContentType acceptType,
184  const Option<process::http::authentication::Principal>& principal) const;
185 
186  mesos::agent::Response::GetExecutors _getExecutors(
187  const process::Owned<ObjectApprovers>& approvers) const;
188 
190  const mesos::agent::Call& call,
191  ContentType acceptType,
192  const Option<process::http::authentication::Principal>& principal) const;
193 
195  const mesos::agent::Call& call,
196  ContentType acceptType,
197  const Option<process::http::authentication::Principal>& principal) const;
198 
199  mesos::agent::Response::GetTasks _getTasks(
200  const process::Owned<ObjectApprovers>& approvers) const;
201 
203  const mesos::agent::Call& call,
204  ContentType acceptType,
205  const Option<process::http::authentication::Principal>& principal) const;
206 
207  process::Future<process::http::Response> getResourceProviders(
208  const mesos::agent::Call& call,
209  ContentType acceptType,
210  const Option<process::http::authentication::Principal>& principal) const;
211 
213  const mesos::agent::Call& call,
214  ContentType acceptType,
215  const Option<process::http::authentication::Principal>& principal) const;
216 
217  mesos::agent::Response::GetState _getState(
218  const process::Owned<ObjectApprovers>& approvers) const;
219 
220  process::Future<process::http::Response> launchNestedContainer(
221  const mesos::agent::Call& call,
222  ContentType acceptType,
223  const Option<process::http::authentication::Principal>& principal) const;
224 
226  const mesos::agent::Call& call,
227  ContentType acceptType,
228  const Option<process::http::authentication::Principal>& principal) const;
229 
230  template <mesos::authorization::Action action>
232  const mesos::agent::Call& call,
233  ContentType acceptType,
234  const Option<process::http::authentication::Principal>& principal) const;
235 
236  template <mesos::authorization::Action action>
238  const ContainerID& containerId,
239  const CommandInfo& commandInfo,
240  const Option<Resources>& resources,
241  const Option<ContainerInfo>& containerInfo,
242  const Option<mesos::slave::ContainerClass>& containerClass,
243  ContentType acceptType,
244  const process::Owned<ObjectApprovers>& approvers) const;
245 
246  process::Future<process::http::Response> waitNestedContainer(
247  const mesos::agent::Call& call,
248  ContentType acceptType,
249  const Option<process::http::authentication::Principal>& principal) const;
250 
252  const mesos::agent::Call& call,
253  ContentType acceptType,
254  const Option<process::http::authentication::Principal>& principal) const;
255 
256  template <authorization::Action action>
258  const mesos::agent::Call& call,
259  ContentType acceptType,
260  const Option<process::http::authentication::Principal>& principal) const;
261 
262  template <authorization::Action action>
264  const ContainerID& containerId,
265  ContentType acceptType,
266  const process::Owned<ObjectApprovers>& approvers,
267  const bool deprecated) const;
268 
269  process::Future<process::http::Response> killNestedContainer(
270  const mesos::agent::Call& call,
271  ContentType acceptType,
272  const Option<process::http::authentication::Principal>& principal) const;
273 
275  const mesos::agent::Call& call,
276  ContentType acceptType,
277  const Option<process::http::authentication::Principal>& principal) const;
278 
279  template <mesos::authorization::Action ACTION>
281  const mesos::agent::Call& call,
282  ContentType acceptType,
283  const Option<process::http::authentication::Principal>& principal) const;
284 
285  template <mesos::authorization::Action ACTION>
287  const ContainerID& containerId,
288  const int signal,
289  ContentType acceptType,
290  const process::Owned<ObjectApprovers>& approvers) const;
291 
292  process::Future<process::http::Response> removeNestedContainer(
293  const mesos::agent::Call& call,
294  ContentType acceptType,
295  const Option<process::http::authentication::Principal>& principal) const;
296 
298  const mesos::agent::Call& call,
299  ContentType acceptType,
300  const Option<process::http::authentication::Principal>& principal) const;
301 
302  template <mesos::authorization::Action ACTION>
304  const mesos::agent::Call& call,
305  ContentType acceptType,
306  const Option<process::http::authentication::Principal>& principal) const;
307 
308  template <mesos::authorization::Action ACTION>
310  const ContainerID& containerId,
311  ContentType acceptType,
312  const process::Owned<ObjectApprovers>& approvers) const;
313 
314  process::Future<process::http::Response> launchNestedContainerSession(
315  const mesos::agent::Call& call,
316  const RequestMediaTypes& mediaTypes,
317  const Option<process::http::authentication::Principal>& principal) const;
318 
319  process::Future<process::http::Response> attachContainerInput(
320  const mesos::agent::Call& call,
322  const RequestMediaTypes& mediaTypes,
323  const Option<process::http::authentication::Principal>& principal) const;
324 
325  process::Future<process::http::Response> _attachContainerInput(
326  const mesos::agent::Call& call,
328  const RequestMediaTypes& mediaTypes) const;
329 
330  process::Future<process::http::Response> attachContainerOutput(
331  const mesos::agent::Call& call,
332  const RequestMediaTypes& mediaTypes,
333  const Option<process::http::authentication::Principal>& principal) const;
334 
335  process::Future<process::http::Response> _attachContainerOutput(
336  const mesos::agent::Call& call,
337  const RequestMediaTypes& mediaTypes) const;
338 
339  process::Future<process::http::Response> addResourceProviderConfig(
340  const mesos::agent::Call& call,
341  const Option<process::http::authentication::Principal>& principal) const;
342 
343  process::Future<process::http::Response> updateResourceProviderConfig(
344  const mesos::agent::Call& call,
345  const Option<process::http::authentication::Principal>& principal) const;
346 
347  process::Future<process::http::Response> removeResourceProviderConfig(
348  const mesos::agent::Call& call,
349  const Option<process::http::authentication::Principal>& principal) const;
350 
352  const mesos::agent::Call& call,
353  ContentType acceptType,
355  principal) const;
356 
357  Slave* slave;
358 
359  // Used to rate limit the statistics endpoint.
360  process::Shared<process::RateLimiter> statisticsLimiter;
361 };
362 
363 } // namespace slave {
364 } // namespace internal {
365 } // namespace mesos {
366 
367 #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:2555
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:275
Definition: slave.hpp:116
Definition: http.hpp:129
Definition: http.hpp:86
Definition: duration.hpp:207
Definition: spec.hpp:30
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:47
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:36
process::Future< process::http::Response > flags(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
Definition: future.hpp:57