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();
}
Aggregations