Search in sources :

Example 6 with PlacementRule

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);
}
Also used : DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Test(org.junit.Test)

Example 7 with PlacementRule

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);
}
Also used : RoundRobinByZoneRule(com.mesosphere.sdk.offer.evaluate.placement.RoundRobinByZoneRule) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) HostnameRule(com.mesosphere.sdk.offer.evaluate.placement.HostnameRule)

Example 8 with PlacementRule

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());
}
Also used : Protos(org.apache.mesos.Protos) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 9 with PlacementRule

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());
}
Also used : Protos(org.apache.mesos.Protos) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 10 with PlacementRule

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;
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) Capabilities(com.mesosphere.sdk.dcos.Capabilities) java.util(java.util) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) PlacementUtils(com.mesosphere.sdk.offer.evaluate.placement.PlacementUtils) Collectors(java.util.stream.Collectors) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)

Aggregations

PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)13 PodSpec (com.mesosphere.sdk.specification.PodSpec)10 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)6 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)6 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)6 PodInstance (com.mesosphere.sdk.specification.PodInstance)6 Protos (org.apache.mesos.Protos)6 Test (org.junit.Test)6 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 ConfigValidationError (com.mesosphere.sdk.config.validate.ConfigValidationError)2 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)2 AndRule (com.mesosphere.sdk.offer.evaluate.placement.AndRule)2 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)2 Collectors (java.util.stream.Collectors)2 Capabilities (com.mesosphere.sdk.dcos.Capabilities)1 HostnameRule (com.mesosphere.sdk.offer.evaluate.placement.HostnameRule)1 InvalidPlacementRule (com.mesosphere.sdk.offer.evaluate.placement.InvalidPlacementRule)1 IsLocalRegionRule (com.mesosphere.sdk.offer.evaluate.placement.IsLocalRegionRule)1 OrRule (com.mesosphere.sdk.offer.evaluate.placement.OrRule)1 PassthroughRule (com.mesosphere.sdk.offer.evaluate.placement.PassthroughRule)1