TaskUtils { public Iterable<Protos.Resource> getScalarResource(Protos.Offer offer, String name, Double value, Double used) { String role = cfg.getFrameworkRole(); List<Protos.Resource> resources = new ArrayList<Protos.Resource>(); double resourceDifference = 0; for (Protos.Resource r : offer.getResourcesList()) { if (r.getName().equals(name) && r.hasRole() && r.getRole().equals(role) && r.hasScalar()) { resourceDifference = Math.max(r.getScalar().getValue() - used, 0.0); if (resourceDifference > 0) { resources.add(Protos.Resource.newBuilder().setName(name).setType(Protos.Value.Type.SCALAR) .setScalar(Protos.Value.Scalar.newBuilder().setValue(Math.min(value, resourceDifference)).build()) .setRole(role).build()); } break; } else if (r.getName().equals(name) && r.hasRole() && r.getRole().equals(role)) { LOGGER.warn("Resource with name: " + name + "expected type to be SCALAR check configuration on: " + offer.getHostname()); } } if (value - resourceDifference > 0) { resources.add(Protos.Resource.newBuilder().setName(name).setType(Protos.Value.Type.SCALAR) .setScalar(Protos.Value.Scalar.newBuilder().setValue(value - resourceDifference).build()) .build()); } return resources; } @Inject  TaskUtils(MyriadConfiguration cfg);  TaskUtils(); double getNodeManagerMemory(); double getNodeManagerMaxCpus(); double getNodeManagerCpus(); Map<String, Long> getNodeManagerPorts(); double getExecutorCpus(); double getExecutorMemory(); Iterable<Protos.Resource> getScalarResource(Protos.Offer offer, String name, Double value, Double used);  }
@Test public void testGetScalarResourcesWithRole() { TaskUtils taskUtils = new TaskUtils(cfgWithRole); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 3.0, 2.0), "cpus", 1.0, 0.0), "cpus", 1.0, 0.0); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 0.0, 2.0), "cpus", 1.0, 1.0), "cpus", 0.0, 1.0); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 1.5, 2.0), "cpus", 2.0, 1.0), "cpus", 0.5, 1.5); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 1.5, 2.0), "cpus", 1.5, 2.0), "cpus", 0.0, 1.5); }
@Test public void testGetScalarResources() { TaskUtils taskUtils = new TaskUtils(cfg); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 0.0, 2.0), "cpus", 1.0, 0.0), "cpus", 0.0, 1.0); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 0.0, 2.0), "cpus", 1.0, 1.0), "cpus", 0.0, 1.0); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 0.0, 2.0), "cpus", 1.0, 1.0), "cpus", 0.0, 1.0); checkResourceList(taskUtils.getScalarResource(createScalarOffer("cpus", 0.0, 2.0), "cpus", 0.5, 1.5), "cpus", 0.0, 0.5); }