YARN-8091. Revisit checkUserAccessToQueue RM REST API. (wangda)
[hadoop.git] / hadoop-yarn-project / hadoop-yarn / hadoop-yarn-server / hadoop-yarn-server-router / src / main / java / org / apache / hadoop / yarn / server / router / webapp / RouterWebServices.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.hadoop.yarn.server.router.webapp;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import javax.ws.rs.DELETE;
32 import javax.ws.rs.DefaultValue;
33 import javax.ws.rs.FormParam;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.POST;
36 import javax.ws.rs.PUT;
37 import javax.ws.rs.Path;
38 import javax.ws.rs.PathParam;
39 import javax.ws.rs.Produces;
40 import javax.ws.rs.QueryParam;
41 import javax.ws.rs.core.Context;
42 import javax.ws.rs.core.MediaType;
43 import javax.ws.rs.core.Response;
44
45 import org.apache.hadoop.classification.InterfaceAudience.Private;
46 import org.apache.hadoop.conf.Configuration;
47 import org.apache.hadoop.http.JettyUtils;
48 import org.apache.hadoop.security.UserGroupInformation;
49 import org.apache.hadoop.security.authorize.AuthorizationException;
50 import org.apache.hadoop.util.ReflectionUtils;
51 import org.apache.hadoop.util.StringUtils;
52 import org.apache.hadoop.yarn.conf.YarnConfiguration;
53 import org.apache.hadoop.yarn.exceptions.YarnException;
54 import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
55 import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts;
56 import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServiceProtocol;
57 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ActivitiesInfo;
58 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppActivitiesInfo;
59 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppAttemptsInfo;
60 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppInfo;
61 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority;
62 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppQueue;
63 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState;
64 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppTimeoutInfo;
65 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppTimeoutsInfo;
66 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationStatisticsInfo;
67 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo;
68 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppsInfo;
69 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterInfo;
70 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo;
71 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken;
72 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LabelsToNodesInfo;
73 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo;
74 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo;
75 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsEntryList;
76 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsInfo;
77 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo;
78 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.RMQueueAclInfo;
79 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDeleteRequestInfo;
80 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationSubmissionRequestInfo;
81 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateRequestInfo;
82 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo;
83 import org.apache.hadoop.yarn.server.router.Router;
84 import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
85 import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
86 import org.apache.hadoop.yarn.util.LRUCacheHashMap;
87 import org.slf4j.Logger;
88 import org.slf4j.LoggerFactory;
89
90 import com.google.common.annotations.VisibleForTesting;
91 import com.google.inject.Inject;
92 import com.google.inject.Singleton;
93
94 /**
95 * RouterWebServices is a service that runs on each router that can be used to
96 * intercept and inspect {@link RMWebServiceProtocol} messages from client to
97 * the cluster resource manager. It listens {@link RMWebServiceProtocol} REST
98 * messages from the client and creates a request intercepting pipeline instance
99 * for each client. The pipeline is a chain of {@link RESTRequestInterceptor}
100 * instances that can inspect and modify the request/response as needed. The
101 * main difference with AMRMProxyService is the protocol they implement.
102 **/
103 @Singleton
104 @Path("/ws/v1/cluster")
105 public class RouterWebServices implements RMWebServiceProtocol {
106
107 private static final Logger LOG =
108 LoggerFactory.getLogger(RouterWebServices.class);
109 private final Router router;
110 private final Configuration conf;
111 private @Context HttpServletResponse response;
112
113 private Map<String, RequestInterceptorChainWrapper> userPipelineMap;
114
115 // -------Default values of QueryParams for RMWebServiceProtocol--------
116
117 public static final String DEFAULT_QUEUE = "default";
118 public static final String DEFAULT_RESERVATION_ID = "";
119 public static final String DEFAULT_START_TIME = "0";
120 public static final String DEFAULT_END_TIME = "-1";
121 public static final String DEFAULT_INCLUDE_RESOURCE = "false";
122
123 @Inject
124 public RouterWebServices(final Router router, Configuration conf) {
125 this.router = router;
126 this.conf = conf;
127 int maxCacheSize =
128 conf.getInt(YarnConfiguration.ROUTER_PIPELINE_CACHE_MAX_SIZE,
129 YarnConfiguration.DEFAULT_ROUTER_PIPELINE_CACHE_MAX_SIZE);
130 this.userPipelineMap = Collections.synchronizedMap(
131 new LRUCacheHashMap<String, RequestInterceptorChainWrapper>(
132 maxCacheSize, true));
133 }
134
135 /**
136 * Returns the comma separated intercepter class names from the configuration.
137 *
138 * @param conf
139 * @return the intercepter class names as an instance of ArrayList
140 */
141 private List<String> getInterceptorClassNames(Configuration config) {
142 String configuredInterceptorClassNames =
143 config.get(YarnConfiguration.ROUTER_WEBAPP_INTERCEPTOR_CLASS_PIPELINE,
144 YarnConfiguration.DEFAULT_ROUTER_WEBAPP_INTERCEPTOR_CLASS);
145
146 List<String> interceptorClassNames = new ArrayList<String>();
147 Collection<String> tempList =
148 StringUtils.getStringCollection(configuredInterceptorClassNames);
149 for (String item : tempList) {
150 interceptorClassNames.add(item.trim());
151 }
152
153 return interceptorClassNames;
154 }
155
156 private void init() {
157 // clear content type
158 response.setContentType(null);
159 }
160
161 @VisibleForTesting
162 protected RequestInterceptorChainWrapper getInterceptorChain(
163 final HttpServletRequest hsr) {
164 String user = "";
165 if (hsr != null) {
166 user = hsr.getRemoteUser();
167 }
168 try {
169 if (user == null || user.equals("")) {
170 // Yarn Router user
171 user = UserGroupInformation.getCurrentUser().getUserName();
172 }
173 } catch (IOException e) {
174 LOG.error("Cannot get user: {}", e.getMessage());
175 }
176 if (!userPipelineMap.containsKey(user)) {
177 initializePipeline(user);
178 }
179 return userPipelineMap.get(user);
180 }
181
182 /**
183 * Gets the Request intercepter chains for all the users.
184 *
185 * @return the request intercepter chains.
186 */
187 @VisibleForTesting
188 protected Map<String, RequestInterceptorChainWrapper> getPipelines() {
189 return this.userPipelineMap;
190 }
191
192 /**
193 * This method creates and returns reference of the first intercepter in the
194 * chain of request intercepter instances.
195 *
196 * @return the reference of the first intercepter in the chain
197 */
198 @VisibleForTesting
199 protected RESTRequestInterceptor createRequestInterceptorChain() {
200
201 List<String> interceptorClassNames = getInterceptorClassNames(conf);
202
203 RESTRequestInterceptor pipeline = null;
204 RESTRequestInterceptor current = null;
205 for (String interceptorClassName : interceptorClassNames) {
206 try {
207 Class<?> interceptorClass = conf.getClassByName(interceptorClassName);
208 if (RESTRequestInterceptor.class.isAssignableFrom(interceptorClass)) {
209 RESTRequestInterceptor interceptorInstance =
210 (RESTRequestInterceptor) ReflectionUtils
211 .newInstance(interceptorClass, conf);
212 if (pipeline == null) {
213 pipeline = interceptorInstance;
214 current = interceptorInstance;
215 continue;
216 } else {
217 current.setNextInterceptor(interceptorInstance);
218 current = interceptorInstance;
219 }
220 } else {
221 throw new YarnRuntimeException(
222 "Class: " + interceptorClassName + " not instance of "
223 + RESTRequestInterceptor.class.getCanonicalName());
224 }
225 } catch (ClassNotFoundException e) {
226 throw new YarnRuntimeException(
227 "Could not instantiate RESTRequestInterceptor: "
228 + interceptorClassName,
229 e);
230 }
231 }
232
233 if (pipeline == null) {
234 throw new YarnRuntimeException(
235 "RequestInterceptor pipeline is not configured in the system");
236 }
237 return pipeline;
238 }
239
240 /**
241 * Initializes the request intercepter pipeline for the specified user.
242 *
243 * @param user
244 */
245 private void initializePipeline(String user) {
246 RequestInterceptorChainWrapper chainWrapper = null;
247 synchronized (this.userPipelineMap) {
248 if (this.userPipelineMap.containsKey(user)) {
249 LOG.info("Request to start an already existing user: {}"
250 + " was received, so ignoring.", user);
251 return;
252 }
253
254 chainWrapper = new RequestInterceptorChainWrapper();
255 this.userPipelineMap.put(user, chainWrapper);
256 }
257
258 // We register the pipeline instance in the map first and then initialize it
259 // later because chain initialization can be expensive and we would like to
260 // release the lock as soon as possible to prevent other applications from
261 // blocking when one application's chain is initializing
262 LOG.info("Initializing request processing pipeline for the user: {}", user);
263
264 try {
265 RESTRequestInterceptor interceptorChain =
266 this.createRequestInterceptorChain();
267 interceptorChain.init(user);
268 chainWrapper.init(interceptorChain);
269 } catch (Exception e) {
270 synchronized (this.userPipelineMap) {
271 this.userPipelineMap.remove(user);
272 }
273 throw e;
274 }
275 }
276
277 /**
278 * Private structure for encapsulating RequestInterceptor and user instances.
279 *
280 */
281 @Private
282 public static class RequestInterceptorChainWrapper {
283 private RESTRequestInterceptor rootInterceptor;
284
285 /**
286 * Initializes the wrapper with the specified parameters.
287 *
288 * @param interceptor the first interceptor in the pipeline
289 */
290 public synchronized void init(RESTRequestInterceptor interceptor) {
291 this.rootInterceptor = interceptor;
292 }
293
294 /**
295 * Gets the root request intercepter.
296 *
297 * @return the root request intercepter
298 */
299 public synchronized RESTRequestInterceptor getRootInterceptor() {
300 return rootInterceptor;
301 }
302
303 /**
304 * Shutdown the chain of interceptors when the object is destroyed.
305 */
306 @Override
307 protected void finalize() {
308 rootInterceptor.shutdown();
309 }
310 }
311
312 @GET
313 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
314 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
315 @Override
316 public ClusterInfo get() {
317 return getClusterInfo();
318 }
319
320 @GET
321 @Path(RMWSConsts.INFO)
322 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
323 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
324 @Override
325 public ClusterInfo getClusterInfo() {
326 init();
327 RequestInterceptorChainWrapper pipeline = getInterceptorChain(null);
328 return pipeline.getRootInterceptor().getClusterInfo();
329 }
330
331 @GET
332 @Path(RMWSConsts.METRICS)
333 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
334 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
335 @Override
336 public ClusterMetricsInfo getClusterMetricsInfo() {
337 init();
338 RequestInterceptorChainWrapper pipeline = getInterceptorChain(null);
339 return pipeline.getRootInterceptor().getClusterMetricsInfo();
340 }
341
342 @GET
343 @Path(RMWSConsts.SCHEDULER)
344 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
345 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
346 @Override
347 public SchedulerTypeInfo getSchedulerInfo() {
348 init();
349 RequestInterceptorChainWrapper pipeline = getInterceptorChain(null);
350 return pipeline.getRootInterceptor().getSchedulerInfo();
351 }
352
353 @POST
354 @Path(RMWSConsts.SCHEDULER_LOGS)
355 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
356 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
357 @Override
358 public String dumpSchedulerLogs(@FormParam(RMWSConsts.TIME) String time,
359 @Context HttpServletRequest hsr) throws IOException {
360 init();
361 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
362 return pipeline.getRootInterceptor().dumpSchedulerLogs(time, hsr);
363 }
364
365 @GET
366 @Path(RMWSConsts.NODES)
367 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
368 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
369 @Override
370 public NodesInfo getNodes(@QueryParam(RMWSConsts.STATES) String states) {
371 init();
372 RequestInterceptorChainWrapper pipeline = getInterceptorChain(null);
373 return pipeline.getRootInterceptor().getNodes(states);
374 }
375
376 @GET
377 @Path(RMWSConsts.NODES_NODEID)
378 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
379 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
380 @Override
381 public NodeInfo getNode(@PathParam(RMWSConsts.NODEID) String nodeId) {
382 init();
383 RequestInterceptorChainWrapper pipeline = getInterceptorChain(null);
384 return pipeline.getRootInterceptor().getNode(nodeId);
385 }
386
387 @GET
388 @Path(RMWSConsts.APPS)
389 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
390 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
391 @Override
392 public AppsInfo getApps(@Context HttpServletRequest hsr,
393 @QueryParam(RMWSConsts.STATE) String stateQuery,
394 @QueryParam(RMWSConsts.STATES) Set<String> statesQuery,
395 @QueryParam(RMWSConsts.FINAL_STATUS) String finalStatusQuery,
396 @QueryParam(RMWSConsts.USER) String userQuery,
397 @QueryParam(RMWSConsts.QUEUE) String queueQuery,
398 @QueryParam(RMWSConsts.LIMIT) String count,
399 @QueryParam(RMWSConsts.STARTED_TIME_BEGIN) String startedBegin,
400 @QueryParam(RMWSConsts.STARTED_TIME_END) String startedEnd,
401 @QueryParam(RMWSConsts.FINISHED_TIME_BEGIN) String finishBegin,
402 @QueryParam(RMWSConsts.FINISHED_TIME_END) String finishEnd,
403 @QueryParam(RMWSConsts.APPLICATION_TYPES) Set<String> applicationTypes,
404 @QueryParam(RMWSConsts.APPLICATION_TAGS) Set<String> applicationTags,
405 @QueryParam(RMWSConsts.DESELECTS) Set<String> unselectedFields) {
406 init();
407 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
408 return pipeline.getRootInterceptor().getApps(hsr, stateQuery, statesQuery,
409 finalStatusQuery, userQuery, queueQuery, count, startedBegin,
410 startedEnd, finishBegin, finishEnd, applicationTypes, applicationTags,
411 unselectedFields);
412 }
413
414 @GET
415 @Path(RMWSConsts.SCHEDULER_ACTIVITIES)
416 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
417 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
418 @Override
419 public ActivitiesInfo getActivities(@Context HttpServletRequest hsr,
420 @QueryParam(RMWSConsts.NODEID) String nodeId) {
421 init();
422 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
423 return pipeline.getRootInterceptor().getActivities(hsr, nodeId);
424 }
425
426 @GET
427 @Path(RMWSConsts.SCHEDULER_APP_ACTIVITIES)
428 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
429 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
430 @Override
431 public AppActivitiesInfo getAppActivities(@Context HttpServletRequest hsr,
432 @QueryParam(RMWSConsts.APP_ID) String appId,
433 @QueryParam(RMWSConsts.MAX_TIME) String time) {
434 init();
435 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
436 return pipeline.getRootInterceptor().getAppActivities(hsr, appId, time);
437 }
438
439 @GET
440 @Path(RMWSConsts.APP_STATISTICS)
441 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
442 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
443 @Override
444 public ApplicationStatisticsInfo getAppStatistics(
445 @Context HttpServletRequest hsr,
446 @QueryParam(RMWSConsts.STATES) Set<String> stateQueries,
447 @QueryParam(RMWSConsts.APPLICATION_TYPES) Set<String> typeQueries) {
448 init();
449 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
450 return pipeline.getRootInterceptor().getAppStatistics(hsr, stateQueries,
451 typeQueries);
452 }
453
454 @GET
455 @Path(RMWSConsts.APPS_APPID)
456 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
457 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
458 @Override
459 public AppInfo getApp(@Context HttpServletRequest hsr,
460 @PathParam(RMWSConsts.APPID) String appId,
461 @QueryParam(RMWSConsts.DESELECTS) Set<String> unselectedFields) {
462 init();
463 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
464 return pipeline.getRootInterceptor().getApp(hsr, appId, unselectedFields);
465 }
466
467 @GET
468 @Path(RMWSConsts.APPS_APPID_STATE)
469 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
470 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
471 @Override
472 public AppState getAppState(@Context HttpServletRequest hsr,
473 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException {
474 init();
475 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
476 return pipeline.getRootInterceptor().getAppState(hsr, appId);
477 }
478
479 @PUT
480 @Path(RMWSConsts.APPS_APPID_STATE)
481 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
482 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
483 @Override
484 public Response updateAppState(AppState targetState,
485 @Context HttpServletRequest hsr,
486 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException,
487 YarnException, InterruptedException, IOException {
488 init();
489 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
490 return pipeline.getRootInterceptor().updateAppState(targetState, hsr,
491 appId);
492 }
493
494 @GET
495 @Path(RMWSConsts.GET_NODE_TO_LABELS)
496 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
497 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
498 @Override
499 public NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr)
500 throws IOException {
501 init();
502 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
503 return pipeline.getRootInterceptor().getNodeToLabels(hsr);
504 }
505
506 @GET
507 @Path(RMWSConsts.LABEL_MAPPINGS)
508 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
509 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
510 @Override
511 public LabelsToNodesInfo getLabelsToNodes(
512 @QueryParam(RMWSConsts.LABELS) Set<String> labels) throws IOException {
513 init();
514 RequestInterceptorChainWrapper pipeline = getInterceptorChain(null);
515 return pipeline.getRootInterceptor().getLabelsToNodes(labels);
516 }
517
518 @POST
519 @Path(RMWSConsts.REPLACE_NODE_TO_LABELS)
520 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
521 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
522 @Override
523 public Response replaceLabelsOnNodes(
524 final NodeToLabelsEntryList newNodeToLabels,
525 @Context HttpServletRequest hsr) throws Exception {
526 init();
527 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
528 return pipeline.getRootInterceptor().replaceLabelsOnNodes(newNodeToLabels,
529 hsr);
530 }
531
532 @POST
533 @Path(RMWSConsts.NODES_NODEID_REPLACE_LABELS)
534 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
535 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
536 @Override
537 public Response replaceLabelsOnNode(
538 @QueryParam(RMWSConsts.LABELS) Set<String> newNodeLabelsName,
539 @Context HttpServletRequest hsr,
540 @PathParam(RMWSConsts.NODEID) String nodeId) throws Exception {
541 init();
542 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
543 return pipeline.getRootInterceptor().replaceLabelsOnNode(newNodeLabelsName,
544 hsr, nodeId);
545 }
546
547 @GET
548 @Path(RMWSConsts.GET_NODE_LABELS)
549 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
550 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
551 @Override
552 public NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr)
553 throws IOException {
554 init();
555 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
556 return pipeline.getRootInterceptor().getClusterNodeLabels(hsr);
557 }
558
559 @POST
560 @Path(RMWSConsts.ADD_NODE_LABELS)
561 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
562 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
563 @Override
564 public Response addToClusterNodeLabels(NodeLabelsInfo newNodeLabels,
565 @Context HttpServletRequest hsr) throws Exception {
566 init();
567 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
568 return pipeline.getRootInterceptor().addToClusterNodeLabels(newNodeLabels,
569 hsr);
570 }
571
572 @POST
573 @Path(RMWSConsts.REMOVE_NODE_LABELS)
574 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
575 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
576 @Override
577 public Response removeFromCluserNodeLabels(
578 @QueryParam(RMWSConsts.LABELS) Set<String> oldNodeLabels,
579 @Context HttpServletRequest hsr) throws Exception {
580 init();
581 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
582 return pipeline.getRootInterceptor()
583 .removeFromCluserNodeLabels(oldNodeLabels, hsr);
584 }
585
586 @GET
587 @Path(RMWSConsts.NODES_NODEID_GETLABELS)
588 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
589 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
590 @Override
591 public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr,
592 @PathParam(RMWSConsts.NODEID) String nodeId) throws IOException {
593 init();
594 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
595 return pipeline.getRootInterceptor().getLabelsOnNode(hsr, nodeId);
596 }
597
598 @GET
599 @Path(RMWSConsts.APPS_APPID_PRIORITY)
600 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
601 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
602 @Override
603 public AppPriority getAppPriority(@Context HttpServletRequest hsr,
604 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException {
605 init();
606 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
607 return pipeline.getRootInterceptor().getAppPriority(hsr, appId);
608 }
609
610 @PUT
611 @Path(RMWSConsts.APPS_APPID_PRIORITY)
612 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
613 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
614 @Override
615 public Response updateApplicationPriority(AppPriority targetPriority,
616 @Context HttpServletRequest hsr,
617 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException,
618 YarnException, InterruptedException, IOException {
619 init();
620 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
621 return pipeline.getRootInterceptor()
622 .updateApplicationPriority(targetPriority, hsr, appId);
623 }
624
625 @GET
626 @Path(RMWSConsts.APPS_APPID_QUEUE)
627 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
628 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
629 @Override
630 public AppQueue getAppQueue(@Context HttpServletRequest hsr,
631 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException {
632 init();
633 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
634 return pipeline.getRootInterceptor().getAppQueue(hsr, appId);
635 }
636
637 @PUT
638 @Path(RMWSConsts.APPS_APPID_QUEUE)
639 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
640 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
641 @Override
642 public Response updateAppQueue(AppQueue targetQueue,
643 @Context HttpServletRequest hsr,
644 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException,
645 YarnException, InterruptedException, IOException {
646 init();
647 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
648 return pipeline.getRootInterceptor().updateAppQueue(targetQueue, hsr,
649 appId);
650 }
651
652 @POST
653 @Path(RMWSConsts.APPS_NEW_APPLICATION)
654 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
655 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
656 @Override
657 public Response createNewApplication(@Context HttpServletRequest hsr)
658 throws AuthorizationException, IOException, InterruptedException {
659 init();
660 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
661 return pipeline.getRootInterceptor().createNewApplication(hsr);
662 }
663
664 @POST
665 @Path(RMWSConsts.APPS)
666 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
667 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
668 @Override
669 public Response submitApplication(ApplicationSubmissionContextInfo newApp,
670 @Context HttpServletRequest hsr)
671 throws AuthorizationException, IOException, InterruptedException {
672 init();
673 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
674 return pipeline.getRootInterceptor().submitApplication(newApp, hsr);
675 }
676
677 @POST
678 @Path(RMWSConsts.DELEGATION_TOKEN)
679 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
680 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
681 @Override
682 public Response postDelegationToken(DelegationToken tokenData,
683 @Context HttpServletRequest hsr) throws AuthorizationException,
684 IOException, InterruptedException, Exception {
685 init();
686 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
687 return pipeline.getRootInterceptor().postDelegationToken(tokenData, hsr);
688 }
689
690 @POST
691 @Path(RMWSConsts.DELEGATION_TOKEN_EXPIRATION)
692 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
693 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
694 @Override
695 public Response postDelegationTokenExpiration(@Context HttpServletRequest hsr)
696 throws AuthorizationException, IOException, Exception {
697 init();
698 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
699 return pipeline.getRootInterceptor().postDelegationTokenExpiration(hsr);
700 }
701
702 @DELETE
703 @Path(RMWSConsts.DELEGATION_TOKEN)
704 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
705 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
706 @Override
707 public Response cancelDelegationToken(@Context HttpServletRequest hsr)
708 throws AuthorizationException, IOException, InterruptedException,
709 Exception {
710 init();
711 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
712 return pipeline.getRootInterceptor().cancelDelegationToken(hsr);
713 }
714
715 @POST
716 @Path(RMWSConsts.RESERVATION_NEW)
717 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
718 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
719 @Override
720 public Response createNewReservation(@Context HttpServletRequest hsr)
721 throws AuthorizationException, IOException, InterruptedException {
722 init();
723 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
724 return pipeline.getRootInterceptor().createNewReservation(hsr);
725 }
726
727 @POST
728 @Path(RMWSConsts.RESERVATION_SUBMIT)
729 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
730 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
731 @Override
732 public Response submitReservation(ReservationSubmissionRequestInfo resContext,
733 @Context HttpServletRequest hsr)
734 throws AuthorizationException, IOException, InterruptedException {
735 init();
736 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
737 return pipeline.getRootInterceptor().submitReservation(resContext, hsr);
738 }
739
740 @POST
741 @Path(RMWSConsts.RESERVATION_UPDATE)
742 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
743 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
744 @Override
745 public Response updateReservation(ReservationUpdateRequestInfo resContext,
746 @Context HttpServletRequest hsr)
747 throws AuthorizationException, IOException, InterruptedException {
748 init();
749 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
750 return pipeline.getRootInterceptor().updateReservation(resContext, hsr);
751 }
752
753 @POST
754 @Path(RMWSConsts.RESERVATION_DELETE)
755 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
756 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
757 @Override
758 public Response deleteReservation(ReservationDeleteRequestInfo resContext,
759 @Context HttpServletRequest hsr)
760 throws AuthorizationException, IOException, InterruptedException {
761 init();
762 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
763 return pipeline.getRootInterceptor().deleteReservation(resContext, hsr);
764 }
765
766 @GET
767 @Path(RMWSConsts.RESERVATION_LIST)
768 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
769 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
770 @Override
771 public Response listReservation(
772 @QueryParam(RMWSConsts.QUEUE) @DefaultValue(DEFAULT_QUEUE) String queue,
773 @QueryParam(RMWSConsts.RESERVATION_ID) @DefaultValue(DEFAULT_RESERVATION_ID) String reservationId,
774 @QueryParam(RMWSConsts.START_TIME) @DefaultValue(DEFAULT_START_TIME) long startTime,
775 @QueryParam(RMWSConsts.END_TIME) @DefaultValue(DEFAULT_END_TIME) long endTime,
776 @QueryParam(RMWSConsts.INCLUDE_RESOURCE) @DefaultValue(DEFAULT_INCLUDE_RESOURCE) boolean includeResourceAllocations,
777 @Context HttpServletRequest hsr) throws Exception {
778 init();
779 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
780 return pipeline.getRootInterceptor().listReservation(queue, reservationId,
781 startTime, endTime, includeResourceAllocations, hsr);
782 }
783
784 @GET
785 @Path(RMWSConsts.APPS_TIMEOUTS_TYPE)
786 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
787 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
788 @Override
789 public AppTimeoutInfo getAppTimeout(@Context HttpServletRequest hsr,
790 @PathParam(RMWSConsts.APPID) String appId,
791 @PathParam(RMWSConsts.TYPE) String type) throws AuthorizationException {
792 init();
793 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
794 return pipeline.getRootInterceptor().getAppTimeout(hsr, appId, type);
795 }
796
797 @GET
798 @Path(RMWSConsts.APPS_TIMEOUTS)
799 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
800 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
801 @Override
802 public AppTimeoutsInfo getAppTimeouts(@Context HttpServletRequest hsr,
803 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException {
804 init();
805 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
806 return pipeline.getRootInterceptor().getAppTimeouts(hsr, appId);
807 }
808
809 @PUT
810 @Path(RMWSConsts.APPS_TIMEOUT)
811 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
812 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
813 @Override
814 public Response updateApplicationTimeout(AppTimeoutInfo appTimeout,
815 @Context HttpServletRequest hsr,
816 @PathParam(RMWSConsts.APPID) String appId) throws AuthorizationException,
817 YarnException, InterruptedException, IOException {
818 init();
819 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
820 return pipeline.getRootInterceptor().updateApplicationTimeout(appTimeout,
821 hsr, appId);
822 }
823
824 @GET
825 @Path(RMWSConsts.APPS_APPID_APPATTEMPTS)
826 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
827 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
828 @Override
829 public AppAttemptsInfo getAppAttempts(@Context HttpServletRequest hsr,
830 @PathParam(RMWSConsts.APPID) String appId) {
831 init();
832 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
833 return pipeline.getRootInterceptor().getAppAttempts(hsr, appId);
834 }
835
836 @GET
837 @Path(RMWSConsts.CHECK_USER_ACCESS_TO_QUEUE)
838 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
839 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
840 @Override
841 public RMQueueAclInfo checkUserAccessToQueue(
842 @PathParam(RMWSConsts.QUEUE) String queue,
843 @QueryParam(RMWSConsts.USER) String username,
844 @QueryParam(RMWSConsts.QUEUE_ACL_TYPE)
845 @DefaultValue("SUBMIT_APPLICATIONS") String queueAclType,
846 @Context HttpServletRequest hsr) throws AuthorizationException {
847 init();
848 RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
849 return pipeline.getRootInterceptor().checkUserAccessToQueue(queue,
850 username, queueAclType, hsr);
851 }
852
853 @GET
854 @Path(RMWSConsts.APPS_APPID_APPATTEMPTS_APPATTEMPTID)
855 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
856 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
857 public org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo getAppAttempt(
858 @Context HttpServletRequest req, @Context HttpServletResponse res,
859 @PathParam(RMWSConsts.APPID) String appId,
860 @PathParam(RMWSConsts.APPATTEMPTID) String appAttemptId) {
861 init();
862 RequestInterceptorChainWrapper pipeline = getInterceptorChain(req);
863 return pipeline.getRootInterceptor().getAppAttempt(req, res, appId,
864 appAttemptId);
865 }
866
867 @GET
868 @Path(RMWSConsts.APPS_APPID_APPATTEMPTS_APPATTEMPTID_CONTAINERS)
869 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
870 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
871 public ContainersInfo getContainers(@Context HttpServletRequest req,
872 @Context HttpServletResponse res,
873 @PathParam(RMWSConsts.APPID) String appId,
874 @PathParam(RMWSConsts.APPATTEMPTID) String appAttemptId) {
875 init();
876 RequestInterceptorChainWrapper pipeline = getInterceptorChain(req);
877 return pipeline.getRootInterceptor().getContainers(req, res, appId,
878 appAttemptId);
879 }
880
881 @GET
882 @Path(RMWSConsts.GET_CONTAINER)
883 @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
884 MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
885 public ContainerInfo getContainer(@Context HttpServletRequest req,
886 @Context HttpServletResponse res,
887 @PathParam(RMWSConsts.APPID) String appId,
888 @PathParam(RMWSConsts.APPATTEMPTID) String appAttemptId,
889 @PathParam(RMWSConsts.CONTAINERID) String containerId) {
890 init();
891 RequestInterceptorChainWrapper pipeline = getInterceptorChain(req);
892 return pipeline.getRootInterceptor().getContainer(req, res, appId,
893 appAttemptId, containerId);
894 }
895
896 @VisibleForTesting
897 protected void setResponse(HttpServletResponse response) {
898 this.response = response;
899 }
900
901 }