com.netflix.fenzo.TaskRequest Java Examples

The following examples show how to use com.netflix.fenzo.TaskRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobTypeFitnessCalculator.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    int totalTasks = 0;
    int totalSameJobTasks = 0;

    for (TaskRequest request : targetVM.getRunningTasks()) {
        totalTasks++;
        if (isSameJobType(taskRequest, request)) {
            totalSameJobTasks++;
        }
    }
    for (TaskAssignmentResult result : targetVM.getTasksCurrentlyAssigned()) {
        totalTasks++;
        if (isSameJobType(taskRequest, result.getRequest())) {
            totalSameJobTasks++;
        }
    }
    if (totalTasks == 0) {
        return EMPTY_HOST_SCORE;
    } else if (totalSameJobTasks == 0) {
        return ZERO_SAME_JOB_TASKS_SCORE;
    }
    return (double) totalSameJobTasks / (double) totalTasks;
}
 
Example #2
Source File: TaskLaunchScheduledServiceTest.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 6 votes vote down vote up
@Test
public void assertRunOneIterationWithScriptJob() throws Exception {
    when(facadeService.getEligibleJobContext()).thenReturn(Lists.newArrayList(
            JobContext.from(CloudJobConfigurationBuilder.createScriptCloudJobConfiguration("script_job", 1), ExecutionType.READY)));
    Map<String, VMAssignmentResult> vmAssignmentResultMap = new HashMap<>();
    vmAssignmentResultMap.put("rs1", new VMAssignmentResult("localhost", Lists.<VirtualMachineLease>newArrayList(new VMLeaseObject(OfferBuilder.createOffer("offer_0"))),
            Sets.newHashSet(mockTaskAssignmentResult("script_job", ExecutionType.READY))));
    when(taskScheduler.scheduleOnce(ArgumentMatchers.<TaskRequest>anyList(), ArgumentMatchers.<VirtualMachineLease>anyList())).thenReturn(new SchedulingResult(vmAssignmentResultMap));
    when(facadeService.loadAppConfig("test_app")).thenReturn(Optional.of(CloudAppConfigurationBuilder.createCloudAppConfiguration("test_app")));
    when(facadeService.load("script_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createScriptCloudJobConfiguration("script_job", 1)));
    when(taskScheduler.getTaskAssigner()).thenReturn(mock(Action2.class));
    taskLaunchScheduledService.runOneIteration();
    verify(facadeService).removeLaunchTasksFromQueue(ArgumentMatchers.<TaskContext>anyList());
    verify(facadeService).isRunning(TaskContext.from(String.format("%s@-@0@-@%s@-@unassigned-slave@-@0", "script_job", ExecutionType.READY)));
    verify(facadeService).loadAppConfig("test_app");
    verify(jobEventBus).post(ArgumentMatchers.<JobStatusTraceEvent>any());
}
 
Example #3
Source File: BatchDifferenceResolver.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Inject
public BatchDifferenceResolver(
        DirectKubeApiServerIntegrator kubeApiServerIntegrator,
        JobManagerConfiguration configuration,
        FeatureActivationConfiguration featureConfiguration,
        DirectKubeConfiguration kubeConfiguration,
        @Named(FeatureRolloutPlans.KUBE_SCHEDULER_FEATURE) Predicate<Pair<JobDescriptor, ApplicationSLA>> kubeSchedulerPredicate,
        ApplicationSlaManagementService capacityGroupService,
        SchedulingService<? extends TaskRequest> schedulingService,
        VirtualMachineMasterService vmService,
        JobStore jobStore,
        ConstraintEvaluatorTransformer<Pair<String, String>> constraintEvaluatorTransformer,
        SystemSoftConstraint systemSoftConstraint,
        SystemHardConstraint systemHardConstraint,
        TitusRuntime titusRuntime) {
    this(kubeApiServerIntegrator, configuration, featureConfiguration, kubeConfiguration, kubeSchedulerPredicate, capacityGroupService,
            schedulingService, vmService, jobStore, constraintEvaluatorTransformer, systemSoftConstraint,
            systemHardConstraint, titusRuntime, Schedulers.computation()
    );
}
 
Example #4
Source File: AgentManagementConstraintTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void taintsAndTolerationsDoNotMatch() {
    AgentInstance instance = createAgentInstance(INSTANCE_GROUP_ID, Collections.singletonMap(SchedulerAttributes.TAINTS, "b,d"));
    when(agentManagementService.findAgentInstance(INSTANCE_ID)).thenReturn(Optional.of(instance));
    AgentInstanceGroup agentInstanceGroup = createAgentInstanceGroup(InstanceGroupLifecycleState.Active, Tier.Flex,
            Collections.singletonMap(SchedulerAttributes.TAINTS, "b,c"));
    when(agentManagementService.findInstanceGroup(INSTANCE_GROUP_ID)).thenReturn(Optional.of(agentInstanceGroup));
    JobDescriptor<BatchJobExt> descriptor = oneTaskBatchJobDescriptor()
            .but(jd -> jd.toBuilder().withAttributes(Collections.singletonMap(JOB_PARAMETER_ATTRIBUTES_TOLERATIONS, "a,b")));
    Job<BatchJobExt> job = JobGenerator.batchJobs(descriptor).getValue();
    TaskRequest taskRequest = createTaskRequest(job);
    Result result = agentManagementConstraint.evaluate(taskRequest,
            createVirtualMachineCurrentStateMock(INSTANCE_ID), mock(TaskTrackerState.class));
    assertThat(result.isSuccessful()).isFalse();
    assertThat(result.getFailureReason()).isEqualToIgnoringCase("Cannot place on instance group or agent instance due to toleration attribute not matching taint attribute");
}
 
Example #5
Source File: TaskScenarioBuilder.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public TaskScenarioBuilder(EmbeddedTitusOperations titusOperations,
                           JobScenarioBuilder jobScenarioBuilder,
                           Observable<Task> eventStream,
                           SchedulingService<? extends TaskRequest> schedulingService,
                           DiagnosticReporter diagnosticReporter) {
    this.jobClient = titusOperations.getV3GrpcClient();
    this.evictionClient = titusOperations.getBlockingGrpcEvictionClient();
    this.jobScenarioBuilder = jobScenarioBuilder;
    this.eventStreamSubscription = eventStream.subscribe(eventStreamSubscriber);
    this.schedulingService = schedulingService;
    this.diagnosticReporter = diagnosticReporter;
    eventStream.take(1).flatMap(task ->
            titusOperations.awaitTaskExecutorHolderOf(task.getId())
    ).subscribe(holder -> {
        taskExecutionHolder = holder;
        logger.info("TaskExecutorHolder set for task {}", holder.getTaskId());
    });
}
 
Example #6
Source File: AppConstraintEvaluatorTest.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 6 votes vote down vote up
private List<TaskRequest> getTasks() {
    List<TaskRequest> result = new ArrayList<>(20);
    for (int i = 0; i < 20; i++) {
        String jobName;
        String appName;
        if (i % 2 == 0) {
            jobName = String.format("foo-%d", i);
            appName = "foo-app";
        } else {
            jobName = String.format("bar-%d", i);
            appName = "bar-app";
        }
        result.add(getTask(jobName));
        Mockito.when(facadeService.load(jobName)).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration(jobName, appName)));
    }
    Mockito.when(facadeService.loadAppConfig("foo-app")).thenReturn(Optional.of(CloudAppConfigurationBuilder.createCloudAppConfiguration("foo-app")));
    Mockito.when(facadeService.loadAppConfig("bar-app")).thenReturn(Optional.of(CloudAppConfigurationBuilder.createCloudAppConfiguration("bar-app")));
    return result;
}
 
