Search in sources :

Example 36 with ResourceCounter

use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.

the class DefaultDeclarativeSlotPoolTest method testReleaseSlotDecreasesFulfilledResourceRequirements.

@Test
public void testReleaseSlotDecreasesFulfilledResourceRequirements() throws InterruptedException {
    final NewSlotsService notifyNewSlots = new NewSlotsService();
    final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPoolWithNewSlotsListener(notifyNewSlots);
    final ResourceCounter resourceRequirements = createResourceRequirements();
    increaseRequirementsAndOfferSlotsToSlotPool(slotPool, resourceRequirements, null);
    final Collection<? extends PhysicalSlot> physicalSlots = notifyNewSlots.takeNewSlots();
    final PhysicalSlot physicalSlot = physicalSlots.iterator().next();
    slotPool.releaseSlot(physicalSlot.getAllocationId(), new FlinkException("Test failure"));
    final ResourceCounter finalResourceRequirements = resourceRequirements.subtract(physicalSlot.getResourceProfile(), 1);
    assertThat(slotPool.getFulfilledResourceRequirements(), is(finalResourceRequirements));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 37 with ResourceCounter

use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.

the class FineGrainedTaskManagerTrackerTest method testAddAndRemovePendingTaskManager.

@Test
public void testAddAndRemovePendingTaskManager() {
    final PendingTaskManager pendingTaskManager = new PendingTaskManager(ResourceProfile.ANY, 1);
    final FineGrainedTaskManagerTracker taskManagerTracker = new FineGrainedTaskManagerTracker();
    final JobID jobId = new JobID();
    final ResourceCounter resourceCounter = ResourceCounter.withResource(ResourceProfile.ANY, 1);
    // Add pending task manager
    taskManagerTracker.addPendingTaskManager(pendingTaskManager);
    taskManagerTracker.replaceAllPendingAllocations(Collections.singletonMap(pendingTaskManager.getPendingTaskManagerId(), Collections.singletonMap(jobId, resourceCounter)));
    assertThat(taskManagerTracker.getPendingTaskManagers().size(), is(1));
    assertThat(taskManagerTracker.getPendingTaskManagersByTotalAndDefaultSlotResourceProfile(ResourceProfile.ANY, ResourceProfile.ANY).size(), is(1));
    // Remove pending task manager
    final Map<JobID, ResourceCounter> records = taskManagerTracker.removePendingTaskManager(pendingTaskManager.getPendingTaskManagerId());
    assertThat(taskManagerTracker.getPendingTaskManagers(), is(empty()));
    assertThat(taskManagerTracker.getPendingAllocationsOfPendingTaskManager(pendingTaskManager.getPendingTaskManagerId()).size(), is(0));
    assertThat(taskManagerTracker.getPendingTaskManagersByTotalAndDefaultSlotResourceProfile(ResourceProfile.ANY, ResourceProfile.ANY).size(), is(0));
    assertTrue(records.containsKey(jobId));
    assertThat(records.get(jobId).getResourceCount(ResourceProfile.ANY), is(1));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 38 with ResourceCounter

use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.

the class AdaptiveSchedulerTest method testHasEnoughResourcesReturnsTrueIfSatisfied.

@Test
public void testHasEnoughResourcesReturnsTrueIfSatisfied() throws Exception {
    final JobGraph jobGraph = createJobGraph();
    final DefaultDeclarativeSlotPool declarativeSlotPool = createDeclarativeSlotPool(jobGraph.getJobID());
    final AdaptiveScheduler scheduler = new AdaptiveSchedulerBuilder(jobGraph, mainThreadExecutor).setDeclarativeSlotPool(declarativeSlotPool).build();
    scheduler.startScheduling();
    final ResourceCounter resourceRequirement = ResourceCounter.withResource(ResourceProfile.UNKNOWN, 1);
    offerSlots(declarativeSlotPool, createSlotOffersForResourceRequirements(resourceRequirement));
    assertThat(scheduler.hasDesiredResources(resourceRequirement)).isTrue();
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobGraphTestUtils.streamingJobGraph(org.apache.flink.runtime.jobgraph.JobGraphTestUtils.streamingJobGraph) DefaultDeclarativeSlotPool(org.apache.flink.runtime.jobmaster.slotpool.DefaultDeclarativeSlotPool) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test) ArchivedExecutionGraphTest(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraphTest) DefaultSchedulerTest(org.apache.flink.runtime.scheduler.DefaultSchedulerTest)

Example 39 with ResourceCounter

use of org.apache.flink.runtime.util.ResourceCounter in project flink by apache.

the class SlotSharingSlotAllocatorTest method testCalculateRequiredSlots.

@Test
public void testCalculateRequiredSlots() {
    final SlotSharingSlotAllocator slotAllocator = SlotSharingSlotAllocator.createSlotSharingSlotAllocator(TEST_RESERVE_SLOT_FUNCTION, TEST_FREE_SLOT_FUNCTION, TEST_IS_SLOT_FREE_FUNCTION);
    final ResourceCounter resourceCounter = slotAllocator.calculateRequiredSlots(Arrays.asList(vertex1, vertex2, vertex3));
    assertThat(resourceCounter.getResources(), contains(ResourceProfile.UNKNOWN));
    assertThat(resourceCounter.getResourceCount(ResourceProfile.UNKNOWN), is(Math.max(vertex1.getParallelism(), vertex2.getParallelism()) + vertex3.getParallelism()));
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test)

Aggregations

ResourceCounter (org.apache.flink.runtime.util.ResourceCounter)39 Test (org.junit.Test)24 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)10 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)8 FlinkException (org.apache.flink.util.FlinkException)7 Map (java.util.Map)5 JobID (org.apache.flink.api.common.JobID)5 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)5 LocalTaskManagerLocation (org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)5 ArrayList (java.util.ArrayList)4 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)4 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)4 HashMap (java.util.HashMap)3 Time (org.apache.flink.api.common.time.Time)3 ArchivedExecutionGraphTest (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraphTest)3 DefaultSchedulerTest (org.apache.flink.runtime.scheduler.DefaultSchedulerTest)3 ResourceRequirement (org.apache.flink.runtime.slots.ResourceRequirement)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 InstanceID (org.apache.flink.runtime.instance.InstanceID)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2