org.elasticsearch.client.transport.TransportClient.addTransportAddress()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.elasticsearch.client.transport.TransportClient.addTransportAddress()方法的一些代码示例,展示了TransportClient.addTransportAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransportClient.addTransportAddress()方法的具体详情如下:
包路径:org.elasticsearch.client.transport.TransportClient
类名称:TransportClient
方法名:addTransportAddress

TransportClient.addTransportAddress介绍

[英]Adds a transport address that will be used to connect to.

The Node this transport address represents will be used if its possible to connect to it. If it is unavailable, it will be automatically connected to once it is up.

In order to get the list of all the current connected nodes, please see #connectedNodes().
[中]添加将用于连接到的传输地址。
如果可能,将使用此传输地址所代表的节点连接到该节点。如果不可用,一旦启动,它将自动连接到。
要获取当前连接的所有节点的列表,请参阅#connectedNodes()。

代码示例

代码示例来源:origin: SonarSource/sonarqube

private static void addHostToClient(HostAndPort host, TransportClient client) {
 try {
  client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHostText()), host.getPortOrDefault(9001)));
 } catch (UnknownHostException e) {
  throw new IllegalStateException("Can not resolve host [" + host + "]", e);
 }
}

代码示例来源:origin: apache/flink

@Override
public TransportClient createClient(Map<String, String> clientConfig) {
  Settings settings = Settings.builder().put(clientConfig)
    .put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
    .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
    .build();
  TransportClient transportClient = new PreBuiltTransportClient(settings);
  for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) {
    transportClient.addTransportAddress(transport);
  }
  // verify that we actually are connected to a cluster
  if (transportClient.connectedNodes().isEmpty()) {
    // close the transportClient here
    IOUtils.closeQuietly(transportClient);
    throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!");
  }
  if (LOG.isInfoEnabled()) {
    LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes());
  }
  return transportClient;
}

代码示例来源:origin: Netflix/conductor

@Override
  public Client get() {

    Settings settings = Settings.builder()
        .put("client.transport.ignore_cluster_name", true)
        .put("client.transport.sniff", true)
        .build();

    TransportClient tc = new PreBuiltTransportClient(settings);

    List<URI> clusterAddresses = configuration.getURIs();

    if (clusterAddresses.isEmpty()) {
      logger.warn(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME +
          " is not set.  Indexing will remain DISABLED.");
    }
    for (URI hostAddress : clusterAddresses) {
      int port = Optional.ofNullable(hostAddress.getPort()).orElse(9200);
      try {
        tc.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAddress.getHost()), port));
      } catch (UnknownHostException uhe){
        throw new ProvisionException("Invalid host" + hostAddress.getHost(), uhe);
      }
    }
    return tc;
  }
}

代码示例来源:origin: apache/flink

@Override
public TransportClient createClient(Map<String, String> clientConfig) {
  Settings settings = Settings.settingsBuilder().put(clientConfig).build();
  TransportClient transportClient = TransportClient.builder().settings(settings).build();
  for (TransportAddress address : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) {
    transportClient.addTransportAddress(address);
  }
  // verify that we actually are connected to a cluster
  if (transportClient.connectedNodes().isEmpty()) {
    // close the transportClient here
    IOUtils.closeQuietly(transportClient);
    throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!");
  }
  if (LOG.isInfoEnabled()) {
    LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes());
  }
  return transportClient;
}

代码示例来源:origin: loklak/loklak_server

/**
 * create a elasticsearch transport client (remote elasticsearch)
 * @param addresses an array of host:port addresses
 * @param clusterName
 */
public ElasticsearchClient(final String[] addresses, final String clusterName) {
  // create default settings and add cluster name
  Settings.Builder settings = Settings.builder()
      .put("cluster.name", clusterName)
      .put("cluster.routing.allocation.enable", "all")
      .put("cluster.routing.allocation.allow_rebalance", "true");
  // create a client
  TransportClient tc = TransportClient.builder()
      .settings(settings.build())
      .build();
  for (String address: addresses) {
    String a = address.trim();
    int p = a.indexOf(':');
    if (p >= 0) try {
      InetAddress i = InetAddress.getByName(a.substring(0, p));
      int port = Integer.parseInt(a.substring(p + 1));
      tc.addTransportAddress(new InetSocketTransportAddress(i, port));
    } catch (UnknownHostException e) {
      DAO.severe(e);
    }
  }
  this.elasticsearchClient = tc;
}

