Search in sources :

Example 6 with Phase

use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.

the class SchedulerRunner method run.

/**
 * Runs the scheduler. Don't forget to call this!
 * This should never exit, instead the entire process will be terminated internally.
 */
@Override
public void run() {
    SchedulerConfig schedulerConfig = schedulerBuilder.getSchedulerConfig();
    ServiceSpec serviceSpec = schedulerBuilder.getServiceSpec();
    Persister persister = schedulerBuilder.getPersister();
    // Get a curator lock, then check the schema version:
    CuratorLocker.lock(serviceSpec.getName(), serviceSpec.getZookeeperConnection());
    // Check and/or initialize schema version before doing any other storage access:
    new SchemaVersionStore(persister).check(SUPPORTED_SCHEMA_VERSION_SINGLE_SERVICE);
    Metrics.configureStatsd(schedulerConfig);
    AbstractScheduler scheduler = schedulerBuilder.build();
    scheduler.start();
    Optional<Scheduler> mesosScheduler = scheduler.getMesosScheduler();
    if (mesosScheduler.isPresent()) {
        ApiServer apiServer = new ApiServer(schedulerConfig, scheduler.getResources());
        apiServer.start(new AbstractLifeCycle.AbstractLifeCycleListener() {

            @Override
            public void lifeCycleStarted(LifeCycle event) {
                scheduler.markApiServerStarted();
            }
        });
        runScheduler(new FrameworkRunner(FrameworkConfig.fromServiceSpec(serviceSpec), PodSpecsCannotUseUnsupportedFeatures.serviceRequestsGpuResources(serviceSpec), schedulerBuilder.isRegionAwarenessEnabled()).getFrameworkInfo(new FrameworkStore(schedulerBuilder.getPersister()).fetchFrameworkId()), mesosScheduler.get(), schedulerBuilder.getServiceSpec(), schedulerBuilder.getSchedulerConfig());
    } else {
        /**
         * If no MesosScheduler is provided this scheduler has been deregistered and should report itself healthy
         * and provide an empty COMPLETE deploy plan so it may complete its UNINSTALL.
         *
         * See {@link UninstallScheduler#getMesosScheduler()}.
         */
        Plan emptyDeployPlan = new Plan() {

            @Override
            public List<Phase> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public Strategy<Phase> getStrategy() {
                return new SerialStrategy<>();
            }

            @Override
            public UUID getId() {
                return UUID.randomUUID();
            }

            @Override
            public String getName() {
                return Constants.DEPLOY_PLAN_NAME;
            }

            @Override
            public List<String> getErrors() {
                return Collections.emptyList();
            }
        };
        try {
            PersisterUtils.clearAllData(persister);
        } catch (PersisterException e) {
            // Best effort.
            LOGGER.error("Failed to clear all data", e);
        }
        ApiServer apiServer = new ApiServer(schedulerConfig, Arrays.asList(new PlansResource(Collections.singletonList(DefaultPlanManager.createProceeding(emptyDeployPlan))), new HealthResource(Collections.emptyList())));
        apiServer.start(new AbstractLifeCycle.AbstractLifeCycleListener() {

            @Override
            public void lifeCycleStarted(LifeCycle event) {
                LOGGER.info("Started trivially healthy API server.");
            }
        });
    }
}
Also used : LifeCycle(org.eclipse.jetty.util.component.LifeCycle) AbstractLifeCycle(org.eclipse.jetty.util.component.AbstractLifeCycle) SchemaVersionStore(com.mesosphere.sdk.state.SchemaVersionStore) Phase(com.mesosphere.sdk.scheduler.plan.Phase) ApiServer(com.mesosphere.sdk.framework.ApiServer) Scheduler(org.apache.mesos.Scheduler) FrameworkRunner(com.mesosphere.sdk.framework.FrameworkRunner) PlansResource(com.mesosphere.sdk.http.endpoints.PlansResource) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) PersisterException(com.mesosphere.sdk.storage.PersisterException) Plan(com.mesosphere.sdk.scheduler.plan.Plan) SerialStrategy(com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy) Persister(com.mesosphere.sdk.storage.Persister) AbstractLifeCycle(org.eclipse.jetty.util.component.AbstractLifeCycle) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) HealthResource(com.mesosphere.sdk.http.endpoints.HealthResource)

