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());
}
}
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;
}
Aggregations