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