Search in sources :

Example 1 with Phase

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

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());
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 3 with Phase

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());
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 4 with Phase

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);
}
Also used : Status(com.mesosphere.sdk.scheduler.plan.Status) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) List(java.util.List) ReflectionToStringBuilder(org.apache.commons.lang3.builder.ReflectionToStringBuilder) Phase(com.mesosphere.sdk.scheduler.plan.Phase) Status(com.mesosphere.sdk.scheduler.plan.Status) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) Step(com.mesosphere.sdk.scheduler.plan.Step) Collectors(java.util.stream.Collectors) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder)

Example 5 with Phase

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);
}
Also used : Status(com.mesosphere.sdk.scheduler.plan.Status) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) List(java.util.List) ReflectionToStringBuilder(org.apache.commons.lang3.builder.ReflectionToStringBuilder) Phase(com.mesosphere.sdk.scheduler.plan.Phase) Plan(com.mesosphere.sdk.scheduler.plan.Plan) Status(com.mesosphere.sdk.scheduler.plan.Status) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) Collectors(java.util.stream.Collectors) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder)

Aggregations

Phase (com.mesosphere.sdk.scheduler.plan.Phase)10 Plan (com.mesosphere.sdk.scheduler.plan.Plan)6 Test (org.junit.Test)4 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 Status (com.mesosphere.sdk.scheduler.plan.Status)2 Step (com.mesosphere.sdk.scheduler.plan.Step)2 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)2 Persister (com.mesosphere.sdk.storage.Persister)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 EqualsBuilder (org.apache.commons.lang3.builder.EqualsBuilder)2 HashCodeBuilder (org.apache.commons.lang3.builder.HashCodeBuilder)2 ReflectionToStringBuilder (org.apache.commons.lang3.builder.ReflectionToStringBuilder)2 ApiServer (com.mesosphere.sdk.framework.ApiServer)1 FrameworkRunner (com.mesosphere.sdk.framework.FrameworkRunner)1 HealthResource (com.mesosphere.sdk.http.endpoints.HealthResource)1 PlansResource (com.mesosphere.sdk.http.endpoints.PlansResource)1 DefaultPlan (com.mesosphere.sdk.scheduler.plan.DefaultPlan)1 SerialStrategy (com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy)1