Search in sources :

Example 56 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class FineGrainedSlotManagerTest method testTimeoutForUnusedTaskManager.

// ---------------------------------------------------------------------------------------------
// Task manager timeout
// ---------------------------------------------------------------------------------------------
/**
 * Tests that formerly used task managers can timeout after all of their slots have been freed.
 */
@Test
public void testTimeoutForUnusedTaskManager() throws Exception {
    final Time taskManagerTimeout = Time.milliseconds(50L);
    final CompletableFuture<InstanceID> releaseResourceFuture = new CompletableFuture<>();
    final AllocationID allocationId = new AllocationID();
    final TaskExecutorConnection taskExecutionConnection = createTaskExecutorConnection();
    final InstanceID instanceId = taskExecutionConnection.getInstanceID();
    new Context() {

        {
            resourceActionsBuilder.setReleaseResourceConsumer((instanceID, e) -> releaseResourceFuture.complete(instanceID));
            slotManagerConfigurationBuilder.setTaskManagerTimeout(taskManagerTimeout);
            runTest(() -> {
                final CompletableFuture<Boolean> registerTaskManagerFuture = new CompletableFuture<>();
                runInMainThread(() -> registerTaskManagerFuture.complete(getSlotManager().registerTaskManager(taskExecutionConnection, new SlotReport(createAllocatedSlotStatus(allocationId, DEFAULT_SLOT_RESOURCE_PROFILE)), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE)));
                assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture), is(true));
                assertEquals(getSlotManager().getTaskManagerIdleSince(instanceId), Long.MAX_VALUE);
                final CompletableFuture<Long> idleSinceFuture = new CompletableFuture<>();
                runInMainThread(() -> {
                    getSlotManager().freeSlot(new SlotID(taskExecutionConnection.getResourceID(), 0), allocationId);
                    idleSinceFuture.complete(getSlotManager().getTaskManagerIdleSince(instanceId));
                });
                assertThat(assertFutureCompleteAndReturn(idleSinceFuture), not(equalTo(Long.MAX_VALUE)));
                assertThat(assertFutureCompleteAndReturn(releaseResourceFuture), is(equalTo(instanceId)));
                // A task manager timeout does not remove the slots from the
                // SlotManager. The receiver of the callback can then decide what to do
                // with the TaskManager.
                assertEquals(DEFAULT_NUM_SLOTS_PER_WORKER, getSlotManager().getNumberRegisteredSlots());
                final CompletableFuture<Boolean> unregisterTaskManagerFuture = new CompletableFuture<>();
                runInMainThread(() -> unregisterTaskManagerFuture.complete(getSlotManager().unregisterTaskManager(taskExecutionConnection.getInstanceID(), TEST_EXCEPTION)));
                assertThat(assertFutureCompleteAndReturn(unregisterTaskManagerFuture), is(true));
                assertEquals(0, getSlotManager().getNumberRegisteredSlots());
            });
        }
    };
}
Also used : InstanceID(org.apache.flink.runtime.instance.InstanceID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) Time(org.apache.flink.api.common.time.Time) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) CompletableFuture(java.util.concurrent.CompletableFuture) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Test(org.junit.Test)

Example 57 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class FineGrainedSlotManagerTest method testGetResourceOverview.

