Search in sources :

Example 11 with ResourceRequirement

use of org.apache.flink.runtime.slots.ResourceRequirement in project flink by apache.

the class DefaultResourceAllocationStrategy method tryFulfillRequirementsForJobWithPendingResources.

private void tryFulfillRequirementsForJobWithPendingResources(JobID jobId, Collection<ResourceRequirement> unfulfilledRequirements, List<InternalResourceInfo> availableResources, ResourceAllocationResult.Builder resultBuilder) {
    for (ResourceRequirement missingResource : unfulfilledRequirements) {
        // for this strategy, all pending resources should have the same default slot resource
        final ResourceProfile effectiveProfile = getEffectiveResourceProfile(missingResource.getResourceProfile(), defaultSlotResourceProfile);
        int numUnfulfilled = tryFulfilledRequirementWithResource(availableResources, missingResource.getNumberOfRequiredSlots(), missingResource.getResourceProfile(), jobId);
        if (!totalResourceProfile.allFieldsNoLessThan(effectiveProfile)) {
            // Can not fulfill this resource type will the default worker.
            resultBuilder.addUnfulfillableJob(jobId);
            continue;
        }
        while (numUnfulfilled > 0) {
            // Circularly add new pending task manager
            final PendingTaskManager newPendingTaskManager = new PendingTaskManager(totalResourceProfile, numSlotsPerWorker);
            resultBuilder.addPendingTaskManagerAllocate(newPendingTaskManager);
            ResourceProfile remainResource = totalResourceProfile;
            while (numUnfulfilled > 0 && canFulfillRequirement(effectiveProfile, remainResource)) {
                numUnfulfilled--;
                resultBuilder.addAllocationOnPendingResource(jobId, newPendingTaskManager.getPendingTaskManagerId(), effectiveProfile);
                remainResource = remainResource.subtract(effectiveProfile);
            }
            if (!remainResource.equals(ResourceProfile.ZERO)) {
                availableResources.add(new InternalResourceInfo(defaultSlotResourceProfile, remainResource, (jobID, slotProfile) -> resultBuilder.addAllocationOnPendingResource(jobID, newPendingTaskManager.getPendingTaskManagerId(), slotProfile)));
            }
        }
    }
}
Also used : List(java.util.List) SlotManagerUtils.getEffectiveResourceProfile(org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerUtils.getEffectiveResourceProfile) JobID(org.apache.flink.api.common.JobID) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ArrayList(java.util.ArrayList) SlotManagerUtils.getEffectiveResourceProfile(org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerUtils.getEffectiveResourceProfile) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement)

Example 12 with ResourceRequirement

use of org.apache.flink.runtime.slots.ResourceRequirement in project flink by apache.

the class JobScopedResourceTracker method getMissingResources.

public Collection<ResourceRequirement> getMissingResources() {
    final Collection<ResourceRequirement> missingResources = new ArrayList<>();
    for (Map.Entry<ResourceProfile, Integer> requirement : resourceRequirements.getResourcesWithCount()) {
        ResourceProfile requirementProfile = requirement.getKey();
        int numRequiredResources = requirement.getValue();
        int numAcquiredResources = resourceToRequirementMapping.getNumFulfillingResources(requirementProfile);
        if (numAcquiredResources < numRequiredResources) {
            missingResources.add(ResourceRequirement.create(requirementProfile, numRequiredResources - numAcquiredResources));
        }
    }
    return missingResources;
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ArrayList(java.util.ArrayList) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) Map(java.util.Map)

Example 13 with ResourceRequirement

use of org.apache.flink.runtime.slots.ResourceRequirement in project flink by apache.

the class DefaultResourceTrackerTest method testGetRequiredResources.

@Test
public void testGetRequiredResources() {
    DefaultResourceTracker tracker = new DefaultResourceTracker();
    ResourceRequirement requirement1 = ResourceRequirement.create(ResourceProfile.ANY, 1);
    ResourceRequirement requirement2 = ResourceRequirement.create(ResourceProfile.ANY, 2);
    tracker.notifyResourceRequirements(JOB_ID_1, Collections.singletonList(requirement1));
    tracker.notifyResourceRequirements(JOB_ID_2, Collections.singletonList(requirement2));
    Map<JobID, Collection<ResourceRequirement>> requiredResources = tracker.getMissingResources();
    assertThat(requiredResources, IsMapContaining.hasEntry(is(JOB_ID_1), contains(requirement1)));
    assertThat(requiredResources, IsMapContaining.hasEntry(is(JOB_ID_2), contains(requirement2)));
}
Also used : Collection(java.util.Collection) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 14 with ResourceRequirement

