Search in sources :

Example 1 with Plan

use of com.mesosphere.sdk.scheduler.plan.Plan 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 Plan

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

the class SchedulerBuilderTest method testDeployPlanOverriddenDuringUpdate.

@Test
public void testDeployPlanOverriddenDuringUpdate() throws Exception {
    Persister persister = new MemPersister();
    SchedulerBuilder builder = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, persister);
    Collection<Plan> plans = builder.selectDeployPlan(getDeployUpdatePlans(), true);
    Assert.assertEquals(1, plans.size());
    Plan deployPlan = plans.stream().filter(plan -> plan.isDeployPlan()).findFirst().get();
    Assert.assertEquals(1, deployPlan.getChildren().size());
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) Plan(com.mesosphere.sdk.scheduler.plan.Plan) DefaultPlan(com.mesosphere.sdk.scheduler.plan.DefaultPlan) Test(org.junit.Test)

Example 3 with Plan

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

the class SchedulerBuilderTest method testDeployPlanPreservedDuringInstall.

@Test
public void testDeployPlanPreservedDuringInstall() throws Exception {
    Persister persister = new MemPersister();
    SchedulerBuilder builder = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, persister);
    Collection<Plan> plans = builder.selectDeployPlan(getDeployUpdatePlans(), false);
    Assert.assertEquals(2, plans.size());
    Plan deployPlan = plans.stream().filter(plan -> plan.isDeployPlan()).findFirst().get();
    Assert.assertEquals(2, deployPlan.getChildren().size());
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) Plan(com.mesosphere.sdk.scheduler.plan.Plan) DefaultPlan(com.mesosphere.sdk.scheduler.plan.DefaultPlan) Test(org.junit.Test)

Example 4 with Plan

use of com.mesosphere.sdk.scheduler.plan.Plan 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)

Example 5 with Plan

use of com.mesosphere.sdk.scheduler.plan.Plan 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)

Aggregations

Plan (com.mesosphere.sdk.scheduler.plan.Plan)9 Phase (com.mesosphere.sdk.scheduler.plan.Phase)6 Persister (com.mesosphere.sdk.storage.Persister)4 DefaultPlan (com.mesosphere.sdk.scheduler.plan.DefaultPlan)3 MemPersister (com.mesosphere.sdk.storage.MemPersister)3 Test (org.junit.Test)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)2 SchedulerDriver (org.apache.mesos.SchedulerDriver)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 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 Status (com.mesosphere.sdk.scheduler.plan.Status)1 Step (com.mesosphere.sdk.scheduler.plan.Step)1 SerialStrategy (com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy)1 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)1 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)1 RawPlan (com.mesosphere.sdk.specification.yaml.RawPlan)1 FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)1