Search in sources :

Example 6 with DiscoveryInfo

use of org.apache.mesos.Protos.DiscoveryInfo in project dcos-commons by mesosphere.

the class NamedVIPEvaluationStageTest method testDiscoveryInfoWhenOnOverlayWithDynamicPort.

@Test
public void testDiscoveryInfoWhenOnOverlayWithDynamicPort() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
    // non-offered port
    Integer containerPort = 0;
    String overlayNetwork = "dcos";
    PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(containerPort, Collections.emptyList(), Optional.of(overlayNetwork));
    NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(containerPort, Optional.empty(), Optional.of(overlayNetwork));
    EvaluationOutcome outcome = vipEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
    String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
    String observedName = discoveryInfo.getName();
    Assert.assertEquals(expectedName, observedName);
    Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    Assert.assertEquals(0, taskBuilder.getResourcesCount());
    Protos.Port port = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(port.getNumber(), DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START.longValue());
    Assert.assertEquals(port.getProtocol(), "sctp");
    Assert.assertEquals(2, port.getLabels().getLabelsCount());
    Collection<EndpointUtils.VipInfo> vips = AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, port);
    Assert.assertEquals(1, vips.size());
    EndpointUtils.VipInfo vip = vips.iterator().next();
    Assert.assertEquals("test-vip", vip.getVipName());
    Assert.assertEquals(80, vip.getVipPort());
    assertIsOverlayLabel(port.getLabels().getLabels(1));
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) EndpointUtils(com.mesosphere.sdk.http.EndpointUtils) Protos(org.apache.mesos.Protos) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Test(org.junit.Test)

Example 7 with DiscoveryInfo

use of org.apache.mesos.Protos.DiscoveryInfo in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveTaskDynamicVIPPortCustomExecutor.

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
public void testReserveTaskDynamicVIPPortCustomExecutor() throws Exception {
    useCustomExecutor();
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getVIPRequirement(80, 0), OfferTestUtils.getOffers(ResourceTestUtils.getUnreservedPorts(10000, 10000)));
    Assert.assertEquals(2, recommendations.size());
    Operation launchOperation = recommendations.get(1).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(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"));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Port(org.apache.mesos.Protos.Port) Resource(org.apache.mesos.Protos.Resource) Label(org.apache.mesos.Protos.Label) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 8 with DiscoveryInfo

use of org.apache.mesos.Protos.DiscoveryInfo 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"));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Port(org.apache.mesos.Protos.Port) Resource(org.apache.mesos.Protos.Resource) Label(org.apache.mesos.Protos.Label) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Aggregations

DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)8 Test (org.junit.Test)7 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)4 Protos (org.apache.mesos.Protos)4 Port (org.apache.mesos.Protos.Port)4 TaskInfo (org.apache.mesos.Protos.TaskInfo)4 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)3 Label (org.apache.mesos.Protos.Label)3 Operation (org.apache.mesos.Protos.Offer.Operation)3 Resource (org.apache.mesos.Protos.Resource)3 EndpointUtils (com.mesosphere.sdk.http.EndpointUtils)2 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)1 JSONObject (org.json.JSONObject)1