Search in sources :

Example 11 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class AbstractFineGrainedSlotManagerITCase method testRequirementDeclarationWithoutFreeSlotsTriggersWorkerAllocation.

// ---------------------------------------------------------------------------------------------
// Requirement declaration
// ---------------------------------------------------------------------------------------------
/**
 * Tests that a requirement declaration with no free slots will trigger the resource allocation.
 */
@Test
public void testRequirementDeclarationWithoutFreeSlotsTriggersWorkerAllocation() throws Exception {
    final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot();
    final CompletableFuture<WorkerResourceSpec> allocateResourceFuture = new CompletableFuture<>();
    new Context() {

        {
            resourceActionsBuilder.setAllocateResourceConsumer(allocateResourceFuture::complete);
            runTest(() -> {
                runInMainThread(() -> getSlotManager().processResourceRequirements(resourceRequirements));
                assertFutureCompleteAndReturn(allocateResourceFuture);
            });
        }
    };
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) Test(org.junit.Test)

Example 12 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class DeclarativeSlotManagerTest method testRequirementDeclarationWithoutFreeSlotsTriggersWorkerAllocation.

/**
 * Tests that a slot request with no free slots will trigger the resource allocation.
 */
@Test
public void testRequirementDeclarationWithoutFreeSlotsTriggersWorkerAllocation() throws Exception {
    final ResourceManagerId resourceManagerId = ResourceManagerId.generate();
    final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot();
    CompletableFuture<WorkerResourceSpec> allocateResourceFuture = new CompletableFuture<>();
    ResourceActions resourceManagerActions = new TestingResourceActionsBuilder().setAllocateResourceConsumer(allocateResourceFuture::complete).build();
    try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
        slotManager.processResourceRequirements(resourceRequirements);
        allocateResourceFuture.get();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResourceManagerId(org.apache.flink.runtime.resourcemanager.ResourceManagerId) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) Test(org.junit.Test)

Example 13 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class TaskExecutorManagerTest method testWorkerOnlyAllocatedIfRequestedSlotCouldBeFulfilled.

/**
 * Test that the task executor manager only allocates new workers if their worker spec can
 * fulfill the requested resource profile.
 */
@Test
public void testWorkerOnlyAllocatedIfRequestedSlotCouldBeFulfilled() {
    final int numCoresPerWorker = 1;
    final WorkerResourceSpec workerResourceSpec = new WorkerResourceSpec.Builder().setCpuCores(numCoresPerWorker).build();
    final ResourceProfile requestedProfile = ResourceProfile.newBuilder().setCpuCores(numCoresPerWorker + 1).build();
    final AtomicInteger resourceRequests = new AtomicInteger(0);
    ResourceActions resourceActions = createResourceActionsBuilder().setAllocateResourceFunction(ignored -> {
        resourceRequests.incrementAndGet();
        return true;
    }).build();
    try (final TaskExecutorManager taskExecutorManager = createTaskExecutorManagerBuilder().setDefaultWorkerResourceSpec(workerResourceSpec).setNumSlotsPerWorker(1).setMaxNumSlots(1).setResourceActions(resourceActions).createTaskExecutorManager()) {
        assertThat(taskExecutorManager.allocateWorker(requestedProfile).orElse(null), nullValue());
        assertThat(resourceRequests.get(), is(0));
    }
}
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) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Test(org.junit.Test)

Example 14 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class TaskExecutorManagerTest method testPendingSlotNotFulfilledIfProfilesAreNotExactMatch.

/**
 * Tests that a pending slot is only fulfilled by an exactly matching received slot.
 */
@Test
public void testPendingSlotNotFulfilledIfProfilesAreNotExactMatch() {
    final int numWorkerCpuCores = 3;
    final WorkerResourceSpec workerResourceSpec = new WorkerResourceSpec.Builder().setCpuCores(numWorkerCpuCores).build();
    final ResourceProfile requestedSlotProfile = ResourceProfile.newBuilder().setCpuCores(numWorkerCpuCores).build();
    final ResourceProfile offeredSlotProfile = ResourceProfile.newBuilder().setCpuCores(numWorkerCpuCores - 1).build();
    try (final TaskExecutorManager taskExecutorManager = createTaskExecutorManagerBuilder().setDefaultWorkerResourceSpec(workerResourceSpec).setNumSlotsPerWorker(// set to one so that the slot profiles directly correspond to
    1).setMaxNumSlots(2).createTaskExecutorManager()) {
        // create pending slot
        taskExecutorManager.allocateWorker(requestedSlotProfile);
        assertThat(taskExecutorManager.getNumberPendingTaskManagerSlots(), is(1));
        createAndRegisterTaskExecutor(taskExecutorManager, 1, offeredSlotProfile);
        // the slot from the task executor should be accepted, but we should still be waiting
        // for the originally requested slot
        assertThat(taskExecutorManager.getNumberRegisteredSlots(), is(1));
        assertThat(taskExecutorManager.getNumberPendingTaskManagerSlots(), is(1));
    }
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Test(org.junit.Test)

Example 15 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class SlotManagerUtilsTest method testGenerateDefaultSlotProfileFromWorkerResourceSpec.

@Test
public void testGenerateDefaultSlotProfileFromWorkerResourceSpec() {
    final int numSlots = 5;
    final ResourceProfile resourceProfile = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(1).setTaskOffHeapMemoryMB(2).setNetworkMemoryMB(3).setManagedMemoryMB(4).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1)).build();
    final WorkerResourceSpec workerResourceSpec = new WorkerResourceSpec.Builder().setCpuCores(1.0 * numSlots).setTaskHeapMemoryMB(1 * numSlots).setTaskOffHeapMemoryMB(2 * numSlots).setNetworkMemoryMB(3 * numSlots).setManagedMemoryMB(4 * numSlots).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, numSlots)).build();
    assertThat(SlotManagerUtils.generateDefaultSlotResourceProfile(workerResourceSpec, numSlots), is(resourceProfile));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Aggregations

WorkerResourceSpec (org.apache.flink.runtime.resourcemanager.WorkerResourceSpec)16 Test (org.junit.Test)12 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 ExternalResource (org.apache.flink.api.common.resources.ExternalResource)4 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)4 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)4 Executor (java.util.concurrent.Executor)3 Time (org.apache.flink.api.common.time.Time)3 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)3 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)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 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2