Search in sources :

Example 11 with StateStore

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

the class DefaultStepFactoryTest method getPodInstanceWithGoalState.

private PodInstance getPodInstanceWithGoalState(GoalState goalState) throws Exception {
    TaskSpec taskSpec = TestPodFactory.getTaskSpecWithGoalState(TestConstants.TASK_NAME, TestConstants.RESOURCE_SET_ID, goalState);
    PodSpec podSpec = DefaultPodSpec.newBuilder(SCHEDULER_CONFIG.getExecutorURI()).type(TestConstants.POD_TYPE).count(1).tasks(Arrays.asList(taskSpec)).build();
    ServiceSpec serviceSpec = DefaultServiceSpec.newBuilder().name(TestConstants.SERVICE_NAME).role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).zookeeperConnection("foo.bar.com").pods(Arrays.asList(podSpec)).build();
    Persister persister = new MemPersister();
    stateStore = new StateStore(persister);
    configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
    UUID configId = configStore.store(serviceSpec);
    configStore.setTargetConfig(configId);
    stepFactory = new DefaultStepFactory(configStore, stateStore);
    return new DefaultPodInstance(podSpec, 0);
}
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) UUID(java.util.UUID)

Example 12 with StateStore

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

the class Expect method knownTasks.

/**
 * Verifies that the scheduler's list of tasks in the state store matches the provided set.
 */
public static Expect knownTasks(Persister persisterWithTasks, String... taskNames) {
    return new Expect() {

        @Override
        public void expect(ClusterState state, SchedulerDriver mockDriver) {
            Set<String> expectedTasks = new HashSet<>(Arrays.asList(taskNames));
            Set<String> tasks = new StateStore(persisterWithTasks).fetchTasks().stream().map(Protos.TaskInfo::getName).collect(Collectors.toSet());
            Assert.assertEquals(expectedTasks, tasks);
        }

        @Override
        public String getDescription() {
            return String.format("State store task names: %s", new StateStore(persisterWithTasks).fetchTasks().stream().map(Protos.TaskInfo::getName).collect(Collectors.toList()));
        }
    };
}
Also used : Protos(org.apache.mesos.Protos) StateStore(com.mesosphere.sdk.state.StateStore) SchedulerDriver(org.apache.mesos.SchedulerDriver)

Example 13 with StateStore

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

the class Expect method reconciledExplicitly.

/**
 * Verifies that an explicit task reconciliation for the task statuses in the provided persister was invoked.
 */
public static Expect reconciledExplicitly(Persister persisterWithStatuses) {
    // Use a custom comparator for sorting: Protos don't implement Comparable
    final Comparator<Protos.TaskStatus> statusComparator = new Comparator<Protos.TaskStatus>() {

        @Override
        public int compare(TaskStatus o1, TaskStatus o2) {
            return o1.getTaskId().getValue().compareTo(o2.getTaskId().getValue());
        }
    };
    return new Expect() {

        // Use this form instead of using ArgumentCaptor.forClass() to avoid problems with typecasting generics:
        @Captor
        private ArgumentCaptor<Collection<Protos.TaskStatus>> statusCaptor;

        @Override
        public void expect(ClusterState state, SchedulerDriver mockDriver) {
            MockitoAnnotations.initMocks(this);
            verify(mockDriver, atLeastOnce()).reconcileTasks(statusCaptor.capture());
            Set<Protos.TaskStatus> expected = new TreeSet<>(statusComparator);
            expected.addAll(new StateStore(persisterWithStatuses).fetchStatuses());
            // We do this arg ourselves, since the in-mock comparison never matches.
            for (Collection<Protos.TaskStatus> reconcileArgs : statusCaptor.getAllValues()) {
                Set<Protos.TaskStatus> got = new TreeSet<>(statusComparator);
                got.addAll(reconcileArgs);
                if (expected.equals(got)) {
                    // Found matching call
                    return;
                }
            }
            Assert.fail(String.format("Expected a task reconcile with arguments: %s, but actual calls were: %s", expected, statusCaptor.getAllValues()));
        }

        @Override
        public String getDescription() {
            return String.format("Explicit task reconcile call for statuses: %s", new StateStore(persisterWithStatuses).fetchStatuses().stream().map(status -> String.format("%s=%s", status.getTaskId().getValue(), status.getState())).collect(Collectors.toList()));
        }
    };
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) Protos(org.apache.mesos.Protos) StateStore(com.mesosphere.sdk.state.StateStore) TaskStatus(org.apache.mesos.Protos.TaskStatus) SchedulerDriver(org.apache.mesos.SchedulerDriver)

Example 14 with StateStore

use of com.mesosphere.sdk.state.StateStore 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)

Example 15 with StateStore

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

the class UninstallSchedulerTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    Persister persister = new MemPersister();
    frameworkStore = new FrameworkStore(persister);
    frameworkStore.storeFrameworkId(TestConstants.FRAMEWORK_ID);
    stateStore = new StateStore(persister);
    stateStore.storeTasks(Collections.singletonList(TASK_A));
    // Have the mock plan customizer default to returning the plan unchanged.
    when(mockPlanCustomizer.updateUninstallPlan(any())).thenAnswer(invocation -> invocation.getArguments()[0]);
}
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) Before(org.junit.Before)

Aggregations

StateStore (com.mesosphere.sdk.state.StateStore)18 MemPersister (com.mesosphere.sdk.storage.MemPersister)12 Persister (com.mesosphere.sdk.storage.Persister)10 FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)6 Before (org.junit.Before)6 UUID (java.util.UUID)5 Protos (org.apache.mesos.Protos)5 OfferOutcomeTracker (com.mesosphere.sdk.offer.history.OfferOutcomeTracker)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)3 Test (org.junit.Test)3 OfferAccepter (com.mesosphere.sdk.offer.OfferAccepter)2 OfferEvaluator (com.mesosphere.sdk.offer.evaluate.OfferEvaluator)2 RecoveryPlanOverrider (com.mesosphere.sdk.scheduler.recovery.RecoveryPlanOverrider)2 RecoveryStep (com.mesosphere.sdk.scheduler.recovery.RecoveryStep)2 UnconstrainedLaunchConstrainer (com.mesosphere.sdk.scheduler.recovery.constrain.UnconstrainedLaunchConstrainer)2 ConfigStore (com.mesosphere.sdk.state.ConfigStore)2 File (java.io.File)2 SchedulerDriver (org.apache.mesos.SchedulerDriver)2 CreateOfferRecommendation (com.mesosphere.sdk.offer.CreateOfferRecommendation)1 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)1