Search in sources :

Example 46 with PodInstanceRequirement

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

the class DefaultPlanGeneratorTest method validatePhase.

private void validatePhase(Phase phase, List<List<String>> stepTasks) {
    Assert.assertEquals(phase.getChildren().size(), stepTasks.size());
    for (int i = 0; i < stepTasks.size(); i++) {
        PodInstanceRequirement podInstanceRequirement = phase.getChildren().get(i).start().get();
        List<String> tasksToLaunch = new ArrayList<>(podInstanceRequirement.getTasksToLaunch());
        for (int j = 0; j < tasksToLaunch.size(); j++) {
            Assert.assertEquals(tasksToLaunch.get(j), stepTasks.get(i).get(j));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)

Example 47 with PodInstanceRequirement

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

the class CassandraRecoveryPlanOverriderTest method replaceSeed.

@Test
public void replaceSeed() throws Exception {
    int nonSeedIndex = 1;
    String taskName = "node-" + nonSeedIndex + "-server";
    StateStoreUtils.storeTaskStatusAsProperty(stateStore, taskName, getFailedTaskStatus(taskName));
    PodInstanceRequirement podInstanceRequirement = getReplacePodInstanceRequirement(nonSeedIndex);
    Optional<Phase> phase = planOverrider.override(podInstanceRequirement);
    Assert.assertTrue(phase.isPresent());
    Assert.assertEquals(3, phase.get().getChildren().size());
    Assert.assertEquals(RecoveryType.PERMANENT, phase.get().getChildren().get(0).getPodInstanceRequirement().get().getRecoveryType());
    Assert.assertEquals(RecoveryType.TRANSIENT, phase.get().getChildren().get(1).getPodInstanceRequirement().get().getRecoveryType());
    Assert.assertEquals(RecoveryType.TRANSIENT, phase.get().getChildren().get(2).getPodInstanceRequirement().get().getRecoveryType());
}
Also used : Phase(com.mesosphere.sdk.scheduler.plan.Phase) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 48 with PodInstanceRequirement

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

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

the class PortEvaluationStageTest method testPortResourceIsIgnoredOnOverlay.

@Test
public void testPortResourceIsIgnoredOnOverlay() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    // request a port that's not available in the offer.
    Integer requestedPort = 80;
    String expectedPortEnvVar = "PORT_TEST_IGNORED";
    String expectedPortName = "overlay-port-name";
    PortSpec portSpec = new PortSpec(getPort(requestedPort), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expectedPortEnvVar, expectedPortName, TestConstants.PORT_VISIBILITY, getOverlayNetworkNames());
    PodInstanceRequirement podInstanceRequirement = getPodInstanceRequirement(portSpec);
    PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
    PortEvaluationStage portEvaluationStage = new PortEvaluationStage(portSpec, 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.getTaskBuilder(TestConstants.TASK_NAME);
    checkDiscoveryInfo(taskBuilder.getDiscovery(), expectedPortName, 80);
    Assert.assertTrue("TaskInfo builder missing DiscoveryInfo", taskBuilder.hasDiscovery());
    Assert.assertEquals(0, taskBuilder.getResourcesCount());
    List<Protos.Environment.Variable> portEnvVars = taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals(expectedPortEnvVar)).collect(Collectors.toList());
    Assert.assertEquals(1, portEnvVars.size());
    Protos.Environment.Variable variable = portEnvVars.get(0);
    Assert.assertEquals(variable.getName(), expectedPortEnvVar);
    Assert.assertEquals(variable.getValue(), requestedPort.toString());
}
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) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Protos(org.apache.mesos.Protos) Test(org.junit.Test)

Example 50 with PodInstanceRequirement

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

the class PortEvaluationStageTest method testDynamicPortResourceOnOverlayAndRequestedPort.

