Search in sources :

Example 1 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class DefaultPlanGeneratorTest method testCustomPhases.

@Test
public void testCustomPhases() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("custom-phases.yml").getFile());
    RawServiceSpec rawServiceSpec = RawServiceSpec.newBuilder(file).build();
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(rawServiceSpec, SCHEDULER_CONFIG, file.getParentFile()).build();
    Persister persister = new MemPersister();
    stateStore = new StateStore(persister);
    configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
    Assert.assertNotNull(serviceSpec);
    DefaultPlanGenerator generator = new DefaultPlanGenerator(configStore, stateStore);
    for (Map.Entry<String, RawPlan> entry : rawServiceSpec.getPlans().entrySet()) {
        Plan plan = generator.generate(entry.getValue(), entry.getKey(), serviceSpec.getPods());
        Assert.assertNotNull(plan);
        Assert.assertEquals(6, plan.getChildren().size());
        Phase serverPhase = plan.getChildren().get(0);
        Phase oncePhase = plan.getChildren().get(1);
        Phase interleavePhase = plan.getChildren().get(2);
        Phase fullCustomPhase = plan.getChildren().get(3);
        Phase partialCustomPhase = plan.getChildren().get(4);
        Phase omitStepPhase = plan.getChildren().get(5);
        validatePhase(serverPhase, Arrays.asList(Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("server")));
        validatePhase(oncePhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("once"), Arrays.asList("once")));
        validatePhase(interleavePhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server")));
        validatePhase(fullCustomPhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server")));
        validatePhase(partialCustomPhase, Arrays.asList(Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("once")));
        validatePhase(omitStepPhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server")));
        Assert.assertEquals("hello-1:[once]", omitStepPhase.getChildren().get(0).getName());
        Assert.assertEquals("hello-1:[server]", omitStepPhase.getChildren().get(1).getName());
    }
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) MemPersister(com.mesosphere.sdk.storage.MemPersister) RawPlan(com.mesosphere.sdk.specification.yaml.RawPlan) StateStore(com.mesosphere.sdk.state.StateStore) RawPlan(com.mesosphere.sdk.specification.yaml.RawPlan) Plan(com.mesosphere.sdk.scheduler.plan.Plan) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) File(java.io.File) Map(java.util.Map)

Example 2 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class DefaultServiceSpecTest method invalidPlanSteps.

@Test(expected = IllegalStateException.class)
public void invalidPlanSteps() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("invalid-plan-steps.yml").getFile());
    RawServiceSpec rawSpec = RawServiceSpec.newBuilder(file).build();
    DefaultScheduler.newBuilder(DefaultServiceSpec.newGenerator(rawSpec, SCHEDULER_CONFIG, file.getParentFile()).build(), SCHEDULER_CONFIG, new MemPersister()).setPlansFrom(rawSpec).build();
}
Also used : RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) MemPersister(com.mesosphere.sdk.storage.MemPersister) File(java.io.File) Test(org.junit.Test)

Example 3 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method testRegionAwarenessDisabledWithSchedulerRegion.

@Test
public void testRegionAwarenessDisabledWithSchedulerRegion() throws PersisterException {
    when(mockSchedulerConfig.getSchedulerRegion()).thenReturn(Optional.of(TestConstants.REMOTE_REGION));
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
    Optional<PlacementRule> rule = updatedServiceSpec.getPods().get(0).getPlacementRule();
    // Pod updated with local region rule:
    Assert.assertTrue(rule.isPresent());
    Assert.assertTrue(rule.get() instanceof IsLocalRegionRule);
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 4 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method testDomainsNotSupportedByCluster.

@Test
public void testDomainsNotSupportedByCluster() throws Exception {
    when(mockCapabilities.supportsDomains()).thenReturn(false);
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
    // No rule changes:
    Assert.assertFalse(updatedServiceSpec.getPods().get(0).getPlacementRule().isPresent());
    // Not hit since unsupported by cluster:
    verify(mockCapabilities, atLeastOnce()).supportsDomains();
    verify(mockSchedulerConfig, never()).isRegionAwarenessEnabled();
    verify(mockSchedulerConfig, never()).getSchedulerRegion();
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 5 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method testRegionAwarenessDisabledWithoutSchedulerRegion.

@Test
public void testRegionAwarenessDisabledWithoutSchedulerRegion() throws PersisterException {
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
    Optional<PlacementRule> rule = updatedServiceSpec.getPods().get(0).getPlacementRule();
    // Pod updated with local region rule:
    Assert.assertTrue(rule.isPresent());
    Assert.assertTrue(rule.get() instanceof IsLocalRegionRule);
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Aggregations

MemPersister (com.mesosphere.sdk.storage.MemPersister)31 Persister (com.mesosphere.sdk.storage.Persister)14 Test (org.junit.Test)13 StateStore (com.mesosphere.sdk.state.StateStore)12 Before (org.junit.Before)9 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)7 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)7 FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)5 UUID (java.util.UUID)5 File (java.io.File)4 OfferOutcomeTracker (com.mesosphere.sdk.offer.history.OfferOutcomeTracker)3 Plan (com.mesosphere.sdk.scheduler.plan.Plan)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)3 OfferAccepter (com.mesosphere.sdk.offer.OfferAccepter)2 OfferEvaluator (com.mesosphere.sdk.offer.evaluate.OfferEvaluator)2 DefaultPlan (com.mesosphere.sdk.scheduler.plan.DefaultPlan)2 ConfigStore (com.mesosphere.sdk.state.ConfigStore)2 StringConfiguration (com.mesosphere.sdk.config.StringConfiguration)1 Capabilities (com.mesosphere.sdk.dcos.Capabilities)1 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)1