Search in sources :

Example 1 with ResourceRequirements

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

the class DeclarativeSlotPoolServiceTest method testConnectToResourceManagerDeclaresRequiredResources.

@Test
public void testConnectToResourceManagerDeclaresRequiredResources() throws Exception {
    final Collection<ResourceRequirement> requiredResources = Arrays.asList(ResourceRequirement.create(ResourceProfile.UNKNOWN, 2), ResourceRequirement.create(ResourceProfile.ZERO, 4));
    try (DeclarativeSlotPoolService declarativeSlotPoolService = createDeclarativeSlotPoolService(new TestingDeclarativeSlotPoolFactory(new TestingDeclarativeSlotPoolBuilder().setGetResourceRequirementsSupplier(() -> requiredResources)))) {
        final TestingResourceManagerGateway resourceManagerGateway = new TestingResourceManagerGateway();
        final CompletableFuture<ResourceRequirements> declaredResourceRequirements = new CompletableFuture<>();
        resourceManagerGateway.setDeclareRequiredResourcesFunction((jobMasterId, resourceRequirements) -> {
            declaredResourceRequirements.complete(resourceRequirements);
            return CompletableFuture.completedFuture(Acknowledge.get());
        });
        declarativeSlotPoolService.connectToResourceManager(resourceManagerGateway);
        final ResourceRequirements resourceRequirements = declaredResourceRequirements.join();
        assertThat(resourceRequirements.getResourceRequirements(), is(requiredResources));
        assertThat(resourceRequirements.getJobId(), is(jobId));
        assertThat(resourceRequirements.getTargetAddress(), is(address));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) Test(org.junit.Test)

Example 2 with ResourceRequirements

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

the class DefaultDeclareResourceRequirementServiceConnectionManagerTest method testRetryDeclareResourceRequirementsIfTransmissionFailed.

@Test
public void testRetryDeclareResourceRequirementsIfTransmissionFailed() throws InterruptedException {
    final DeclareResourceRequirementServiceConnectionManager declareResourceRequirementServiceConnectionManager = createResourceManagerConnectionManager();
    final FailingDeclareResourceRequirementsService failingDeclareResourceRequirementsService = new FailingDeclareResourceRequirementsService(4);
    declareResourceRequirementServiceConnectionManager.connect(failingDeclareResourceRequirementsService);
    final ResourceRequirements resourceRequirements = createResourceRequirements();
    declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements);
    scheduledExecutor.triggerNonPeriodicScheduledTasksWithRecursion();
    assertThat(failingDeclareResourceRequirementsService.nextResourceRequirements(), is(resourceRequirements));
    assertThat(failingDeclareResourceRequirementsService.hasResourceRequirements(), is(false));
}
Also used : ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) Test(org.junit.Test)

Example 3 with ResourceRequirements

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

the class DefaultDeclareResourceRequirementServiceConnectionManagerTest method testNewResourceRequirementsOverrideOldRequirements.

@Test
public void testNewResourceRequirementsOverrideOldRequirements() throws InterruptedException {
    final DeclareResourceRequirementServiceConnectionManager declareResourceRequirementServiceConnectionManager = createResourceManagerConnectionManager();
    final ResourceRequirements resourceRequirements1 = createResourceRequirements(Arrays.asList(ResourceRequirement.create(ResourceProfile.UNKNOWN, 1)));
    final ResourceRequirements resourceRequirements2 = createResourceRequirements(Arrays.asList(ResourceRequirement.create(ResourceProfile.UNKNOWN, 2)));
    final FailingDeclareResourceRequirementsService failingDeclareResourceRequirementsService = new FailingDeclareResourceRequirementsService(1);
    declareResourceRequirementServiceConnectionManager.connect(failingDeclareResourceRequirementsService);
    declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements1);
    failingDeclareResourceRequirementsService.waitForResourceRequirementsDeclaration();
    declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements2);
    scheduledExecutor.triggerNonPeriodicScheduledTasksWithRecursion();
    assertThat(failingDeclareResourceRequirementsService.nextResourceRequirements(), is(resourceRequirements2));
    assertThat(failingDeclareResourceRequirementsService.hasResourceRequirements(), is(false));
}
Also used : ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) Test(org.junit.Test)

