Search in sources :

Example 11 with InetSocketTransportAddress

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

the class AbstractNodeTest method createIndices.

@BeforeMethod
public void createIndices() throws Exception {
    startNode("1");
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
    NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
    InetSocketTransportAddress address = (InetSocketTransportAddress) response.iterator().next().getTransport().getAddress().publishAddress();
    addresses.put("1", address);
    client("1").admin().indices().create(new CreateIndexRequest(INDEX)).actionGet();
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project storm-elastic-search by hmsonline.

the class ElasticSearchBolt method prepare.

@Override
@SuppressWarnings("rawtypes")
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    String elasticSearchHost = (String) stormConf.get(StormElasticSearchConstants.ES_HOST);
    Integer elasticSearchPort = ((Long) stormConf.get(StormElasticSearchConstants.ES_PORT)).intValue();
    String elasticSearchCluster = (String) stormConf.get(StormElasticSearchConstants.ES_CLUSTER_NAME);
    Boolean localMode = (Boolean) stormConf.get(ELASTIC_LOCAL_MODE);
    if (localMode != null && localMode) {
        client = nodeBuilder().local(true).node().client();
    } else {
        Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", elasticSearchCluster).build();
        client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(elasticSearchHost, elasticSearchPort));
    }
}
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 13 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project storm-elastic-search by hmsonline.

the class ElasticSearchFunction method prepare.

@SuppressWarnings("rawtypes")
@Override
public void prepare(Map conf, TridentOperationContext context) {
    super.prepare(conf, context);
    String clusterName = (String) conf.get(StormElasticSearchConstants.ES_CLUSTER_NAME);
    String host = (String) conf.get(StormElasticSearchConstants.ES_HOST);
    Integer port = (Integer) conf.get(StormElasticSearchConstants.ES_PORT);
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build();
    client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(host, port));
}
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 14 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project elasticsearch-jetty by sonian.

the class JettyHttpServerTransport method doStart.

@Override
protected void doStart() throws ElasticsearchException {
    PortsRange portsRange = new PortsRange(port);
    final AtomicReference<Exception> lastException = new AtomicReference<Exception>();
    Log.setLog(loggerWrapper);
    portsRange.iterate(new PortsRange.PortCallback() {

        @Override
        public boolean onPortNumber(int portNumber) {
            try {
                Server server = null;
                XmlConfiguration lastXmlConfiguration = null;
                Object[] objs = new Object[jettyConfig.length];
                Map<String, String> esProperties = jettySettings(bindHost, portNumber);
                for (int i = 0; i < jettyConfig.length; i++) {
                    String configFile = jettyConfig[i];
                    URL config = environment.resolveConfig(configFile);
                    XmlConfiguration xmlConfiguration = new XmlConfiguration(config);
                    // in the later configurations
                    if (lastXmlConfiguration != null) {
                        xmlConfiguration.getIdMap().putAll(lastXmlConfiguration.getIdMap());
                    } else {
                        xmlConfiguration.getIdMap().put("ESServerTransport", JettyHttpServerTransport.this);
                        xmlConfiguration.getIdMap().put("ESClient", client);
                    }
                    // Inject elasticsearch properties
                    xmlConfiguration.getProperties().putAll(esProperties);
                    objs[i] = xmlConfiguration.configure();
                    lastXmlConfiguration = xmlConfiguration;
                }
                // Find jetty Server with id  jettyConfigServerId
                Object serverObject = lastXmlConfiguration.getIdMap().get(jettyConfigServerId);
                if (serverObject != null) {
                    if (serverObject instanceof Server) {
                        server = (Server) serverObject;
                    }
                } else {
                    // For compatibility - if it's not available, find first available jetty Server
                    for (Object obj : objs) {
                        if (obj instanceof Server) {
                            server = (Server) obj;
                            break;
                        }
                    }
                }
                if (server == null) {
                    logger.error("Cannot find server with id [{}] in configuration files [{}]", jettyConfigServerId, jettyConfig);
                    lastException.set(new ElasticsearchException("Cannot find server with id " + jettyConfigServerId));
                    return true;
                }
                // Keep it for now for backward compatibility with previous versions of jetty.xml
                server.setAttribute(TRANSPORT_ATTRIBUTE, JettyHttpServerTransport.this);
                // Start all lifecycle objects configured by xml configurations
                for (Object obj : objs) {
                    if (obj instanceof LifeCycle) {
                        LifeCycle lifeCycle = (LifeCycle) obj;
                        if (!lifeCycle.isRunning()) {
                            lifeCycle.start();
                        }
                    }
                }
                jettyServer = server;
                lastException.set(null);
            } catch (BindException e) {
                lastException.set(e);
                return false;
            } catch (Exception e) {
                logger.error("Jetty Startup Failed ", e);
                lastException.set(e);
                return true;
            }
            return true;
        }
    });
    if (lastException.get() != null) {
        throw new BindHttpException("Failed to bind to [" + port + "]", lastException.get());
    }
    InetSocketAddress jettyBoundAddress = findFirstInetConnector(jettyServer);
    if (jettyBoundAddress != null) {
        InetSocketAddress publishAddress;
        try {
            publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), jettyBoundAddress.getPort());
        } catch (Exception e) {
            throw new BindTransportException("Failed to resolve publish address", e);
        }
        this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(jettyBoundAddress), new InetSocketTransportAddress(publishAddress));
    } else {
        throw new BindHttpException("Failed to find a jetty connector with Inet transport");
    }
}
Also used : LifeCycle(org.eclipse.jetty.util.component.LifeCycle) Server(org.eclipse.jetty.server.Server) AtomicReference(java.util.concurrent.atomic.AtomicReference) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ElasticsearchException(org.elasticsearch.ElasticsearchException) PortsRange(org.elasticsearch.common.transport.PortsRange) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) ElasticsearchException(org.elasticsearch.ElasticsearchException) BindTransportException(org.elasticsearch.transport.BindTransportException) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) Map(java.util.Map)

Example 15 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project elasticsearch-suggest-plugin by spinscale.

the class RestSuggestActionTest method setPort.

@Before
public void setPort() {
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().setHttp(true).execute().actionGet();
    port = ((InetSocketTransportAddress) response.getNodes()[0].getHttp().address().boundAddress()).address().getPort();
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Before(org.junit.Before)

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