use of org.apache.flink.runtime.taskexecutor.SlotStatus in project flink by apache.
the class TaskExecutorManager method registerTaskManager.
public boolean registerTaskManager(final TaskExecutorConnection taskExecutorConnection, SlotReport initialSlotReport, ResourceProfile totalResourceProfile, ResourceProfile defaultSlotResourceProfile) {
if (isMaxSlotNumExceededAfterRegistration(initialSlotReport)) {
LOG.info("The total number of slots exceeds the max limitation {}, releasing the excess task executor.", maxSlotNum);
resourceActions.releaseResource(taskExecutorConnection.getInstanceID(), new FlinkException("The total number of slots exceeds the max limitation."));
return false;
}
TaskManagerRegistration taskManagerRegistration = new TaskManagerRegistration(taskExecutorConnection, StreamSupport.stream(initialSlotReport.spliterator(), false).map(SlotStatus::getSlotID).collect(Collectors.toList()), totalResourceProfile, defaultSlotResourceProfile);
taskManagerRegistrations.put(taskExecutorConnection.getInstanceID(), taskManagerRegistration);
// next register the new slots
for (SlotStatus slotStatus : initialSlotReport) {
if (slotStatus.getJobID() == null) {
findAndRemoveExactlyMatchingPendingTaskManagerSlot(slotStatus.getResourceProfile());
}
}
return true;
}
use of org.apache.flink.runtime.taskexecutor.SlotStatus in project flink by apache.
the class DeclarativeSlotManagerTest method testReportAllocatedSlot.
/**
* Tests that free slots which are reported as allocated won't be considered for fulfilling
* other pending slot requests.
*
* <p>See: FLINK-8505
*/
@Test
public void testReportAllocatedSlot() throws Exception {
final ResourceID taskManagerId = ResourceID.generate();
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().createTestingTaskExecutorGateway();
final TaskExecutorConnection taskExecutorConnection = new TaskExecutorConnection(taskManagerId, taskExecutorGateway);
final ResourceTracker resourceTracker = new DefaultResourceTracker();
final DefaultSlotTracker slotTracker = new DefaultSlotTracker();
try (DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setResourceTracker(resourceTracker).setSlotTracker(slotTracker).buildAndStartWithDirectExec()) {
// initially report a single slot as free
final SlotID slotId = new SlotID(taskManagerId, 0);
final SlotReport initialSlotReport = new SlotReport(createFreeSlotStatus(slotId));
slotManager.registerTaskManager(taskExecutorConnection, initialSlotReport, ResourceProfile.ANY, ResourceProfile.ANY);
assertThat(slotManager.getNumberRegisteredSlots(), is(equalTo(1)));
// Now report this slot as allocated
final SlotStatus slotStatus = createAllocatedSlotStatus(slotId);
final SlotReport slotReport = new SlotReport(slotStatus);
slotManager.reportSlotStatus(taskExecutorConnection.getInstanceID(), slotReport);
final JobID jobId = new JobID();
// this resource requirement should not be fulfilled
ResourceRequirements requirements = createResourceRequirementsForSingleSlot(jobId);
slotManager.processResourceRequirements(requirements);
assertThat(slotTracker.getSlot(slotId).getJobId(), is(slotStatus.getJobID()));
assertThat(getTotalResourceCount(resourceTracker.getMissingResources().get(jobId)), is(1));
}
}
use of org.apache.flink.runtime.taskexecutor.SlotStatus in project flink by apache.
the class TaskExecutorManagerTest method createAndRegisterTaskExecutor.
private static InstanceID createAndRegisterTaskExecutor(TaskExecutorManager taskExecutorManager, int numSlots, ResourceProfile resourceProfile) {
final TaskExecutorConnection taskExecutorConnection = createTaskExecutorConnection();
List<SlotStatus> slotStatuses = IntStream.range(0, numSlots).mapToObj(slotNumber -> new SlotStatus(new SlotID(taskExecutorConnection.getResourceID(), slotNumber), resourceProfile)).collect(Collectors.toList());
final SlotReport slotReport = new SlotReport(slotStatuses);
taskExecutorManager.registerTaskManager(taskExecutorConnection, slotReport, resourceProfile.multiply(numSlots), resourceProfile);
return taskExecutorConnection.getInstanceID();
}
Aggregations