Source:
public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) { LOGGER.info("resourceOffers() with offers", offers.size()); if (!reconcileTasks.isEmpty()) { LOGGER.info("declining all offers.. got some reconcile tasks"); for (Protos.Offer offer : offers) { driver.declineOffer(offer.getId()); } return; } int desiredInstances = crateState.desiredInstances(); int toKill = crateInstances.size() - desiredInstances; if (toKill > 0) { killInstances(driver, toKill); } else if (toKill < 0) { int toSpawn = toKill * -1; List<Protos.TaskInfo> tasks = new ArrayList<>(toSpawn); List<Protos.OfferID> offerIDs = new ArrayList<>(toSpawn); for (Protos.Offer offer : offers) { if (crateInstances.anyOnHost(offer.getHostname())) { LOGGER.info("got already an instance on {}, rejecting offer {}", offer.getHostname(), offer.getId().getValue()); driver.declineOffer(offer.getId()); continue; } if (!resourceConfiguration.matches(offer.getResourcesList())) { LOGGER.info("can't use offer {}; not enough resources", offer.getId().getValue()); continue; } UUID id = UUID.randomUUID(); CrateContainer container = new CrateContainer( id, "mesos", offer.getHostname(), crateInstances.hosts(), resourceConfiguration); Protos.TaskInfo taskInfo = container.taskInfo(offer); LOGGER.info("Launching task {}", container.taskId().getValue()); crateInstances.addInstance(new CrateInstance(container, taskInfo)); tasks.add(taskInfo); LOGGER.debug("task: {}", taskInfo); offerIDs.add(offer.getId()); } if (!tasks.isEmpty()) { Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build(); driver.launchTasks(offerIDs, tasks, filters); } } crateState.instances(crateInstances); }

Target:
public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) { LOGGER.info("resourceOffers() with offers", offers.size()); if (!reconcileTasks.isEmpty()) { LOGGER.info("declining all offers.. got some reconcile tasks"); for (Protos.Offer offer : offers) { driver.declineOffer(offer.getId()); } return; } int desiredInstances = crateState.desiredInstances(); int toKill = crateInstances.size() - desiredInstances; if (toKill > 0) { killInstances(driver, toKill); } else if (toKill < 0) { int toSpawn = toKill * -1; List<Protos.TaskInfo> tasks = new ArrayList<>(toSpawn); List<Protos.OfferID> offerIDs = new ArrayList<>(toSpawn); for (Protos.Offer offer : offers) { if (crateInstances.anyOnHost(offer.getHostname())) { LOGGER.info("got already an instance on {}, rejecting offer {}", offer.getHostname(), offer.getId().getValue()); driver.declineOffer(offer.getId()); continue; } if (!resourceConfiguration.matches(offer.getResourcesList())) { LOGGER.info("can't use offer {}; not enough resources", offer.getId().getValue()); continue; } CrateContainer container = new CrateContainer( "mesos", offer.getHostname(), crateInstances.hosts(), resourceConfiguration); Protos.TaskInfo taskInfo = container.taskInfo(offer); LOGGER.info("Launching task {}", container.taskId().getValue()); crateInstances.addInstance(new CrateInstance(container, taskInfo)); tasks.add(taskInfo); LOGGER.debug("task: {}", taskInfo); offerIDs.add(offer.getId()); } if (!tasks.isEmpty()) { Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build(); driver.launchTasks(offerIDs, tasks, filters); } } crateState.instances(crateInstances); }