代码示例来源:origin: apache/flume

/**
 * Open client to elaticsearch cluster
 * 
 * @param clusterName
 */
private void openClient(String clusterName) {
 logger.info("Using ElasticSearch hostnames: {} ",
   Arrays.toString(serverAddresses));
 Settings settings = ImmutableSettings.settingsBuilder()
   .put("cluster.name", clusterName).build();
 TransportClient transportClient = new TransportClient(settings);
 for (InetSocketTransportAddress host : serverAddresses) {
  transportClient.addTransportAddress(host);
 }
 if (client != null) {
  client.close();
 }
 client = transportClient;
}

代码示例来源:origin: alibaba/canal

for (String host : hostArray) {
  int i = host.indexOf(":");
  transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(host.substring(0, i)),
    Integer.parseInt(host.substring(i + 1))));

代码示例来源:origin: thinkaurelius/titan

@Override
  public Connection connect(Configuration config) throws IOException {
    log.debug("Configuring TransportClient");
    ImmutableSettings.Builder settingsBuilder = settingsBuilder(config);
    if (config.has(ElasticSearchIndex.CLIENT_SNIFF)) {
      String k = "client.transport.sniff";
      settingsBuilder.put(k, config.get(ElasticSearchIndex.CLIENT_SNIFF));
      log.debug("Set {}: {}", k, config.get(ElasticSearchIndex.CLIENT_SNIFF));
    }
    TransportClient tc = new TransportClient(settingsBuilder.build());
    int defaultPort = config.has(INDEX_PORT) ? config.get(INDEX_PORT) : ElasticSearchIndex.HOST_PORT_DEFAULT;
    for (String host : config.get(INDEX_HOSTS)) {
      String[] hostparts = host.split(":");
      String hostname = hostparts[0];
      int hostport = defaultPort;
      if (hostparts.length == 2) hostport = Integer.parseInt(hostparts[1]);
      log.info("Configured remote host: {} : {}", hostname, hostport);
      tc.addTransportAddress(new InetSocketTransportAddress(hostname, hostport));
    }
    return new Connection(null, tc);
  }
},

代码示例来源:origin: apache/nifi

