use of org.apache.mesos.Protos.Label in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveTaskDynamicVIPPort.
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
public void testReserveTaskDynamicVIPPort() throws Exception {
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getVIPRequirement(80, 0), OfferTestUtils.getCompleteOffers(ResourceTestUtils.getUnreservedPorts(10000, 10000)));
Assert.assertEquals(5, recommendations.size());
Operation launchOperation = recommendations.get(4).getOperation();
TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
Resource fulfilledPortResource = taskInfo.getResources(0);
Assert.assertEquals(10000, fulfilledPortResource.getRanges().getRange(0).getBegin());
Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
DiscoveryInfo discoveryInfo = taskInfo.getDiscovery();
Assert.assertEquals(discoveryInfo.getName(), taskInfo.getName());
Assert.assertEquals(discoveryInfo.getVisibility(), DiscoveryInfo.Visibility.CLUSTER);
Port discoveryPort = discoveryInfo.getPorts().getPorts(0);
Assert.assertEquals(discoveryPort.getProtocol(), "tcp");
Assert.assertEquals(discoveryPort.getVisibility(), DiscoveryInfo.Visibility.EXTERNAL);
Assert.assertEquals(discoveryPort.getNumber(), 10000);
Label vipLabel = discoveryPort.getLabels().getLabels(0);
Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
Assert.assertEquals(vipLabel.getValue(), TestConstants.VIP_NAME + "-0:80");
Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_0"));
}
Aggregations