Example #7
Source File: AgentManagementConstraintTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #8
Source File: JobSpreadingFitnessCalculator.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    List<TaskRequest> allTasksOnAgent = FitnessCalculatorFunctions.getAllTasksOnAgent(targetVM);
    String jobId = FitnessCalculatorFunctions.getJob(taskRequest).getId();
    long matchingTaskCount = FitnessCalculatorFunctions.countMatchingTasks(allTasksOnAgent, taskOnAgent -> {
        String taskOnAgentJobId = FitnessCalculatorFunctions.getJob(taskRequest).getId();
        return jobId.equals(taskOnAgentJobId);
    });

    if (matchingTaskCount == 0) {
        return NO_MATCHING_TASK_SCORE;
    }

    double matchingTaskRatio = 1.0 / (double) matchingTaskCount;
    return matchingTaskRatio * MATCHING_TASK_SCORE;
}
 
Example #9
Source File: SecurityGroupSpreadingFitnessCalculator.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    List<TaskRequest> allTasksOnAgent = FitnessCalculatorFunctions.getAllTasksOnAgent(targetVM);
    List<String> taskSecurityGroups = getSecurityGroups(taskRequest);
    long matchingTaskCount = FitnessCalculatorFunctions.countMatchingTasks(allTasksOnAgent, taskOnAgent -> {
        List<String> taskOnAgentJoinedSecurityGroups = getSecurityGroups(taskOnAgent);
        return areSecurityGroupsEqual(taskSecurityGroups, taskOnAgentJoinedSecurityGroups);
    });

    if (matchingTaskCount == 0) {
        return NO_MATCHING_TASK_SCORE;
    }

    double matchingTaskRatio = 1.0 / (double) matchingTaskCount;
    return matchingTaskRatio * MATCHING_TASK_SCORE;
}
 
