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  mesos::agent::Response::GetFrameworks _getFrameworks(
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 
194  mesos::agent::Response::GetExecutors _getExecutors(
195  const process::Owned<ObjectApprovers>& approvers) const;
196 
198  const mesos::agent::Call& call,
199  ContentType acceptType,
200  const Option<process::http::authentication::Principal>& principal) const;
201 
203  const mesos::agent::Call& call,
204  ContentType acceptType,
205  const Option<process::http::authentication::Principal>& principal) const;
206 
207  mesos::agent::Response::GetTasks _getTasks(
208  const process::Owned<ObjectApprovers>& approvers) const;
209 
211  const mesos::agent::Call& call,
212  ContentType acceptType,
213  const Option<process::http::authentication::Principal>& principal) const;
214 
215  process::Future<process::http::Response> getResourceProviders(
216  const mesos::agent::Call& call,
217  ContentType acceptType,
218  const Option<process::http::authentication::Principal>& principal) const;
219 
221  const mesos::agent::Call& call,
222  ContentType acceptType,
223  const Option<process::http::authentication::Principal>& principal) const;
224 
225  mesos::agent::Response::GetState _getState(
226  const process::Owned<ObjectApprovers>& approvers) const;
227 
228  process::Future<process::http::Response> launchNestedContainer(
229  const mesos::agent::Call& call,
230  ContentType acceptType,
231  const Option<process::http::authentication::Principal>& principal) const;
232 
234  const mesos::agent::Call& call,
235  ContentType acceptType,
236  const Option<process::http::authentication::Principal>& principal) const;
237 
238  template <mesos::authorization::Action action>
240  const mesos::agent::Call& call,
241  ContentType acceptType,
242  const Option<process::http::authentication::Principal>& principal) const;
243 
244  template <mesos::authorization::Action action>
246  const ContainerID& containerId,
247  const CommandInfo& commandInfo,
248  const Option<Resources>& resources,
249  const Option<ContainerInfo>& containerInfo,
250  const Option<mesos::slave::ContainerClass>& containerClass,
251  ContentType acceptType,
252  const process::Owned<ObjectApprovers>& approvers) const;
253 
254  process::Future<process::http::Response> waitNestedContainer(
255  const mesos::agent::Call& call,
256  ContentType acceptType,
257  const Option<process::http::authentication::Principal>& principal) const;
258 
260  const mesos::agent::Call& call,
261  ContentType acceptType,
262  const Option<process::http::authentication::Principal>& principal) const;
263 
264  template <authorization::Action action>
266  const mesos::agent::Call& call,
267  ContentType acceptType,
268  const Option<process::http::authentication::Principal>& principal) const;
269 
270  template <authorization::Action action>
272  const ContainerID& containerId,
273  ContentType acceptType,
274  const process::Owned<ObjectApprovers>& approvers,
275  const bool deprecated) const;
276 
277  process::Future<process::http::Response> killNestedContainer(
278  const mesos::agent::Call& call,
279  ContentType acceptType,
280  const Option<process::http::authentication::Principal>& principal) const;
281 
283  const mesos::agent::Call& call,
284  ContentType acceptType,
285  const Option<process::http::authentication::Principal>& principal) const;
286 
287  template <mesos::authorization::Action ACTION>
289  const mesos::agent::Call& call,
290  ContentType acceptType,
291  const Option<process::http::authentication::Principal>& principal) const;
292 
293  template <mesos::authorization::Action ACTION>
295  const ContainerID& containerId,
296  const int signal,
297  ContentType acceptType,
298  const process::Owned<ObjectApprovers>& approvers) const;
299 
300  process::Future<process::http::Response> removeNestedContainer(
301  const mesos::agent::Call& call,
302  ContentType acceptType,
303  const Option<process::http::authentication::Principal>& principal) const;
304 
306  const mesos::agent::Call& call,
307  ContentType acceptType,
308  const Option<process::http::authentication::Principal>& principal) const;
309 
310  template <mesos::authorization::Action ACTION>
312  const mesos::agent::Call& call,
313  ContentType acceptType,
314  const Option<process::http::authentication::Principal>& principal) const;
315 
316  template <mesos::authorization::Action ACTION>
318  const ContainerID& containerId,
319  ContentType acceptType,
320  const process::Owned<ObjectApprovers>& approvers) const;
321 
322  process::Future<process::http::Response> launchNestedContainerSession(
323  const mesos::agent::Call& call,
324  const RequestMediaTypes& mediaTypes,
325  const Option<process::http::authentication::Principal>& principal) const;
326 
327  process::Future<process::http::Response> attachContainerInput(
328  const mesos::agent::Call& call,
330  const RequestMediaTypes& mediaTypes,
331  const Option<process::http::authentication::Principal>& principal) const;
332 
333  process::Future<process::http::Response> _attachContainerInput(
334  const mesos::agent::Call& call,
336  const RequestMediaTypes& mediaTypes) const;
337 
338  process::Future<process::http::Response> acknowledgeContainerInputResponse(
339  const ContainerID& containerId) const;
340 
341  process::Future<process::http::Response> attachContainerOutput(
342  const mesos::agent::Call& call,
343  const RequestMediaTypes& mediaTypes,
344  const Option<process::http::authentication::Principal>& principal) const;
345 
346  process::Future<process::http::Response> _attachContainerOutput(
347  const mesos::agent::Call& call,
348  const RequestMediaTypes& mediaTypes) const;
349 
350  process::Future<process::http::Response> addResourceProviderConfig(
351  const mesos::agent::Call& call,
352  const Option<process::http::authentication::Principal>& principal) const;
353 
354  process::Future<process::http::Response> updateResourceProviderConfig(
355  const mesos::agent::Call& call,
356  const Option<process::http::authentication::Principal>& principal) const;
357 
358  process::Future<process::http::Response> removeResourceProviderConfig(
359  const mesos::agent::Call& call,
360  const Option<process::http::authentication::Principal>& principal) const;
361 
362  process::Future<process::http::Response> markResourceProviderGone(
363  const mesos::agent::Call& call,
364  const Option<process::http::authentication::Principal>& principal) const;
365 
367  const mesos::agent::Call& call,
368  ContentType acceptType,
370  principal) const;
371 
372  Slave* slave;
373 
374  // Used to rate limit the statistics endpoint.
375  process::Shared<process::RateLimiter> statisticsLimiter;
376 };
377 
378 } // namespace slave {
379 } // namespace internal {
380 } // namespace mesos {
381 
382 #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:2782
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:338
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