Search in sources :

Example 6 with TaskException

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;
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) TaskException(com.mesosphere.sdk.offer.TaskException) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec)

Aggregations

TaskException (com.mesosphere.sdk.offer.TaskException)6 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)5 Protos (org.apache.mesos.Protos)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)1 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)1 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)1 GoalState (com.mesosphere.sdk.specification.GoalState)1 PodInstance (com.mesosphere.sdk.specification.PodInstance)1 PodSpec (com.mesosphere.sdk.specification.PodSpec)1 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)1 ConfigStoreException (com.mesosphere.sdk.state.ConfigStoreException)1 Date (java.util.Date)1 TreeSet (java.util.TreeSet)1 TaskInfo (org.apache.mesos.Protos.TaskInfo)1