Search in sources :

Example 1 with FrameworkStore

use of com.mesosphere.sdk.state.FrameworkStore in project dcos-commons by mesosphere.

the class DefaultPlanCoordinatorTest method setupTest.

@Before
public void setupTest() throws Exception {
    MockitoAnnotations.initMocks(this);
    serviceSpecification = DefaultServiceSpec.newBuilder().name(SERVICE_NAME).role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).zookeeperConnection("foo.bar.com").pods(Arrays.asList(podA)).build();
    Persister persister = new MemPersister();
    FrameworkStore frameworkStore = new FrameworkStore(persister);
    frameworkStore.storeFrameworkId(TestConstants.FRAMEWORK_ID);
    stateStore = new StateStore(persister);
    stepFactory = new DefaultStepFactory(mock(ConfigStore.class), stateStore);
    phaseFactory = new DefaultPhaseFactory(stepFactory);
    planScheduler = new DefaultPlanScheduler(new OfferAccepter(Arrays.asList()), new OfferEvaluator(frameworkStore, stateStore, new OfferOutcomeTracker(), TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Optional.empty(), true), stateStore);
    serviceSpecificationB = DefaultServiceSpec.newBuilder().name(SERVICE_NAME + "-B").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).zookeeperConnection("foo.bar.com").pods(Arrays.asList(podB)).build();
}
Also used : OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) OfferAccepter(com.mesosphere.sdk.offer.OfferAccepter) MemPersister(com.mesosphere.sdk.storage.MemPersister) StateStore(com.mesosphere.sdk.state.StateStore) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) OfferEvaluator(com.mesosphere.sdk.offer.evaluate.OfferEvaluator) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) Before(org.junit.Before)

Example 2 with FrameworkStore

use of com.mesosphere.sdk.state.FrameworkStore in project dcos-commons by mesosphere.

the class DefaultRecoveryPlanManagerTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    failureMonitor = spy(new TestingFailureMonitor());
    launchConstrainer = spy(new TestingLaunchConstrainer());
    offerAccepter = mock(OfferAccepter.class);
    Persister persister = new MemPersister();
    frameworkStore = new FrameworkStore(persister);
    stateStore = new StateStore(persister);
    File recoverySpecFile = new File(getClass().getClassLoader().getResource("recovery-plan-manager-test.yml").getPath());
    serviceSpec = DefaultServiceSpec.newGenerator(recoverySpecFile, SCHEDULER_CONFIG).build();
    configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
    UUID configTarget = configStore.store(serviceSpec);
    configStore.setTargetConfig(configTarget);
    taskInfo = TaskInfo.newBuilder(taskInfo).setLabels(new TaskLabelWriter(taskInfo).setTargetConfiguration(configTarget).setIndex(0).toProto()).setName("test-task-type-0-test-task-name").setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, "test-task-type-0-test-task-name")).build();
    taskInfos = Collections.singletonList(taskInfo);
    recoveryManager = spy(new DefaultRecoveryPlanManager(stateStore, configStore, new HashSet<>(Arrays.asList(taskInfo.getName())), launchConstrainer, failureMonitor));
    mockDeployManager = mock(PlanManager.class);
    final Plan mockDeployPlan = mock(Plan.class);
    when(mockDeployManager.getPlan()).thenReturn(mockDeployPlan);
    planScheduler = new DefaultPlanScheduler(offerAccepter, new OfferEvaluator(frameworkStore, stateStore, new OfferOutcomeTracker(), serviceSpec.getName(), configTarget, ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Optional.empty(), true), stateStore);
    planCoordinator = new DefaultPlanCoordinator(Arrays.asList(mockDeployManager, recoveryManager));
}
Also used : TestingLaunchConstrainer(com.mesosphere.sdk.scheduler.recovery.constrain.TestingLaunchConstrainer) OfferAccepter(com.mesosphere.sdk.offer.OfferAccepter) MemPersister(com.mesosphere.sdk.storage.MemPersister) StateStore(com.mesosphere.sdk.state.StateStore) OfferEvaluator(com.mesosphere.sdk.offer.evaluate.OfferEvaluator) OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) TestingFailureMonitor(com.mesosphere.sdk.scheduler.recovery.monitor.TestingFailureMonitor) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) File(java.io.File) Before(org.junit.Before)

Example 3 with FrameworkStore

use of com.mesosphere.sdk.state.FrameworkStore in project dcos-commons by mesosphere.

the class UninstallSchedulerTest method testAllButDeregisteredPlanCompletes.

@Test
public void testAllButDeregisteredPlanCompletes() throws Exception {
    // New empty state store: No framework ID is set yet, and there are no tasks, and no SchedulerDriver
    Persister persister = new MemPersister();
    UninstallScheduler uninstallScheduler = new UninstallScheduler(getServiceSpec(), new FrameworkStore(persister), new StateStore(persister), mockConfigStore, FrameworkConfig.fromServiceSpec(getServiceSpec()), SchedulerConfigTestUtils.getTestSchedulerConfig(), Optional.empty(), Optional.of(mockSecretsClient));
    // Returns a simple placeholder plan with status COMPLETE
    PlanCoordinator planCoordinator = uninstallScheduler.getPlanCoordinator();
    Plan plan = planCoordinator.getPlanManagers().stream().findFirst().get().getPlan();
    Assert.assertTrue(plan.toString(), plan.isComplete());
    Assert.assertTrue(plan.getChildren().isEmpty());
    // Doesn't want to register with Mesos:
    Assert.assertFalse(uninstallScheduler.getMesosScheduler().isPresent());
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) StateStore(com.mesosphere.sdk.state.StateStore) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) Test(org.junit.Test)

Example 4 with FrameworkStore

use of com.mesosphere.sdk.state.FrameworkStore 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 5 with FrameworkStore

use of com.mesosphere.sdk.state.FrameworkStore in project dcos-commons by mesosphere.

the class OfferEvaluatorTestBase method beforeEach.

@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    Persister persister = new MemPersister();
    frameworkStore = new FrameworkStore(persister);
    frameworkStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id").build());
    stateStore = new StateStore(persister);
    targetConfig = UUID.randomUUID();
    evaluator = new OfferEvaluator(frameworkStore, stateStore, new OfferOutcomeTracker(), TestConstants.SERVICE_NAME, targetConfig, ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SCHEDULER_CONFIG, Optional.empty(), true);
}
Also used : OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) MemPersister(com.mesosphere.sdk.storage.MemPersister) StateStore(com.mesosphere.sdk.state.StateStore) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) Before(org.junit.Before)

Aggregations

FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)7 StateStore (com.mesosphere.sdk.state.StateStore)6 Persister (com.mesosphere.sdk.storage.Persister)6 MemPersister (com.mesosphere.sdk.storage.MemPersister)5 Before (org.junit.Before)4 OfferOutcomeTracker (com.mesosphere.sdk.offer.history.OfferOutcomeTracker)3 OfferAccepter (com.mesosphere.sdk.offer.OfferAccepter)2 OfferEvaluator (com.mesosphere.sdk.offer.evaluate.OfferEvaluator)2 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)2 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 AndRule (com.mesosphere.sdk.offer.evaluate.placement.AndRule)1 IsLocalRegionRule (com.mesosphere.sdk.offer.evaluate.placement.IsLocalRegionRule)1 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)1 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)1 Phase (com.mesosphere.sdk.scheduler.plan.Phase)1 Plan (com.mesosphere.sdk.scheduler.plan.Plan)1 SerialStrategy (com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy)1