Search in sources :

Example 26 with ServiceSpec

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);
}
Also used : OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) Protos(org.apache.mesos.Protos) java.util(java.util) com.mesosphere.sdk.offer(com.mesosphere.sdk.offer) Logger(org.slf4j.Logger) DecommissionRecorder(com.mesosphere.sdk.scheduler.decommission.DecommissionRecorder) OfferEvaluator(com.mesosphere.sdk.offer.evaluate.OfferEvaluator) ArtifactQueries(com.mesosphere.sdk.http.queries.ArtifactQueries) StringPropertyDeserializer(com.mesosphere.sdk.http.types.StringPropertyDeserializer) Collectors(java.util.stream.Collectors) PersisterException(com.mesosphere.sdk.storage.PersisterException) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskKiller(com.mesosphere.sdk.framework.TaskKiller) EndpointProducer(com.mesosphere.sdk.http.types.EndpointProducer) com.mesosphere.sdk.state(com.mesosphere.sdk.state) com.mesosphere.sdk.http.endpoints(com.mesosphere.sdk.http.endpoints) com.mesosphere.sdk.scheduler.plan(com.mesosphere.sdk.scheduler.plan) Persister(com.mesosphere.sdk.storage.Persister) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FrameworkConfig(com.mesosphere.sdk.framework.FrameworkConfig) DecommissionRecorder(com.mesosphere.sdk.scheduler.decommission.DecommissionRecorder)

Example 27 with ServiceSpec

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;
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec)

Example 28 with ServiceSpec

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.");
            }
        });
    }
}
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 29 with ServiceSpec

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());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 30 with ServiceSpec

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());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Aggregations

ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)61 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)55 Test (org.junit.Test)51 MemPersister (com.mesosphere.sdk.storage.MemPersister)7 PodSpec (com.mesosphere.sdk.specification.PodSpec)6 Collectors (java.util.stream.Collectors)5 ConfigStoreException (com.mesosphere.sdk.state.ConfigStoreException)3 java.util (java.util)3 Protos (org.apache.mesos.Protos)3 Capabilities (com.mesosphere.sdk.dcos.Capabilities)2 TaskException (com.mesosphere.sdk.offer.TaskException)2 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)2 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)2 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)2 Persister (com.mesosphere.sdk.storage.Persister)2 PersisterException (com.mesosphere.sdk.storage.PersisterException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2