Example #10
Source File: ClusterAgentAutoScaler.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public ClusterAgentAutoScaler(TitusRuntime titusRuntime,
                              ClusterOperationsConfiguration configuration,
                              AgentManagementService agentManagementService,
                              V3JobOperations v3JobOperations,
                              SchedulingService<? extends TaskRequest> schedulingService,
                              Scheduler scheduler) {
    this.titusRuntime = titusRuntime;
    this.configuration = configuration;
    this.agentManagementService = agentManagementService;
    this.v3JobOperations = v3JobOperations;
    this.schedulingService = schedulingService;
    this.scheduler = scheduler;
    this.clock = titusRuntime.getClock();
    this.taskIdsForPreviousScaleUps = CacheBuilder.newBuilder()
            .expireAfterWrite(TASK_IDS_PREVIOUSLY_SCALED_TTL_MS, TimeUnit.MILLISECONDS)
            .build();
    this.tierTierAutoScalerExecutions = new HashMap<>();
}
 
Example #11
Source File: AgentLaunchGuardConstraint.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #12
Source File: JobReconciliationFrameworkFactory.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Inject
public JobReconciliationFrameworkFactory(JobManagerConfiguration jobManagerConfiguration,
                                         FeatureActivationConfiguration featureConfiguration,
                                         @Named(BATCH_RESOLVER) DifferenceResolver<JobManagerReconcilerEvent> batchDifferenceResolver,
                                         @Named(SERVICE_RESOLVER) DifferenceResolver<JobManagerReconcilerEvent> serviceDifferenceResolver,
                                         JobStore store,
                                         SchedulingService<? extends TaskRequest> schedulingService,
                                         ApplicationSlaManagementService capacityGroupService,
                                         SystemSoftConstraint systemSoftConstraint,
                                         SystemHardConstraint systemHardConstraint,
                                         ConstraintEvaluatorTransformer<Pair<String, String>> constraintEvaluatorTransformer,
                                         @Named(JOB_PERMISSIVE_SANITIZER) EntitySanitizer permissiveEntitySanitizer,
                                         @Named(JOB_STRICT_SANITIZER) EntitySanitizer strictEntitySanitizer,
                                         TitusRuntime titusRuntime) {
    this(jobManagerConfiguration, featureConfiguration, batchDifferenceResolver, serviceDifferenceResolver, store,
            schedulingService, capacityGroupService, systemSoftConstraint, systemHardConstraint,
            constraintEvaluatorTransformer, permissiveEntitySanitizer, strictEntitySanitizer, titusRuntime,
            Optional.empty());
}
 
Example #13
Source File: AgentManagementConstraintTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void instanceGroupDoesNotHaveGpus() {
    AgentInstance instance = createAgentInstance(INSTANCE_GROUP_ID);
    when(agentManagementService.findAgentInstance(INSTANCE_ID)).thenReturn(Optional.of(instance));
    AgentInstanceGroup agentInstanceGroup = createAgentInstanceGroup(InstanceGroupLifecycleState.Active, Tier.Flex);
    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(1).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 have gpus");
}
 
