Search in sources :

Example 16 with DefaultPodInstance

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

the class PortEvaluationStageTest method getPodInstanceRequirement.

private PodInstanceRequirement getPodInstanceRequirement(PortSpec... portSpecs) {
    // Build Pod
    ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id("resourceSet").cpus(1.0).addResource(Arrays.asList(portSpecs)).build();
    CommandSpec commandSpec = DefaultCommandSpec.newBuilder(Collections.emptyMap()).value("./cmd").build();
    TaskSpec taskSpec = DefaultTaskSpec.newBuilder().name(TestConstants.TASK_NAME).commandSpec(commandSpec).goalState(GoalState.RUNNING).resourceSet(resourceSet).build();
    PodSpec podSpec = DefaultPodSpec.newBuilder("executor-uri").addTask(taskSpec).count(1).type(TestConstants.POD_TYPE).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    return PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
}
Also used : DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)

Example 17 with DefaultPodInstance

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

the class PortEvaluationStageTest method testPortEnvvarOnReadinessCheckCustomExecutor.

@Test
public void testPortEnvvarOnReadinessCheckCustomExecutor() throws Exception {
    DefaultPodInstance podInstance = getPodInstance("valid-port-readinesscheck.yml");
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build();
    PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, false);
    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);
}
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 18 with DefaultPodInstance

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

the class CassandraRecoveryPlanOverriderTest method getPodInstanceRequirement.

private PodInstanceRequirement getPodInstanceRequirement(int nodeIndex, RecoveryType recoveryType) throws Exception {
    PodSpec podSpec = serviceSpec.getPods().get(0);
    PodInstance podInstance = new DefaultPodInstance(podSpec, nodeIndex);
    return PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("server")).recoveryType(recoveryType).build();
}
Also used : DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)

Example 19 with DefaultPodInstance

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

the class PortEvaluationStageTest method testPortEnvvarOnHealthCheck.

@Test
public void testPortEnvvarOnHealthCheck() throws Exception {
    DefaultPodInstance podInstance = getPodInstance("valid-port-healthcheck.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.getCompleteOffer(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;
    for (int i = 0; i < taskBuilder.getHealthCheck().getCommand().getEnvironment().getVariablesCount(); i++) {
        Protos.Environment.Variable variable = taskBuilder.getHealthCheck().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 20 with DefaultPodInstance

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

the class RoundRobinByAttributeRuleTest 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) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) 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)

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