Java Code Examples for org.apache.mesos.Protos#DiscoveryInfo

The following examples show how to use org.apache.mesos.Protos#DiscoveryInfo . 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: CassandraDaemonTaskTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishDiscoveryInfo() {
    CassandraConfig cassandraConfig = CassandraConfig.builder().setPublishDiscoveryInfo(true).build();

    CassandraDaemonTask daemonTask = testTaskFactory.create(
            TEST_DAEMON_NAME,
            TEST_CONFIG_NAME,
            testTaskExecutor,
            cassandraConfig);

    Protos.DiscoveryInfo discovery = daemonTask.getTaskInfo().getDiscovery();
    Assert.assertEquals("Test Cluster.test-daemon-task-name", discovery.getName());
    Assert.assertEquals(Protos.DiscoveryInfo.Visibility.EXTERNAL, discovery.getVisibility());
    Assert.assertEquals(1, discovery.getPorts().getPortsCount());
    Assert.assertEquals(9042, discovery.getPorts().getPorts(0).getNumber());
    Assert.assertEquals("NativeTransport", discovery.getPorts().getPorts(0).getName());
}
 
Example 2
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
private Protos.TaskInfo buildNativeTask(Protos.Offer offer, Configuration configuration, Clock clock, Long elasticSearchNodeId) {
    final List<Integer> ports = getPorts(offer, configuration);
    final List<Protos.Resource> resources = getResources(configuration, ports);
    final Protos.DiscoveryInfo discovery = getDiscovery(ports, configuration);
    final Protos.Labels labels = getLabels(configuration);

    final String hostAddress = resolveHostAddress(offer, ports);

    LOGGER.info("Creating Elasticsearch task with resources: " + resources.toString());

    final List<String> args = configuration.esArguments(clusterState, discovery, offer.getSlaveId());

    return Protos.TaskInfo.newBuilder()
            .setName(configuration.getTaskName())
            .setData(toData(offer.getHostname(), hostAddress, clock.nowUTC()))
            .setTaskId(Protos.TaskID.newBuilder().setValue(taskId(offer, clock)))
            .setSlaveId(offer.getSlaveId())
            .addAllResources(resources)
            .setDiscovery(discovery)
            .setLabels(labels)
            .setCommand(nativeCommand(configuration, args, elasticSearchNodeId))
            .build();
}
 
Example 3
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
private Protos.TaskInfo buildDockerTask(Protos.Offer offer, Configuration configuration, Clock clock, Long elasticSearchNodeId) {
    final List<Integer> ports = getPorts(offer, configuration);
    final List<Protos.Resource> resources = getResources(configuration, ports);
    final Protos.DiscoveryInfo discovery = getDiscovery(ports, configuration);
    final Protos.Labels labels = getLabels(configuration);

    final String hostAddress = resolveHostAddress(offer, ports);

    LOGGER.info("Creating Elasticsearch task with resources: " + resources.toString());

    final Protos.TaskID taskId = Protos.TaskID.newBuilder().setValue(taskId(offer, clock)).build();
    final List<String> args = configuration.esArguments(clusterState, discovery, offer.getSlaveId());
    final Protos.ContainerInfo containerInfo = getContainer(configuration, taskId, elasticSearchNodeId, offer.getSlaveId());

    return Protos.TaskInfo.newBuilder()
            .setName(configuration.getTaskName())
            .setData(toData(offer.getHostname(), hostAddress, clock.nowUTC()))
            .setTaskId(taskId)
            .setSlaveId(offer.getSlaveId())
            .addAllResources(resources)
            .setDiscovery(discovery)
            .setLabels(labels)
            .setCommand(dockerCommand(configuration, args, elasticSearchNodeId))
            .setContainer(containerInfo)
            .build();
}
 
Example 4
Source File: CassandraDaemonTaskTest.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcosNamedVipDiscoveryInfo() {
    CassandraDaemonTask daemonTask = testTaskFactory.create(
            TEST_DAEMON_NAME,
            TEST_CONFIG_NAME,
            testTaskExecutor,
            CassandraConfig.DEFAULT);

    Protos.DiscoveryInfo discovery = daemonTask.getTaskInfo().getDiscovery();
    Assert.assertEquals("test-daemon-task-name", discovery.getName());
    Assert.assertEquals(Protos.DiscoveryInfo.Visibility.EXTERNAL, discovery.getVisibility());
    Assert.assertEquals(1, discovery.getPorts().getPortsCount());
    Assert.assertEquals(9042, discovery.getPorts().getPorts(0).getNumber());
    Assert.assertEquals("tcp", discovery.getPorts().getPorts(0).getProtocol());
}
 
Example 5
Source File: PodInfoBuilder.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static Protos.DiscoveryInfo getDiscoveryInfo(DiscoverySpec discoverySpec, int index) {
  Protos.DiscoveryInfo.Builder builder = Protos.DiscoveryInfo.newBuilder();
  if (discoverySpec.getPrefix().isPresent()) {
    builder.setName(String.format("%s-%d", discoverySpec.getPrefix().get(), index));
  }
  if (discoverySpec.getVisibility().isPresent()) {
    builder.setVisibility(discoverySpec.getVisibility().get());
  } else {
    builder.setVisibility(Constants.DEFAULT_TASK_DISCOVERY_VISIBILITY);
  }

  return builder.build();
}
 