@Test
public void testGetResourceOverview() throws Exception {
    final TaskExecutorConnection taskExecutorConnection1 = createTaskExecutorConnection();
    final TaskExecutorConnection taskExecutorConnection2 = createTaskExecutorConnection();
    final ResourceID resourceId1 = ResourceID.generate();
    final ResourceID resourceId2 = ResourceID.generate();
    final SlotID slotId1 = new SlotID(resourceId1, 0);
    final SlotID slotId2 = new SlotID(resourceId2, 0);
    final ResourceProfile resourceProfile1 = ResourceProfile.fromResources(1, 10);
    final ResourceProfile resourceProfile2 = ResourceProfile.fromResources(2, 20);
    final SlotStatus slotStatus1 = new SlotStatus(slotId1, resourceProfile1, new JobID(), new AllocationID());
    final SlotStatus slotStatus2 = new SlotStatus(slotId2, resourceProfile2, new JobID(), new AllocationID());
    final SlotReport slotReport1 = new SlotReport(slotStatus1);
    final SlotReport slotReport2 = new SlotReport(slotStatus2);
    new Context() {

        {
            runTest(() -> {
                final CompletableFuture<Boolean> registerTaskManagerFuture1 = new CompletableFuture<>();
                final CompletableFuture<Boolean> registerTaskManagerFuture2 = new CompletableFuture<>();
                runInMainThread(() -> {
                    registerTaskManagerFuture1.complete(getSlotManager().registerTaskManager(taskExecutorConnection1, slotReport1, resourceProfile1.multiply(2), resourceProfile1));
                    registerTaskManagerFuture2.complete(getSlotManager().registerTaskManager(taskExecutorConnection2, slotReport2, resourceProfile2.multiply(2), resourceProfile2));
                });
                assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture1), is(true));
                assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture2), is(true));
                assertThat(getSlotManager().getFreeResource(), equalTo(resourceProfile1.merge(resourceProfile2)));
                assertThat(getSlotManager().getFreeResourceOf(taskExecutorConnection1.getInstanceID()), equalTo(resourceProfile1));
                assertThat(getSlotManager().getFreeResourceOf(taskExecutorConnection2.getInstanceID()), equalTo(resourceProfile2));
                assertThat(getSlotManager().getRegisteredResource(), equalTo(resourceProfile1.merge(resourceProfile2).multiply(2)));
                assertThat(getSlotManager().getRegisteredResourceOf(taskExecutorConnection1.getInstanceID()), equalTo(resourceProfile1.multiply(2)));
                assertThat(getSlotManager().getRegisteredResourceOf(taskExecutorConnection2.getInstanceID()), equalTo(resourceProfile2.multiply(2)));
            });
        }
    };
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) JobID(org.apache.flink.api.common.JobID) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Test(org.junit.Test)

Example 58 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class FineGrainedSlotManagerTest method testTaskManagerUnregistration.

/**
 * Tests that un-registration of task managers will free and remove all allocated slots.
 */
@Test
public void testTaskManagerUnregistration() throws Exception {
    final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> new CompletableFuture<>()).createTestingTaskExecutorGateway();
    final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(ResourceID.generate(), taskExecutorGateway);
    final AllocationID allocationId = new AllocationID();
    final SlotReport slotReport = new SlotReport(createAllocatedSlotStatus(allocationId, DEFAULT_SLOT_RESOURCE_PROFILE));
    new Context() {

        {
            runTest(() -> {
                final CompletableFuture<Boolean> registerTaskManagerFuture = new CompletableFuture<>();
                final CompletableFuture<Boolean> unRegisterTaskManagerFuture = new CompletableFuture<>();
                runInMainThread(() -> registerTaskManagerFuture.complete(getSlotManager().registerTaskManager(taskManagerConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE)));
                assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture), is(true));
                assertThat(getTaskManagerTracker().getRegisteredTaskManagers().size(), is(1));
                final Optional<TaskManagerSlotInformation> slot = getTaskManagerTracker().getAllocatedOrPendingSlot(allocationId);
                assertTrue(slot.isPresent());
                assertTrue(slot.get().getState() == SlotState.ALLOCATED);
                runInMainThread(() -> unRegisterTaskManagerFuture.complete(getSlotManager().unregisterTaskManager(taskManagerConnection.getInstanceID(), TEST_EXCEPTION)));
                assertThat(assertFutureCompleteAndReturn(unRegisterTaskManagerFuture), is(true));
                assertThat(getTaskManagerTracker().getRegisteredTaskManagers(), is(empty()));
                assertFalse(getTaskManagerTracker().getAllocatedOrPendingSlot(allocationId).isPresent());
            });
        }
    };
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Test(org.junit.Test)

Example 59 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class FineGrainedTaskManagerTrackerTest method testFreeSlot.

