Search in sources :

Example 21 with InetSocketTransportAddress

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

the class PostgresNetty method bindAddress.

private InetSocketTransportAddress bindAddress(final InetAddress hostAddress) {
    PortsRange portsRange = new PortsRange(port);
    final AtomicReference<Exception> lastException = new AtomicReference<>();
    final AtomicReference<InetSocketAddress> boundSocket = new AtomicReference<>();
    boolean success = portsRange.iterate(new PortsRange.PortCallback() {

        @Override
        public boolean onPortNumber(int portNumber) {
            try {
                synchronized (serverChannels) {
                    Channel channel = bootstrap.bind(new InetSocketAddress(hostAddress, portNumber));
                    serverChannels.add(channel);
                    boundSocket.set((InetSocketAddress) channel.getLocalAddress());
                }
            } catch (Exception e) {
                lastException.set(e);
                return false;
            }
            return true;
        }
    });
    if (!success) {
        throw new BindPostgresException("Failed to bind to [" + port + "]", lastException.get());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Bound psql to address {{}}", NetworkAddress.format(boundSocket.get()));
    }
    return new InetSocketTransportAddress(boundSocket.get());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) AtomicReference(java.util.concurrent.atomic.AtomicReference) PortsRange(org.elasticsearch.common.transport.PortsRange) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) BindHttpException(org.elasticsearch.http.BindHttpException) IOException(java.io.IOException)

Example 22 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project wonderdog by infochimps-labs.

the class ElasticSearchStreamingInputFormat method startTransportClient.

//
// == Connecting to Elasticsearch and Querying ==
// 
private void startTransportClient(JobConf conf) {
    this.client = new TransportClient();
    Map<String, String> settings = parsedSettings(conf);
    String host = hostname(settings);
    if (host.toString().length() == 0) {
        System.exit(1);
    }
    LOG.info("Attempting to connect to Elasticsearch node at " + host + ":9300");
    this.client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(host, 9300));
    LOG.info("Connected to Elasticsearch cluster");
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 23 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project wonderdog by infochimps-labs.

the class ElasticSearchStreamingRecordWriter method buildTransportClient.

/**
       Build a transport client that will connect to some
       Elasticsearch node.
       
     */
private Client buildTransportClient() {
    LOG.info("Connecting transport client to " + transportHost + ":" + Integer.toString(transportPort));
    Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.ignore_cluster_name", "true").build();
    return new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(transportHost, transportPort));
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 24 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project elasticsearch-jdbc by jprante.

the class NodeTestUtils method findNodeAddresses.

protected void findNodeAddresses() {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    Iterator<NodeInfo> it = response.iterator();
    hosts = new LinkedList<>();
    hosts = new LinkedList<>();
    while (it.hasNext()) {
        NodeInfo nodeInfo = it.next();
        TransportInfo transportInfo = nodeInfo.getTransport();
        TransportAddress address = transportInfo.getAddress().publishAddress();
        if (address instanceof InetSocketTransportAddress) {
            InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) address;
            hosts.add(inetSocketTransportAddress.address().getHostName() + ":" + inetSocketTransportAddress.address().getPort());
        }
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) TransportInfo(org.elasticsearch.transport.TransportInfo) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 25 with InetSocketTransportAddress

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

the class ElasticsearchClusterBaseTest method cleanUpOnce.

@BeforeClass
public static void cleanUpOnce() throws Exception {
    deleteDirectory("target/testcluster/");
    clusterName = "es-cl-run-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {

        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(3).basePath("target/testcluster/").useLogger());
    // wait for green status
    runner.ensureGreen();
    client = new PreBuiltTransportClient(getSettings()).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9301));
}
Also used : ElasticsearchClusterRunner(org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) Builder(org.elasticsearch.common.settings.Settings.Builder) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) BeforeClass(org.junit.BeforeClass)

Aggregations

InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)35 TransportClient (org.elasticsearch.client.transport.TransportClient)15 Settings (org.elasticsearch.common.settings.Settings)14 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)7 TransportAddress (org.elasticsearch.common.transport.TransportAddress)7 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)7 InetSocketAddress (java.net.InetSocketAddress)5 UnknownHostException (java.net.UnknownHostException)5 IOException (java.io.IOException)4 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)3 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Logger (org.apache.log4j.Logger)2 ElasticsearchClusterRunner (org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner)2