Example 6
Source File: NamedVIPEvaluationStageTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: NamedVIPEvaluationStageTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: NamedVIPEvaluationStageTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: NamedVIPEvaluationStageTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: PortEvaluationStageTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 11
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
private Protos.DiscoveryInfo getDiscovery(List<Integer> ports, Configuration configuration) {
    Protos.DiscoveryInfo.Builder discovery = Protos.DiscoveryInfo.newBuilder();
    Protos.Ports.Builder discoveryPorts = Protos.Ports.newBuilder();
    discoveryPorts.addPorts(Discovery.CLIENT_PORT_INDEX, Protos.Port.newBuilder().setNumber(ports.get(0)).setName(Discovery.CLIENT_PORT_NAME).setProtocol("tcp"));
    discoveryPorts.addPorts(Discovery.TRANSPORT_PORT_INDEX, Protos.Port.newBuilder().setNumber(ports.get(1)).setName(Discovery.TRANSPORT_PORT_NAME).setProtocol("tcp"));
    discovery.setPorts(discoveryPorts);
    discovery.setVisibility(Protos.DiscoveryInfo.Visibility.EXTERNAL);
    discovery.setName(configuration.getTaskName());
    return discovery.build();
}
 
Example 12
Source File: ConfigurationTest.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateArguments() {
    Configuration configuration = new Configuration(ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, "aa");
    final ClusterState clusterState = Mockito.mock(ClusterState.class);
    final int port = 1234;
    final Protos.DiscoveryInfo discoveryInfo = Protos.DiscoveryInfo.newBuilder().setPorts(Protos.Ports.newBuilder()
            .addPorts(Protos.Port.newBuilder().setNumber(port))
            .addPorts(Protos.Port.newBuilder().setNumber(port)))
            .setVisibility(Protos.DiscoveryInfo.Visibility.EXTERNAL)
            .build();
    Protos.SlaveID slaveID = Protos.SlaveID.newBuilder().setValue("SLAVE").build();
    final List<String> arguments = configuration.esArguments(clusterState, discoveryInfo, slaveID);
    String allArgs = arguments.toString();
    assertTrue(allArgs.contains(Integer.toString(port)));
}
 
Example 13
Source File: Configuration.java    From elasticsearch with Apache License 2.0 4 votes vote down vote up
public List<String> esArguments(ClusterState clusterState, Protos.DiscoveryInfo discoveryInfo, Protos.SlaveID slaveID) {
    List<String> args = new ArrayList<>();
    List<Protos.TaskInfo> taskList = clusterState.getTaskList();
    String hostAddress = "";
    if (taskList.size() > 0) {
        Protos.TaskInfo taskInfo = taskList.get(0);
        String taskId = taskInfo.getTaskId().getValue();
        InetSocketAddress transportAddress = clusterState.getGuiTaskList().get(taskId).getTransportAddress();
        hostAddress = NetworkUtils.addressToString(transportAddress, getIsUseIpAddress()).replace("http://", "");
    }
    addIfNotEmpty(args, "--default.discovery.zen.ping.unicast.hosts", hostAddress);
    args.add("--default.http.port=" + discoveryInfo.getPorts().getPorts(Discovery.CLIENT_PORT_INDEX).getNumber());
    args.add("--default.transport.tcp.port=" + discoveryInfo.getPorts().getPorts(Discovery.TRANSPORT_PORT_INDEX).getNumber());
    args.add("--default.cluster.name=" + getElasticsearchClusterName());
    args.add("--default.node.master=true");
    args.add("--default.node.data=true");
    args.add("--default.node.local=false");
    args.add("--default.index.number_of_replicas=0");
    args.add("--default.index.auto_expand_replicas=0-all");
    if (!isFrameworkUseDocker()) {
        String taskSpecificDataDir = taskSpecificHostDir(slaveID);
        args.add("--path.home=" + HOST_PATH_HOME); // Cannot be overidden
        args.add("--default.path.data=" + taskSpecificDataDir);
        args.add("--path.conf=" + HOST_PATH_CONF); // Cannot be overidden
    } else {
        args.add("--path.data=" + CONTAINER_PATH_DATA); // Cannot be overidden
    }
    args.add("--default.bootstrap.mlockall=true");
    args.add("--default.network.bind_host=0.0.0.0");
    args.add("--default.network.publish_host=_non_loopback:ipv4_");
    args.add("--default.gateway.recover_after_nodes=1");
    args.add("--default.gateway.expected_nodes=1");
    args.add("--default.indices.recovery.max_bytes_per_sec=100mb");
    args.add("--default.discovery.type=zen");
    args.add("--default.discovery.zen.fd.ping_timeout=30s");
    args.add("--default.discovery.zen.fd.ping_interval=1s");
    args.add("--default.discovery.zen.fd.ping_retries=30");
    args.add("--default.discovery.zen.ping.multicast.enabled=false");


    return args;
}