Search in sources :

Example 16 with ServiceSpec

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

the class SchedulerBuilderTest method testRegionAwarenessEnabledWithoutSchedulerRegion.

@Test
public void testRegionAwarenessEnabledWithoutSchedulerRegion() throws PersisterException {
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).withSingleRegionConstraint().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 17 with ServiceSpec

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

the class PodSpecsCannotShrinkTest method testAllowedPodRemoveIsValid.

@Test
public void testAllowedPodRemoveIsValid() throws InvalidRequirementException {
    when(mockPodSpecB1.getAllowDecommission()).thenReturn(true);
    ServiceSpec serviceSpec1 = getServiceSpec(mockPodSpecA1, mockPodSpecB1);
    ServiceSpec serviceSpec2 = getServiceSpec("svc2", mockPodSpecA1);
    Assert.assertEquals(0, VALIDATOR.validate(Optional.of(serviceSpec1), serviceSpec2).size());
    Assert.assertEquals(0, VALIDATOR.validate(Optional.of(serviceSpec2), serviceSpec1).size());
    Assert.assertEquals(0, VALIDATOR.validate(Optional.of(serviceSpec1), serviceSpec1).size());
    Assert.assertEquals(0, VALIDATOR.validate(Optional.of(serviceSpec2), serviceSpec2).size());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 18 with ServiceSpec

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

the class ConfigurationUpdaterTest method testPodsUsersUnsetInPreviousServiceSpecButSetToRootInNewServiceSpec.

@Test
public void testPodsUsersUnsetInPreviousServiceSpecButSetToRootInNewServiceSpec() throws ConfigStoreException {
    final ConfigurationUpdater<ServiceSpec> configurationUpdater = new DefaultConfigurationUpdater(mockStateStore, mockConfigStore, DefaultServiceSpec.getComparatorInstance(), DefaultConfigValidators.getValidators(SchedulerConfigTestUtils.getTestSchedulerConfig()));
    when(mockConfigStore.getTargetConfig()).thenReturn(TARGET_ID);
    DefaultServiceSpec.Builder serviceSpecWithUser = DefaultServiceSpec.newBuilder(ORIGINAL_SERVICE_SPECIFICATION).user(DcosConstants.DEFAULT_SERVICE_USER);
    List<PodSpec> podsWithoutUsers = new ArrayList<>();
    for (PodSpec podSpec : ORIGINAL_SERVICE_SPECIFICATION.getPods()) {
        podsWithoutUsers.add(DefaultPodSpec.newBuilder(podSpec).user(null).build());
    }
    serviceSpecWithUser.pods(podsWithoutUsers);
    when(mockConfigStore.fetch(TARGET_ID)).thenReturn(serviceSpecWithUser.build());
    // set the pod users for the new service spec to "root" to match the default of the non-set user from
    // previous service spec
    List<PodSpec> podsWithUsers = new ArrayList<>();
    for (PodSpec podSpec : ORIGINAL_SERVICE_SPECIFICATION_WITH_USER.getPods()) {
        podsWithUsers.add(DefaultPodSpec.newBuilder(podSpec).user(DcosConstants.DEFAULT_SERVICE_USER).build());
    }
    ServiceSpec SERVICE_SPECIFICATION_WITH_USER = DefaultServiceSpec.newBuilder(ORIGINAL_SERVICE_SPECIFICATION_WITH_USER).pods(podsWithUsers).build();
    ConfigurationUpdater.UpdateResult result = configurationUpdater.updateConfiguration(SERVICE_SPECIFICATION_WITH_USER);
    Assert.assertEquals(TARGET_ID, result.getTargetId());
    Assert.assertEquals(0, result.getErrors().size());
}
Also used : DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) Test(org.junit.Test)

Example 19 with ServiceSpec

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

the class PreReservationCannotChangeTest method testSwappedPodsDoesPassesValidation.

@Test
public void testSwappedPodsDoesPassesValidation() {
    Optional<ServiceSpec> serviceSpec1 = Optional.of(DefaultServiceSpec.newBuilder().name("svc1").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec1, mockPodSpec2)).build());
    final ServiceSpec serviceSpec2 = DefaultServiceSpec.newBuilder().name("svc1").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec2, mockPodSpec1)).build();
    assertThat(VALIDATOR.validate(serviceSpec1, serviceSpec2), is(empty()));
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 20 with ServiceSpec

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

the class PreReservationCannotChangeTest method testSecondPodChangesReservedRoleFailsValidation.

@Test
public void testSecondPodChangesReservedRoleFailsValidation() {
    Optional<ServiceSpec> serviceSpec1 = Optional.of(DefaultServiceSpec.newBuilder().name("svc1").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec1, mockPodSpec2)).build());
    final ServiceSpec serviceSpec2 = DefaultServiceSpec.newBuilder().name("svc1").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec1, mockPodSpec2WithDifferentRole)).build();
    assertThat(VALIDATOR.validate(serviceSpec1, serviceSpec2), hasSize(1));
}
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