@Test
public void testFreeSlot() {
    final FineGrainedTaskManagerTracker taskManagerTracker = new FineGrainedTaskManagerTracker();
    final ResourceProfile totalResource = ResourceProfile.fromResources(10, 1000);
    final AllocationID allocationId1 = new AllocationID();
    final AllocationID allocationId2 = new AllocationID();
    final JobID jobId = new JobID();
    taskManagerTracker.addTaskManager(TASK_EXECUTOR_CONNECTION, totalResource, totalResource);
    taskManagerTracker.notifySlotStatus(allocationId1, jobId, TASK_EXECUTOR_CONNECTION.getInstanceID(), ResourceProfile.fromResources(3, 200), SlotState.PENDING);
    taskManagerTracker.notifySlotStatus(allocationId2, jobId, TASK_EXECUTOR_CONNECTION.getInstanceID(), ResourceProfile.fromResources(2, 300), SlotState.ALLOCATED);
    // Free pending slot
    taskManagerTracker.notifySlotStatus(allocationId1, jobId, TASK_EXECUTOR_CONNECTION.getInstanceID(), ResourceProfile.fromResources(3, 200), SlotState.FREE);
    assertFalse(taskManagerTracker.getAllocatedOrPendingSlot(allocationId1).isPresent());
    assertThat(taskManagerTracker.getRegisteredTaskManager(TASK_EXECUTOR_CONNECTION.getInstanceID()).get().getAvailableResource(), is(ResourceProfile.fromResources(8, 700)));
    // Free allocated slot
    taskManagerTracker.notifySlotStatus(allocationId2, jobId, TASK_EXECUTOR_CONNECTION.getInstanceID(), ResourceProfile.fromResources(2, 300), SlotState.FREE);
    assertFalse(taskManagerTracker.getAllocatedOrPendingSlot(allocationId2).isPresent());
    assertThat(taskManagerTracker.getRegisteredTaskManager(TASK_EXECUTOR_CONNECTION.getInstanceID()).get().getAvailableResource(), is(totalResource));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 60 with AllocationID

use of org.apache.flink.runtime.clusterframework.types.AllocationID in project flink by apache.

the class FineGrainedTaskManagerTrackerTest method testGetStatistics.

@Test
public void testGetStatistics() {
    final FineGrainedTaskManagerTracker taskManagerTracker = new FineGrainedTaskManagerTracker();
    final ResourceProfile totalResource = ResourceProfile.fromResources(10, 1000);
    final ResourceProfile defaultSlotResource = ResourceProfile.fromResources(1, 100);
    final AllocationID allocationId1 = new AllocationID();
    final AllocationID allocationId2 = new AllocationID();
    final JobID jobId = new JobID();
    taskManagerTracker.addTaskManager(TASK_EXECUTOR_CONNECTION, totalResource, defaultSlotResource);
    taskManagerTracker.notifySlotStatus(allocationId1, jobId, TASK_EXECUTOR_CONNECTION.getInstanceID(), ResourceProfile.fromResources(3, 200), SlotState.ALLOCATED);
    taskManagerTracker.notifySlotStatus(allocationId2, jobId, TASK_EXECUTOR_CONNECTION.getInstanceID(), defaultSlotResource, SlotState.ALLOCATED);
    taskManagerTracker.addPendingTaskManager(new PendingTaskManager(ResourceProfile.fromResources(4, 200), 1));
    assertThat(taskManagerTracker.getFreeResource(), is(ResourceProfile.fromResources(6, 700)));
    assertThat(taskManagerTracker.getRegisteredResource(), is(totalResource));
    assertThat(taskManagerTracker.getNumberRegisteredSlots(), is(10));
    assertThat(taskManagerTracker.getNumberFreeSlots(), is(8));
    assertThat(taskManagerTracker.getPendingResource(), is(ResourceProfile.fromResources(4, 200)));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)194 Test (org.junit.Test)137 JobID (org.apache.flink.api.common.JobID)106 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)60 CompletableFuture (java.util.concurrent.CompletableFuture)56 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)56 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)53 ArrayList (java.util.ArrayList)39 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)36 Collection (java.util.Collection)35 Time (org.apache.flink.api.common.time.Time)35 Configuration (org.apache.flink.configuration.Configuration)34 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)34 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)34 List (java.util.List)32 TestLogger (org.apache.flink.util.TestLogger)32 FlinkException (org.apache.flink.util.FlinkException)31 Matchers.is (org.hamcrest.Matchers.is)31 Assert.assertThat (org.junit.Assert.assertThat)31 Arrays (java.util.Arrays)30