@Test public void instanceOnlyRunsGpuTasks() { AgentInstance instance = createAgentInstance(INSTANCE_GROUP_ID); when(agentManagementService.findAgentInstance(INSTANCE_ID)).thenReturn(Optional.of(instance)); AgentInstanceGroup agentInstanceGroup = createAgentInstanceGroup(InstanceGroupLifecycleState.Active, Tier.Flex, 1); when(agentManagementService.findInstanceGroup(INSTANCE_GROUP_ID)).thenReturn(Optional.of(agentInstanceGroup)); JobDescriptor<BatchJobExt> descriptor = oneTaskBatchJobDescriptor() .but(jd -> jd.getContainer().but(c -> c.toBuilder().withContainerResources( c.getContainerResources().toBuilder().withGpu(0).build() ))); Job<BatchJobExt> gpuBatchJob = JobGenerator.batchJobs(descriptor).getValue(); TaskRequest taskRequest = createTaskRequest(gpuBatchJob); Result result = agentManagementConstraint.evaluate(taskRequest, createVirtualMachineCurrentStateMock(INSTANCE_ID), mock(TaskTrackerState.class)); assertThat(result.isSuccessful()).isFalse(); assertThat(result.getFailureReason()).isEqualToIgnoringCase("Instance group does not run non gpu tasks"); }
@Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { V3QueueableTask v3QueueableTask = (V3QueueableTask) taskRequest; Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } AgentInstance instance = instanceOpt.get(); String instanceGroupId = instance.getInstanceGroupId(); Optional<AgentInstanceGroup> instanceGroupOpt = agentManagementService.findInstanceGroup(instanceGroupId); if (!instanceGroupOpt.isPresent()) { return Failure.INSTANCE_GROUP_NOT_FOUND.toResult(); } AgentInstanceGroup instanceGroup = instanceGroupOpt.get(); Result instanceGroupEvaluationResult = evaluateInstanceGroup(instanceGroup); if (instanceGroupEvaluationResult != VALID) { return instanceGroupEvaluationResult; } Result instanceEvaluationResult = evaluateInstance(instance); if (instanceEvaluationResult != VALID) { return instanceEvaluationResult; } return evaluateTask(v3QueueableTask, instanceGroup, instance); }
AgentManagementConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { V3QueueableTask v3QueueableTask = (V3QueueableTask) taskRequest; Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } AgentInstance instance = instanceOpt.get(); String instanceGroupId = instance.getInstanceGroupId(); Optional<AgentInstanceGroup> instanceGroupOpt = agentManagementService.findInstanceGroup(instanceGroupId); if (!instanceGroupOpt.isPresent()) { return Failure.INSTANCE_GROUP_NOT_FOUND.toResult(); } AgentInstanceGroup instanceGroup = instanceGroupOpt.get(); Result instanceGroupEvaluationResult = evaluateInstanceGroup(instanceGroup); if (instanceGroupEvaluationResult != VALID) { return instanceGroupEvaluationResult; } Result instanceEvaluationResult = evaluateInstance(instance); if (instanceEvaluationResult != VALID) { return instanceEvaluationResult; } return evaluateTask(v3QueueableTask, instanceGroup, instance); } }
AgentManagementConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { V3QueueableTask v3QueueableTask = (V3QueueableTask) taskRequest; Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } AgentInstance instance = instanceOpt.get(); String instanceGroupId = instance.getInstanceGroupId(); Optional<AgentInstanceGroup> instanceGroupOpt = agentManagementService.findInstanceGroup(instanceGroupId); if (!instanceGroupOpt.isPresent()) { return Failure.INSTANCE_GROUP_NOT_FOUND.toResult(); } AgentInstanceGroup instanceGroup = instanceGroupOpt.get(); Result instanceGroupEvaluationResult = evaluateInstanceGroup(instanceGroup); if (instanceGroupEvaluationResult != VALID) { return instanceGroupEvaluationResult; } Result instanceEvaluationResult = evaluateInstance(instance); if (instanceEvaluationResult != VALID) { return instanceEvaluationResult; } return evaluateTask(v3QueueableTask, instanceGroup, instance); } @Inject  AgentManagementConstraint(SchedulerConfiguration schedulerConfiguration,
                                     AgentManagementService agentManagementService,
                                     AgentStatusMonitor agentStatusMonitor); }
AgentManagementConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { V3QueueableTask v3QueueableTask = (V3QueueableTask) taskRequest; Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } AgentInstance instance = instanceOpt.get(); String instanceGroupId = instance.getInstanceGroupId(); Optional<AgentInstanceGroup> instanceGroupOpt = agentManagementService.findInstanceGroup(instanceGroupId); if (!instanceGroupOpt.isPresent()) { return Failure.INSTANCE_GROUP_NOT_FOUND.toResult(); } AgentInstanceGroup instanceGroup = instanceGroupOpt.get(); Result instanceGroupEvaluationResult = evaluateInstanceGroup(instanceGroup); if (instanceGroupEvaluationResult != VALID) { return instanceGroupEvaluationResult; } Result instanceEvaluationResult = evaluateInstance(instance); if (instanceEvaluationResult != VALID) { return instanceEvaluationResult; } return evaluateTask(v3QueueableTask, instanceGroup, instance); } @Inject  AgentManagementConstraint(SchedulerConfiguration schedulerConfiguration,
                                     AgentManagementService agentManagementService,
                                     AgentStatusMonitor agentStatusMonitor); static boolean isAgentManagementConstraintReason(String reason); @Override String getName(); @Override Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState); }
AgentManagementConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { V3QueueableTask v3QueueableTask = (V3QueueableTask) taskRequest; Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } AgentInstance instance = instanceOpt.get(); String instanceGroupId = instance.getInstanceGroupId(); Optional<AgentInstanceGroup> instanceGroupOpt = agentManagementService.findInstanceGroup(instanceGroupId); if (!instanceGroupOpt.isPresent()) { return Failure.INSTANCE_GROUP_NOT_FOUND.toResult(); } AgentInstanceGroup instanceGroup = instanceGroupOpt.get(); Result instanceGroupEvaluationResult = evaluateInstanceGroup(instanceGroup); if (instanceGroupEvaluationResult != VALID) { return instanceGroupEvaluationResult; } Result instanceEvaluationResult = evaluateInstance(instance); if (instanceEvaluationResult != VALID) { return instanceEvaluationResult; } return evaluateTask(v3QueueableTask, instanceGroup, instance); } @Inject  AgentManagementConstraint(SchedulerConfiguration schedulerConfiguration,
                                     AgentManagementService agentManagementService,
                                     AgentStatusMonitor agentStatusMonitor); static boolean isAgentManagementConstraintReason(String reason); @Override String getName(); @Override Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState); static final String NAME; }