MesosNimbus implements INimbus { protected List<Resource> getResourcesScalar(final List<Resource> offerResources, final double value, final String name) { List<Resource> resources = new ArrayList<>(); double valueNeeded = value; for (Resource r : offerResources) { if (r.hasReservation()) { continue; } if (r.getType() == Type.SCALAR && r.getName().equals(name)) { if (r.getScalar().getValue() > valueNeeded) { resources.add( r.toBuilder() .setScalar(Scalar.newBuilder().setValue(valueNeeded)) .build() ); return resources; } else if (Math.abs(r.getScalar().getValue() - valueNeeded) < 0.0001) { resources.add( r.toBuilder() .setScalar(Scalar.newBuilder().setValue(valueNeeded)) .build() ); return resources; } else { resources.add(r.toBuilder().build()); valueNeeded -= r.getScalar().getValue(); } } } return resources; } MesosNimbus(); static void main(String[] args); @Override IScheduler getForcedScheduler(); @Override String getHostName(Map<String, SupervisorDetails> map, String nodeId); @Override void prepare(Map conf, String localDir); void doRegistration(final SchedulerDriver driver, Protos.FrameworkID id); void shutdown(); void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers); void offerRescinded(OfferID id); void taskLost(final TaskID taskId); boolean isHostAccepted(String hostname); @Override Collection<WorkerSlot> allSlotsAvailableForScheduling(
          Collection<SupervisorDetails> existingSupervisors, Topologies topologies, Set<String> topologiesMissingAssignments); @Override void assignSlots(Topologies topologies, Map<String, Collection<WorkerSlot>> slots); static final String CONF_EXECUTOR_URI; static final String CONF_MASTER_URL; static final String CONF_MASTER_FAILOVER_TIMEOUT_SECS; static final String CONF_MESOS_ALLOWED_HOSTS; static final String CONF_MESOS_DISALLOWED_HOSTS; static final String CONF_MESOS_ROLE; static final String CONF_MESOS_PRINCIPAL; static final String CONF_MESOS_SECRET_FILE; static final String CONF_MESOS_CHECKPOINT; static final String CONF_MESOS_OFFER_LRU_CACHE_SIZE; static final String CONF_MESOS_OFFER_FILTER_SECONDS; static final String CONF_MESOS_OFFER_EXPIRY_MULTIPLIER; static final String CONF_MESOS_LOCAL_FILE_SERVER_PORT; static final String CONF_MESOS_FRAMEWORK_NAME; static final String CONF_MESOS_PREFER_RESERVED_RESOURCES; static final String CONF_MESOS_CONTAINER_DOCKER_IMAGE; static final String FRAMEWORK_ID; }
@Test public void testGetResourcesScalar() throws Exception { MesosNimbus mesosNimbus = new MesosNimbus(); assertEquals( Arrays.asList(TestUtils.buildScalarResource("cpus", 1.0)), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 1.0, "cpus" ) ); assertEquals( Arrays.asList(TestUtils.buildScalarResource("mem", 2.0)), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 2.0, "mem" ) ); assertEquals( Arrays.asList( TestUtils.buildScalarResource("cpus", 1.0), TestUtils.buildScalarResourceWithRole("cpus", 1.0, "reserved") ), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 2.0, "cpus" ) ); assertEquals( Arrays.asList( TestUtils.buildScalarResource("mem", 2.0), TestUtils.buildScalarResourceWithRole("mem", 1.0, "reserved") ), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 3.0, "mem" ) ); assertEquals( Arrays.asList( TestUtils.buildScalarResource("cpus", 1.0), TestUtils.buildScalarResourceWithRole("cpus", 3.0, "reserved") ), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 4.0, "cpus" ) ); assertEquals( Arrays.asList( TestUtils.buildScalarResource("mem", 2.0), TestUtils.buildScalarResourceWithRole("mem", 4.0, "reserved") ), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 6.0, "mem" ) ); assertEquals( Arrays.asList( TestUtils.buildScalarResource("cpus", 1.0), TestUtils.buildScalarResourceWithRole("cpus", 0.5, "reserved") ), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 1.5, "cpus" ) ); assertEquals( Arrays.asList( TestUtils.buildScalarResource("mem", 2.0), TestUtils.buildScalarResourceWithRole("mem", 0.5, "reserved") ), mesosNimbus.getResourcesScalar( TestUtils.buildResourceList(1, 2, 3, 4), 2.5, "mem" ) ); }