SchedConfCLI extends Configured implements Tool { @VisibleForTesting int getSchedulerConf(String webAppAddress, WebResource resource) throws Exception { ClientResponse response = null; resource = (resource != null) ? resource : initializeWebResource(webAppAddress); try { Builder builder; if (UserGroupInformation.isSecurityEnabled()) { builder = resource .path("ws").path("v1").path("cluster") .path("scheduler-conf").accept(MediaType.APPLICATION_XML); } else { builder = resource .path("ws").path("v1").path("cluster").path("scheduler-conf") .queryParam("user.name", UserGroupInformation.getCurrentUser() .getShortUserName()).accept(MediaType.APPLICATION_XML); } response = builder.get(ClientResponse.class); if (response != null) { if (response.getStatus() == Status.OK.getStatusCode()) { ConfInfo schedulerConf = response.getEntity(ConfInfo.class); JAXBContext jaxbContext = JAXBContext.newInstance(ConfInfo.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); StringWriter sw = new StringWriter(); jaxbMarshaller.marshal(schedulerConf, sw); prettyFormatWithIndent(sw.toString(), 2); return 0; } else { System.err.println("Failed to get scheduler configuration: " + response.getEntity(String.class)); } } else { System.err.println("Failed to get scheduler configuration: " + "null response"); } return -1; } finally { if (response != null) { response.close(); } destroyClient(); } } SchedConfCLI(); static void main(String[] args); @Override int run(String[] args);  }
@Test(timeout = 10000) public void testGetSchedulerConf() throws Exception { ByteArrayOutputStream sysOutStream = new ByteArrayOutputStream(); PrintStream sysOut = new PrintStream(sysOutStream); System.setOut(sysOut); try { super.setUp(); GuiceServletConfig.setInjector( Guice.createInjector(new WebServletModule())); int exitCode = cli.getSchedulerConf("", resource()); assertEquals("SchedConfCLI failed to run", 0, exitCode); assertTrue("Failed to get scheduler configuration", sysOutStream.toString().contains("testqueue")); } finally { cleanUp(); } }