use of com.mesosphere.sdk.offer.evaluate.placement.PlacementRule in project dcos-commons by mesosphere.
the class PlacementRuleEvaluationStageTest method testOfferPassesPlacementRule.
@Test
public void testOfferPassesPlacementRule() throws Exception {
String agent = "test-agent";
Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
PlacementRule rule = AgentRule.require(agent);
Protos.Offer offer = offerWithAgent(agent, offered);
MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
DefaultPodSpec.newBuilder(podSpec).placementRule(rule);
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
List<String> taskNames = TaskUtils.getTaskNames(podInstance);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, taskNames).build();
PlacementRuleEvaluationStage placementRuleEvaluationStage = new PlacementRuleEvaluationStage(Collections.emptyList(), rule);
EvaluationOutcome outcome = placementRuleEvaluationStage.evaluate(mesosResourcePool, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap()));
Assert.assertTrue(outcome.isPassing());
Assert.assertEquals(3, mesosResourcePool.getUnreservedMergedPool().size());
Assert.assertTrue(Math.abs(mesosResourcePool.getUnreservedMergedPool().get("cpus").getScalar().getValue() - 1.1) < 0.01);
}
use of com.mesosphere.sdk.offer.evaluate.placement.PlacementRule in project dcos-commons by mesosphere.
the class ZoneValidatorTest method getServiceSpec.
private static ServiceSpec getServiceSpec(boolean referenceZones) {
PlacementRule zoneRule = new RoundRobinByZoneRule(3);
PlacementRule hostRule = new HostnameRule(ExactMatcher.create("hostname"));
PlacementRule rule = referenceZones ? zoneRule : hostRule;
PodSpec podSpec = getPodSpec(getTaskSpec(Collections.emptyMap()));
podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(rule).build();
return getServiceSpec(podSpec);
}
use of com.mesosphere.sdk.offer.evaluate.placement.PlacementRule in project dcos-commons by mesosphere.
the class OfferEvaluatorPlacementTest method testAvoidAgentsCustomExecutor.
@Test
public void testAvoidAgentsCustomExecutor() throws Exception {
useCustomExecutor();
Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
// Don't launch
PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList(TestConstants.AGENT_ID.getValue()), Collections.emptyList()).get();
PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(offeredCpu)));
Assert.assertEquals(0, recommendations.size());
// Launch
placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList("some-random-agent"), Collections.emptyList()).get();
podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
podInstance = new DefaultPodInstance(podSpec, 0);
podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
Assert.assertEquals(2, recommendations.size());
}
use of com.mesosphere.sdk.offer.evaluate.placement.PlacementRule in project dcos-commons by mesosphere.
the class OfferEvaluatorPlacementTest method testColocateAgentsCustomExecutor.
@Test
public void testColocateAgentsCustomExecutor() throws Exception {
useCustomExecutor();
Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
// Don't launch
PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList("some-random-agent")).get();
PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(offeredCpu)));
Assert.assertEquals(0, recommendations.size());
// Launch
placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList(TestConstants.AGENT_ID.getValue())).get();
podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
podInstance = new DefaultPodInstance(podSpec, 0);
podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
Assert.assertEquals(2, recommendations.size());
}
use of com.mesosphere.sdk.offer.evaluate.placement.PlacementRule in project dcos-commons by mesosphere.
the class DomainCapabilityValidator method validate.
@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
if (Capabilities.getInstance().supportsDomains()) {
return Collections.emptyList();
}
List<PodSpec> podSpecs = newConfig.getPods().stream().filter(podSpec -> podSpec.getPlacementRule().isPresent()).collect(Collectors.toList());
List<ConfigValidationError> errors = new ArrayList<>();
for (PodSpec podSpec : podSpecs) {
PlacementRule placementRule = podSpec.getPlacementRule().get();
if (PlacementUtils.placementRuleReferencesZone(podSpec)) {
String errMsg = String.format("The PlacementRule for PodSpec '%s' may not reference Zones prior to DC/OS 1.11.", podSpec.getType());
errors.add(ConfigValidationError.valueError("PlacementRule", placementRule.toString(), errMsg));
}
if (PlacementUtils.placementRuleReferencesRegion(podSpec)) {
String errMsg = String.format("The PlacementRule for PodSpec '%s' may not reference Regions prior to DC/OS 1.11.", podSpec.getType());
errors.add(ConfigValidationError.valueError("PlacementRule", placementRule.toString(), errMsg));
}
}
return errors;
}
Aggregations