use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testDuplicateResourceRequirementDeclarationAfterSuccessfulAllocation.
/**
* Tests that duplicate resource requirement declaration do not result in additional slots being
* allocated after a pending slot request has been fulfilled but not yet freed.
*/
@Test
public void testDuplicateResourceRequirementDeclarationAfterSuccessfulAllocation() throws Exception {
final List<CompletableFuture<Void>> allocateResourceFutures = new ArrayList<>();
allocateResourceFutures.add(new CompletableFuture<>());
allocateResourceFutures.add(new CompletableFuture<>());
final ResourceRequirements requirements = createResourceRequirementsForSingleSlot();
new Context() {
{
resourceActionsBuilder.setAllocateResourceConsumer(ignored -> {
if (allocateResourceFutures.get(0).isDone()) {
allocateResourceFutures.get(1).complete(null);
} else {
allocateResourceFutures.get(0).complete(null);
}
});
runTest(() -> {
runInMainThread(() -> getSlotManager().processResourceRequirements(requirements));
assertFutureCompleteAndReturn(allocateResourceFutures.get(0));
runInMainThread(() -> getSlotManager().processResourceRequirements(requirements));
// check that we have only called the resource allocation only for the
// first slot request, since the second request is a duplicate
assertFutureNotComplete(allocateResourceFutures.get(1));
});
}
};
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testSlotRequestFailure.
// ---------------------------------------------------------------------------------------------
// Slot allocation failure handling
// ---------------------------------------------------------------------------------------------
/**
* Tests that the SlotManager retries allocating a slot if the TaskExecutor#requestSlot call
* fails.
*/
@Test
public void testSlotRequestFailure() throws Exception {
final JobID jobId = new JobID();
final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot(jobId);
final CompletableFuture<Acknowledge> slotRequestFuture1 = new CompletableFuture<>();
final CompletableFuture<Acknowledge> slotRequestFuture2 = CompletableFuture.completedFuture(Acknowledge.get());
final Iterator<CompletableFuture<Acknowledge>> slotRequestFutureIterator = Arrays.asList(slotRequestFuture1, slotRequestFuture2).iterator();
final ArrayBlockingQueue<AllocationID> allocationIds = new ArrayBlockingQueue<>(2);
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
allocationIds.put(requestSlotParameters.f2);
return slotRequestFutureIterator.next();
})).createTestingTaskExecutorGateway();
final ResourceID resourceId = ResourceID.generate();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceId, taskExecutorGateway);
final SlotReport slotReport = new SlotReport();
new Context() {
{
runTest(() -> {
runInMainThread(() -> {
getSlotManager().registerTaskManager(taskManagerConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
getSlotManager().processResourceRequirements(resourceRequirements);
});
final AllocationID firstAllocationId = allocationIds.take();
assertThat(allocationIds, is(empty()));
// let the first attempt fail --> this should trigger a second attempt
runInMainThread(() -> slotRequestFuture1.completeExceptionally(new SlotAllocationException("Test exception.")));
final AllocationID secondAllocationId = allocationIds.take();
assertThat(allocationIds, is(empty()));
final TaskManagerSlotInformation slot = getTaskManagerTracker().getAllocatedOrPendingSlot(secondAllocationId).get();
assertEquals(jobId, slot.getJobId());
assertFalse(getTaskManagerTracker().getAllocatedOrPendingSlot(firstAllocationId).isPresent());
});
}
};
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testRequirementDeclaration.
private void testRequirementDeclaration(RequirementDeclarationScenario scenario) throws Exception {
final ResourceID resourceID = ResourceID.generate();
final JobID jobId = new JobID();
final SlotID slotId = SlotID.getDynamicSlotID(resourceID);
final String targetAddress = "localhost";
final ResourceRequirements requirements = ResourceRequirements.create(jobId, targetAddress, Collections.singleton(ResourceRequirement.create(DEFAULT_SLOT_RESOURCE_PROFILE, 1)));
final CompletableFuture<Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId>> requestFuture = new CompletableFuture<>();
// accept an incoming slot request
final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
requestFuture.complete(tuple6);
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskExecutorConnection = new TaskExecutorConnection(resourceID, taskExecutorGateway);
new Context() {
{
runTest(() -> {
if (scenario == RequirementDeclarationScenario.TASK_EXECUTOR_REGISTRATION_BEFORE_REQUIREMENT_DECLARATION) {
runInMainThread(() -> getSlotManager().registerTaskManager(taskExecutorConnection, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE));
}
runInMainThread(() -> getSlotManager().processResourceRequirements(requirements));
if (scenario == RequirementDeclarationScenario.TASK_EXECUTOR_REGISTRATION_AFTER_REQUIREMENT_DECLARATION) {
runInMainThread(() -> getSlotManager().registerTaskManager(taskExecutorConnection, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE));
}
assertThat(assertFutureCompleteAndReturn(requestFuture), is(equalTo(Tuple6.of(slotId, jobId, assertFutureCompleteAndReturn(requestFuture).f2, DEFAULT_SLOT_RESOURCE_PROFILE, targetAddress, getResourceManagerId()))));
final TaskManagerSlotInformation slot = getTaskManagerTracker().getAllocatedOrPendingSlot(assertFutureCompleteAndReturn(requestFuture).f2).get();
assertEquals("The slot has not been allocated to the expected allocation id.", assertFutureCompleteAndReturn(requestFuture).f2, slot.getAllocationId());
});
}
};
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testResourceCanBeAllocatedForDifferentJobAfterFree.
/**
* Tests that a resource allocated for one job can be allocated for another job after being
* freed.
*/
private void testResourceCanBeAllocatedForDifferentJobAfterFree(SecondRequirementDeclarationTime secondRequirementDeclarationTime) throws Exception {
final CompletableFuture<AllocationID> allocationIdFuture1 = new CompletableFuture<>();
final CompletableFuture<AllocationID> allocationIdFuture2 = new CompletableFuture<>();
final ResourceRequirements resourceRequirements1 = createResourceRequirementsForSingleSlot();
final ResourceRequirements resourceRequirements2 = createResourceRequirementsForSingleSlot();
final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
if (!allocationIdFuture1.isDone()) {
allocationIdFuture1.complete(tuple6.f2);
} else {
allocationIdFuture2.complete(tuple6.f2);
}
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final ResourceID resourceID = ResourceID.generate();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceID, taskExecutorGateway);
final SlotReport slotReport = new SlotReport();
new Context() {
{
runTest(() -> {
runInMainThread(() -> {
getSlotManager().registerTaskManager(taskManagerConnection, slotReport, DEFAULT_SLOT_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
getSlotManager().processResourceRequirements(resourceRequirements1);
});
final AllocationID allocationId1 = assertFutureCompleteAndReturn(allocationIdFuture1);
TaskManagerSlotInformation slot = getTaskManagerTracker().getAllocatedOrPendingSlot(allocationId1).get();
assertEquals("The slot has not been allocated to the expected job id.", resourceRequirements1.getJobId(), slot.getJobId());
if (secondRequirementDeclarationTime == SecondRequirementDeclarationTime.BEFORE_FREE) {
runInMainThread(() -> getSlotManager().processResourceRequirements(resourceRequirements2));
}
// clear resource requirements first so that the freed slot isn't
// immediately re-assigned to the job
runInMainThread(() -> {
getSlotManager().processResourceRequirements(ResourceRequirements.create(resourceRequirements1.getJobId(), resourceRequirements1.getTargetAddress(), Collections.emptyList()));
getSlotManager().freeSlot(SlotID.getDynamicSlotID(resourceID), allocationId1);
});
if (secondRequirementDeclarationTime == SecondRequirementDeclarationTime.AFTER_FREE) {
runInMainThread(() -> getSlotManager().processResourceRequirements(resourceRequirements2));
}
slot = getTaskManagerTracker().getAllocatedOrPendingSlot(assertFutureCompleteAndReturn(allocationIdFuture2)).get();
assertEquals("The slot has not been allocated to the expected job id.", resourceRequirements2.getJobId(), slot.getJobId());
});
}
};
}
use of org.apache.flink.runtime.slots.ResourceRequirements 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);
});
}
};
}
Aggregations