Example #14
Source File: ImageSpreadingFitnessCalculator.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    List<TaskRequest> allTasksOnAgent = FitnessCalculatorFunctions.getAllTasksOnAgent(targetVM);
    AgentResourceCacheImage taskRequestImage = AgentResourceCacheFunctions.getImage(taskRequest);
    long matchingTaskCount = FitnessCalculatorFunctions.countMatchingTasks(allTasksOnAgent, taskOnAgent -> {
        AgentResourceCacheImage taskOnAgentImage = AgentResourceCacheFunctions.getImage(taskOnAgent);
        return taskRequestImage.equals(taskOnAgentImage);
    });

    if (matchingTaskCount == 0) {
        return NO_MATCHING_TASK_SCORE;
    }

    double matchingTaskRatio = 1.0 / (double) matchingTaskCount;
    return matchingTaskRatio * MATCHING_TASK_SCORE;
}
 
Example #15
Source File: V3UniqueHostConstraint.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    V3QueueableTask v3FenzoTask = (V3QueueableTask) taskRequest;
    String jobId = v3FenzoTask.getJob().getId();

    for (TaskRequest running : targetVM.getRunningTasks()) {
        if (check(jobId, running)) {
            return INVALID;
        }
    }

    for (TaskAssignmentResult assigned : targetVM.getTasksCurrentlyAssigned()) {
        if (check(jobId, assigned.getRequest())) {
            return INVALID;
        }
    }

    return VALID;
}
 
Example #16
Source File: SchedulerModule.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    bind(VMOperations.class).to(VMOperationsImpl.class);
    bind(TierSlaUpdater.class).to(DefaultTierSlaUpdater.class);
    bind(PreferentialNamedConsumableResourceEvaluator.class).to(TitusNetworkInterfaceFitnessEvaluator.class);
    bind(new TypeLiteral<SchedulingService<? extends TaskRequest>>() {
    }).to(DefaultSchedulingService.class).asEagerSingleton();
    bind(AgentResourceCache.class).to(DefaultAgentResourceCache.class);

    bind(SystemSoftConstraint.class).to(DefaultSystemSoftConstraint.class);
    bind(SystemHardConstraint.class).to(DefaultSystemHardConstraint.class);

    bind(AgentQualityTracker.class).to(ContainerFailureBasedAgentQualityTracker.class);
    bind(V3_CONSTRAINT_EVALUATOR_TRANSFORMER_TYPE).to(V3ConstraintEvaluatorTransformer.class);

    bind(SchedulerServiceGrpc.SchedulerServiceImplBase.class).to(DefaultSchedulerServiceGrpc.class);

    bind(SchedulerService.class).to(DefaultSchedulerService.class);
}
 
Example #17
Source File: TaskPlacementFailureClassifier.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private void updateInternal(SchedulingResult schedulingResult) {
    Map<FailureKind, Map<T, List<TaskPlacementFailure>>> failures = new HashMap<>();

    for (Map.Entry<TaskRequest, List<TaskAssignmentResult>> entry : schedulingResult.getFailures().entrySet()) {
        // assume all TaskRequests are of the correct type
        @SuppressWarnings("unchecked") T taskRequest = (T) entry.getKey();
        List<TaskAssignmentResult> assignmentResults = entry.getValue();

        if (assignmentResults.isEmpty()) {
            invariants.inconsistent("Task placement failure with empty failure set: taskId=%s", taskRequest.getId());
            continue;
        }

        process(taskRequest, assignmentResults, failures);
    }

    this.failuresRef.set(failures);
}
 
Example #18
Source File: ActiveHostConstraint.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, configuration.getInstanceAttributeName(), targetVM);
    if (!instanceOpt.isPresent()) {
        return INVALID;
    }

    AgentInstance instance = instanceOpt.get();
    String instanceGroupId = instance.getInstanceGroupId();

    Optional<AgentInstanceGroup> instanceGroupOpt = agentManagementService.findInstanceGroup(instanceGroupId);
    if (!instanceGroupOpt.isPresent()) {
        return INVALID;
    }

    AgentInstanceGroup instanceGroup = instanceGroupOpt.get();
    InstanceGroupLifecycleState state = instanceGroup.getLifecycleStatus().getState();

    if (state != InstanceGroupLifecycleState.Active) {
        return INVALID;
    }

    return VALID;
}
 
