NMWebServices { @GET @Path("/resources/{resourcename}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) public Object getNMResourceInfo( @PathParam("resourcename") String resourceName) throws YarnException { init(); ResourcePluginManager rpm = this.nmContext.getResourcePluginManager(); if (rpm != null && rpm.getNameToPlugins() != null) { ResourcePlugin plugin = rpm.getNameToPlugins().get(resourceName); if (plugin != null) { NMResourceInfo nmResourceInfo = plugin.getNMResourceInfo(); if (nmResourceInfo != null) { return nmResourceInfo; } } } return new NMResourceInfo(); } @Inject  NMWebServices(final Context nm, final ResourceView view,
      final WebApp webapp);  NMWebServices(final Context nm, final ResourceView view,
      final WebApp webapp, HttpServletResponse response); @GET @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) NodeInfo get(); @GET @Path("/info") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) NodeInfo getNodeInfo(); @GET @Path("/apps") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) AppsInfo getNodeApps(@javax.ws.rs.core.Context HttpServletRequest hsr,
      @QueryParam("state") String stateQuery,
      @QueryParam("user") String userQuery); @GET @Path("/apps/{appid}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) AppInfo getNodeApp(@PathParam("appid") String appId); @GET @Path("/containers") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) ContainersInfo getNodeContainers(@javax.ws.rs.core.Context
      HttpServletRequest hsr); @GET @Path("/containers/{containerid}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) ContainerInfo getNodeContainer(@javax.ws.rs.core.Context
      HttpServletRequest hsr, @PathParam("containerid") String id); @GET @Path("/containers/{containerid}/logs") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) Response getContainerLogsInfo(
      @javax.ws.rs.core.Context HttpServletRequest hsr,
      @javax.ws.rs.core.Context HttpServletResponse res,
      @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr); @GET @Path("/containers/{containerid}/logs/{filename}") @Produces({ MediaType.TEXT_PLAIN + "; " + JettyUtils.UTF_8 }) @Public @Unstable Response getContainerLogFile(
      @PathParam(YarnWebServiceParams.CONTAINER_ID)
      final String containerIdStr,
      @PathParam(YarnWebServiceParams.CONTAINER_LOG_FILE_NAME)
      String filename,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_FORMAT)
      String format,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_SIZE)
      String size); @GET @Path("/containerlogs/{containerid}/{filename}") @Produces({ MediaType.TEXT_PLAIN + "; " + JettyUtils.UTF_8 }) @Public @Unstable Response getLogs(
      @PathParam(YarnWebServiceParams.CONTAINER_ID)
      final String containerIdStr,
      @PathParam(YarnWebServiceParams.CONTAINER_LOG_FILE_NAME)
      String filename,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_FORMAT)
      String format,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_SIZE)
      String size); @GET @Path("/resources/{resourcename}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) Object getNMResourceInfo(
      @PathParam("resourcename")
          String resourceName);  }
@Test public void testGetNMResourceInfo() throws YarnException, InterruptedException, JSONException { ResourcePluginManager rpm = mock(ResourcePluginManager.class); Map<String, ResourcePlugin> namesToPlugins = new HashMap<>(); ResourcePlugin mockPlugin1 = mock(ResourcePlugin.class); NMResourceInfo nmResourceInfo1 = new NMResourceInfo() { public long a = 1000L; }; when(mockPlugin1.getNMResourceInfo()).thenReturn(nmResourceInfo1); namesToPlugins.put("resource-1", mockPlugin1); namesToPlugins.put("yarn.io/resource-1", mockPlugin1); ResourcePlugin mockPlugin2 = mock(ResourcePlugin.class); namesToPlugins.put("resource-2", mockPlugin2); when(rpm.getNameToPlugins()).thenReturn(namesToPlugins); nmContext.setResourcePluginManager(rpm); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("node").path( "resources").path("resource-2").accept(MediaType.APPLICATION_JSON).get( ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); Assert.assertEquals(0, json.length()); response = r.path("ws").path("v1").path("node").path( "resources").path("resource-3").accept(MediaType.APPLICATION_JSON).get( ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); json = response.getEntity(JSONObject.class); Assert.assertEquals(0, json.length()); response = r.path("ws").path("v1").path("node").path( "resources").path("resource-1").accept(MediaType.APPLICATION_JSON).get( ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); json = response.getEntity(JSONObject.class); Assert.assertEquals(1000, json.get("a")); response = r.path("ws").path("v1").path("node").path("resources").path( "yarn.io%2Fresource-1").accept(MediaType.APPLICATION_JSON).get( ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); json = response.getEntity(JSONObject.class); Assert.assertEquals(1000, json.get("a")); }