Search in sources :

Example 51 with PodInstanceRequirement

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

the class PortEvaluationStageTest method testDynamicPortResourceOnOverlay.

@Test
public void testDynamicPortResourceOnOverlay() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    Integer expectedDynamicOverlayPort = DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START;
    String expectedDynamicOverlayPortEnvvar = "PORT_TEST_DYNAMIC_OVERLAY";
    String expectedPortName = "dyn-port-name";
    long expectedDynamicallyAssignedPort = 1025;
    PortSpec portSpec = new PortSpec(getPort(0), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expectedDynamicOverlayPortEnvvar, 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, expectedDynamicallyAssignedPort);
    Assert.assertEquals(0, taskBuilder.getResourcesCount());
    List<Protos.Environment.Variable> portEnvVars = taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals(expectedDynamicOverlayPortEnvvar)).collect(Collectors.toList());
    Assert.assertEquals(1, portEnvVars.size());
    Protos.Environment.Variable variable = portEnvVars.get(0);
    Assert.assertEquals(variable.getName(), expectedDynamicOverlayPortEnvvar);
    Assert.assertEquals(variable.getValue(), expectedDynamicOverlayPort.toString());
    Assert.assertEquals(variable.getName(), expectedDynamicOverlayPortEnvvar);
    Assert.assertEquals(variable.getValue(), 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