for (final InetSocketAddress host : esHosts) {
  try {
    transportClient.addTransportAddress(new InetSocketTransportAddress(host));
  } catch (IllegalArgumentException iae) {
    log.error("Could not add transport address {}", new Object[]{host});

代码示例来源:origin: brianfrankcooper/YCSB

String[] nodes = h.split(":");
try {
 tClient.addTransportAddress(new InetSocketTransportAddress(
   InetAddress.getByName(nodes[0]),
   Integer.parseInt(nodes[1])

代码示例来源:origin: brianfrankcooper/YCSB

throw new IllegalArgumentException("unable to parse port [" + nodes[1] + "]", e);
client.addTransportAddress(new InetSocketTransportAddress(address, port));

代码示例来源:origin: apache/usergrid

/**
 * Create the transport client
 * @return
 */
private Client createTransportClient() {
  final String clusterName = indexFig.getClusterName();
  final int port = indexFig.getPort();
  ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put( "cluster.name", clusterName )
    .put( "client.transport.sniff", true );
  String nodeName = indexFig.getNodeName();
  if ( "default".equals( nodeName ) ) {
    // no nodeName was specified, use hostname
    try {
      nodeName = InetAddress.getLocalHost().getHostName();
    }
    catch ( UnknownHostException ex ) {
      nodeName = "client-" + RandomStringUtils.randomAlphabetic( 8 );
      logger.warn( "Couldn't get hostname to use as ES node name, using {}", nodeName );
    }
  }
  settings.put( "node.name", nodeName );
  TransportClient transportClient = new TransportClient( settings.build() );
  // we will connect to ES on all configured hosts
  for ( String host : indexFig.getHosts().split( "," ) ) {
    transportClient.addTransportAddress( new InetSocketTransportAddress( host, port ) );
  }
  return transportClient;
}

代码示例来源:origin: apache/flink

transportClient.addTransportAddress(transport);

代码示例来源:origin: floragunncom/search-guard

protected TransportClient getUserTransportClient(ClusterInfo info, String keyStore, Settings initTransportClientSettings) {
  
  final String prefix = getResourceFolder()==null?"":getResourceFolder()+"/";
  
  Settings tcSettings = Settings.builder()
      .put("cluster.name", info.clustername)
      .put("searchguard.ssl.transport.truststore_filepath",
          FileHelper.getAbsoluteFilePathFromClassPath(prefix+"truststore.jks"))
      .put("searchguard.ssl.transport.enforce_hostname_verification", false)
      .put("searchguard.ssl.transport.keystore_filepath",
          FileHelper.getAbsoluteFilePathFromClassPath(prefix+keyStore))
      .put(initTransportClientSettings)
      .build();
  
  TransportClient tc = new TransportClientImpl(tcSettings, asCollection(Netty4Plugin.class, SearchGuardPlugin.class));
  tc.addTransportAddress(new TransportAddress(new InetSocketAddress(info.nodeHost, info.nodePort)));
  return tc;
}

代码示例来源:origin: floragunncom/search-guard

protected TransportClient getInternalTransportClient(ClusterInfo info, Settings initTransportClientSettings) {
  
  final String prefix = getResourceFolder()==null?"":getResourceFolder()+"/";
  
  Settings tcSettings = Settings.builder()
      .put("cluster.name", info.clustername)
      .put("searchguard.ssl.transport.truststore_filepath",
          FileHelper.getAbsoluteFilePathFromClassPath(prefix+"truststore.jks"))
      .put("searchguard.ssl.transport.enforce_hostname_verification", false)
      .put("searchguard.ssl.transport.keystore_filepath",
          FileHelper.getAbsoluteFilePathFromClassPath(prefix+"kirk-keystore.jks"))
      .put(initTransportClientSettings)
      .build();
  
  TransportClient tc = new TransportClientImpl(tcSettings, asCollection(Netty4Plugin.class, SearchGuardPlugin.class));
  tc.addTransportAddress(new TransportAddress(new InetSocketAddress(info.nodeHost, info.nodePort)));
  return tc;
}

代码示例来源:origin: thinkaurelius/titan

if (hostparts.length == 2) hostport = Integer.parseInt(hostparts[1]);
log.info("Configured remote host: {} : {}", hostname, hostport);
tc.addTransportAddress(new InetSocketTransportAddress(hostname, hostport));

代码示例来源:origin: apache/nifi

for (final InetSocketAddress host : esHosts) {
  try {
    transportClient.addTransportAddress(new InetSocketTransportAddress(host));
  } catch (IllegalArgumentException iae) {
    log.error("Could not add transport address {}", new Object[]{host});

代码示例来源:origin: lianggzone/springboot-action

@Bean
  public Client client() {
    TransportClient client = new TransportClient();
    TransportAddress address = new InetSocketTransportAddress(hostname, port);
    
    client.addTransportAddress(address);
    return client;
  }
}

代码示例来源:origin: yacy/yacy_grid_mcp

/**
 * create a elasticsearch transport client (remote elasticsearch)
 * @param addresses an array of host:port addresses
 * @param clusterName
 */
public ElasticsearchClient(final String[] addresses, final String clusterName) {
  // create default settings and add cluster name
  Settings.Builder settings = Settings.builder()
      .put("cluster.routing.allocation.enable", "all")
      .put("cluster.routing.allocation.allow_rebalance", "always");
  if (clusterName != null) settings.put("cluster.name", clusterName);
  
  // create a client
  TransportClient tc = new PreBuiltTransportClient(settings.build());
  for (String address: addresses) {
    String a = address.trim();
    int p = a.indexOf(':');
    if (p >= 0) try {
      InetAddress i = InetAddress.getByName(a.substring(0, p));
      int port = Integer.parseInt(a.substring(p + 1));
      tc.addTransportAddress(new InetSocketTransportAddress(i, port));
    } catch (UnknownHostException e) {
      Data.logger.warn("", e);
    }
  }
  this.elasticsearchClient = tc;
}

代码示例来源:origin: floragunncom/search-guard

tc.addTransportAddress(new TransportAddress(new InetSocketAddress(info.nodeHost, info.nodePort)));
Assert.assertEquals(info.numNodes,
    tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());

相关文章

微信公众号

最新文章

更多