.addAll(Iterables.transform(possibleVictims, Tasks.ASSIGNED_TO_SLAVE_HOST))
.addAll(Iterables.transform(offers, OFFER_TO_HOST)).build();
String host = Iterables.getOnlyElement(hosts);
ResourceSlot slackResources =
ResourceSlot.sum(Iterables.transform(offers, OFFER_TO_RESOURCE_SLOT));
if (!Iterables.isEmpty(offers)) {
if (Iterables.size(offers) > 1) {
// There are multiple offers for the same host. Since both have maintenance information
// we don't preempt with this information and wait for mesos to merge the two offers for
// us.
return Optional.absent();
}
IHostAttributes attributes = Iterables.getOnlyElement(
FluentIterable.from(offers).transform(OFFER_TO_ATTRIBUTES).toSet());
Set<SchedulingFilter.Veto> vetoes = schedulingFilter.filter(
slackResources,
attributes,
pendingTask.getTask(),
pendingTask.getTaskId(),
attributeAggregate);
if (vetoes.isEmpty()) {
return Optional.<Set<IAssignedTask>>of(ImmutableSet.<IAssignedTask>of());
}
}
FluentIterable<IAssignedTask> preemptableTasks =
FluentIterable.from(possibleVictims).filter(canPreempt(pendingTask));
if (preemptableTasks.isEmpty()) {
return Optional.absent();
}
List<IAssignedTask> toPreemptTasks = Lists.newArrayList();
Iterable<IAssignedTask> sortedVictims = RESOURCE_ORDER.immutableSortedCopy(preemptableTasks);
for (IAssignedTask victim : sortedVictims) {
toPreemptTasks.add(victim);
ResourceSlot totalResource = ResourceSlot.sum(
ResourceSlot.sum(Iterables.transform(toPreemptTasks, TASK_TO_RESOURCES)),
slackResources);
Optional<IHostAttributes> attributes = getHostAttributes(host);
if (!attributes.isPresent()) {