Example #19
Source File: CachedImageFitnessCalculator.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    Optional<AgentResourceCacheInstance> instanceOpt = agentResourceCache.get(targetVM.getHostname());
    if (instanceOpt.isPresent()) {
        AgentResourceCacheInstance instance = instanceOpt.get();
        AgentResourceCacheImage image = AgentResourceCacheFunctions.getImage(taskRequest);
        if (instance.getImages().contains(image)) {
            return IMAGE_CACHED_SCORE;
        }
    }
    return IMAGE_NOT_CACHED_SCORE;
}
 
Example #20
Source File: SchedulerUtils.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static boolean isLaunchingLessThanNumberOfTasks(Map<String, Task> tasksById, VirtualMachineCurrentState targetVM,
                                                       int numberOfTasks) {
    int launchingTaskCount = 0;
    for (TaskRequest running : targetVM.getRunningTasks()) {
        if (isTaskLaunching(tasksById, running)) {
            launchingTaskCount++;
        }
        if (launchingTaskCount >= numberOfTasks) {
            return false;
        }
    }
    return true;
}
 
Example #21
Source File: TitusFitnessCalculator.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    if (isCriticalTier(taskRequest) && isServiceJob(taskRequest)) {
        if (configuration.isCriticalServiceJobSpreadingEnabled()) {
            return criticalServiceJobSpreader.calculateFitness(taskRequest, targetVM, taskTrackerState);
        } else {
            return criticalServiceJobBinPacker.calculateFitness(taskRequest, targetVM, taskTrackerState);
        }
    }
    return defaultFitnessCalculator.calculateFitness(taskRequest, targetVM, taskTrackerState);
}
 
Example #22
Source File: SchedulerUtils.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static boolean isTaskLaunching(Map<String, Task> tasksById, TaskRequest request) {
    Task current = tasksById.get(request.getId());
    if (current == null) {
        return false;
    }
    TaskState state = current.getStatus().getState();
    return state == TaskState.Accepted || state == TaskState.Launched || state == TaskState.StartInitiated;
}
 
Example #23
Source File: SchedulerTestUtils.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static VirtualMachineCurrentState createVirtualMachineCurrentStateMock(String id, List<TaskRequest> runningTasks,
                                                                              List<TaskAssignmentResult> assignedTasks) {
    VirtualMachineCurrentState currentState = mock(VirtualMachineCurrentState.class);
    VirtualMachineLease lease = mock(VirtualMachineLease.class);
    Map<String, Protos.Attribute> attributes = new HashMap<>();
    attributes.put("id", Protos.Attribute.newBuilder().setName("id").setType(Protos.Value.Type.TEXT).setText(Protos.Value.Text.newBuilder().setValue(id)).build());
    when(lease.getAttributeMap()).thenReturn(attributes);
    when(currentState.getCurrAvailableResources()).thenReturn(lease);
    when(currentState.getRunningTasks()).thenReturn(runningTasks);
    when(currentState.getTasksCurrentlyAssigned()).thenReturn(assignedTasks);
    return currentState;
}
 
Example #24
Source File: FitnessCalculatorFunctions.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static long countMatchingTasks(List<TaskRequest> tasksOnAgent, Predicate<TaskRequest> predicate) {
    int count = 0;
    for (TaskRequest taskRequest : tasksOnAgent) {
        if (predicate.test(taskRequest)) {
            count++;
        }
    }
    return count;
}
 
Example #25
Source File: V3ZoneBalancedHardConstraintEvaluator.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    // Ignore the constraint for non-V3 tasks.
    if (!(taskRequest instanceof V3QueueableTask)) {
        return VALID;
    }

    String targetZoneId = SchedulerUtils.getAttributeValueOrEmptyString(targetVM, zoneAttributeName);
    if (targetZoneId.isEmpty()) {
        return NO_ZONE_ID;
    }

    V3QueueableTask v3FenzoTask = (V3QueueableTask) taskRequest;
    return evaluate(targetZoneId, v3FenzoTask.getJob().getId(), taskTrackerState);
}
 