@Test
public void testDynamicPortResourceOnOverlayAndRequestedPort() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    Integer expectedExplicitOverlayPort = DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START;
    Integer expectedDynamicOverlayPort = DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START + 1;
    String expectedExplicitOverlayPortEnvvar = "PORT_TEST_EXPLICIT";
    String expextedDynamicOverlayPortEnvvar = "PORT_TEST_DYNAMIC";
    String expectedExplicitPortName = "explicit-port";
    String expectedDynamicPortName = "dynamic-port";
    PortSpec portSpec = new PortSpec(getPort(DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expectedExplicitOverlayPortEnvvar, expectedExplicitPortName, TestConstants.PORT_VISIBILITY, getOverlayNetworkNames());
    PortSpec dynamPortSpec = new PortSpec(getPort(0), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expextedDynamicOverlayPortEnvvar, expectedDynamicPortName, TestConstants.PORT_VISIBILITY, getOverlayNetworkNames());
    PodInstanceRequirement podInstanceRequirement = getPodInstanceRequirement(portSpec, dynamPortSpec);
    PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
    Assert.assertTrue(String.format("podInfoBuilder has incorrect number of pre-assigned overlay ports " + "should be 1, got %s", podInfoBuilder.getAssignedOverlayPorts().size()), podInfoBuilder.getAssignedOverlayPorts().size() == 1);
    PortEvaluationStage portEvaluationStage_ = new PortEvaluationStage(portSpec, TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
    EvaluationOutcome outcome0 = portEvaluationStage_.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome0.isPassing());
    Assert.assertEquals(0, outcome0.getOfferRecommendations().size());
    PortEvaluationStage portEvaluationStage = new PortEvaluationStage(dynamPortSpec, TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
    EvaluationOutcome outcome1 = portEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome1.isPassing());
    Assert.assertEquals(0, outcome1.getOfferRecommendations().size());
    Assert.assertTrue(String.format("podInfoBuilder has incorrect number of assigned overlay ports, " + "should be 2 got %s", podInfoBuilder.getAssignedOverlayPorts().size()), podInfoBuilder.getAssignedOverlayPorts().size() == 2);
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    checkDiscoveryInfo(taskBuilder.getDiscovery(), expectedExplicitPortName, expectedExplicitOverlayPort);
    checkDiscoveryInfo(taskBuilder.getDiscovery(), expectedDynamicPortName, expectedDynamicOverlayPort);
    Assert.assertEquals(0, taskBuilder.getResourcesCount());
    Map<String, String> portEnvVarMap = taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals(expectedExplicitOverlayPortEnvvar) || variable.getName().equals(expextedDynamicOverlayPortEnvvar)).collect(Collectors.toMap(Protos.Environment.Variable::getName, Protos.Environment.Variable::getValue));
    Assert.assertEquals(2, portEnvVarMap.size());
    Assert.assertTrue(portEnvVarMap.containsKey(expectedExplicitOverlayPortEnvvar));
    Assert.assertTrue(portEnvVarMap.containsKey(expextedDynamicOverlayPortEnvvar));
    Assert.assertTrue(portEnvVarMap.get(expectedExplicitOverlayPortEnvvar).equals(expectedExplicitOverlayPort.toString()));
    Assert.assertTrue(portEnvVarMap.get(expextedDynamicOverlayPortEnvvar).equals(expectedDynamicOverlayPort.toString()));
}
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) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Protos(org.apache.mesos.Protos) Test(org.junit.Test)

Aggregations

PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)51 Test (org.junit.Test)47 Protos (org.apache.mesos.Protos)38 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)21 Resource (org.apache.mesos.Protos.Resource)17 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)16 Operation (org.apache.mesos.Protos.Offer.Operation)15 Collectors (java.util.stream.Collectors)10 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)8 java.util (java.util)8 Assert (org.junit.Assert)8 ArtifactResource (com.mesosphere.sdk.http.endpoints.ArtifactResource)7 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)7 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)7 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)6 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)6 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)6 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)6 PodInstance (com.mesosphere.sdk.specification.PodInstance)6 PodSpec (com.mesosphere.sdk.specification.PodSpec)6