use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class DeclarativeSlotPoolServiceTest method testConnectToResourceManagerDeclaresRequiredResources.
@Test
public void testConnectToResourceManagerDeclaresRequiredResources() throws Exception {
final Collection<ResourceRequirement> requiredResources = Arrays.asList(ResourceRequirement.create(ResourceProfile.UNKNOWN, 2), ResourceRequirement.create(ResourceProfile.ZERO, 4));
try (DeclarativeSlotPoolService declarativeSlotPoolService = createDeclarativeSlotPoolService(new TestingDeclarativeSlotPoolFactory(new TestingDeclarativeSlotPoolBuilder().setGetResourceRequirementsSupplier(() -> requiredResources)))) {
final TestingResourceManagerGateway resourceManagerGateway = new TestingResourceManagerGateway();
final CompletableFuture<ResourceRequirements> declaredResourceRequirements = new CompletableFuture<>();
resourceManagerGateway.setDeclareRequiredResourcesFunction((jobMasterId, resourceRequirements) -> {
declaredResourceRequirements.complete(resourceRequirements);
return CompletableFuture.completedFuture(Acknowledge.get());
});
declarativeSlotPoolService.connectToResourceManager(resourceManagerGateway);
final ResourceRequirements resourceRequirements = declaredResourceRequirements.join();
assertThat(resourceRequirements.getResourceRequirements(), is(requiredResources));
assertThat(resourceRequirements.getJobId(), is(jobId));
assertThat(resourceRequirements.getTargetAddress(), is(address));
}
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class DefaultDeclareResourceRequirementServiceConnectionManagerTest method testRetryDeclareResourceRequirementsIfTransmissionFailed.
@Test
public void testRetryDeclareResourceRequirementsIfTransmissionFailed() throws InterruptedException {
final DeclareResourceRequirementServiceConnectionManager declareResourceRequirementServiceConnectionManager = createResourceManagerConnectionManager();
final FailingDeclareResourceRequirementsService failingDeclareResourceRequirementsService = new FailingDeclareResourceRequirementsService(4);
declareResourceRequirementServiceConnectionManager.connect(failingDeclareResourceRequirementsService);
final ResourceRequirements resourceRequirements = createResourceRequirements();
declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements);
scheduledExecutor.triggerNonPeriodicScheduledTasksWithRecursion();
assertThat(failingDeclareResourceRequirementsService.nextResourceRequirements(), is(resourceRequirements));
assertThat(failingDeclareResourceRequirementsService.hasResourceRequirements(), is(false));
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class DefaultDeclareResourceRequirementServiceConnectionManagerTest method testNewResourceRequirementsOverrideOldRequirements.
@Test
public void testNewResourceRequirementsOverrideOldRequirements() throws InterruptedException {
final DeclareResourceRequirementServiceConnectionManager declareResourceRequirementServiceConnectionManager = createResourceManagerConnectionManager();
final ResourceRequirements resourceRequirements1 = createResourceRequirements(Arrays.asList(ResourceRequirement.create(ResourceProfile.UNKNOWN, 1)));
final ResourceRequirements resourceRequirements2 = createResourceRequirements(Arrays.asList(ResourceRequirement.create(ResourceProfile.UNKNOWN, 2)));
final FailingDeclareResourceRequirementsService failingDeclareResourceRequirementsService = new FailingDeclareResourceRequirementsService(1);
declareResourceRequirementServiceConnectionManager.connect(failingDeclareResourceRequirementsService);
declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements1);
failingDeclareResourceRequirementsService.waitForResourceRequirementsDeclaration();
declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements2);
scheduledExecutor.triggerNonPeriodicScheduledTasksWithRecursion();
assertThat(failingDeclareResourceRequirementsService.nextResourceRequirements(), is(resourceRequirements2));
assertThat(failingDeclareResourceRequirementsService.hasResourceRequirements(), is(false));
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class DefaultDeclareResourceRequirementServiceConnectionManagerTest method testDeclareResourceRequirementsSendsRequirementsIfConnected.
@Test
public void testDeclareResourceRequirementsSendsRequirementsIfConnected() {
final DeclareResourceRequirementServiceConnectionManager declareResourceRequirementServiceConnectionManager = createResourceManagerConnectionManager();
final CompletableFuture<ResourceRequirements> declareResourceRequirementsFuture = new CompletableFuture<>();
declareResourceRequirementServiceConnectionManager.connect(resourceRequirements -> {
declareResourceRequirementsFuture.complete(resourceRequirements);
return CompletableFuture.completedFuture(Acknowledge.get());
});
final ResourceRequirements resourceRequirements = createResourceRequirements();
declareResourceRequirementServiceConnectionManager.declareResourceRequirements(resourceRequirements);
assertThat(declareResourceRequirementsFuture.join(), is(resourceRequirements));
}
use of org.apache.flink.runtime.slots.ResourceRequirements in project flink by apache.
the class DeclarativeSlotManagerTest method testSlotReportWithConflictingJobIdDuringSlotAllocation.
/**
* Tests that a pending slot allocation is cancelled if a slot report indicates that the slot is
* already allocated by another job.
*/
@Test
public void testSlotReportWithConflictingJobIdDuringSlotAllocation() throws Exception {
final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot();
final ArrayBlockingQueue<SlotID> requestedSlotIds = new ArrayBlockingQueue<>(2);
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
requestedSlotIds.put(requestSlotParameters.f0);
return new CompletableFuture<>();
})).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskExecutorConnection = createTaskExecutorConnection(taskExecutorGateway);
final ResourceID resourceId = taskExecutorConnection.getResourceID();
final SlotID slotId1 = new SlotID(resourceId, 0);
final SlotID slotId2 = new SlotID(resourceId, 1);
final SlotReport slotReport = new SlotReport(Arrays.asList(createFreeSlotStatus(slotId1), createFreeSlotStatus(slotId2)));
final ScheduledExecutor mainThreadExecutor = new ManuallyTriggeredScheduledExecutor();
try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setScheduledExecutor(mainThreadExecutor).build()) {
slotManager.start(ResourceManagerId.generate(), mainThreadExecutor, new TestingResourceActionsBuilder().build());
slotManager.registerTaskManager(taskExecutorConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
slotManager.processResourceRequirements(resourceRequirements);
final SlotID firstRequestedSlotId = requestedSlotIds.take();
final SlotID freeSlotId = firstRequestedSlotId.equals(slotId1) ? slotId2 : slotId1;
final SlotReport newSlotReport = new SlotReport(Arrays.asList(createAllocatedSlotStatus(firstRequestedSlotId), createFreeSlotStatus(freeSlotId)));
slotManager.reportSlotStatus(taskExecutorConnection.getInstanceID(), newSlotReport);
final SlotID secondRequestedSlotId = requestedSlotIds.take();
assertEquals(freeSlotId, secondRequestedSlotId);
}
}
Aggregations