use of org.apache.flink.runtime.slots.ResourceRequirement in project flink by apache.

the class DefaultResourceAllocationStrategyTest method testFulfillRequirementWithRegisteredResources.

@Test
public void testFulfillRequirementWithRegisteredResources() {
    final TaskManagerInfo taskManager = new TestingTaskManagerInfo(DEFAULT_SLOT_RESOURCE.multiply(10), DEFAULT_SLOT_RESOURCE.multiply(10), DEFAULT_SLOT_RESOURCE);
    final JobID jobId = new JobID();
    final List<ResourceRequirement> requirements = new ArrayList<>();
    final ResourceProfile largeResource = DEFAULT_SLOT_RESOURCE.multiply(8);
    final TaskManagerResourceInfoProvider taskManagerResourceInfoProvider = TestingTaskManagerResourceInfoProvider.newBuilder().setRegisteredTaskManagersSupplier(() -> Collections.singleton(taskManager)).build();
    requirements.add(ResourceRequirement.create(largeResource, 1));
    requirements.add(ResourceRequirement.create(ResourceProfile.UNKNOWN, 2));
    final ResourceAllocationResult result = STRATEGY.tryFulfillRequirements(Collections.singletonMap(jobId, requirements), taskManagerResourceInfoProvider);
    assertThat(result.getUnfulfillableJobs(), is(empty()));
    assertThat(result.getAllocationsOnPendingResources().keySet(), is(empty()));
    assertThat(result.getPendingTaskManagersToAllocate(), is(empty()));
    assertThat(result.getAllocationsOnRegisteredResources().get(jobId).get(taskManager.getInstanceId()).getResourceCount(DEFAULT_SLOT_RESOURCE), is(2));
    assertThat(result.getAllocationsOnRegisteredResources().get(jobId).get(taskManager.getInstanceId()).getResourceCount(largeResource), is(1));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ArrayList(java.util.ArrayList) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 15 with ResourceRequirement

use of org.apache.flink.runtime.slots.ResourceRequirement in project flink by apache.

the class DefaultResourceAllocationStrategyTest method testUnfulfillableRequirement.

@Test
public void testUnfulfillableRequirement() {
    final TaskManagerInfo taskManager = new TestingTaskManagerInfo(DEFAULT_SLOT_RESOURCE.multiply(NUM_OF_SLOTS), DEFAULT_SLOT_RESOURCE.multiply(NUM_OF_SLOTS), DEFAULT_SLOT_RESOURCE);
    final JobID jobId = new JobID();
    final List<ResourceRequirement> requirements = new ArrayList<>();
    final ResourceProfile unfulfillableResource = DEFAULT_SLOT_RESOURCE.multiply(8);
    final TaskManagerResourceInfoProvider taskManagerResourceInfoProvider = TestingTaskManagerResourceInfoProvider.newBuilder().setRegisteredTaskManagersSupplier(() -> Collections.singleton(taskManager)).build();
    requirements.add(ResourceRequirement.create(unfulfillableResource, 1));
    final ResourceAllocationResult result = STRATEGY.tryFulfillRequirements(Collections.singletonMap(jobId, requirements), taskManagerResourceInfoProvider);
    assertThat(result.getUnfulfillableJobs(), contains(jobId));
    assertThat(result.getPendingTaskManagersToAllocate(), is(empty()));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ArrayList(java.util.ArrayList) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

ResourceRequirement (org.apache.flink.runtime.slots.ResourceRequirement)15 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)10 JobID (org.apache.flink.api.common.JobID)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)6 Map (java.util.Map)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 ResourceRequirements (org.apache.flink.runtime.slots.ResourceRequirements)4 List (java.util.List)3 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)3 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)3 InstanceID (org.apache.flink.runtime.instance.InstanceID)3 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)3 SlotManagerMetricGroup (org.apache.flink.runtime.metrics.groups.SlotManagerMetricGroup)3 ResourceManagerId (org.apache.flink.runtime.resourcemanager.ResourceManagerId)3 TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)3 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)3 SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)3 TaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorGateway)3