Search in sources :

Example 6 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class PortEvaluationStageTest method testHealthCheckPortEnvvarIsCorrectOnOverlay.

@Test
public void testHealthCheckPortEnvvarIsCorrectOnOverlay() throws Exception {
    DefaultPodInstance podInstance = getPodInstance("valid-port-healthcheck-overlay.yml");
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build();
    PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    PortEvaluationStage portEvaluationStage = new PortEvaluationStage(getPortSpec(podInstance), TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
    EvaluationOutcome outcome = portEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Assert.assertEquals(0, outcome.getOfferRecommendations().size());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilders().stream().findFirst().get();
    Assert.assertTrue(taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals("PORT_TEST_PORT") && variable.getValue().equals("10000")).count() == 1);
    Assert.assertTrue(taskBuilder.getHealthCheck().getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals("PORT_TEST_PORT") && variable.getValue().equals("10000")).count() == 1);
}
Also used : Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) java.util(java.util) com.mesosphere.sdk.offer(com.mesosphere.sdk.offer) TestPlacementUtils(com.mesosphere.sdk.offer.evaluate.placement.TestPlacementUtils) com.mesosphere.sdk.testutils(com.mesosphere.sdk.testutils) Test(org.junit.Test) ArtifactResource(com.mesosphere.sdk.http.endpoints.ArtifactResource) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Collectors(java.util.stream.Collectors) File(java.io.File) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) Assert(org.junit.Assert) DcosConstants(com.mesosphere.sdk.dcos.DcosConstants) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 7 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class PortEvaluationStageTest method getPodInstance.

private DefaultPodInstance getPodInstance(String serviceSpecFileName) throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource(serviceSpecFileName).getFile());
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();
    PodSpec podSpec = DefaultPodSpec.newBuilder(serviceSpec.getPods().get(0)).placementRule(TestPlacementUtils.PASS).build();
    serviceSpec = DefaultServiceSpec.newBuilder(serviceSpec).pods(Arrays.asList(podSpec)).build();
    return new DefaultPodInstance(serviceSpec.getPods().get(0), 0);
}
Also used : DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) File(java.io.File)

Example 8 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.

the class PortEvaluationStageTest method testPortEnvvarOnReadinessCheck.

@Test
public void testPortEnvvarOnReadinessCheck() throws Exception {
    DefaultPodInstance podInstance = getPodInstance("valid-port-readinesscheck.yml");
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build();
    PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    PortEvaluationStage portEvaluationStage = new PortEvaluationStage(getPortSpec(podInstance), TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
    EvaluationOutcome outcome = portEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Assert.assertEquals(1, outcome.getOfferRecommendations().size());
    OfferRecommendation recommendation = outcome.getOfferRecommendations().iterator().next();
    Assert.assertEquals(Protos.Offer.Operation.Type.RESERVE, recommendation.getOperation().getType());
    Protos.Resource resource = recommendation.getOperation().getReserve().getResources(0);
    Assert.assertEquals(10000, resource.getRanges().getRange(0).getBegin(), resource.getRanges().getRange(0).getEnd());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilders().stream().findFirst().get();
    boolean portInTaskEnv = false;
    for (int i = 0; i < taskBuilder.getCommand().getEnvironment().getVariablesCount(); i++) {
        Protos.Environment.Variable variable = taskBuilder.getCommand().getEnvironment().getVariables(i);
        if (Objects.equals(variable.getName(), "PORT_TEST_PORT")) {
            Assert.assertEquals(variable.getValue(), "10000");
            portInTaskEnv = true;
        }
    }
    Assert.assertTrue(portInTaskEnv);
    boolean portInHealthEnv = false;
    Protos.CheckInfo readinessCheck = taskBuilder.getCheck();
    for (int i = 0; i < readinessCheck.getCommand().getCommand().getEnvironment().getVariablesCount(); i++) {
        Protos.Environment.Variable variable = readinessCheck.getCommand().getCommand().getEnvironment().getVariables(i);
        if (Objects.equals(variable.getName(), "PORT_TEST_PORT")) {
            Assert.assertEquals(variable.getValue(), "10000");
            portInHealthEnv = true;
        }
    }
    Assert.assertTrue(portInHealthEnv);
}
Also used : PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Test(org.junit.Test)

Example 9 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance 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 10 with DefaultPodInstance

use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance 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)

Aggregations

DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)20 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)12 Protos (org.apache.mesos.Protos)12 Test (org.junit.Test)12 PodSpec (com.mesosphere.sdk.specification.PodSpec)9 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)7 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)6 PodInstance (com.mesosphere.sdk.specification.PodInstance)6 InvalidRequirementException (com.mesosphere.sdk.offer.InvalidRequirementException)4 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 ArtifactResource (com.mesosphere.sdk.http.endpoints.ArtifactResource)3 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)3 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)3 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)3 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)3 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)3 File (java.io.File)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Assert (org.junit.Assert)3