Search in sources :

Example 26 with ResourceCounter

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

the class DefaultDeclarativeSlotPool method getFulfilledRequirements.

private ResourceCounter getFulfilledRequirements(Iterable<? extends AllocatedSlot> allocatedSlots) {
    ResourceCounter resourceDecrement = ResourceCounter.empty();
    for (AllocatedSlot allocatedSlot : allocatedSlots) {
        final ResourceProfile matchingResourceProfile = getMatchingResourceProfile(allocatedSlot.getAllocationId());
        resourceDecrement = resourceDecrement.add(matchingResourceProfile, 1);
    }
    return resourceDecrement;
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter)

Example 27 with ResourceCounter

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

the class SlotPoolUtils method calculateResourceCounter.

static ResourceCounter calculateResourceCounter(ResourceProfile[] resourceProfiles) {
    final Map<ResourceProfile, Integer> resources = Arrays.stream(resourceProfiles).collect(Collectors.groupingBy(Function.identity(), reducing(0, e -> 1, Integer::sum)));
    final ResourceCounter increment = ResourceCounter.withResources(resources);
    return increment;
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter)

Example 28 with ResourceCounter

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

the class DefaultDeclarativeSlotPoolTest method testReturnIdleSlotsAfterTimeout.

@Test
public void testReturnIdleSlotsAfterTimeout() {
    final Time idleSlotTimeout = Time.seconds(10);
    final long offerTime = 0;
    final DefaultDeclarativeSlotPool slotPool = DefaultDeclarativeSlotPoolBuilder.builder().setIdleSlotTimeout(idleSlotTimeout).build();
    final ResourceCounter resourceRequirements = createResourceRequirements();
    final FreeSlotConsumer freeSlotConsumer = new FreeSlotConsumer();
    final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setFreeSlotFunction(freeSlotConsumer).createTestingTaskExecutorGateway();
    final Collection<SlotOffer> acceptedSlots = increaseRequirementsAndOfferSlotsToSlotPool(slotPool, resourceRequirements, new LocalTaskManagerLocation(), testingTaskExecutorGateway);
    // decrease the resource requirements so that slots are no longer needed
    slotPool.decreaseResourceRequirementsBy(resourceRequirements);
    slotPool.releaseIdleSlots(offerTime + idleSlotTimeout.toMilliseconds());
    final Collection<AllocationID> freedSlots = freeSlotConsumer.drainFreedSlots();
    assertThat(acceptedSlots, is(not(empty())));
    assertThat(freedSlots, containsInAnyOrder(acceptedSlots.stream().map(SlotOffer::getAllocationId).toArray()));
    assertNoAvailableAndRequiredResources(slotPool);
}
Also used : SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Time(org.apache.flink.api.common.time.Time) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) TestingTaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway) Test(org.junit.Test)

Example 29 with ResourceCounter

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

the class DefaultDeclarativeSlotPoolTest method testOfferSlots.

@Test
public void testOfferSlots() throws InterruptedException {
    final NewSlotsService notifyNewSlots = new NewSlotsService();
    final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPoolWithNewSlotsListener(notifyNewSlots);
    final ResourceCounter resourceRequirements = createResourceRequirements();
    slotPool.increaseResourceRequirementsBy(resourceRequirements);
    Collection<SlotOffer> slotOffers = createSlotOffersForResourceRequirements(resourceRequirements);
    final Collection<SlotOffer> acceptedSlots = SlotPoolTestUtils.offerSlots(slotPool, slotOffers);
    assertThat(acceptedSlots, containsInAnyOrder(slotOffers.toArray()));
    final Collection<PhysicalSlot> newSlots = drainNewSlotService(notifyNewSlots);
    assertThat(newSlots, containsInAnyOrder(slotOffers.stream().map(DefaultDeclarativeSlotPoolTest::matchesSlotOffer).collect(Collectors.toList())));
    assertThat(slotPool.getAllSlotsInformation(), containsInAnyOrder(newSlots.stream().map(DefaultAllocatedSlotPoolTest::matchesPhysicalSlot).collect(Collectors.toList())));
}
Also used : SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) Test(org.junit.Test)

Example 30 with ResourceCounter

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

the class DefaultDeclarativeSlotPoolTest method testReleaseSlotsOnlyReturnsFulfilledRequirementsOfReservedSlots.

@Test
public void testReleaseSlotsOnlyReturnsFulfilledRequirementsOfReservedSlots() {
    withSlotPoolContainingOneTaskManagerWithTwoSlotsWithUniqueResourceProfiles((slotPool, freeSlot, slotToReserve, taskManagerLocation) -> {
        slotPool.reserveFreeSlot(slotToReserve.getAllocationId(), slotToReserve.getResourceProfile()).tryAssignPayload(new TestingPhysicalSlotPayload());
        final ResourceCounter fulfilledRequirements = slotPool.releaseSlots(taskManagerLocation.getResourceID(), new FlinkException("Test failure"));
        assertThat(fulfilledRequirements.getResourceCount(freeSlot.getResourceProfile()), is(0));
        assertThat(fulfilledRequirements.getResourceCount(slotToReserve.getResourceProfile()), is(1));
    });
}
Also used : ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) FlinkException(org.apache.flink.util.FlinkException) 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