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());
}
Aggregations