Search in sources :

Example 21 with ServiceSpec

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

the class PodSpecsCannotShrinkTest method testReducingPodCountIsInvalid.

@Test
public void testReducingPodCountIsInvalid() {
    final ServiceSpec serviceWithManyPods = getServiceSpec(mockPodSpecA1WithHigherCount);
    final ServiceSpec serviceWithFewPods = getServiceSpec(mockPodSpecA1);
    assertThat(VALIDATOR.validate(Optional.of(serviceWithManyPods), serviceWithFewPods), hasSize(1));
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 22 with ServiceSpec

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

the class PodSpecsCannotShrinkTest method testAllowedPodRenameIsValid.

@Test
public void testAllowedPodRenameIsValid() throws InvalidRequirementException {
    when(mockPodSpecB1.getAllowDecommission()).thenReturn(true);
    ServiceSpec serviceSpec1 = getServiceSpec(mockPodSpecA1, mockPodSpecB1);
    ServiceSpec serviceSpec2 = getServiceSpec("svc2", mockPodSpecA1, mockPodSpecB2);
    Assert.assertEquals(0, VALIDATOR.validate(Optional.of(serviceSpec1), serviceSpec2).size());
    // Still fails in the other direction since B2 doesn't have the decommission bit set:
    Assert.assertEquals(1, 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 23 with ServiceSpec

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

the class PodSpecsCannotShrinkTest method testReducingBothAllowedPodCountIsValid.

@Test
public void testReducingBothAllowedPodCountIsValid() {
    when(mockPodSpecA1.getAllowDecommission()).thenReturn(true);
    when(mockPodSpecA1WithHigherCount.getAllowDecommission()).thenReturn(true);
    final ServiceSpec serviceWithManyPods = getServiceSpec(mockPodSpecA1WithHigherCount);
    final ServiceSpec serviceWithFewPods = getServiceSpec(mockPodSpecA1);
    assertThat(VALIDATOR.validate(Optional.of(serviceWithManyPods), serviceWithFewPods), hasSize(0));
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 24 with ServiceSpec

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

the class PodSpecsCannotShrinkTest method testPodRenameIsInvalid.

@Test
public void testPodRenameIsInvalid() throws InvalidRequirementException {
    ServiceSpec serviceSpec1 = getServiceSpec(mockPodSpecA1, mockPodSpecB1);
    ServiceSpec serviceSpec2 = getServiceSpec("svc2", mockPodSpecA1, mockPodSpecB2);
    Assert.assertEquals(1, VALIDATOR.validate(Optional.of(serviceSpec1), serviceSpec2).size());
    Assert.assertEquals(1, 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 25 with ServiceSpec

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

the class PlacementRuleIsValid method validate.

@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
    List<PodSpec> podSpecs = newConfig.getPods().stream().filter(podSpec -> podSpec.getPlacementRule().isPresent()).collect(Collectors.toList());
    List<ConfigValidationError> errors = new ArrayList<>();
    for (final PodSpec podSpec : podSpecs) {
        PlacementRule placementRule = podSpec.getPlacementRule().get();
        if (!isValid(placementRule)) {
            String errMsg = String.format("The PlacementRule for PodSpec '%s' had invalid constraints", podSpec.getType());
            errors.add(ConfigValidationError.valueError("PlacementRule", placementRule.toString(), errMsg));
        }
    }
    return errors;
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) List(java.util.List) OrRule(com.mesosphere.sdk.offer.evaluate.placement.OrRule) InvalidPlacementRule(com.mesosphere.sdk.offer.evaluate.placement.InvalidPlacementRule) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) Collection(java.util.Collection) Optional(java.util.Optional) Collectors(java.util.stream.Collectors) AndRule(com.mesosphere.sdk.offer.evaluate.placement.AndRule) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) ArrayList(java.util.ArrayList) PodSpec(com.mesosphere.sdk.specification.PodSpec) InvalidPlacementRule(com.mesosphere.sdk.offer.evaluate.placement.InvalidPlacementRule) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) ArrayList(java.util.ArrayList)

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