use of org.apache.mesos.v1.scheduler.Protos.Call.Decline in project Singularity by HubSpot.
the class SingularityMesosSchedulerClient method decline.
/**
* Sent by the scheduler to explicitly decline offer(s) received. Note that this is same as sending an
* ACCEPT call with no operations.
*
* @param offerIds
*/
public void decline(List<OfferID> offerIds) {
Builder decline = build().setDecline(Decline.newBuilder().addAllOfferIds(offerIds));
sendCall(decline, Type.DECLINE);
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Decline in project Singularity by HubSpot.
the class SingularityMesosSchedulerImpl method resourceOffers.
@Timed
@Override
public void resourceOffers(List<Offer> offers) {
if (!isRunning()) {
LOG.info("Scheduler is in state {}, declining {} offer(s)", state.name(), offers.size());
mesosSchedulerClient.decline(offers.stream().map(Offer::getId).collect(Collectors.toList()));
return;
}
callWithOffersLock(() -> {
final long start = System.currentTimeMillis();
lastOfferTimestamp = Optional.of(start);
LOG.info("Received {} offer(s)", offers.size());
boolean delclineImmediately = false;
if (disasterManager.isDisabled(SingularityAction.PROCESS_OFFERS)) {
LOG.info("Processing offers is currently disabled, declining {} offers", offers.size());
delclineImmediately = true;
}
if (delayWhenStatusUpdateDeltaTooLarge && statusUpdateDeltaAvg.get() > delayWhenDeltaOverMs) {
LOG.info("Status update delta is too large ({}), declining offers while status updates catch up", statusUpdateDeltaAvg.get());
delclineImmediately = true;
}
if (delclineImmediately) {
mesosSchedulerClient.decline(offers.stream().map(Offer::getId).collect(Collectors.toList()));
return;
}
if (offerCacheEnabled) {
if (disasterManager.isDisabled(SingularityAction.CACHE_OFFERS)) {
offerCache.disableOfferCache();
} else {
offerCache.enableOfferCache();
}
}
List<Offer> offersToCheck = new ArrayList<>(offers);
List<CachedOffer> cachedOfferList = offerCache.checkoutOffers();
Map<String, CachedOffer> cachedOffers = new HashMap<>();
for (CachedOffer cachedOffer : cachedOfferList) {
cachedOffers.put(cachedOffer.getOfferId(), cachedOffer);
offersToCheck.add(cachedOffer.getOffer());
}
offers.parallelStream().forEach((offer) -> {
String rolesInfo = MesosUtils.getRoles(offer).toString();
LOG.debug("Received offer ID {} with roles {} from {} ({}) for {} cpu(s), {} memory, {} ports, and {} disk", offer.getId().getValue(), rolesInfo, offer.getHostname(), offer.getAgentId().getValue(), MesosUtils.getNumCpus(offer), MesosUtils.getMemory(offer), MesosUtils.getNumPorts(offer), MesosUtils.getDisk(offer));
CheckResult checkResult = slaveAndRackManager.checkOffer(offer);
if (checkResult == CheckResult.NOT_ACCEPTING_TASKS) {
mesosSchedulerClient.decline(Collections.singletonList(offer.getId()));
offersToCheck.remove(offer);
LOG.debug("Will decline offer {}, slave {} is not currently in a state to launch tasks", offer.getId().getValue(), offer.getHostname());
}
});
final Set<OfferID> acceptedOffers = Sets.newHashSetWithExpectedSize(offersToCheck.size());
try {
Collection<SingularityOfferHolder> offerHolders = offerScheduler.checkOffers(offersToCheck);
for (SingularityOfferHolder offerHolder : offerHolders) {
if (!offerHolder.getAcceptedTasks().isEmpty()) {
List<Offer> leftoverOffers = offerHolder.launchTasksAndGetUnusedOffers(mesosSchedulerClient);
leftoverOffers.forEach((o) -> {
if (cachedOffers.containsKey(o.getId().getValue())) {
offerCache.returnOffer(cachedOffers.remove(o.getId().getValue()));
} else {
offerCache.cacheOffer(start, o);
}
});
List<Offer> offersAcceptedFromSlave = offerHolder.getOffers();
offersAcceptedFromSlave.removeAll(leftoverOffers);
offersAcceptedFromSlave.stream().filter((offer) -> cachedOffers.containsKey(offer.getId().getValue())).map((o) -> cachedOffers.remove(o.getId().getValue())).forEach(offerCache::useOffer);
acceptedOffers.addAll(offersAcceptedFromSlave.stream().map(Offer::getId).collect(Collectors.toList()));
} else {
offerHolder.getOffers().forEach((o) -> {
if (cachedOffers.containsKey(o.getId().getValue())) {
offerCache.returnOffer(cachedOffers.remove(o.getId().getValue()));
} else {
offerCache.cacheOffer(start, o);
}
});
}
}
LOG.info("{} remaining offers not accounted for in offer check", cachedOffers.size());
cachedOffers.values().forEach(offerCache::returnOffer);
} catch (Throwable t) {
LOG.error("Received fatal error while handling offers - will decline all available offers", t);
mesosSchedulerClient.decline(offersToCheck.stream().filter((o) -> !acceptedOffers.contains(o.getId()) && !cachedOffers.containsKey(o.getId().getValue())).map(Offer::getId).collect(Collectors.toList()));
offersToCheck.forEach((o) -> {
if (cachedOffers.containsKey(o.getId().getValue())) {
offerCache.returnOffer(cachedOffers.get(o.getId().getValue()));
}
});
throw t;
}
LOG.info("Finished handling {} new offer(s) ({}), {} accepted, {} declined/cached", offers.size(), JavaUtils.duration(start), acceptedOffers.size(), offers.size() - acceptedOffers.size());
}, "resourceOffers");
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Decline in project Singularity by HubSpot.
the class SingularityMesosSchedulerClient method revive.
/**
* Sent by the scheduler to remove any/all filters that it has previously set via ACCEPT or DECLINE calls.
*/
public void revive() {
Builder revive = build();
sendCall(revive, Type.REVIVE);
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Decline in project Singularity by HubSpot.
the class SingularityMesosSchedulerClient method decline.
public void decline(List<OfferID> offerIds, Filters filters) {
Builder decline = build().setDecline(Decline.newBuilder().addAllOfferIds(offerIds).setFilters(filters));
sendCall(decline, Type.DECLINE);
}
Aggregations