Search in sources :

Example 6 with ConfigStoreException

use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.

the class TaskUtils method getPodSpec.

private static PodSpec getPodSpec(ConfigStore<ServiceSpec> configStore, Protos.TaskInfo taskInfo) throws TaskException {
    UUID configId = new TaskLabelReader(taskInfo).getTargetConfiguration();
    ServiceSpec serviceSpec;
    try {
        serviceSpec = configStore.fetch(configId);
    } catch (ConfigStoreException e) {
        throw new TaskException(String.format("Unable to retrieve ServiceSpecification ID %s referenced by TaskInfo[%s]", configId, taskInfo.getName()), e);
    }
    Optional<PodSpec> podSpecOptional = getPodSpec(serviceSpec, taskInfo);
    if (!podSpecOptional.isPresent()) {
        throw new TaskException(String.format("No TaskSpecification found for TaskInfo[%s]", taskInfo.getName()));
    } else {
        return podSpecOptional.get();
    }
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException)

Example 7 with ConfigStoreException

use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.

the class SchedulerBuilder method getDefaultScheduler.

/**
 * Creates a new scheduler instance with the provided values or their defaults.
 *
 * @return a new scheduler instance
 * @throws IllegalArgumentException if config validation failed when updating the target config.
 */
private DefaultScheduler getDefaultScheduler(ServiceSpec serviceSpec, FrameworkStore frameworkStore, StateStore stateStore, ConfigStore<ServiceSpec> configStore) throws ConfigStoreException {
    // Determine whether deployment had previously completed BEFORE we update the config.
    // Plans may be generated from the config content.
    boolean hasCompletedDeployment = StateStoreUtils.getDeploymentWasCompleted(stateStore);
    if (!hasCompletedDeployment) {
        try {
            // Check for completion against the PRIOR service spec. For example, if the new service spec has n+1
            // nodes, then we want to check that the prior n nodes had successfully deployed.
            ServiceSpec lastServiceSpec = configStore.fetch(configStore.getTargetConfig());
            Optional<Plan> deployPlan = getDeployPlan(getPlans(stateStore, configStore, lastServiceSpec, yamlPlans));
            if (deployPlan.isPresent() && deployPlan.get().isComplete()) {
                logger.info("Marking deployment as having been previously completed");
                StateStoreUtils.setDeploymentWasCompleted(stateStore);
                hasCompletedDeployment = true;
            }
        } catch (ConfigStoreException e) {
            // This is expected during initial deployment, when there is no prior configuration.
            logger.info("Unable to retrieve last configuration. Assuming that no prior deployment has completed");
        }
    }
    // Update/validate config as needed to reflect the new service spec:
    Collection<ConfigValidator<ServiceSpec>> configValidators = new ArrayList<>();
    configValidators.addAll(DefaultConfigValidators.getValidators(schedulerConfig));
    configValidators.addAll(customConfigValidators);
    final ConfigurationUpdater.UpdateResult configUpdateResult = updateConfig(serviceSpec, stateStore, configStore, configValidators);
    if (!configUpdateResult.getErrors().isEmpty()) {
        logger.warn("Failed to update configuration due to validation errors: {}", configUpdateResult.getErrors());
        try {
            // If there were errors, stick with the last accepted target configuration.
            serviceSpec = configStore.fetch(configStore.getTargetConfig());
        } catch (ConfigStoreException e) {
            // Uh oh. Bail.
            logger.error("Failed to retrieve previous target configuration", e);
            throw new IllegalArgumentException(e);
        }
    }
    // Now that a ServiceSpec has been chosen, generate the plans.
    Collection<Plan> plans = getPlans(stateStore, configStore, serviceSpec, yamlPlans);
    plans = selectDeployPlan(plans, hasCompletedDeployment);
    Optional<Plan> deployPlan = getDeployPlan(plans);
    if (!deployPlan.isPresent()) {
        throw new IllegalArgumentException("No deploy plan provided: " + plans);
    }
    List<String> errors = configUpdateResult.getErrors().stream().map(ConfigValidationError::toString).collect(Collectors.toList());
    if (!errors.isEmpty()) {
        plans = setDeployPlanErrors(plans, deployPlan.get(), errors);
    }
    PlanManager deploymentPlanManager = DefaultPlanManager.createProceeding(getDeployPlan(plans).get());
    PlanManager recoveryPlanManager = getRecoveryPlanManager(serviceSpec, Optional.ofNullable(recoveryPlanOverriderFactory), stateStore, configStore, plans);
    Optional<PlanManager> decommissionPlanManager = getDecommissionPlanManager(serviceSpec, stateStore);
    PlanCoordinator planCoordinator = buildPlanCoordinator(serviceSpec.getName(), deploymentPlanManager, recoveryPlanManager, decommissionPlanManager, plans);
    return new DefaultScheduler(serviceSpec, FrameworkConfig.fromServiceSpec(serviceSpec), schedulerConfig, namespace, customResources, planCoordinator, Optional.ofNullable(planCustomizer), frameworkStore, stateStore, configStore, templateUrlFactory.orElse(ArtifactResource.getUrlFactory(serviceSpec.getName())), endpointProducers);
}
Also used : DefaultRecoveryPlanManager(com.mesosphere.sdk.scheduler.recovery.DefaultRecoveryPlanManager) ConfigValidator(com.mesosphere.sdk.config.validate.ConfigValidator) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) RawPlan(com.mesosphere.sdk.specification.yaml.RawPlan) ConfigurationUpdater(com.mesosphere.sdk.config.ConfigurationUpdater) DefaultConfigurationUpdater(com.mesosphere.sdk.config.DefaultConfigurationUpdater)

