Java Code Examples for org.apache.mesos.Protos#Port
The following examples show how to use
org.apache.mesos.Protos#Port .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuxLabelAccess.java From dcos-commons with Apache License 2.0 | 5 votes |
/** * 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; }
Example 2
Source File: TaskPortLookup.java From dcos-commons with Apache License 2.0 | 5 votes |
TaskPortLookup(Protos.TaskInfo currentTask) { this.lastTaskPorts = new HashMap<>(); for (Protos.Port port : currentTask.getDiscovery().getPorts().getPortsList()) { if (!StringUtils.isEmpty(port.getName())) { this.lastTaskPorts.put(port.getName(), (long) port.getNumber()); } } }
Example 3
Source File: AuxLabelAccessTest.java From dcos-commons with Apache License 2.0 | 5 votes |
private static Protos.Port withLabel(String key, String value) { Protos.Port.Builder portBuilder = newPortBuilder(); portBuilder.getLabelsBuilder().addLabelsBuilder() .setKey(key) .setValue(value); return portBuilder.build(); }
Example 4
Source File: NamedVIPEvaluationStageTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@Test public void testDiscoveryInfoPopulated() throws Exception { Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000); Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts); PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(10000, Collections.emptyList(), Optional.empty()); // Evaluate stage NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(10000, Optional.empty(), Optional.empty()); 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.Port port = discoveryInfo.getPorts().getPorts(0); Assert.assertEquals(port.getNumber(), 10000); Assert.assertEquals(port.getProtocol(), "sctp"); Assert.assertEquals(1, port.getLabels().getLabelsCount()); Protos.Label vipLabel = port.getLabels().getLabels(0); Assert.assertEquals("pod-type-0-test-task-name", discoveryInfo.getName()); Assert.assertTrue(vipLabel.getKey().startsWith("VIP_")); Assert.assertEquals(vipLabel.getValue(), "test-vip:80"); }
Example 5
Source File: NamedVIPEvaluationStageTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@Test public void testDiscoveryInfoWhenOnOverlay() throws Exception { Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000); Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts); Integer containerPort = 80; // non-offered port 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(), containerPort.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)); }
Example 6
Source File: NamedVIPEvaluationStageTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@Test public void testDiscoveryInfoOnBridgeNetwork() throws Exception { Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000); Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts); Integer containerPort = 10000; // non-offered port String bridgeNetwork = "mesos-bridge"; PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork( containerPort, Collections.emptyList(), Optional.of(bridgeNetwork)); NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork( containerPort, Optional.empty(), Optional.of(bridgeNetwork)); 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(1, taskBuilder.getResourcesCount()); // expect that bridge uses ports Protos.Port port = discoveryInfo.getPorts().getPorts(0); Assert.assertEquals(port.getNumber(), containerPort.longValue()); Assert.assertEquals(port.getProtocol(), "sctp"); Assert.assertEquals(2, port.getLabels().getLabelsCount()); Protos.Label vipLabel = port.getLabels().getLabels(0); Assert.assertTrue(vipLabel.getKey().startsWith("VIP_")); Assert.assertEquals(vipLabel.getValue(), "test-vip:80"); assertIsBridgeLabel(port.getLabels().getLabels(1)); }
Example 7
Source File: NamedVIPEvaluationStageTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@Test public void testDiscoveryInfoWhenOnOverlayWithDynamicPort() throws Exception { Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000); Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts); Integer containerPort = 0; // non-offered port 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)); }
Example 8
Source File: PortEvaluationStageTest.java From dcos-commons with Apache License 2.0 | 5 votes |
private static void checkDiscoveryInfo(Protos.DiscoveryInfo discoveryInfo, String expectedPortName, long expectedPort) { Assert.assertEquals(Constants.DEFAULT_TASK_DISCOVERY_VISIBILITY, discoveryInfo.getVisibility()); List<Protos.Port> ports = discoveryInfo.getPorts().getPortsList().stream() .filter(p -> p.getName().equals(expectedPortName)) .collect(Collectors.toList()); Assert.assertTrue(String.format("Didn't find port with name %s, got ports %s", expectedPortName, ports.toString()), ports.size() == 1); Protos.Port port = ports.get(0); Assert.assertTrue(String.format("Port %s has incorrect number got %d should be %d", port.toString(), port.getNumber(), expectedPort), port.getNumber() == expectedPort); Assert.assertEquals(Constants.DISPLAYED_PORT_VISIBILITY, port.getVisibility()); }