本文整理汇总了Java中org.apache.mesos.Protos.Port方法的典型用法代码示例。如果您正苦于以下问题:Java Protos.Port方法的具体用法?Java Protos.Port怎么用?Java Protos.Port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.Protos
的用法示例。
在下文中一共展示了Protos.Port方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVIPsFromLabels
import org.apache.mesos.Protos; //导入方法依赖的package包/类
/**
* 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;
}
示例2: TaskPortLookup
import org.apache.mesos.Protos; //导入方法依赖的package包/类
TaskPortLookup(Protos.TaskInfo currentTask) {
this.lastTaskPorts = new HashMap<>();
for (Protos.Port port : currentTask.getDiscovery().getPorts().getPortsList()) {
if (!Strings.isEmpty(port.getName())) {
this.lastTaskPorts.put(port.getName(), (long) port.getNumber());
}
}
}
示例3: withLabel
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private static Protos.Port withLabel(String key, String value) {
Protos.Port.Builder portBuilder = newPortBuilder();
portBuilder.getLabelsBuilder().addLabelsBuilder()
.setKey(key)
.setValue(value);
return portBuilder.build();
}
示例4: testDiscoveryInfoPopulated
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@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");
}
示例5: testDiscoveryInfoWhenOnOverlay
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@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));
}
示例6: testDiscoveryInfoOnBridgeNetwork
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@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));
}
示例7: testDiscoveryInfoWhenOnOverlayWithDynamicPort
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@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));
}
示例8: checkDiscoveryInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
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());
}