Example 8 with ConfigStoreException

use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.

the class SchedulerBuilder method getPlans.

/**
 * Gets or generate plans against the given service spec.
 *
 * @param stateStore The state store to use for plan generation.
 * @param configStore The config store to use for plan generation.
 * @return a collection of plans
 */
private Collection<Plan> getPlans(StateStore stateStore, ConfigStore<ServiceSpec> configStore, ServiceSpec serviceSpec, Map<String, RawPlan> yamlPlans) {
    final String plansType;
    final Collection<Plan> plans;
    if (!yamlPlans.isEmpty()) {
        plansType = "YAML";
        // Note: Any internal Plan generation must only be AFTER updating/validating the config. Otherwise plans
        // may look at the old config and mistakenly think they're COMPLETE.
        DefaultPlanGenerator planGenerator = new DefaultPlanGenerator(configStore, stateStore);
        plans = yamlPlans.entrySet().stream().map(e -> planGenerator.generate(e.getValue(), e.getKey(), serviceSpec.getPods())).collect(Collectors.toList());
    } else {
        plansType = "generated";
        try {
            if (!configStore.list().isEmpty()) {
                PlanFactory planFactory = new DeployPlanFactory(new DefaultPhaseFactory(new DefaultStepFactory(configStore, stateStore)));
                plans = Arrays.asList(planFactory.getPlan(configStore.fetch(configStore.getTargetConfig())));
            } else {
                plans = Collections.emptyList();
            }
        } catch (ConfigStoreException e) {
            throw new IllegalStateException(e);
        }
    }
    logger.info("Got {} {} plan{}: {}", plans.size(), plansType, plans.size() == 1 ? "" : "s", plans.stream().map(plan -> plan.getName()).collect(Collectors.toList()));
    return plans;
}
Also used : ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) DecommissionPlanFactory(com.mesosphere.sdk.scheduler.decommission.DecommissionPlanFactory) RawPlan(com.mesosphere.sdk.specification.yaml.RawPlan)

Example 9 with ConfigStoreException

use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.

the class ConfigQueriesTest method testGetTargetFailsConfig.

@Test
public void testGetTargetFailsConfig() throws ConfigStoreException {
    when(mockConfigStore.getTargetConfig()).thenReturn(ID2);
    when(mockConfigStore.fetch(ID2)).thenThrow(new ConfigStoreException(Reason.STORAGE_ERROR, "hi"));
    Response response = ConfigQueries.getTarget(mockConfigStore);
    assertEquals(500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) Test(org.junit.Test)

Example 10 with ConfigStoreException

use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.

the class ConfigQueriesTest method testGetTargetIdMissing.

@Test
public void testGetTargetIdMissing() throws ConfigStoreException {
    when(mockConfigStore.getTargetConfig()).thenThrow(new ConfigStoreException(Reason.NOT_FOUND, "hi"));
    Response response = ConfigQueries.getTargetId(mockConfigStore);
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) Test(org.junit.Test)

Aggregations

ConfigStoreException (com.mesosphere.sdk.state.ConfigStoreException)22 Test (org.junit.Test)11 Response (javax.ws.rs.core.Response)9 UUID (java.util.UUID)5 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)3 TaskException (com.mesosphere.sdk.offer.TaskException)2 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)2 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)2 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)2 RawPlan (com.mesosphere.sdk.specification.yaml.RawPlan)2 ConfigStore (com.mesosphere.sdk.state.ConfigStore)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ConfigurationUpdater (com.mesosphere.sdk.config.ConfigurationUpdater)1 DefaultConfigurationUpdater (com.mesosphere.sdk.config.DefaultConfigurationUpdater)1 ConfigValidationError (com.mesosphere.sdk.config.validate.ConfigValidationError)1 ConfigValidator (com.mesosphere.sdk.config.validate.ConfigValidator)1 AndRule (com.mesosphere.sdk.offer.evaluate.placement.AndRule)1 IsLocalRegionRule (com.mesosphere.sdk.offer.evaluate.placement.IsLocalRegionRule)1 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)1