Search in sources :

Example 21 with ResourceCounter

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);
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) InstanceID(org.apache.flink.runtime.instance.InstanceID) ArrayList(java.util.ArrayList) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) Map(java.util.Map) JobID(org.apache.flink.api.common.JobID)

Example 22 with ResourceCounter

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));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter)

Example 23 with ResourceCounter

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();
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) SlotInfo(org.apache.flink.runtime.jobmaster.SlotInfo)

Example 24 with ResourceCounter

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);
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter)

Example 25 with ResourceCounter

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);
    }
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter)

Aggregations

ResourceCounter (org.apache.flink.runtime.util.ResourceCounter)39 Test (org.junit.Test)24 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)10 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)8 FlinkException (org.apache.flink.util.FlinkException)7 Map (java.util.Map)5 JobID (org.apache.flink.api.common.JobID)5 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)5 LocalTaskManagerLocation (org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)5 ArrayList (java.util.ArrayList)4 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)4 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)4 HashMap (java.util.HashMap)3 Time (org.apache.flink.api.common.time.Time)3 ArchivedExecutionGraphTest (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraphTest)3 DefaultSchedulerTest (org.apache.flink.runtime.scheduler.DefaultSchedulerTest)3 ResourceRequirement (org.apache.flink.runtime.slots.ResourceRequirement)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 InstanceID (org.apache.flink.runtime.instance.InstanceID)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2