Example 7 with Phase

use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.

the class Expect method stepStatus.

/**
 * Verifies that the indicated plan.phase.step has the expected status.
 */
public static Expect stepStatus(String planName, String phaseName, String stepName, Status expectedStatus) {
    return new Expect() {

        @Override
        public void expect(ClusterState state, SchedulerDriver mockDriver) {
            Plan recoveryPlan = state.getPlans().stream().filter(plan -> plan.getName().equals(planName)).findAny().get();
            Phase phase = recoveryPlan.getChildren().stream().filter(p -> p.getName().equals(phaseName)).findAny().get();
            Step step = phase.getChildren().stream().filter(s -> s.getName().equals(stepName)).findAny().get();
            Assert.assertEquals(expectedStatus, step.getStatus());
        }

        @Override
        public String getDescription() {
            return String.format("For Phase: %s, Step: %s, Status is %s", phaseName, stepName, expectedStatus);
        }
    };
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) Step(com.mesosphere.sdk.scheduler.plan.Step) Plan(com.mesosphere.sdk.scheduler.plan.Plan) SchedulerDriver(org.apache.mesos.SchedulerDriver)

Example 8 with Phase

use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.

the class CassandraRecoveryPlanOverriderTest method replaceSeed.

@Test
public void replaceSeed() throws Exception {
    int nonSeedIndex = 1;
    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(3, phase.get().getChildren().size());
    Assert.assertEquals(RecoveryType.PERMANENT, phase.get().getChildren().get(0).getPodInstanceRequirement().get().getRecoveryType());
    Assert.assertEquals(RecoveryType.TRANSIENT, phase.get().getChildren().get(1).getPodInstanceRequirement().get().getRecoveryType());
    Assert.assertEquals(RecoveryType.TRANSIENT, phase.get().getChildren().get(2).getPodInstanceRequirement().get().getRecoveryType());
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 9 with Phase

use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.

the class DecommissionPlanFactoryTest method testBigPlanConstruction.

@Test
public void testBigPlanConstruction() {
    when(mockStateStore.fetchTasks()).thenReturn(tasks);
    DecommissionPlanFactory factory = new DecommissionPlanFactory(mockServiceSpec, mockStateStore);
    // any tasks with existing decommission bits but which are not to be decommissioned have had their decommission bits cleared (see list above):
    for (String taskToClear : Arrays.asList("podA-0-taskA", "podB-0-taskB")) {
        verify(mockStateStore, times(1)).storeGoalOverrideStatus(taskToClear, GoalStateOverride.Status.INACTIVE);
    }
    // any tasks to decommission that were paused or no-override are assigned with a pending decommission bit:
    for (String taskToClear : Arrays.asList("podA-2-taskA", "podB-1-taskB", "podE-0-taskA")) {
        verify(mockStateStore, times(1)).storeGoalOverrideStatus(taskToClear, GoalStateOverride.DECOMMISSIONED.newStatus(GoalStateOverride.Progress.PENDING));
    }
    Assert.assertEquals(14, factory.getResourceSteps().size());
    Assert.assertTrue(factory.getPlan().isPresent());
    Plan plan = factory.getPlan().get();
    Assert.assertEquals(6, plan.getChildren().size());
    Assert.assertEquals(Status.PENDING, plan.getStatus());
    Phase phase = plan.getChildren().get(0);
    Assert.assertEquals("podD-1", phase.getName());
    Assert.assertEquals(3, phase.getChildren().size());
    Assert.assertEquals("kill-podD-1-taskA", phase.getChildren().get(0).getName());
    Assert.assertEquals("unreserve-podD-1-taskA-resource0", phase.getChildren().get(1).getName());
    Assert.assertEquals("erase-podD-1-taskA", phase.getChildren().get(2).getName());
    phase = plan.getChildren().get(1);
    Assert.assertEquals("podD-0", phase.getName());
    Assert.assertEquals(5, phase.getChildren().size());
    Assert.assertEquals("kill-podD-0-taskA", phase.getChildren().get(0).getName());
    Assert.assertEquals("unreserve-podD-0-taskA-resource0", phase.getChildren().get(1).getName());
    Assert.assertEquals("unreserve-podD-0-taskA-resource1", phase.getChildren().get(2).getName());
    Assert.assertEquals("unreserve-podD-0-taskA-resource2", phase.getChildren().get(3).getName());
    Assert.assertEquals("erase-podD-0-taskA", phase.getChildren().get(4).getName());
    phase = plan.getChildren().get(2);
    Assert.assertEquals("podE-0", phase.getName());
    Assert.assertEquals(4, phase.getChildren().size());
    Assert.assertEquals("kill-podE-0-taskA", phase.getChildren().get(0).getName());
    Assert.assertEquals("unreserve-podE-0-taskA-resource0", phase.getChildren().get(1).getName());
    Assert.assertEquals("unreserve-podE-0-taskA-resource1", phase.getChildren().get(2).getName());
    Assert.assertEquals("erase-podE-0-taskA", phase.getChildren().get(3).getName());
    phase = plan.getChildren().get(3);
    Assert.assertEquals("podB-1", phase.getName());
    Assert.assertEquals(7, phase.getChildren().size());
    Assert.assertEquals("kill-podB-1-taskA", phase.getChildren().get(0).getName());
    Assert.assertEquals("kill-podB-1-taskB", phase.getChildren().get(1).getName());
    Assert.assertEquals("unreserve-podB-1-taskA-resource0", phase.getChildren().get(2).getName());
    Assert.assertEquals("unreserve-podB-1-taskB-resource0", phase.getChildren().get(3).getName());
    Assert.assertEquals("unreserve-podB-1-taskB-resource1", phase.getChildren().get(4).getName());
    Assert.assertEquals("erase-podB-1-taskA", phase.getChildren().get(5).getName());
    Assert.assertEquals("erase-podB-1-taskB", phase.getChildren().get(6).getName());
    phase = plan.getChildren().get(4);
    Assert.assertEquals("podA-2", phase.getName());
    Assert.assertEquals(5, phase.getChildren().size());
    Assert.assertEquals("kill-podA-2-taskA", phase.getChildren().get(0).getName());
    Assert.assertEquals("unreserve-podA-2-taskA-resource0", phase.getChildren().get(1).getName());
    Assert.assertEquals("unreserve-podA-2-taskA-resource1", phase.getChildren().get(2).getName());
    Assert.assertEquals("unreserve-podA-2-taskA-resource2", phase.getChildren().get(3).getName());
    Assert.assertEquals("erase-podA-2-taskA", phase.getChildren().get(4).getName());
    phase = plan.getChildren().get(5);
    Assert.assertEquals("podA-1", phase.getName());
    Assert.assertEquals(4, phase.getChildren().size());
    Assert.assertEquals("kill-podA-1-taskA", phase.getChildren().get(0).getName());
    Assert.assertEquals("unreserve-podA-1-taskA-resource0", phase.getChildren().get(1).getName());
    Assert.assertEquals("unreserve-podA-1-taskA-resource1", phase.getChildren().get(2).getName());
    Assert.assertEquals("erase-podA-1-taskA", phase.getChildren().get(3).getName());
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) Plan(com.mesosphere.sdk.scheduler.plan.Plan) Test(org.junit.Test)

Example 10 with Phase

use of com.mesosphere.sdk.scheduler.plan.Phase in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method getDeployUpdatePlans.

// Deploy plan has 2 phases, update plan has 1 for distinguishing which was chosen.
private static Collection<Plan> getDeployUpdatePlans() {
    Phase phase = mock(Phase.class);
    Plan deployPlan = new DefaultPlan(Constants.DEPLOY_PLAN_NAME, Arrays.asList(phase, phase));
    Assert.assertEquals(2, deployPlan.getChildren().size());
    Plan updatePlan = new DefaultPlan(Constants.UPDATE_PLAN_NAME, Arrays.asList(phase));
    Assert.assertEquals(1, updatePlan.getChildren().size());
    return Arrays.asList(deployPlan, updatePlan);
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) DefaultPlan(com.mesosphere.sdk.scheduler.plan.DefaultPlan) Plan(com.mesosphere.sdk.scheduler.plan.Plan) DefaultPlan(com.mesosphere.sdk.scheduler.plan.DefaultPlan)

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