Search in sources :

Example 1 with Label

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

the class OfferEvaluatorPortsTest method testReserveTaskNamedVIPPort.

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
public void testReserveTaskNamedVIPPort() throws Exception {
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getVIPRequirement(80, 10000), 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 + "-10000:80");
    Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
    Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_10000"));
}
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 2 with Label

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

the class AuxLabelAccessTest method testCreateVipLabel.

@Test
public void testCreateVipLabel() {
    Protos.Port.Builder portBuilder = newPortBuilder();
    AuxLabelAccess.setVIPLabels(portBuilder, newVIPSpec("vip", 5));
    Collection<Protos.Label> labels = portBuilder.getLabels().getLabelsList();
    assertEquals(1, labels.size());
    Label label = labels.iterator().next();
    assertTrue(label.getKey().startsWith("VIP_"));
    assertEquals("vip:5", label.getValue());
    Collection<EndpointUtils.VipInfo> vips = AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, portBuilder.build());
    assertEquals(1, vips.size());
    EndpointUtils.VipInfo vip = vips.iterator().next();
    assertEquals("vip", vip.getVipName());
    assertEquals(5, vip.getVipPort());
}
Also used : EndpointUtils(com.mesosphere.sdk.http.EndpointUtils) Label(org.apache.mesos.Protos.Label) VipInfo(com.mesosphere.sdk.http.EndpointUtils.VipInfo) VipInfo(com.mesosphere.sdk.http.EndpointUtils.VipInfo) Test(org.junit.Test)

Example 3 with Label

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

the class AuxLabelAccess method getVIPsFromLabels.

/**
 * Returns the VIP information, if any, within the provided {@link Protos.Port}.
 * This is the inverse of {@link #setVIPLabels(org.apache.mesos.Protos.Port.Builder, NamedVIPSpec)}.
 */
public static Collection<VipInfo> getVIPsFromLabels(String taskName, Protos.Port port) {
    List<VipInfo> vips = new ArrayList<>();
    for (Label label : port.getLabels().getLabelsList()) {
        Optional<EndpointUtils.VipInfo> vipInfo = parseVipLabel(taskName, label);
        if (!vipInfo.isPresent()) {
            // Label doesn't appear to be for a VIP
            continue;
        }
        vips.add(vipInfo.get());
    }
    return vips;
}
Also used : ArrayList(java.util.ArrayList) Label(org.apache.mesos.Protos.Label) VipInfo(com.mesosphere.sdk.http.EndpointUtils.VipInfo)

Example 4 with Label

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

the class AuxLabelAccessTest method testCreateVipLabelOnOverlay.

@Test
public void testCreateVipLabelOnOverlay() {
    Protos.Port.Builder portBuilder = newPortBuilder();
    AuxLabelAccess.setVIPLabels(portBuilder, newVIPSpec("vip", 5, "dcos"));
    Collection<Protos.Label> labels = portBuilder.getLabels().getLabelsList();
    assertEquals(2, labels.size());
    assertEquals(1, labels.stream().filter(label -> label.getKey().startsWith("VIP_") && label.getValue().equals("vip:5")).collect(Collectors.toList()).size());
    assertEquals(1, labels.stream().filter(label -> label.getKey().equals(LabelConstants.VIP_OVERLAY_FLAG_KEY) && label.getValue().equals(LabelConstants.VIP_OVERLAY_FLAG_VALUE)).collect(Collectors.toList()).size());
    Collection<EndpointUtils.VipInfo> vips = AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, portBuilder.build());
    assertEquals(1, vips.size());
    EndpointUtils.VipInfo vip = vips.iterator().next();
    assertEquals("vip", vip.getVipName());
    assertEquals(5, vip.getVipPort());
}
Also used : Protos(org.apache.mesos.Protos) Arrays(java.util.Arrays) Label(org.apache.mesos.Protos.Label) TestConstants(com.mesosphere.sdk.testutils.TestConstants) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) EndpointUtils(com.mesosphere.sdk.http.EndpointUtils) VipInfo(com.mesosphere.sdk.http.EndpointUtils.VipInfo) NamedVIPSpec(com.mesosphere.sdk.specification.NamedVIPSpec) Assert.assertEquals(org.junit.Assert.assertEquals) EndpointUtils(com.mesosphere.sdk.http.EndpointUtils) Label(org.apache.mesos.Protos.Label) VipInfo(com.mesosphere.sdk.http.EndpointUtils.VipInfo) VipInfo(com.mesosphere.sdk.http.EndpointUtils.VipInfo) Test(org.junit.Test)

Example 5 with Label

use of org.apache.mesos.Protos.Label 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)

Aggregations

Label (org.apache.mesos.Protos.Label)6 Test (org.junit.Test)5 VipInfo (com.mesosphere.sdk.http.EndpointUtils.VipInfo)3 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)3 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)3 Operation (org.apache.mesos.Protos.Offer.Operation)3 Port (org.apache.mesos.Protos.Port)3 Resource (org.apache.mesos.Protos.Resource)3 TaskInfo (org.apache.mesos.Protos.TaskInfo)3 EndpointUtils (com.mesosphere.sdk.http.EndpointUtils)2 NamedVIPSpec (com.mesosphere.sdk.specification.NamedVIPSpec)1 TestConstants (com.mesosphere.sdk.testutils.TestConstants)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Protos (org.apache.mesos.Protos)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Mockito (org.mockito.Mockito)1