Search in sources :

Example 16 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec 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 17 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec 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 18 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec 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 19 with PodSpec

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

the class RoundRobinByHostnameRuleTest method getPodInstance.

private static PodInstance getPodInstance(TaskInfo taskInfo) {
    try {
        TaskLabelReader labels = new TaskLabelReader(taskInfo);
        ResourceSet resourceSet = PodInstanceRequirementTestUtils.getCpuResourceSet(1.0);
        PodSpec podSpec = PodInstanceRequirementTestUtils.getRequirement(resourceSet, labels.getType(), labels.getIndex()).getPodInstance().getPod();
        return new DefaultPodInstance(podSpec, labels.getIndex());
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) PodSpec(com.mesosphere.sdk.specification.PodSpec) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) InvalidRequirementException(com.mesosphere.sdk.offer.InvalidRequirementException) TaskException(com.mesosphere.sdk.offer.TaskException)

Example 20 with PodSpec

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

the class DefaultConfigurationUpdater method needsConfigUpdate.

private static boolean needsConfigUpdate(Protos.TaskInfo taskInfo, ServiceSpec targetConfig, ServiceSpec taskConfig) {
    if (targetConfig.equals(taskConfig)) {
        LOGGER.info("Task '{}' is up to date: Task's target ServiceSpec matches the current ServiceSpec", taskInfo.getName());
        return false;
    }
    final String podType;
    final boolean isPermanentlyFailed;
    try {
        TaskLabelReader reader = new TaskLabelReader(taskInfo);
        podType = reader.getType();
        isPermanentlyFailed = reader.isPermanentlyFailed();
    } catch (TaskException e) {
        LOGGER.error(String.format("Unable to extract pod type from task '%s'. Will assume the task needs a configuration update", taskInfo.getName()), e);
        return true;
    }
    // to transition from their former config to the new target.
    if (isPermanentlyFailed) {
        return false;
    }
    Optional<PodSpec> targetSpecOptional = getPodSpec(targetConfig, podType);
    Optional<PodSpec> taskSpecOptional = getPodSpec(taskConfig, podType);
    if (!targetSpecOptional.isPresent() || !taskSpecOptional.isPresent()) {
        LOGGER.info("Task '{}' needs a configuration update: " + "PodSpec '{}' was {} in task's config, but is {} in current target config", taskInfo.getName(), podType, taskSpecOptional.isPresent() ? "present" : "missing", targetSpecOptional.isPresent() ? "present" : "missing");
        return true;
    }
    boolean updateNeeded = !areMatching(targetSpecOptional.get(), taskSpecOptional.get());
    if (updateNeeded) {
        LOGGER.info("Task '{}' needs a configuration update: PodSpec '{}' has changed", taskInfo.getName(), podType);
    } else {
        LOGGER.info("Task '{}' is up to date: PodSpec '{}' is the same", taskInfo.getName(), podType);
    }
    return updateNeeded;
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) TaskException(com.mesosphere.sdk.offer.TaskException) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec)

Aggregations

PodSpec (com.mesosphere.sdk.specification.PodSpec)35 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)21 Test (org.junit.Test)16 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)10 PodInstance (com.mesosphere.sdk.specification.PodInstance)10 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)9 Protos (org.apache.mesos.Protos)8 Collectors (java.util.stream.Collectors)7 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)6 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)6 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)4 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)4 List (java.util.List)4 InvalidRequirementException (com.mesosphere.sdk.offer.InvalidRequirementException)3 TaskException (com.mesosphere.sdk.offer.TaskException)3 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 ConfigValidationError (com.mesosphere.sdk.config.validate.ConfigValidationError)2