Example #26
Source File: AvailabilityZoneConstraint.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, configuration.getInstanceAttributeName(), targetVM);
    if (!instanceOpt.isPresent()) {
        return MACHINE_DOES_NOT_EXIST;
    }

    AgentInstance agentInstance = instanceOpt.get();
    String instanceAvailabilityZone = agentInstance.getAttributes().getOrDefault(configuration.getAvailabilityZoneAttributeName(), "");
    return instanceAvailabilityZone.equalsIgnoreCase(availabilityZone) ? VALID : AVAILABILITY_ZONE_DOES_NOT_MATCH;
}
 
Example #27
Source File: MachineGroupConstraint.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, configuration.getInstanceAttributeName(), targetVM);
    if (!instanceOpt.isPresent()) {
        return MACHINE_DOES_NOT_EXIST;
    }

    AgentInstance agentInstance = instanceOpt.get();

    return agentInstance.getInstanceGroupId().equalsIgnoreCase(machineGroup) ? VALID : MACHINE_GROUP_DOES_NOT_MATCH;
}
 
Example #28
Source File: SystemSelectorConstraintEvaluator.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    List<Match> matches = systemSelectorService.getMustMatchesForEvaluation();
    for (Match match : matches) {
        String selectExpression = match.getSelectExpression();
        Map<String, Object> context = createContext(taskRequest, targetVM, agentManagementService, schedulerConfiguration);
        boolean selectResult = false;
        try {
            logger.debug("Evaluating select expression: {} for taskRequest: {} on targetVM: {}", selectExpression, taskRequest, targetVM);
            selectResult = systemSelectorEvaluator.evaluate(selectExpression, context);
            logger.debug("Evaluated select expression: {} for taskRequest: {} on targetVM: {} with result: {}",
                    selectExpression, taskRequest, targetVM, selectResult);
        } catch (SchedulerException ignored) {
        }
        if (selectResult) {
            String matchExpression = match.getMatchExpression();
            boolean matchResult;
            try {
                logger.debug("Evaluating match expression: {} for taskRequest: {} on targetVM: {}", matchExpression, taskRequest, targetVM);
                matchResult = systemSelectorEvaluator.evaluate(matchExpression, context);
                logger.debug("Evaluated match expression: {} for taskRequest: {} on targetVM: {} with result: {}",
                        matchExpression, taskRequest, targetVM, matchResult);
            } catch (SchedulerException e) {
                return VALID;
            }
            if (!matchResult) {
                return INVALID;
            }
        }

    }
    return VALID;
}
 
Example #29
Source File: AgentManagementConstraintTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void taintsAndInstanceTolerationsMatch() {
    AgentInstance instance = createAgentInstance(INSTANCE_GROUP_ID, Collections.singletonMap(SchedulerAttributes.TAINTS, "b,c"));
    when(agentManagementService.findAgentInstance(INSTANCE_ID)).thenReturn(Optional.of(instance));
    AgentInstanceGroup agentInstanceGroup = createAgentInstanceGroup(InstanceGroupLifecycleState.Active, Tier.Flex);
    when(agentManagementService.findInstanceGroup(INSTANCE_GROUP_ID)).thenReturn(Optional.of(agentInstanceGroup));
    JobDescriptor<BatchJobExt> descriptor = oneTaskBatchJobDescriptor()
            .but(jd -> jd.toBuilder().withAttributes(Collections.singletonMap(JOB_PARAMETER_ATTRIBUTES_TOLERATIONS, "a,b,c")));
    Job<BatchJobExt> job = JobGenerator.batchJobs(descriptor).getValue();
    TaskRequest taskRequest = createTaskRequest(job);
    Result result = agentManagementConstraint.evaluate(taskRequest,
            createVirtualMachineCurrentStateMock(INSTANCE_ID), mock(TaskTrackerState.class));
    assertThat(result.isSuccessful()).isTrue();
}
 
Example #30
Source File: FitnessCalculatorFunctions.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static List<TaskRequest> getAllTasksOnAgent(VirtualMachineCurrentState targetVm) {
    List<TaskRequest> tasksOnAgent = new ArrayList<>(targetVm.getRunningTasks());
    for (TaskAssignmentResult taskAssignmentResult : targetVm.getTasksCurrentlyAssigned()) {
        tasksOnAgent.add(taskAssignmentResult.getRequest());
    }
    return tasksOnAgent;
}