SubmarineResourceUtils { public static Resource convertYarnResourceToServiceResource( org.apache.hadoop.yarn.api.records.Resource yarnResource) { Resource serviceResource = new Resource(); serviceResource.setCpus(yarnResource.getVirtualCores()); serviceResource.setMemory(String.valueOf(yarnResource.getMemorySize())); Map<String, ResourceInformation> riMap = new HashMap<>(); for (org.apache.hadoop.yarn.api.records.ResourceInformation ri : yarnResource.getAllResourcesListCopy()) { ResourceInformation serviceRi = new ResourceInformation(); serviceRi.setValue(ri.getValue()); serviceRi.setUnit(ri.getUnits()); riMap.put(ri.getName(), serviceRi); } serviceResource.setResourceInformations(riMap); return serviceResource; } private  SubmarineResourceUtils(); static Resource convertYarnResourceToServiceResource(
      org.apache.hadoop.yarn.api.records.Resource yarnResource);  }
@Test public void testConvertResourceWithCustomResource() { initResourceTypes(); Resource res = Resource.newInstance(4096, 12, ImmutableMap.of(CUSTOM_RESOURCE_NAME, 20L)); org.apache.hadoop.yarn.service.api.records.Resource serviceResource = SubmarineResourceUtils.convertYarnResourceToServiceResource(res); assertEquals(12, serviceResource.getCpus().intValue()); assertEquals(4096, (int) Integer.valueOf(serviceResource.getMemory())); Map<String, ResourceInformation> additionalResources = serviceResource.getAdditional(); assertEquals(3, additionalResources.size()); ResourceInformation customResourceRI = additionalResources.get(CUSTOM_RESOURCE_NAME); assertEquals("G", customResourceRI.getUnit()); assertEquals(20L, (long) customResourceRI.getValue()); }