RMWebServices { @POST @Path("/scheduler/logs") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String dumpSchedulerLogs(@FormParam("time") String time, @Context HttpServletRequest hsr) throws IOException { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); ApplicationACLsManager aclsManager = rm.getApplicationACLsManager(); if (aclsManager.areACLsEnabled()) { if (callerUGI == null || !aclsManager.isAdmin(callerUGI)) { String msg = "Only admins can carry out this operation."; throw new ForbiddenException(msg); } } ResourceScheduler rs = rm.getResourceScheduler(); int period = Integer.parseInt(time); if (period <= 0) { throw new BadRequestException("Period must be greater than 0"); } final String logHierarchy = "org.apache.hadoop.yarn.server.resourcemanager.scheduler"; String logfile = "yarn-scheduler-debug.log"; if (rs instanceof CapacityScheduler) { logfile = "yarn-capacity-scheduler-debug.log"; } else if (rs instanceof FairScheduler) { logfile = "yarn-fair-scheduler-debug.log"; } AdHocLogDumper dumper = new AdHocLogDumper(logHierarchy, logfile); dumper.dumpLogs("DEBUG", period * 1000); return "Capacity scheduler logs are being created."; } @Inject  RMWebServices(final ResourceManager rm, Configuration conf);   RMWebServices(ResourceManager rm, Configuration conf,
      HttpServletResponse response); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) ClusterInfo get(); @GET @Path("/info") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) ClusterInfo getClusterInfo(); @GET @Path("/metrics") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) ClusterMetricsInfo getClusterMetricsInfo(); @GET @Path("/scheduler") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) SchedulerTypeInfo getSchedulerInfo(); @POST @Path("/scheduler/logs") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) String dumpSchedulerLogs(@FormParam("time") String time,
      @Context HttpServletRequest hsr); @GET @Path("/nodes") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) NodesInfo getNodes(@QueryParam("states") String states); @GET @Path("/nodes/{nodeId}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) NodeInfo getNode(@PathParam("nodeId") String nodeId); @GET @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) AppsInfo getApps(@Context HttpServletRequest hsr,
      @QueryParam("state") String stateQuery,
      @QueryParam("states") Set<String> statesQuery,
      @QueryParam("finalStatus") String finalStatusQuery,
      @QueryParam("user") String userQuery,
      @QueryParam("queue") String queueQuery,
      @QueryParam("limit") String count,
      @QueryParam("startedTimeBegin") String startedBegin,
      @QueryParam("startedTimeEnd") String startedEnd,
      @QueryParam("finishedTimeBegin") String finishBegin,
      @QueryParam("finishedTimeEnd") String finishEnd,
      @QueryParam("applicationTypes") Set<String> applicationTypes,
      @QueryParam("applicationTags") Set<String> applicationTags); @GET @Path("/appstatistics") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) ApplicationStatisticsInfo getAppStatistics(
      @Context HttpServletRequest hsr,
      @QueryParam("states") Set<String> stateQueries,
      @QueryParam("applicationTypes") Set<String> typeQueries); @GET @Path("/apps/{appid}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) AppInfo getApp(@Context HttpServletRequest hsr,
      @PathParam("appid") String appId); @GET @Path("/apps/{appid}/appattempts") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) AppAttemptsInfo getAppAttempts(@Context HttpServletRequest hsr,
      @PathParam("appid") String appId); @GET @Path("/apps/{appid}/state") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) AppState getAppState(@Context HttpServletRequest hsr,
      @PathParam("appid") String appId); @PUT @Path("/apps/{appid}/state") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response updateAppState(AppState targetState,
      @Context HttpServletRequest hsr, @PathParam("appid") String appId); @GET @Path("/get-node-to-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr); @GET @Path("/label-mappings") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) LabelsToNodesInfo getLabelsToNodes(
      @QueryParam("labels") Set<String> labels); @POST @Path("/replace-node-to-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response replaceLabelsOnNodes(final NodeToLabelsEntryList newNodeToLabels,
      @Context HttpServletRequest hsr); @POST @Path("/nodes/{nodeId}/replace-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response replaceLabelsOnNode(
      @QueryParam("labels") Set<String> newNodeLabelsName,
      @Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId); @GET @Path("/get-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr); @POST @Path("/add-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response addToClusterNodeLabels(final NodeLabelsInfo newNodeLabels,
      @Context HttpServletRequest hsr); @POST @Path("/remove-node-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response removeFromCluserNodeLabels(
      @QueryParam("labels") Set<String> oldNodeLabels,
      @Context HttpServletRequest hsr); @GET @Path("/nodes/{nodeId}/get-labels") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr,
      @PathParam("nodeId") String nodeId); @GET @Path("/apps/{appid}/priority") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) AppPriority getAppPriority(@Context HttpServletRequest hsr,
      @PathParam("appid") String appId); @PUT @Path("/apps/{appid}/priority") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response updateApplicationPriority(AppPriority targetPriority,
      @Context HttpServletRequest hsr, @PathParam("appid") String appId); @GET @Path("/apps/{appid}/queue") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) AppQueue getAppQueue(@Context HttpServletRequest hsr,
      @PathParam("appid") String appId); @PUT @Path("/apps/{appid}/queue") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response updateAppQueue(AppQueue targetQueue,
      @Context HttpServletRequest hsr, @PathParam("appid") String appId); @POST @Path("/apps/new-application") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response createNewApplication(@Context HttpServletRequest hsr); @POST @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response submitApplication(ApplicationSubmissionContextInfo newApp,
      @Context HttpServletRequest hsr); @POST @Path("/delegation-token") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response postDelegationToken(DelegationToken tokenData,
      @Context HttpServletRequest hsr); @POST @Path("/delegation-token/expiration") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response postDelegationTokenExpiration(@Context HttpServletRequest hsr); @DELETE @Path("/delegation-token") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response cancelDelegationToken(@Context HttpServletRequest hsr); @POST @Path("/reservation/submit") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response submitReservation(
      ReservationSubmissionRequestInfo resContext,
      @Context HttpServletRequest hsr); @POST @Path("/reservation/update") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response updateReservation(ReservationUpdateRequestInfo resContext,
      @Context HttpServletRequest hsr); @POST @Path("/reservation/delete") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response deleteReservation(ReservationDeleteRequestInfo resContext,
      @Context HttpServletRequest hsr); final static String DELEGATION_TOKEN_HEADER; }
