Search in sources :

Example 1 with RawPlan

use of com.mesosphere.sdk.specification.yaml.RawPlan in project dcos-commons by mesosphere.

the class DefaultPlanGeneratorTest method testCustomPhases.

@Test
public void testCustomPhases() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("custom-phases.yml").getFile());
    RawServiceSpec rawServiceSpec = RawServiceSpec.newBuilder(file).build();
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(rawServiceSpec, SCHEDULER_CONFIG, file.getParentFile()).build();
    Persister persister = new MemPersister();
    stateStore = new StateStore(persister);
    configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
    Assert.assertNotNull(serviceSpec);
    DefaultPlanGenerator generator = new DefaultPlanGenerator(configStore, stateStore);
    for (Map.Entry<String, RawPlan> entry : rawServiceSpec.getPlans().entrySet()) {
        Plan plan = generator.generate(entry.getValue(), entry.getKey(), serviceSpec.getPods());
        Assert.assertNotNull(plan);
        Assert.assertEquals(6, plan.getChildren().size());
        Phase serverPhase = plan.getChildren().get(0);
        Phase oncePhase = plan.getChildren().get(1);
        Phase interleavePhase = plan.getChildren().get(2);
        Phase fullCustomPhase = plan.getChildren().get(3);
        Phase partialCustomPhase = plan.getChildren().get(4);
        Phase omitStepPhase = plan.getChildren().get(5);
        validatePhase(serverPhase, Arrays.asList(Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("server")));
        validatePhase(oncePhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("once"), Arrays.asList("once")));
        validatePhase(interleavePhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server")));
        validatePhase(fullCustomPhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server")));
        validatePhase(partialCustomPhase, Arrays.asList(Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("once")));
        validatePhase(omitStepPhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server")));
        Assert.assertEquals("hello-1:[once]", omitStepPhase.getChildren().get(0).getName());
        Assert.assertEquals("hello-1:[server]", omitStepPhase.getChildren().get(1).getName());
    }
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) MemPersister(com.mesosphere.sdk.storage.MemPersister) RawPlan(com.mesosphere.sdk.specification.yaml.RawPlan) StateStore(com.mesosphere.sdk.state.StateStore) RawPlan(com.mesosphere.sdk.specification.yaml.RawPlan) Plan(com.mesosphere.sdk.scheduler.plan.Plan) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) File(java.io.File) Map(java.util.Map)

Example 2 with RawPlan

use of com.mesosphere.sdk.specification.yaml.RawPlan 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)

Aggregations

RawPlan (com.mesosphere.sdk.specification.yaml.RawPlan)2 DecommissionPlanFactory (com.mesosphere.sdk.scheduler.decommission.DecommissionPlanFactory)1 Phase (com.mesosphere.sdk.scheduler.plan.Phase)1 Plan (com.mesosphere.sdk.scheduler.plan.Plan)1 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)1 ConfigStoreException (com.mesosphere.sdk.state.ConfigStoreException)1 StateStore (com.mesosphere.sdk.state.StateStore)1 MemPersister (com.mesosphere.sdk.storage.MemPersister)1 Persister (com.mesosphere.sdk.storage.Persister)1 File (java.io.File)1 Map (java.util.Map)1