use of com.mesosphere.sdk.offer.TaskException in project dcos-commons by mesosphere.
the class DefaultConfigurationUpdater method needsConfigUpdate.
private static boolean needsConfigUpdate(Protos.TaskInfo taskInfo, ServiceSpec targetConfig, ServiceSpec taskConfig) {
if (targetConfig.equals(taskConfig)) {
LOGGER.info("Task '{}' is up to date: Task's target ServiceSpec matches the current ServiceSpec", taskInfo.getName());
return false;
}
final String podType;
final boolean isPermanentlyFailed;
try {
TaskLabelReader reader = new TaskLabelReader(taskInfo);
podType = reader.getType();
isPermanentlyFailed = reader.isPermanentlyFailed();
} catch (TaskException e) {
LOGGER.error(String.format("Unable to extract pod type from task '%s'. Will assume the task needs a configuration update", taskInfo.getName()), e);
return true;
}
// to transition from their former config to the new target.
if (isPermanentlyFailed) {
return false;
}
Optional<PodSpec> targetSpecOptional = getPodSpec(targetConfig, podType);
Optional<PodSpec> taskSpecOptional = getPodSpec(taskConfig, podType);
if (!targetSpecOptional.isPresent() || !taskSpecOptional.isPresent()) {
LOGGER.info("Task '{}' needs a configuration update: " + "PodSpec '{}' was {} in task's config, but is {} in current target config", taskInfo.getName(), podType, taskSpecOptional.isPresent() ? "present" : "missing", targetSpecOptional.isPresent() ? "present" : "missing");
return true;
}
boolean updateNeeded = !areMatching(targetSpecOptional.get(), taskSpecOptional.get());
if (updateNeeded) {
LOGGER.info("Task '{}' needs a configuration update: PodSpec '{}' has changed", taskInfo.getName(), podType);
} else {
LOGGER.info("Task '{}' is up to date: PodSpec '{}' is the same", taskInfo.getName(), podType);
}
return updateNeeded;
}
Aggregations