Search in sources :

Example 46 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project api-core by ca-cwds.

the class ElasticUtils method getValidatedESNodes.

@SuppressWarnings("fb-contrib:CLI_CONSTANT_LIST_INDEX")
private static List<InetSocketTransportAddress> getValidatedESNodes(ElasticsearchConfiguration config) {
    final List<InetSocketTransportAddress> addressList = new ArrayList<>();
    final List<String> nodesList = new ArrayList<>();
    // If provided use Host and Port as a first node. For backward compatibility
    if (config.getElasticsearchHost() != null && config.getElasticsearchPort() != null) {
        nodesList.add(config.getElasticsearchHost().concat(":").concat(config.getElasticsearchPort()));
    }
    // Example: host1:port1,host2:port2,...etc.
    if (config.getElasticsearchNodes() != null) {
        nodesList.addAll(Arrays.asList(config.getElasticsearchNodes().split(",")));
    }
    // remove duplicates if any.
    final Map<String, String[]> nodesMap = new HashMap<>(nodesList.size());
    for (String node : nodesList) {
        nodesMap.put(node, node.split(":"));
    }
    for (Map.Entry<String, String[]> entry : nodesMap.entrySet()) {
        String[] hostPort = entry.getValue();
        if (hostPort.length >= 2) {
            LOGGER.info("Adding new ES Node host:[{}] port:[{}] to elasticsearch client", hostPort[0], hostPort[1]);
            try {
                addressList.add(new InetSocketTransportAddress(InetAddress.getByName(hostPort[0]), Integer.parseInt(hostPort[1])));
            } catch (UnknownHostException e) {
                LOGGER.error("Error adding Node: {}", e.getMessage(), e);
            }
        }
    }
    return addressList;
}
Also used : UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 47 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project fabric8 by jboss-fuse.

the class FabricDiscovery method doStart.

@Override
protected void doStart() throws ElasticsearchException {
    logger.debug("Starting FabricDiscovery");
    Map<String, String> nodeAttributes = discoveryNodeService.buildAttributes();
    // note, we rely on the fact that its a new id each time we start, see FD and "kill -9" handling
    String nodeId = UUID.randomUUID().toString();
    String host = settings.get("discovery.publish.host");
    String port = settings.get("discovery.publish.port");
    if (host != null && port != null) {
        TransportAddress address = new InetSocketTransportAddress(host, Integer.parseInt(port));
        localNode = new DiscoveryNode(settings.get("name"), nodeId, address, nodeAttributes, Version.CURRENT);
    } else {
        localNode = new DiscoveryNode(settings.get("name"), nodeId, transportService.boundAddress().publishAddress(), nodeAttributes, Version.CURRENT);
    }
    tracker.open();
    logger.debug("FabricDiscovery started");
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 48 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project incubator-skywalking by apache.

the class ElasticSearchClient method initialize.

@Override
public void initialize() throws ClientException {
    Settings settings = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", clusterTransportSniffer).build();
    client = new PreBuiltTransportClient(settings);
    List<AddressPairs> pairsList = parseClusterNodes(clusterNodes);
    for (AddressPairs pairs : pairsList) {
        try {
            ((PreBuiltTransportClient) client).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(pairs.host), pairs.port));
        } catch (UnknownHostException e) {
            throw new ElasticSearchClientException(e.getMessage(), e);
        }
    }
    this.ready = true;
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) UnknownHostException(java.net.UnknownHostException) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 49 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project ff4j by ff4j.

the class ElasticConnection method initTransportClient.

private void initTransportClient() {
    TransportClient tClient = new TransportClient();
    if (!Util.isEmpty(urlSet)) {
        for (URL url : urlSet) {
            tClient.addTransportAddress(new InetSocketTransportAddress(url.getHost(), url.getPort()));
        }
    }
    esClient = tClient;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) URL(java.net.URL)

Example 50 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project kylo by Teradata.

the class IndexElasticSearchTest method setUp.

@Before
public void setUp() throws IOException {
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    insertDocument = classloader.getResourceAsStream("elasticsearch/insert.json");
    updateDocument = classloader.getResourceAsStream("elasticsearch/update.json");
    metadataDocument = classloader.getResourceAsStream("elasticsearch/metadata.json");
    Settings settings = Settings.settingsBuilder().put("cluster.name", TEST_CLUSTER).build();
    esClient = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(TEST_HOST), 9300));
}
Also used : InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Aggregations

InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)69 TransportClient (org.elasticsearch.client.transport.TransportClient)37 Settings (org.elasticsearch.common.settings.Settings)35 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)25 UnknownHostException (java.net.UnknownHostException)17 InetSocketAddress (java.net.InetSocketAddress)11 TransportAddress (org.elasticsearch.common.transport.TransportAddress)10 HashMap (java.util.HashMap)8 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)7 Builder (org.elasticsearch.common.settings.Settings.Builder)7 ArrayList (java.util.ArrayList)6 Client (org.elasticsearch.client.Client)6 Bean (org.springframework.context.annotation.Bean)5 InetAddress (java.net.InetAddress)4 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4 Node (org.elasticsearch.node.Node)4 File (java.io.File)3 IOException (java.io.IOException)3 Properties (java.util.Properties)3