Search in sources :

Example 41 with TaskExecutorConnection

use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.

the class FineGrainedSlotManagerTest method testSlotAllocationForPendingTaskManagerWillBeRespected.

@Test
public void testSlotAllocationForPendingTaskManagerWillBeRespected() throws Exception {
    final JobID jobId = new JobID();
    final CompletableFuture<Void> requestResourceFuture = new CompletableFuture<>();
    final PendingTaskManager pendingTaskManager = new PendingTaskManager(DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_NUM_SLOTS_PER_WORKER);
    final CompletableFuture<Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId>> requestSlotFuture = new CompletableFuture<>();
    final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
        requestSlotFuture.complete(tuple6);
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).createTestingTaskExecutorGateway();
    final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(ResourceID.generate(), taskExecutorGateway);
    new Context() {

        {
            resourceAllocationStrategyBuilder.setTryFulfillRequirementsFunction(((jobIDCollectionMap, taskManagerResourceInfoProvider) -> ResourceAllocationResult.builder().addPendingTaskManagerAllocate(pendingTaskManager).addAllocationOnPendingResource(jobId, pendingTaskManager.getPendingTaskManagerId(), DEFAULT_SLOT_RESOURCE_PROFILE).build()));
            resourceActionsBuilder.setAllocateResourceConsumer(ignored -> requestResourceFuture.complete(null));
            runTest(() -> {
                runInMainThread(() -> getSlotManager().processResourceRequirements(createResourceRequirements(jobId, 1)));
                assertFutureCompleteAndReturn(requestResourceFuture);
                runInMainThread(() -> getSlotManager().registerTaskManager(taskManagerConnection, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE));
                final Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId> requestSlot = assertFutureCompleteAndReturn(requestSlotFuture);
                assertEquals(jobId, requestSlot.f1);
                assertEquals(DEFAULT_SLOT_RESOURCE_PROFILE, requestSlot.f3);
            });
        }
    };
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) Matchers.not(org.hamcrest.Matchers.not) Tuple6(org.apache.flink.api.java.tuple.Tuple6) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) CompletableFuture(java.util.concurrent.CompletableFuture) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) Matchers.empty(org.hamcrest.Matchers.empty) Collection(java.util.Collection) ResourceManagerId(org.apache.flink.runtime.resourcemanager.ResourceManagerId) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) InstanceID(org.apache.flink.runtime.instance.InstanceID) SlotManagerMetricGroup(org.apache.flink.runtime.metrics.groups.SlotManagerMetricGroup) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) Consumer(java.util.function.Consumer) List(java.util.List) JobID(org.apache.flink.api.common.JobID) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Assert.assertFalse(org.junit.Assert.assertFalse) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) Optional(java.util.Optional) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Assume.assumeTrue(org.junit.Assume.assumeTrue) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) CompletableFuture(java.util.concurrent.CompletableFuture) Tuple6(org.apache.flink.api.java.tuple.Tuple6) ResourceManagerId(org.apache.flink.runtime.resourcemanager.ResourceManagerId) JobID(org.apache.flink.api.common.JobID) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Test(org.junit.Test)

Example 42 with TaskExecutorConnection

use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.

the class FineGrainedSlotManagerTest method testMaxTotalResourceExceededRegisterResource.

private void testMaxTotalResourceExceededRegisterResource(Consumer<SlotManagerConfigurationBuilder> maxTotalResourceSetter) throws Exception {
    final TaskExecutorConnection taskManagerConnection1 = createTaskExecutorConnection();
    final TaskExecutorConnection taskManagerConnection2 = createTaskExecutorConnection();
    final CompletableFuture<Boolean> registerTaskManagerFuture1 = new CompletableFuture<>();
    final CompletableFuture<Boolean> registerTaskManagerFuture2 = new CompletableFuture<>();
    final CompletableFuture<InstanceID> releaseResourceFuture = new CompletableFuture<>();
    new Context() {

        {
            maxTotalResourceSetter.accept(slotManagerConfigurationBuilder);
            resourceActionsBuilder.setReleaseResourceConsumer((instanceId, ignore) -> releaseResourceFuture.complete(instanceId));
            runTest(() -> {
                runInMainThread(() -> registerTaskManagerFuture1.complete(getSlotManager().registerTaskManager(taskManagerConnection1, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE)));
                assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture1), is(true));
                assertFutureNotComplete(releaseResourceFuture);
                assertThat(getTaskManagerTracker().getRegisteredTaskManagers().size(), equalTo(1));
                assertTrue(getTaskManagerTracker().getRegisteredTaskManager(taskManagerConnection1.getInstanceID()).isPresent());
                runInMainThread(() -> registerTaskManagerFuture2.complete(getSlotManager().registerTaskManager(taskManagerConnection2, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE)));
                assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture2), is(false));
                assertThat(releaseResourceFuture.get(), is(taskManagerConnection2.getInstanceID()));
                assertThat(getTaskManagerTracker().getRegisteredTaskManagers().size(), equalTo(1));
                assertFalse(getTaskManagerTracker().getRegisteredTaskManager(taskManagerConnection2.getInstanceID()).isPresent());
            });
        }
    };
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) InstanceID(org.apache.flink.runtime.instance.InstanceID) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)

Aggregations

TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)42 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)40 Test (org.junit.Test)38 CompletableFuture (java.util.concurrent.CompletableFuture)33 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)32 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)30 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)30 JobID (org.apache.flink.api.common.JobID)29 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)29 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)24 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)24 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)23 ResourceRequirements (org.apache.flink.runtime.slots.ResourceRequirements)23 SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)22 Assert.assertThat (org.junit.Assert.assertThat)21 Tuple6 (org.apache.flink.api.java.tuple.Tuple6)20 ResourceManagerId (org.apache.flink.runtime.resourcemanager.ResourceManagerId)20 ResourceRequirement (org.apache.flink.runtime.slots.ResourceRequirement)20 TaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorGateway)20 Matchers.empty (org.hamcrest.Matchers.empty)20