use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class UserCannotChangeTest method testMultiplePodsAllSettingDifferentUsers.
@Test
public void testMultiplePodsAllSettingDifferentUsers() {
when(mockOldPodSpec.getUser()).thenReturn(Optional.of(USER_A + "-1"));
when(mockOldPodSpec2.getUser()).thenReturn(Optional.of(USER_A + "-2"));
when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_B + "-1"));
when(mockNewPodSpec2.getUser()).thenReturn(Optional.of(USER_B + "-2"));
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());
}
use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class RegionCannotChangeTest method testNoRegion.
@Test
public void testNoRegion() {
ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec)).build();
ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec)).build();
Assert.assertEquals(0, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class RegionCannotChangeTest method testUpdateToRegionFromBlank.
@Test
public void testUpdateToRegionFromBlank() {
ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec)).build();
ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockPodSpec)).region(REGION_A).build();
Assert.assertEquals(1, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class SchedulerBuilderTest method testExistingRegionRuleUnmodified.
@Test
public void testExistingRegionRuleUnmodified() throws PersisterException {
PlacementRule remoteRegionRule = RegionRuleFactory.getInstance().require(ExactMatcher.create(TestConstants.REMOTE_REGION));
PlacementRule localRegionRule = new IsLocalRegionRule();
ServiceSpec serviceSpec = DefaultServiceSpec.newBuilder(minimalServiceSpec).addPod(DefaultPodSpec.newBuilder(getPodSpec("foo")).placementRule(remoteRegionRule).build()).addPod(DefaultPodSpec.newBuilder(getPodSpec("bar")).placementRule(localRegionRule).build()).build();
ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(serviceSpec, mockSchedulerConfig, new MemPersister()).withSingleRegionConstraint().build().getServiceSpec();
// Pod without placement rules from valid-minimal.yml had a rule added:
Assert.assertTrue(updatedServiceSpec.getPods().get(0).getPlacementRule().get() instanceof IsLocalRegionRule);
// Pods with region placement rules were left as-is:
Assert.assertSame(remoteRegionRule, updatedServiceSpec.getPods().get(1).getPlacementRule().get());
Assert.assertSame(localRegionRule, updatedServiceSpec.getPods().get(2).getPlacementRule().get());
}
use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.
the class SchedulerBuilderTest method testRegionAwarenessEnabledJavaWithSchedulerRegion.
@Test
public void testRegionAwarenessEnabledJavaWithSchedulerRegion() throws PersisterException {
when(mockSchedulerConfig.getSchedulerRegion()).thenReturn(Optional.of(TestConstants.REMOTE_REGION));
ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).withSingleRegionConstraint().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);
// Not hit since enabled directly in java:
verify(mockSchedulerConfig, never()).isRegionAwarenessEnabled();
}
Aggregations