Search in sources :

Example 26 with SlotStatus

use of org.apache.flink.runtime.taskexecutor.SlotStatus in project flink by apache.

the class TaskExecutorManager method registerTaskManager.

public boolean registerTaskManager(final TaskExecutorConnection taskExecutorConnection, SlotReport initialSlotReport, ResourceProfile totalResourceProfile, ResourceProfile defaultSlotResourceProfile) {
    if (isMaxSlotNumExceededAfterRegistration(initialSlotReport)) {
        LOG.info("The total number of slots exceeds the max limitation {}, releasing the excess task executor.", maxSlotNum);
        resourceActions.releaseResource(taskExecutorConnection.getInstanceID(), new FlinkException("The total number of slots exceeds the max limitation."));
        return false;
    }
    TaskManagerRegistration taskManagerRegistration = new TaskManagerRegistration(taskExecutorConnection, StreamSupport.stream(initialSlotReport.spliterator(), false).map(SlotStatus::getSlotID).collect(Collectors.toList()), totalResourceProfile, defaultSlotResourceProfile);
    taskManagerRegistrations.put(taskExecutorConnection.getInstanceID(), taskManagerRegistration);
    // next register the new slots
    for (SlotStatus slotStatus : initialSlotReport) {
        if (slotStatus.getJobID() == null) {
            findAndRemoveExactlyMatchingPendingTaskManagerSlot(slotStatus.getResourceProfile());
        }
    }
    return true;
}
Also used : SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) FlinkException(org.apache.flink.util.FlinkException)

Example 27 with SlotStatus

use of org.apache.flink.runtime.taskexecutor.SlotStatus in project flink by apache.

the class DeclarativeSlotManagerTest method testReportAllocatedSlot.

/**
 * Tests that free slots which are reported as allocated won't be considered for fulfilling
 * other pending slot requests.
 *
 * <p>See: FLINK-8505
 */
@Test
public void testReportAllocatedSlot() throws Exception {
    final ResourceID taskManagerId = ResourceID.generate();
    final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().createTestingTaskExecutorGateway();
    final TaskExecutorConnection taskExecutorConnection = new TaskExecutorConnection(taskManagerId, taskExecutorGateway);
    final ResourceTracker resourceTracker = new DefaultResourceTracker();
    final DefaultSlotTracker slotTracker = new DefaultSlotTracker();
    try (DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setResourceTracker(resourceTracker).setSlotTracker(slotTracker).buildAndStartWithDirectExec()) {
        // initially report a single slot as free
        final SlotID slotId = new SlotID(taskManagerId, 0);
        final SlotReport initialSlotReport = new SlotReport(createFreeSlotStatus(slotId));
        slotManager.registerTaskManager(taskExecutorConnection, initialSlotReport, ResourceProfile.ANY, ResourceProfile.ANY);
        assertThat(slotManager.getNumberRegisteredSlots(), is(equalTo(1)));
        // Now report this slot as allocated
        final SlotStatus slotStatus = createAllocatedSlotStatus(slotId);
        final SlotReport slotReport = new SlotReport(slotStatus);
        slotManager.reportSlotStatus(taskExecutorConnection.getInstanceID(), slotReport);
        final JobID jobId = new JobID();
        // this resource requirement should not be fulfilled
        ResourceRequirements requirements = createResourceRequirementsForSingleSlot(jobId);
        slotManager.processResourceRequirements(requirements);
        assertThat(slotTracker.getSlot(slotId).getJobId(), is(slotStatus.getJobID()));
        assertThat(getTotalResourceCount(resourceTracker.getMissingResources().get(jobId)), is(1));
    }
}
Also used : SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingTaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway) JobID(org.apache.flink.api.common.JobID) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) Test(org.junit.Test)

Example 28 with SlotStatus

use of org.apache.flink.runtime.taskexecutor.SlotStatus in project flink by apache.

the class TaskExecutorManagerTest method createAndRegisterTaskExecutor.

private static InstanceID createAndRegisterTaskExecutor(TaskExecutorManager taskExecutorManager, int numSlots, ResourceProfile resourceProfile) {
    final TaskExecutorConnection taskExecutorConnection = createTaskExecutorConnection();
    List<SlotStatus> slotStatuses = IntStream.range(0, numSlots).mapToObj(slotNumber -> new SlotStatus(new SlotID(taskExecutorConnection.getResourceID(), slotNumber), resourceProfile)).collect(Collectors.toList());
    final SlotReport slotReport = new SlotReport(slotStatuses);
    taskExecutorManager.registerTaskManager(taskExecutorConnection, slotReport, resourceProfile.multiply(numSlots), resourceProfile);
    return taskExecutorConnection.getInstanceID();
}
Also used : IntStream(java.util.stream.IntStream) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) CompletableFuture(java.util.concurrent.CompletableFuture) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) Executor(java.util.concurrent.Executor) Test(org.junit.Test) InstanceID(org.apache.flink.runtime.instance.InstanceID) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) TestingUtils(org.apache.flink.testutils.TestingUtils) List(java.util.List) JobID(org.apache.flink.api.common.JobID) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) Matchers.is(org.hamcrest.Matchers.is) 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) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) TaskExecutorConnection(org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)

Aggregations

SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)28 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)23 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)21 Test (org.junit.Test)20 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)17 JobID (org.apache.flink.api.common.JobID)15 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)10 TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)8 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)7 SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)6 Time (org.apache.flink.api.common.time.Time)5 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 RegistrationResponse (org.apache.flink.runtime.registration.RegistrationResponse)4 TaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorGateway)4 FlinkException (org.apache.flink.util.FlinkException)4 ArrayList (java.util.ArrayList)3 TimeoutException (java.util.concurrent.TimeoutException)3 InstanceID (org.apache.flink.runtime.instance.InstanceID)3 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)3