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  // /slave/containerizer/debug
85  const process::http::Request& request,
87 
88  static std::string API_HELP();
89  static std::string EXECUTOR_HELP();
90  static std::string RESOURCE_PROVIDER_HELP();
91  static std::string FLAGS_HELP();
92  static std::string HEALTH_HELP();
93  static std::string STATE_HELP();
94  static std::string STATISTICS_HELP();
95  static std::string CONTAINERS_HELP();
96  static std::string CONTAINERIZER_DEBUG_HELP();
97 
98 private:
99  JSON::Object _flags() const;
100 
101  // Continuation for `/api` endpoint that handles streaming and non-streaming
102  // requests. In case of a streaming request, `call` would be the first
103  // record and additional records can be read using the `reader`. For
104  // non-streaming requests, `reader` would be set to `None()`.
106  const agent::Call& call,
108  const RequestMediaTypes& mediaTypes,
109  const Option<process::http::authentication::Principal>& principal) const;
110 
111  // Make continuation for `statistics` `static` as it might
112  // execute when the invoking `Http` is already destructed.
113  process::http::Response _statistics(
114  const ResourceUsage& usage,
115  const process::http::Request& request) const;
116 
117  // Continuation for `/containers` endpoint
119  const process::http::Request& request,
120  const Option<process::http::authentication::Principal>& principal) const;
121 
122  // Helper function to collect containers status and resource statistics.
123  process::Future<JSON::Array> __containers(
124  const process::Owned<ObjectApprovers>& approvers,
125  Option<IDAcceptor<ContainerID>> selectContainerId,
126  bool showNestedContainers,
127  bool showStandaloneContainers) const;
128 
129  // Continuation for `/containerizer/debug` endpoint
130  process::Future<JSON::Object> _containerizerDebug() const;
131 
132  // Helper routines for endpoint authorization.
133  Try<std::string> extractEndpoint(const process::http::URL& url) const;
134 
135  // Agent API handlers.
137  const mesos::agent::Call& call,
138  ContentType acceptType,
139  const Option<process::http::authentication::Principal>& principal) const;
140 
142  const mesos::agent::Call& call,
143  ContentType acceptType,
144  const Option<process::http::authentication::Principal>& principal) const;
145 
147  const mesos::agent::Call& call,
148  ContentType acceptType,
149  const Option<process::http::authentication::Principal>& principal) const;
150 
152  const mesos::agent::Call& call,
153  ContentType acceptType,
154  const Option<process::http::authentication::Principal>& principal) const;
155 
157  const mesos::agent::Call& call,
158  ContentType acceptType,
159  const Option<process::http::authentication::Principal>& principal) const;
160 
162  const mesos::agent::Call& call,
163  ContentType acceptType,
164  const Option<process::http::authentication::Principal>& principal) const;
165 
167  const mesos::agent::Call& call,
168  ContentType acceptType,
169  const Option<process::http::authentication::Principal>& principal) const;
170 
172  const mesos::agent::Call& call,
173  ContentType acceptType,
174  const Option<process::http::authentication::Principal>& principal) const;
175 
177  const mesos::agent::Call& call,
178  ContentType acceptType,
179  const Option<process::http::authentication::Principal>& principal) const;
180 
182  const mesos::agent::Call& call,
183  ContentType acceptType,
184  const Option<process::http::authentication::Principal>& principal) const;
185 
186  std::function<void(JSON::ObjectWriter*)> jsonifyGetFrameworks(
187  const process::Owned<ObjectApprovers>& approvers) const;
188  std::string serializeGetFrameworks(
189  const process::Owned<ObjectApprovers>& approvers) const;
190 
192  const mesos::agent::Call& call,
193  ContentType acceptType,
194  const Option<process::http::authentication::Principal>& principal) const;
195 
196  std::function<void(JSON::ObjectWriter*)> jsonifyGetExecutors(
197  const process::Owned<ObjectApprovers>& approvers) const;
198  std::string serializeGetExecutors(
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 
207  const mesos::agent::Call& call,
208  ContentType acceptType,
209  const Option<process::http::authentication::Principal>& principal) const;
210 
211  std::function<void(JSON::ObjectWriter*)> jsonifyGetTasks(
212  const process::Owned<ObjectApprovers>& approvers) const;
213  std::string serializeGetTasks(
214  const process::Owned<ObjectApprovers>& approvers) const;
215 
217  const mesos::agent::Call& call,
218  ContentType acceptType,
219  const Option<process::http::authentication::Principal>& principal) const;
220 
221  process::Future<process::http::Response> getResourceProviders(
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 
231  std::function<void(JSON::ObjectWriter*)> jsonifyGetState(
232  const process::Owned<ObjectApprovers>& approvers) const;
233  std::string serializeGetState(
234  const process::Owned<ObjectApprovers>& approvers) const;
235 
236  process::Future<process::http::Response> launchNestedContainer(
237  const mesos::agent::Call& call,
238  ContentType acceptType,
239  const Option<process::http::authentication::Principal>& principal) const;
240 
242  const mesos::agent::Call& call,
243  ContentType acceptType,
244  const Option<process::http::authentication::Principal>& principal) const;
245 
246  template <mesos::authorization::Action action>
248  const mesos::agent::Call& call,
249  ContentType acceptType,
250  const Option<process::http::authentication::Principal>& principal) const;
251 
252  template <mesos::authorization::Action action>
254  const ContainerID& containerId,
255  const CommandInfo& commandInfo,
256  const Option<Resources>& resourceRequests,
257  const Option<
258  google::protobuf::Map<std::string, Value::Scalar>>& resourceLimits,
259  const Option<ContainerInfo>& containerInfo,
260  const Option<mesos::slave::ContainerClass>& containerClass,
261  ContentType acceptType,
262  const process::Owned<ObjectApprovers>& approvers) const;
263 
264  process::Future<process::http::Response> waitNestedContainer(
265  const mesos::agent::Call& call,
266  ContentType acceptType,
267  const Option<process::http::authentication::Principal>& principal) const;
268 
270  const mesos::agent::Call& call,
271  ContentType acceptType,
272  const Option<process::http::authentication::Principal>& principal) const;
273 
274  template <authorization::Action action>
276  const mesos::agent::Call& call,
277  ContentType acceptType,
278  const Option<process::http::authentication::Principal>& principal) const;
279 
280  template <authorization::Action action>
282  const ContainerID& containerId,
283  ContentType acceptType,
284  const process::Owned<ObjectApprovers>& approvers,
285  const bool deprecated) const;
286 
287  process::Future<process::http::Response> killNestedContainer(
288  const mesos::agent::Call& call,
289  ContentType acceptType,
290  const Option<process::http::authentication::Principal>& principal) const;
291 
293  const mesos::agent::Call& call,
294  ContentType acceptType,
295  const Option<process::http::authentication::Principal>& principal) const;
296 
297  template <mesos::authorization::Action ACTION>
299  const mesos::agent::Call& call,
300  ContentType acceptType,
301  const Option<process::http::authentication::Principal>& principal) const;
302 
303  template <mesos::authorization::Action ACTION>
305  const ContainerID& containerId,
306  const int signal,
307  ContentType acceptType,
308  const process::Owned<ObjectApprovers>& approvers) const;
309 
310  process::Future<process::http::Response> removeNestedContainer(
311  const mesos::agent::Call& call,
312  ContentType acceptType,
313  const Option<process::http::authentication::Principal>& principal) const;
314 
316  const mesos::agent::Call& call,
317  ContentType acceptType,
318  const Option<process::http::authentication::Principal>& principal) const;
319 
320  template <mesos::authorization::Action ACTION>
322  const mesos::agent::Call& call,
323  ContentType acceptType,
324  const Option<process::http::authentication::Principal>& principal) const;
325 
326  template <mesos::authorization::Action ACTION>
328  const ContainerID& containerId,
329  ContentType acceptType,
330  const process::Owned<ObjectApprovers>& approvers) const;
331 
332  process::Future<process::http::Response> launchNestedContainerSession(
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> attachContainerInput(
338  const mesos::agent::Call& call,
340  const RequestMediaTypes& mediaTypes,
341  const Option<process::http::authentication::Principal>& principal) const;
342 
343  process::Future<process::http::Response> _attachContainerInput(
344  const mesos::agent::Call& call,
346  const RequestMediaTypes& mediaTypes) const;
347 
348  process::Future<process::http::Response> acknowledgeContainerInputResponse(
349  const ContainerID& containerId) const;
350 
351  process::Future<process::http::Response> attachContainerOutput(
352  const mesos::agent::Call& call,
353  const RequestMediaTypes& mediaTypes,
354  const Option<process::http::authentication::Principal>& principal) const;
355 
356  process::Future<process::http::Response> _attachContainerOutput(
357  const mesos::agent::Call& call,
358  const RequestMediaTypes& mediaTypes) const;
359 
360  process::Future<process::http::Response> addResourceProviderConfig(
361  const mesos::agent::Call& call,
362  const Option<process::http::authentication::Principal>& principal) const;
363 
364  process::Future<process::http::Response> updateResourceProviderConfig(
365  const mesos::agent::Call& call,
366  const Option<process::http::authentication::Principal>& principal) const;
367 
368  process::Future<process::http::Response> removeResourceProviderConfig(
369  const mesos::agent::Call& call,
370  const Option<process::http::authentication::Principal>& principal) const;
371 
372  process::Future<process::http::Response> markResourceProviderGone(
373  const mesos::agent::Call& call,
374  const Option<process::http::authentication::Principal>& principal) const;
375 
377  const mesos::agent::Call& call,
378  ContentType acceptType,
380  principal) const;
381 
382  Slave* slave;
383 
384  // Used to rate limit the statistics endpoint.
385  process::Shared<process::RateLimiter> statisticsLimiter;
386 };
387 
388 } // namespace slave {
389 } // namespace internal {
390 } // namespace mesos {
391 
392 #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 > containerizerDebug(const process::http::Request &request, const Option< process::http::authentication::Principal > &principal) const
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:2851
static std::string STATISTICS_HELP()
Definition: http.hpp:533
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:471
Definition: slave.hpp:118
Definition: http.hpp:130
static std::string CONTAINERIZER_DEBUG_HELP()
Definition: http.hpp:88
Definition: duration.hpp:207
Definition: agent.hpp:25
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:612
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