OfferUtils { public static Resource getYarnResourcesFromMesosOffers(Collection<Offer> offers) { double cpus = 0.0; double mem = 0.0; for (Protos.Offer offer : offers) { for (Protos.Resource resource : offer.getResourcesList()) { if (resource.getName().equalsIgnoreCase("cpus")) { cpus += resource.getScalar().getValue(); } else if (resource.getName().equalsIgnoreCase("mem")) { mem += resource.getScalar().getValue(); } } } return Resource.newInstance((int) mem, (int) cpus); }  static Resource getYarnResourcesFromMesosOffers(Collection<Offer> offers);  }
@Test public void testgetYarnResourcesFromMesosOffers() throws Exception { org.apache.hadoop.yarn.api.records.Resource resource = OfferUtils.getYarnResourcesFromMesosOffers(offers); assertEquals(6.0, resource.getMemory(), 1.0); assertEquals(3.0, resource.getVirtualCores(), 1.0); }