Example 4 with ResourceRequirements

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

the class DefaultDeclareResourceRequirementServiceConnectionManagerTest method testDeclareResourceRequirementsSendsRequirementsIfConnected.

@Test
public void testDeclareResourceRequirementsSendsRequirementsIfConnected() {
    final DeclareResourceRequirementServiceConnectionManager declareResourceRequirementServiceConnectionManager = createResourceManagerConnectionManager();
    final CompletableFuture<ResourceRequirements> declareResourceRequirementsFuture = new CompletableFuture<>();
    declareResourceRequirementServiceConnectionManager.connect(resourceRequirements -> {
        declareResourceRequirementsFuture.complete(resourceRequirements);
        return CompletableFuture.completedFuture(Acknowledge.get());
    });
    final ResourceRequirements resourceRequirements = createResourceRequirements();
    declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements);
    assertThat(declareResourceRequirementsFuture.join(), is(resourceRequirements));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) Test(org.junit.Test)

Example 5 with ResourceRequirements

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

the class DeclarativeSlotManagerTest method testSlotReportWithConflictingJobIdDuringSlotAllocation.

/**
 * Tests that a pending slot allocation is cancelled if a slot report indicates that the slot is
 * already allocated by another job.
 */
@Test
public void testSlotReportWithConflictingJobIdDuringSlotAllocation() throws Exception {
    final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot();
    final ArrayBlockingQueue<SlotID> requestedSlotIds = new ArrayBlockingQueue<>(2);
    final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
        requestedSlotIds.put(requestSlotParameters.f0);
        return new CompletableFuture<>();
    })).createTestingTaskExecutorGateway();
    final TaskExecutorConnection taskExecutorConnection = createTaskExecutorConnection(taskExecutorGateway);
    final ResourceID resourceId = taskExecutorConnection.getResourceID();
    final SlotID slotId1 = new SlotID(resourceId, 0);
    final SlotID slotId2 = new SlotID(resourceId, 1);
    final SlotReport slotReport = new SlotReport(Arrays.asList(createFreeSlotStatus(slotId1), createFreeSlotStatus(slotId2)));
    final ScheduledExecutor mainThreadExecutor = new ManuallyTriggeredScheduledExecutor();
    try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setScheduledExecutor(mainThreadExecutor).build()) {
        slotManager.start(ResourceManagerId.generate(), mainThreadExecutor, new TestingResourceActionsBuilder().build());
        slotManager.registerTaskManager(taskExecutorConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
        slotManager.processResourceRequirements(resourceRequirements);
        final SlotID firstRequestedSlotId = requestedSlotIds.take();
        final SlotID freeSlotId = firstRequestedSlotId.equals(slotId1) ? slotId2 : slotId1;
        final SlotReport newSlotReport = new SlotReport(Arrays.asList(createAllocatedSlotStatus(firstRequestedSlotId), createFreeSlotStatus(freeSlotId)));
        slotManager.reportSlotStatus(taskExecutorConnection.getInstanceID(), newSlotReport);
        final SlotID secondRequestedSlotId = requestedSlotIds.take();
        assertEquals(freeSlotId, secondRequestedSlotId);
    }
}
Also used : SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) ManuallyTriggeredScheduledExecutor(org.apache.flink.util.concurrent.ManuallyTriggeredScheduledExecutor) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) ManuallyTriggeredScheduledExecutor(org.apache.flink.util.concurrent.ManuallyTriggeredScheduledExecutor) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingTaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Test(org.junit.Test)

Aggregations

ResourceRequirements (org.apache.flink.runtime.slots.ResourceRequirements)25 Test (org.junit.Test)22 CompletableFuture (java.util.concurrent.CompletableFuture)20 TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)16 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)16 JobID (org.apache.flink.api.common.JobID)14 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)14 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)14 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)13 ArrayList (java.util.ArrayList)12 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)12 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)12 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)12 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)11 ResourceManagerId (org.apache.flink.runtime.resourcemanager.ResourceManagerId)11 ResourceRequirement (org.apache.flink.runtime.slots.ResourceRequirement)11 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)10 TaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorGateway)10 List (java.util.List)9 Tuple6 (org.apache.flink.api.java.tuple.Tuple6)9