本文整理汇总了Java中org.apache.mesos.Protos.DiscoveryInfo类的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryInfo类的具体用法?Java DiscoveryInfo怎么用?Java DiscoveryInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryInfo类属于org.apache.mesos.Protos包,在下文中一共展示了DiscoveryInfo类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureDiscoveryInfos
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
private void configureDiscoveryInfos(IAssignedTask task, TaskInfo.Builder taskBuilder) {
DiscoveryInfo.Builder builder = taskBuilder.getDiscoveryBuilder();
builder.setVisibility(DiscoveryInfo.Visibility.CLUSTER);
builder.setName(getInverseJobSourceName(task.getTask().getJob()));
builder.setEnvironment(task.getTask().getJob().getEnvironment());
// A good sane choice for default location is current Aurora cluster name.
builder.setLocation(serverInfo.getClusterName());
for (Map.Entry<String, Integer> entry : task.getAssignedPorts().entrySet()) {
builder.getPortsBuilder().addPorts(
Port.newBuilder()
.setName(entry.getKey())
.setNumber(entry.getValue())
.setProtocol(DEFAULT_PORT_PROTOCOL)
);
}
}
示例2: PortSpec
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
@JsonCreator
public PortSpec(
@JsonProperty("value") Protos.Value value,
@JsonProperty("role") String role,
@JsonProperty("pre-reserved-role") String preReservedRole,
@JsonProperty("principal") String principal,
@JsonProperty("env-key") String envKey,
@JsonProperty("port-name") String portName,
@JsonProperty("visibility") DiscoveryInfo.Visibility visibility,
@JsonProperty("network-names") Collection<String> networkNames) {
super(Constants.PORTS_RESOURCE_TYPE, value, role, preReservedRole, principal);
this.envKey = envKey;
this.portName = portName;
this.visibility = visibility;
this.networkNames = networkNames;
}
示例3: NamedVIPSpec
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
@JsonCreator
public NamedVIPSpec(
@JsonProperty("value") Protos.Value value,
@JsonProperty("role") String role,
@JsonProperty("pre-reserved-role") String preReservedRole,
@JsonProperty("principal") String principal,
@JsonProperty("env-key") String envKey,
@JsonProperty("port-name") String portName,
@JsonProperty("protocol") String protocol,
@JsonProperty("visibility") DiscoveryInfo.Visibility visibility,
@JsonProperty("vip-name") String vipName,
@JsonProperty("vip-port") Integer vipPort,
@JsonProperty("network-names") Collection<String> networkNames) {
super(value, role, preReservedRole, principal, envKey, portName, visibility, networkNames);
this.protocol = protocol;
this.vipName = vipName;
this.vipPort = vipPort;
ValidationUtils.validate(this);
}
示例4: getNamedVIPSpec
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
private static NamedVIPSpec getNamedVIPSpec(int taskPort, Collection<String> networkNames) {
Protos.Value.Builder valueBuilder = Protos.Value.newBuilder()
.setType(Protos.Value.Type.RANGES);
valueBuilder.getRangesBuilder().addRangeBuilder()
.setBegin(taskPort)
.setEnd(taskPort);
return new NamedVIPSpec(
valueBuilder.build(),
TestConstants.ROLE,
Constants.ANY_ROLE,
TestConstants.PRINCIPAL,
TestConstants.PORT_ENV_NAME + "_VIP_" + taskPort,
TestConstants.VIP_NAME + "-" + taskPort,
"sctp",
DiscoveryInfo.Visibility.EXTERNAL,
"test-vip",
80,
networkNames);
}
示例5: testReserveTaskNamedVIPPort
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
@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"));
}
示例6: testReserveTaskDynamicVIPPort
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
@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"));
}
示例7: testReserveTaskDynamicVIPPortCustomExecutor
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
@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"));
}
示例8: testDiscoveryInfoPopulated
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的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");
}
示例9: testDiscoveryInfoWhenOnOverlay
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的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));
}
示例10: testDiscoveryInfoOnBridgeNetwork
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的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));
}
示例11: testDiscoveryInfoWhenOnOverlayWithDynamicPort
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的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));
}
示例12: CassandraTask
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
protected CassandraTask(
final String name,
final String configName,
final CassandraTaskExecutor executor,
final double cpus,
final int memoryMb,
final int diskMb,
final VolumeRequirement.VolumeMode volumeMode,
final VolumeRequirement.VolumeType volumeType,
final Collection<Integer> ports,
@Nullable final DiscoveryInfo discoveryInfo,
final CassandraData data) {
String role = executor.getRole();
String principal = executor.getPrincipal();
Protos.TaskInfo.Builder builder = Protos.TaskInfo.newBuilder()
.setTaskId(createId(name))
.setName(name)
.setSlaveId(EMPTY_SLAVE_ID)
.setExecutor(executor.getExecutorInfo())
.addAllResources(Arrays.asList(
ResourceUtils.getDesiredScalar(role, principal, "cpus", cpus),
ResourceUtils.getDesiredScalar(role, principal, "mem", memoryMb)))
.setData(data.getBytes());
final Protos.Label label = Protos.Label.newBuilder()
.setKey("config_target")
.setValue(configName)
.build();
builder.setLabels(Protos.Labels.newBuilder().addLabels(label));
if (!volumeMode.equals(VolumeRequirement.VolumeMode.NONE)) {
if (volumeType.equals(VolumeRequirement.VolumeType.MOUNT)) {
builder.addResources(ResourceUtils.getDesiredMountVolume(role, principal, diskMb, CassandraConfig.VOLUME_PATH));
} else {
builder.addResources(ResourceUtils.getDesiredRootVolume(role, principal, diskMb, CassandraConfig.VOLUME_PATH));
}
}
if (!ports.isEmpty()) {
builder.addResources(ResourceUtils.getDesiredRanges(role, principal, "ports", Algorithms.createRanges(ports)));
}
if (discoveryInfo != null) {
builder.setDiscovery(discoveryInfo);
}
info = builder.build();
}
示例13: getDiscoveryEndpoints
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
/**
* Returns a mapping of endpoint type to host:port (or ip:port) endpoints, endpoint type.
*/
private Map<String, JSONObject> getDiscoveryEndpoints() throws TaskException {
Map<String, JSONObject> endpointsByName = new TreeMap<>();
for (TaskInfo taskInfo : stateStore.fetchTasks()) {
if (!taskInfo.hasDiscovery()) {
LOGGER.debug("Task lacks any discovery information, no endpoints to report: {}",
taskInfo.getName());
continue;
}
// TODO(mrb): Also extract DiscoveryInfo from executor, when executors get the ability to specify resources
DiscoveryInfo discoveryInfo = taskInfo.getDiscovery();
// Autoip hostname:
String autoIpTaskName = discoveryInfo.hasName() ? discoveryInfo.getName() : taskInfo.getName();
// Hostname of agent at offer time:
String nativeHost = new TaskLabelReader(taskInfo).getHostname();
// get IP address(es) from container status on the latest TaskStatus, if the latest TaskStatus has an IP
// otherwise use the lastest TaskStatus' IP stored in the stateStore
List<String> ipAddresses = reconcileIpAddresses(taskInfo.getName());
for (Port port : discoveryInfo.getPorts().getPortsList()) {
if (port.getVisibility() != Constants.DISPLAYED_PORT_VISIBILITY) {
LOGGER.debug(
"Port {} in task {} has {} visibility. {} is needed to be listed in endpoints.",
port.getName(), taskInfo.getName(), port.getVisibility(),
Constants.DISPLAYED_PORT_VISIBILITY);
continue;
}
final String hostIpString;
switch (ipAddresses.size()) {
case 0:
hostIpString = nativeHost;
break;
case 1:
hostIpString = ipAddresses.get(0);
break;
default:
hostIpString = ipAddresses.toString();
break;
}
addPortToEndpoints(
endpointsByName,
serviceName,
taskInfo.getName(),
port,
EndpointUtils.toAutoIpEndpoint(serviceName, autoIpTaskName, port.getNumber()),
EndpointUtils.toEndpoint(hostIpString, port.getNumber()));
}
}
return endpointsByName;
}
示例14: getVisibility
import org.apache.mesos.Protos.DiscoveryInfo; //导入依赖的package包/类
@JsonProperty("visibility")
public DiscoveryInfo.Visibility getVisibility() {
return visibility;
}