Search in sources :

Example 11 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class UserCannotChangeTest method testMultiplePodsOldSettingNoUserNewSettingOneUser.

@Test
public void testMultiplePodsOldSettingNoUserNewSettingOneUser() {
    when(mockOldPodSpec.getUser()).thenReturn(Optional.empty());
    when(mockOldPodSpec2.getUser()).thenReturn(Optional.empty());
    when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_B + "-1"));
    when(mockNewPodSpec2.getUser()).thenReturn(Optional.of(USER_B + "-1"));
    ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec, mockOldPodSpec2)).build();
    ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec, mockNewPodSpec2)).build();
    Assert.assertEquals(3, 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 12 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec 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 13 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec 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 14 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec 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)

Example 15 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method testRegionAwarenessEnabledEnvWithSchedulerRegion.

@Test
public void testRegionAwarenessEnabledEnvWithSchedulerRegion() throws PersisterException {
    when(mockSchedulerConfig.getSchedulerRegion()).thenReturn(Optional.of(TestConstants.REMOTE_REGION));
    when(mockSchedulerConfig.isRegionAwarenessEnabled()).thenReturn(true);
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
    Optional<PlacementRule> rule = updatedServiceSpec.getPods().get(0).getPlacementRule();
    // Pod updated with exact region rule:
    Assert.assertTrue(rule.isPresent());
    Assert.assertTrue(rule.get() instanceof RegionRule);
    verify(mockSchedulerConfig).isRegionAwarenessEnabled();
}
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

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