Search in sources :

Example 61 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project vertigo by KleeGroup.

the class ESTransportSearchServicesPlugin method createClient.

/**
 * {@inheritDoc}
 */
@Override
protected Client createClient() {
    client = new PreBuiltTransportClient(buildNodeSettings());
    for (final String serverName : serversNames) {
        final String[] serverNameSplit = serverName.split(":");
        Assertion.checkArgument(serverNameSplit.length == 2, "La déclaration du serveur doit être au format host:port ({0}", serverName);
        final int port = Integer.parseInt(serverNameSplit[1]);
        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(serverNameSplit[0], port)));
    }
    return client;
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) InetSocketAddress(java.net.InetSocketAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 62 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project vertigo by KleeGroup.

the class ESTransportSearchServicesPlugin method createClient.

/**
 * {@inheritDoc}
 */
@Override
protected Client createClient() {
    client = TransportClient.builder().settings(buildNodeSettings()).build();
    for (final String serverName : serversNames) {
        final String[] serverNameSplit = serverName.split(":");
        Assertion.checkArgument(serverNameSplit.length == 2, "La déclaration du serveur doit être au format host:port ({0}", serverName);
        final int port = Integer.parseInt(serverNameSplit[1]);
        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(serverNameSplit[0], port)));
    }
    return client;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 63 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project arctic-sea by 52North.

the class KibanaExporter method main.

// CHECKSTYLE:OFF
public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.out.printf("Usage: java KibanaExporter.jar %s %s%n", "localhost:9300", "my-cluster-name");
        System.exit(0);
    }
    if (!args[0].contains(":")) {
        throw new IllegalArgumentException(String.format("%s not a valid format. Expected <hostname>:<port>.", args[0]));
    }
    // set ES address
    String[] split = args[0].split(":");
    InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getByName(split[0]), Integer.parseInt(split[1], 10));
    // set cluster name
    Builder tcSettings = Settings.settingsBuilder();
    tcSettings.put("cluster.name", args[1]);
    System.out.println("Connection to " + args[1]);
    client = TransportClient.builder().settings(tcSettings).build();
    client.addTransportAddress(address);
    // search index pattern for needle
    searchIndexPattern();
    KibanaConfigHolderDto holder = new KibanaConfigHolderDto();
    System.out.println("Reading .kibana index");
    SearchResponse resp = client.prepareSearch(".kibana").setSize(1000).get();
    Arrays.asList(resp.getHits().getHits()).stream().map(KibanaExporter::parseSearchHit).forEach(holder::add);
    System.out.println("Reading finished");
    ObjectMapper mapper = new ObjectMapper();
    // we love pretty things
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    File f = new File("kibana_config.json");
    try (FileOutputStream out = new FileOutputStream(f, false)) {
        mapper.writeValue(out, holder);
    }
    System.out.println("File outputted to: " + f.getAbsolutePath());
    client.close();
}
Also used : KibanaConfigHolderDto(org.n52.iceland.statistics.api.utils.dto.KibanaConfigHolderDto) Builder(org.elasticsearch.common.settings.Settings.Builder) FileOutputStream(java.io.FileOutputStream) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 64 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project samza by apache.

the class TransportClientFactory method getClient.

@Override
public Client getClient() {
    Settings settings = Settings.settingsBuilder().put(clientSettings).build();
    TransportAddress address = new InetSocketTransportAddress(new InetSocketAddress(transportHost, transportPort));
    return TransportClient.builder().settings(settings).build().addTransportAddress(address);
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) InetSocketAddress(java.net.InetSocketAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 65 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project jstorm by alibaba.

the class EsConfig method getTransportAddresses.

List<TransportAddress> getTransportAddresses() throws UnknownHostException {
    List<TransportAddress> transportAddresses = Lists.newArrayList();
    for (String node : nodes) {
        String[] hostAndPort = node.split(DELIMITER);
        Preconditions.checkArgument(hostAndPort.length == 2, "Incorrect node format");
        String host = hostAndPort[0];
        int port = Integer.parseInt(hostAndPort[1]);
        InetSocketTransportAddress inetSocketTransportAddress = new InetSocketTransportAddress(InetAddress.getByName(host), port);
        transportAddresses.add(inetSocketTransportAddress);
    }
    return transportAddresses;
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

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