use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class FineGrainedSlotManager method allocateSlotsAccordingTo.
private void allocateSlotsAccordingTo(Map<JobID, Map<InstanceID, ResourceCounter>> result) {
final List<CompletableFuture<Void>> allocationFutures = new ArrayList<>();
for (Map.Entry<JobID, Map<InstanceID, ResourceCounter>> jobEntry : result.entrySet()) {
final JobID jobID = jobEntry.getKey();
for (Map.Entry<InstanceID, ResourceCounter> tmEntry : jobEntry.getValue().entrySet()) {
final InstanceID instanceID = tmEntry.getKey();
for (Map.Entry<ResourceProfile, Integer> slotEntry : tmEntry.getValue().getResourcesWithCount()) {
for (int i = 0; i < slotEntry.getValue(); ++i) {
allocationFutures.add(slotStatusSyncer.allocateSlot(instanceID, jobID, jobMasterTargetAddresses.get(jobID), slotEntry.getKey()));
}
}
}
}
FutureUtils.combineAll(allocationFutures).whenCompleteAsync((s, t) -> {
if (t != null) {
// If there is allocation failure, we need to trigger it again.
checkResourceRequirementsWithDelay();
}
}, mainThreadExecutor);
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class AdaptiveScheduler method goToWaitingForResources.
@Override
public void goToWaitingForResources() {
final ResourceCounter desiredResources = calculateDesiredResources();
declarativeSlotPool.setResourceRequirements(desiredResources);
transitionToState(new WaitingForResources.Factory(this, LOG, desiredResources, this.initialResourceAllocationTimeout, this.resourceStabilizationTimeout));
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class AdaptiveScheduler method hasDesiredResources.
// ----------------------------------------------------------------
@Override
public boolean hasDesiredResources(ResourceCounter desiredResources) {
final Collection<? extends SlotInfo> allSlots = declarativeSlotPool.getFreeSlotsInformation();
ResourceCounter outstandingResources = desiredResources;
final Iterator<? extends SlotInfo> slotIterator = allSlots.iterator();
while (!outstandingResources.isEmpty() && slotIterator.hasNext()) {
final SlotInfo slotInfo = slotIterator.next();
final ResourceProfile resourceProfile = slotInfo.getResourceProfile();
if (outstandingResources.containsResource(resourceProfile)) {
outstandingResources = outstandingResources.subtract(resourceProfile, 1);
} else {
outstandingResources = outstandingResources.subtract(ResourceProfile.UNKNOWN, 1);
}
}
return outstandingResources.isEmpty();
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class DeclarativeSlotPoolService method internalReleaseTaskManager.
private void internalReleaseTaskManager(ResourceID taskManagerId, Exception cause) {
assertHasBeenStarted();
final ResourceCounter previouslyFulfilledRequirement = declarativeSlotPool.releaseSlots(taskManagerId, cause);
onReleaseTaskManager(previouslyFulfilledRequirement);
}
use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.
the class DeclarativeSlotPoolService method failAllocation.
@Override
public Optional<ResourceID> failAllocation(@Nullable ResourceID taskManagerId, AllocationID allocationId, Exception cause) {
assertHasBeenStarted();
Preconditions.checkNotNull(allocationId);
Preconditions.checkNotNull(taskManagerId, "This slot pool only supports failAllocation calls coming from the TaskExecutor.");
final ResourceCounter previouslyFulfilledRequirements = declarativeSlotPool.releaseSlot(allocationId, cause);
onFailAllocation(previouslyFulfilledRequirements);
if (declarativeSlotPool.containsSlots(taskManagerId)) {
return Optional.empty();
} else {
return Optional.of(taskManagerId);
}
}
Aggregations