Search in sources :

Example 1 with OfferOutcome

use of com.mesosphere.sdk.offer.history.OfferOutcome in project dcos-commons by mesosphere.

the class OfferEvaluator method evaluate.

public List<OfferRecommendation> evaluate(PodInstanceRequirement podInstanceRequirement, List<Protos.Offer> offers) throws InvalidRequirementException, IOException {
    // All tasks in the service (used by some PlacementRules):
    Map<String, Protos.TaskInfo> allTasks = stateStore.fetchTasks().stream().collect(Collectors.toMap(Protos.TaskInfo::getName, Function.identity()));
    // Preexisting tasks for this pod (if any):
    Map<String, Protos.TaskInfo> thisPodTasks = TaskUtils.getTaskNames(podInstanceRequirement.getPodInstance()).stream().map(taskName -> allTasks.get(taskName)).filter(taskInfo -> taskInfo != null).collect(Collectors.toMap(Protos.TaskInfo::getName, Function.identity()));
    for (int i = 0; i < offers.size(); ++i) {
        List<OfferEvaluationStage> evaluationStages = getEvaluationPipeline(podInstanceRequirement, allTasks.values(), thisPodTasks);
        Protos.Offer offer = offers.get(i);
        MesosResourcePool resourcePool = new MesosResourcePool(offer, OfferEvaluationUtils.getRole(podInstanceRequirement.getPodInstance().getPod()));
        Map<TaskSpec, GoalStateOverride> overrideMap = new HashMap<>();
        for (TaskSpec taskSpec : podInstanceRequirement.getPodInstance().getPod().getTasks()) {
            GoalStateOverride override = stateStore.fetchGoalOverrideStatus(TaskSpec.getInstanceName(podInstanceRequirement.getPodInstance(), taskSpec)).target;
            overrideMap.put(taskSpec, override);
        }
        PodInfoBuilder podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, serviceName, getTargetConfig(podInstanceRequirement, thisPodTasks.values()), templateUrlFactory, schedulerConfig, thisPodTasks.values(), frameworkStore.fetchFrameworkId().get(), useDefaultExecutor, overrideMap);
        List<EvaluationOutcome> outcomes = new ArrayList<>();
        int failedOutcomeCount = 0;
        for (OfferEvaluationStage evaluationStage : evaluationStages) {
            EvaluationOutcome outcome = evaluationStage.evaluate(resourcePool, podInfoBuilder);
            outcomes.add(outcome);
            if (!outcome.isPassing()) {
                failedOutcomeCount++;
            }
        }
        StringBuilder outcomeDetails = new StringBuilder();
        for (EvaluationOutcome outcome : outcomes) {
            logOutcome(outcomeDetails, outcome, "");
        }
        if (outcomeDetails.length() != 0) {
            // trim extra trailing newline:
            outcomeDetails.deleteCharAt(outcomeDetails.length() - 1);
        }
        if (failedOutcomeCount != 0) {
            logger.info("Offer {}, {}: failed {} of {} evaluation stages:\n{}", i + 1, offer.getId().getValue(), failedOutcomeCount, evaluationStages.size(), outcomeDetails.toString());
            offerOutcomeTracker.track(new OfferOutcome(podInstanceRequirement.getName(), false, offer, outcomeDetails.toString()));
        } else {
            List<OfferRecommendation> recommendations = outcomes.stream().map(outcome -> outcome.getOfferRecommendations()).flatMap(xs -> xs.stream()).collect(Collectors.toList());
            logger.info("Offer {}: passed all {} evaluation stages, returning {} recommendations:\n{}", i + 1, evaluationStages.size(), recommendations.size(), outcomeDetails.toString());
            offerOutcomeTracker.track(new OfferOutcome(podInstanceRequirement.getName(), true, offer, outcomeDetails.toString()));
            return recommendations;
        }
    }
    return Collections.emptyList();
}
Also used : OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) java.util(java.util) com.mesosphere.sdk.offer(com.mesosphere.sdk.offer) Logger(org.slf4j.Logger) IOException(java.io.IOException) RecoveryType(com.mesosphere.sdk.scheduler.recovery.RecoveryType) TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) ArtifactQueries(com.mesosphere.sdk.http.queries.ArtifactQueries) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FailureUtils(com.mesosphere.sdk.scheduler.recovery.FailureUtils) TextFormat(com.google.protobuf.TextFormat) OfferOutcome(com.mesosphere.sdk.offer.history.OfferOutcome) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride) OfferOutcome(com.mesosphere.sdk.offer.history.OfferOutcome) Protos(org.apache.mesos.Protos)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 TextFormat (com.google.protobuf.TextFormat)1 ArtifactQueries (com.mesosphere.sdk.http.queries.ArtifactQueries)1 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)1 OfferOutcome (com.mesosphere.sdk.offer.history.OfferOutcome)1 OfferOutcomeTracker (com.mesosphere.sdk.offer.history.OfferOutcomeTracker)1 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)1 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)1 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)1 FailureUtils (com.mesosphere.sdk.scheduler.recovery.FailureUtils)1 RecoveryType (com.mesosphere.sdk.scheduler.recovery.RecoveryType)1 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)1 FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)1 GoalStateOverride (com.mesosphere.sdk.state.GoalStateOverride)1 StateStore (com.mesosphere.sdk.state.StateStore)1 IOException (java.io.IOException)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Protos (org.apache.mesos.Protos)1