use of com.mesosphere.sdk.scheduler.plan.Phase 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.scheduler.plan.Phase in project dcos-commons by mesosphere.
the class CassandraRecoveryPlanOverriderTest method replaceNonSeed.
@Test
public void replaceNonSeed() throws Exception {
int nonSeedIndex = 2;
String taskName = "node-" + nonSeedIndex + "-server";
StateStoreUtils.storeTaskStatusAsProperty(stateStore, taskName, getFailedTaskStatus(taskName));
PodInstanceRequirement podInstanceRequirement = getReplacePodInstanceRequirement(nonSeedIndex);
Optional<Phase> phase = planOverrider.override(podInstanceRequirement);
Assert.assertTrue(phase.isPresent());
Assert.assertEquals(1, phase.get().getChildren().size());
Assert.assertEquals(RecoveryType.PERMANENT, phase.get().getChildren().get(0).getPodInstanceRequirement().get().getRecoveryType());
}
use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.
the class CassandraRecoveryPlanOverriderTest method ovverrideNoOp.
@Test
public void ovverrideNoOp() throws Exception {
PodInstanceRequirement podInstanceRequirement = getRestartPodInstanceRequirement(0);
Optional<Phase> phase = planOverrider.override(podInstanceRequirement);
Assert.assertFalse(phase.isPresent());
}
use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.
the class PhaseInfo method forPhase.
public static PhaseInfo forPhase(final Phase phase) {
// Calculate the status of the phase based on the steps, THEN generate the StepInfos for those steps.
// This ordering is a workaround for potential inconsistency when step statuses change while we're rendering the
// plan. By fetching step statuses after the phase status, inconsistencies should typically appear as e.g. a
// phase that's IN_PROGRESS when the steps are COMPLETE. If we did the phase status last, then we'd risk getting
// the opposite of that, which is less intuitive to an end user.
// phase status first ...
Status phaseStatus = phase.getStatus();
List<StepInfo> stepInfos = // ... then steps
phase.getChildren().stream().map(step -> StepInfo.forStep(step)).collect(Collectors.toList());
return new PhaseInfo(phase.getId().toString(), phase.getName(), stepInfos, phase.getStrategy().getName(), phaseStatus);
}
use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.
the class PlanInfo method forPlan.
public static PlanInfo forPlan(final Plan plan) {
// Calculate the status of the plan based on the phases, THEN generate the PhaseInfos for those phases.
// This ordering is a workaround for potential inconsistency when step statuses change while we're rendering the
// plan. By fetching phase statuses after the plan status, inconsistencies should typically appear as e.g. a
// plan that's IN_PROGRESS when the steps or phases are COMPLETE. If we did the plan status last, then we'd risk
// getting the opposite of that, which is less intuitive to an end user.
// plan status first ...
Status planStatus = plan.getStatus();
List<PhaseInfo> phaseInfos = // ... then phases
plan.getChildren().stream().map(phase -> PhaseInfo.forPhase(phase)).collect(Collectors.toList());
return new PlanInfo(phaseInfos, plan.getStrategy().getName(), plan.getErrors(), planStatus);
}
Aggregations