@Test public void testDumpingSchedulerLogs() throws Exception { ResourceManager mockRM = mock(ResourceManager.class); Configuration conf = new YarnConfiguration(); HttpServletRequest mockHsr = mock(HttpServletRequest.class); ApplicationACLsManager aclsManager = new ApplicationACLsManager(conf); when(mockRM.getApplicationACLsManager()).thenReturn(aclsManager); RMWebServices webSvc = new RMWebServices(mockRM, conf, mock(HttpServletResponse.class)); webSvc.dumpSchedulerLogs("1", mockHsr); Thread.sleep(1000); checkSchedulerLogFileAndCleanup(); conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true); conf.setStrings(YarnConfiguration.YARN_ADMIN_ACL, "admin"); aclsManager = new ApplicationACLsManager(conf); when(mockRM.getApplicationACLsManager()).thenReturn(aclsManager); webSvc = new RMWebServices(mockRM, conf, mock(HttpServletResponse.class)); boolean exceptionThrown = false; try { webSvc.dumpSchedulerLogs("1", mockHsr); fail("Dumping logs should fail"); } catch (ForbiddenException ae) { exceptionThrown = true; } assertTrue("ForbiddenException expected", exceptionThrown); exceptionThrown = false; when(mockHsr.getUserPrincipal()).thenReturn(new Principal() { @Override public String getName() { return "testuser"; } }); try { webSvc.dumpSchedulerLogs("1", mockHsr); fail("Dumping logs should fail"); } catch (ForbiddenException ae) { exceptionThrown = true; } assertTrue("ForbiddenException expected", exceptionThrown); when(mockHsr.getUserPrincipal()).thenReturn(new Principal() { @Override public String getName() { return "admin"; } }); webSvc.dumpSchedulerLogs("1", mockHsr); Thread.sleep(1000); checkSchedulerLogFileAndCleanup(); }