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