AgentLaunchGuardConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { if (!schedulerConfiguration.isGlobalTaskLaunchingConstraintEvaluatorEnabled()) { return VALID; } int maxLaunchingTasksPerMachine = schedulerConfiguration.getMaxLaunchingTasksPerMachine(); int assigned = targetVM.getTasksCurrentlyAssigned().size(); if (assigned >= maxLaunchingTasksPerMachine) { return INVALID; } int remaining = Math.max(maxLaunchingTasksPerMachine - assigned, 0); return isLaunchingLessThanNumberOfTasks(taskIdMapRef.get(), targetVM, remaining) ? VALID : INVALID; } @Inject  AgentLaunchGuardConstraint(SchedulerConfiguration schedulerConfiguration,
                                      V3JobOperations v3JobOperations); @Override String getName(); @Override void prepare(); @Override Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState); static boolean isAgentLaunchGuardConstraintReason(String reason); static final String NAME; }
@Test public void zeroConcurrentLaunchLimitPreventsScheduling() { when(schedulerConfiguration.getMaxLaunchingTasksPerMachine()).thenReturn(0); Result result = agentLaunchGuardConstraint.evaluate( createTaskRequest(TASK_ID), createVirtualMachineCurrentStateMock(INSTANCE_ID, Collections.emptyList(), Collections.emptyList()), taskTrackerState); assertThat(result.isSuccessful()).isFalse(); }
@Test public void agentHasLessThanConcurrentLaunchesLimit() { Result result = agentLaunchGuardConstraint.evaluate( createTaskRequest(TASK_ID), createVirtualMachineCurrentStateMock(INSTANCE_ID, Collections.emptyList(), Collections.emptyList()), taskTrackerState); assertThat(result.isSuccessful()).isTrue(); }