use of org.apache.flink.runtime.resourcemanager.ResourceManagerId 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();
}
}
use of org.apache.flink.runtime.resourcemanager.ResourceManagerId in project flink by apache.
the class DeclarativeSlotManagerTest method testReceivingUnknownSlotReport.
/**
* Tests that the slot manager ignores slot reports of unknown origin (not registered task
* managers).
*/
@Test
public void testReceivingUnknownSlotReport() throws Exception {
final ResourceManagerId resourceManagerId = ResourceManagerId.generate();
final ResourceActions resourceManagerActions = new TestingResourceActionsBuilder().build();
final InstanceID unknownInstanceID = new InstanceID();
final SlotID unknownSlotId = new SlotID(ResourceID.generate(), 0);
final SlotReport unknownSlotReport = new SlotReport(createFreeSlotStatus(unknownSlotId));
try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
// check that we don't have any slots registered
assertThat(slotManager.getNumberRegisteredSlots(), is(0));
// this should not update anything since the instance id is not known to the slot
// manager
assertFalse(slotManager.reportSlotStatus(unknownInstanceID, unknownSlotReport));
assertThat(slotManager.getNumberRegisteredSlots(), is(0));
}
}
use of org.apache.flink.runtime.resourcemanager.ResourceManagerId in project flink by apache.
the class FineGrainedSlotManagerTest method testSlotAllocationAccordingToStrategyResult.
// ---------------------------------------------------------------------------------------------
// Handle result from ResourceAllocationStrategy
// ---------------------------------------------------------------------------------------------
@Test
public void testSlotAllocationAccordingToStrategyResult() throws Exception {
final CompletableFuture<Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId>> requestSlotFuture = new CompletableFuture<>();
final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
requestSlotFuture.complete(tuple6);
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(ResourceID.generate(), taskExecutorGateway);
final JobID jobId = new JobID();
final SlotReport slotReport = new SlotReport();
new Context() {
{
resourceAllocationStrategyBuilder.setTryFulfillRequirementsFunction(((jobIDCollectionMap, taskManagerResourceInfoProvider) -> ResourceAllocationResult.builder().addAllocationOnRegisteredResource(jobId, taskManagerConnection.getInstanceID(), DEFAULT_SLOT_RESOURCE_PROFILE).build()));
runTest(() -> {
runInMainThread(() -> {
getSlotManager().registerTaskManager(taskManagerConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
getSlotManager().processResourceRequirements(createResourceRequirements(jobId, 1));
});
final Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId> requestSlot = assertFutureCompleteAndReturn(requestSlotFuture);
assertEquals(jobId, requestSlot.f1);
assertEquals(DEFAULT_SLOT_RESOURCE_PROFILE, requestSlot.f3);
});
}
};
}
use of org.apache.flink.runtime.resourcemanager.ResourceManagerId in project flink by apache.
the class FineGrainedSlotManagerTest method testSlotAllocationForPendingTaskManagerWillBeRespected.
@Test
public void testSlotAllocationForPendingTaskManagerWillBeRespected() throws Exception {
final JobID jobId = new JobID();
final CompletableFuture<Void> requestResourceFuture = new CompletableFuture<>();
final PendingTaskManager pendingTaskManager = new PendingTaskManager(DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_NUM_SLOTS_PER_WORKER);
final CompletableFuture<Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId>> requestSlotFuture = new CompletableFuture<>();
final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
requestSlotFuture.complete(tuple6);
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(ResourceID.generate(), taskExecutorGateway);
new Context() {
{
resourceAllocationStrategyBuilder.setTryFulfillRequirementsFunction(((jobIDCollectionMap, taskManagerResourceInfoProvider) -> ResourceAllocationResult.builder().addPendingTaskManagerAllocate(pendingTaskManager).addAllocationOnPendingResource(jobId, pendingTaskManager.getPendingTaskManagerId(), DEFAULT_SLOT_RESOURCE_PROFILE).build()));
resourceActionsBuilder.setAllocateResourceConsumer(ignored -> requestResourceFuture.complete(null));
runTest(() -> {
runInMainThread(() -> getSlotManager().processResourceRequirements(createResourceRequirements(jobId, 1)));
assertFutureCompleteAndReturn(requestResourceFuture);
runInMainThread(() -> getSlotManager().registerTaskManager(taskManagerConnection, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE));
final Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId> requestSlot = assertFutureCompleteAndReturn(requestSlotFuture);
assertEquals(jobId, requestSlot.f1);
assertEquals(DEFAULT_SLOT_RESOURCE_PROFILE, requestSlot.f3);
});
}
};
}
Aggregations