use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class DefaultScheduler method getOfferAccepter.
private static OfferAccepter getOfferAccepter(StateStore stateStore, ServiceSpec serviceSpec, PlanCoordinator planCoordinator) {
List<OperationRecorder> recorders = new ArrayList<>();
recorders.add(new PersistentLaunchRecorder(stateStore, serviceSpec));
Optional<DecommissionPlanManager> decommissionManager = getDecomissionManager(planCoordinator);
if (decommissionManager.isPresent()) {
Collection<Step> steps = decommissionManager.get().getPlan().getChildren().stream().flatMap(phase -> phase.getChildren().stream()).collect(Collectors.toList());
recorders.add(new DecommissionRecorder(stateStore, steps));
}
return new OfferAccepter(recorders);
}
use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class StateStoreUtilsTest method newConfigStore.
private ConfigStore<ServiceSpec> newConfigStore(final Persister persister) throws Exception {
ServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(new File(StateStoreUtilsTest.class.getClassLoader().getResource("resource-set-seq.yml").getFile()), SchedulerConfigTestUtils.getTestSchedulerConfig()).build();
ConfigStore<ServiceSpec> configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
// At startup, the the service spec must be stored, and the target config must be set to the stored spec.
configStore.setTargetConfig(configStore.store(serviceSpec));
return configStore;
}
use of com.mesosphere.sdk.specification.ServiceSpec 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.specification.ServiceSpec in project dcos-commons by mesosphere.
the class UserCannotChangeTest method testSameServiceUser.
@Test
public void testSameServiceUser() {
when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_A));
ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec)).user(USER_A).build();
ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec)).user(USER_A).build();
Assert.assertEquals(0, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class UserCannotChangeTest method testMoreNewPodsThanOldPods.
@Test
public void testMoreNewPodsThanOldPods() {
when(mockOldPodSpec.getUser()).thenReturn(Optional.of(USER_A));
when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_A));
when(mockNewPodSpec2.getUser()).thenReturn(Optional.of(USER_B));
ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec)).build();
ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec, mockNewPodSpec2)).build();
Assert.assertEquals(0, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
Aggregations