use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.
the class DeclarativeSlotManager method maybeReclaimInactiveSlots.
private void maybeReclaimInactiveSlots(JobID jobId) {
if (!resourceTracker.getAcquiredResources(jobId).isEmpty()) {
final Collection<TaskExecutorConnection> taskExecutorsWithAllocatedSlots = slotTracker.getTaskExecutorsWithAllocatedSlotsForJob(jobId);
for (TaskExecutorConnection taskExecutorConnection : taskExecutorsWithAllocatedSlots) {
final TaskExecutorGateway taskExecutorGateway = taskExecutorConnection.getTaskExecutorGateway();
taskExecutorGateway.freeInactiveSlots(jobId, taskManagerRequestTimeout);
}
}
}
use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection 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);
}
}
use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.
the class DeclarativeSlotManagerTest method testRequirementDeclaration.
private void testRequirementDeclaration(RequirementDeclarationScenario scenario) throws Exception {
final ResourceManagerId resourceManagerId = ResourceManagerId.generate();
final ResourceID resourceID = ResourceID.generate();
final JobID jobId = new JobID();
final SlotID slotId = new SlotID(resourceID, 0);
final String targetAddress = "localhost";
final ResourceProfile resourceProfile = ResourceProfile.fromResources(42.0, 1337);
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.of(tuple6.f0, tuple6.f1, tuple6.f2, tuple6.f3, tuple6.f4, tuple6.f5));
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskExecutorConnection = new TaskExecutorConnection(resourceID, taskExecutorGateway);
final SlotStatus slotStatus = new SlotStatus(slotId, resourceProfile);
final SlotReport slotReport = new SlotReport(slotStatus);
final DefaultSlotTracker slotTracker = new DefaultSlotTracker();
try (DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setSlotTracker(slotTracker).buildAndStartWithDirectExec(resourceManagerId, new TestingResourceActionsBuilder().build())) {
if (scenario == RequirementDeclarationScenario.TASK_EXECUTOR_REGISTRATION_BEFORE_REQUIREMENT_DECLARATION) {
slotManager.registerTaskManager(taskExecutorConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
}
final ResourceRequirements requirements = ResourceRequirements.create(jobId, targetAddress, Collections.singleton(ResourceRequirement.create(resourceProfile, 1)));
slotManager.processResourceRequirements(requirements);
if (scenario == RequirementDeclarationScenario.TASK_EXECUTOR_REGISTRATION_AFTER_REQUIREMENT_DECLARATION) {
slotManager.registerTaskManager(taskExecutorConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
}
assertThat(requestFuture.get(), is(equalTo(Tuple6.of(slotId, jobId, requestFuture.get().f2, resourceProfile, targetAddress, resourceManagerId))));
DeclarativeTaskManagerSlot slot = slotTracker.getSlot(slotId);
assertEquals("The slot has not been allocated to the expected allocation id.", jobId, slot.getJobId());
}
}
use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.
the class DeclarativeSlotManagerTest method testNotificationAboutNotEnoughResources.
private static void testNotificationAboutNotEnoughResources(boolean withNotificationGracePeriod) throws Exception {
final JobID jobId = new JobID();
final int numRequiredSlots = 3;
final int numExistingSlots = 1;
List<Tuple2<JobID, Collection<ResourceRequirement>>> notEnoughResourceNotifications = new ArrayList<>();
ResourceActions resourceManagerActions = new TestingResourceActionsBuilder().setAllocateResourceFunction(ignored -> false).setNotEnoughResourcesConsumer((jobId1, acquiredResources) -> notEnoughResourceNotifications.add(Tuple2.of(jobId1, acquiredResources))).build();
try (DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().buildAndStart(ResourceManagerId.generate(), new ManuallyTriggeredScheduledExecutor(), resourceManagerActions)) {
if (withNotificationGracePeriod) {
// this should disable notifications
slotManager.setFailUnfulfillableRequest(false);
}
final ResourceID taskExecutorResourceId = ResourceID.generate();
final TaskExecutorConnection taskExecutionConnection = new TaskExecutorConnection(taskExecutorResourceId, new TestingTaskExecutorGatewayBuilder().createTestingTaskExecutorGateway());
final SlotReport slotReport = createSlotReport(taskExecutorResourceId, numExistingSlots);
slotManager.registerTaskManager(taskExecutionConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
ResourceRequirements resourceRequirements = createResourceRequirements(jobId, numRequiredSlots);
slotManager.processResourceRequirements(resourceRequirements);
if (withNotificationGracePeriod) {
assertThat(notEnoughResourceNotifications, empty());
// re-enable notifications which should also trigger another resource check
slotManager.setFailUnfulfillableRequest(true);
}
assertThat(notEnoughResourceNotifications, hasSize(1));
Tuple2<JobID, Collection<ResourceRequirement>> notification = notEnoughResourceNotifications.get(0);
assertThat(notification.f0, is(jobId));
assertThat(notification.f1, hasItem(ResourceRequirement.create(ResourceProfile.ANY, numExistingSlots)));
// another slot report that does not indicate any changes should not trigger another
// notification
slotManager.reportSlotStatus(taskExecutionConnection.getInstanceID(), slotReport);
assertThat(notEnoughResourceNotifications, hasSize(1));
}
}
use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.
the class DeclarativeSlotManagerTest method testTaskExecutorFailedHandling.
@Test
public void testTaskExecutorFailedHandling() throws Exception {
final ResourceTracker resourceTracker = new DefaultResourceTracker();
try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setResourceTracker(resourceTracker).buildAndStartWithDirectExec()) {
JobID jobId = new JobID();
slotManager.processResourceRequirements(createResourceRequirements(jobId, 2));
final TaskExecutorConnection taskExecutionConnection1 = createTaskExecutorConnection();
final SlotReport slotReport1 = createSlotReport(taskExecutionConnection1.getResourceID(), 2);
slotManager.registerTaskManager(taskExecutionConnection1, slotReport1, ResourceProfile.ANY, ResourceProfile.ANY);
slotManager.unregisterTaskManager(taskExecutionConnection1.getInstanceID(), TEST_EXCEPTION);
assertThat(getTotalResourceCount(resourceTracker.getMissingResources().get(jobId)), is(2));
}
}
Aggregations