use of com.mesosphere.sdk.state.GoalStateOverride in project dcos-commons by mesosphere.
the class PodQueries method overrideGoalState.
private static Response overrideGoalState(StateStore stateStore, String podInstanceName, Set<String> taskNameFilter, GoalStateOverride override) {
Optional<Collection<TaskInfoAndStatus>> allPodTasks = GroupedTasks.create(stateStore).getPodInstanceTasks(podInstanceName);
if (!allPodTasks.isPresent()) {
return podNotFoundResponse(podInstanceName);
}
Collection<TaskInfoAndStatus> podTasks = RequestUtils.filterPodTasks(podInstanceName, allPodTasks.get(), taskNameFilter);
if (podTasks.isEmpty() || podTasks.size() < taskNameFilter.size()) {
// one or more requested tasks were not found.
LOGGER.error("Request had task filter: {} but pod '{}' tasks are: {} (matching: {})", taskNameFilter, podInstanceName, allPodTasks.get().stream().map(t -> t.getInfo().getName()).collect(Collectors.toList()), podTasks.stream().map(t -> t.getInfo().getName()).collect(Collectors.toList()));
return podNotFoundResponse(podInstanceName);
}
// invoke the restart request itself against ALL tasks. this ensures that they're ALL flagged as failed via
// FailureUtils, which is then checked by DefaultRecoveryPlanManager.
LOGGER.info("Performing {} goal state override of {} tasks in pod {}:", override, podTasks.size(), podInstanceName);
// First pass: Store the desired override for each task
GoalStateOverride.Status pendingStatus = override.newStatus(GoalStateOverride.Progress.PENDING);
for (TaskInfoAndStatus taskToOverride : podTasks) {
stateStore.storeGoalOverrideStatus(taskToOverride.getInfo().getName(), pendingStatus);
}
// Second pass: Restart the tasks. They will be updated to IN_PROGRESS once we receive a terminal TaskStatus.
return killTasks(podInstanceName, podTasks, RecoveryType.TRANSIENT);
}
use of com.mesosphere.sdk.state.GoalStateOverride 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