MesosNimbus implements INimbus { protected List<Resource> subtractResourcesRange(final List<Resource> offerResources, final long value, final String name) { List<Resource> resources = new ArrayList<>(); for (Resource r : offerResources) { if (r.hasReservation()) { continue; } if (r.getType() == Type.RANGES && r.getName().equals(name)) { Resource.Builder remaining = r.toBuilder(); Ranges.Builder ranges = Ranges.newBuilder(); for (Range range : r.getRanges().getRangeList()) { if (value >= range.getBegin() && value <= range.getEnd()) { if (range.getBegin() <= value && range.getEnd() >= value) { if (range.getBegin() == value && range.getEnd() > value) { ranges.addRange( Range.newBuilder().setBegin(range.getBegin() + 1).setEnd(range.getEnd()).build() ); } else if (range.getBegin() < value && range.getEnd() == value) { ranges.addRange( Range.newBuilder().setBegin(range.getBegin()).setEnd(range.getEnd() - 1).build() ); } else if (range.getBegin() < value && range.getEnd() > value) { ranges.addRange( Range.newBuilder().setBegin(range.getBegin()).setEnd(value - 1).build() ); ranges.addRange( Range.newBuilder().setBegin(value + 1).setEnd(range.getEnd()).build() ); } else { } } } else { ranges.addRange(range.toBuilder().build()); } } remaining.setRanges(ranges.build()); if (remaining.getRanges().getRangeCount() > 0) { resources.add(remaining.build()); } } else { resources.add(r.toBuilder().build()); } } 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 testSubtractResourcesRange() throws Exception { MesosNimbus mesosNimbus = new MesosNimbus(); assertEquals( Arrays.asList( TestUtils.buildScalarResource("cpus", 1.0), TestUtils.buildScalarResource("mem", 2.0), TestUtils.buildScalarResourceWithRole("cpus", 3.0, "reserved"), TestUtils.buildScalarResourceWithRole("mem", 4.0, "reserved") ), mesosNimbus.subtractResourcesRange( TestUtils.buildRangeResourceList(100, 100), 100, "ports" ) ); assertEquals( Arrays.asList( TestUtils.buildMultiRangeResource("ports", 100, 104, 106, 200), TestUtils.buildMultiRangeResourceWithRole("ports", 100, 104, 106, 200, "reserved"), TestUtils.buildScalarResource("cpus", 1.0), TestUtils.buildScalarResource("mem", 2.0), TestUtils.buildScalarResourceWithRole("cpus", 3.0, "reserved"), TestUtils.buildScalarResourceWithRole("mem", 4.0, "reserved") ), mesosNimbus.subtractResourcesRange( TestUtils.buildRangeResourceList(100, 200), 105, "ports" ) ); }