use of org.elasticsearch.client.transport.TransportClient in project elasticsearch by elastic.
the class Netty4TransportMultiPortIntegrationIT method testThatTransportClientCanConnect.
public void testThatTransportClientCanConnect() throws Exception {
Settings settings = Settings.builder().put("cluster.name", internalCluster().getClusterName()).put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
try (TransportClient transportClient = new MockTransportClient(settings, Netty4Plugin.class)) {
transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), randomPort));
ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
}
}
use of org.elasticsearch.client.transport.TransportClient in project elasticsearch by elastic.
the class ESSmokeClientTestCase method startClient.
private static Client startClient(Path tempDir, TransportAddress... transportAddresses) {
Settings.Builder builder = Settings.builder().put("node.name", "qa_smoke_client_" + counter.getAndIncrement()).put("client.transport.ignore_cluster_name", true).put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
final Collection<Class<? extends Plugin>> plugins;
if (random().nextBoolean()) {
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
plugins = Collections.singleton(MockTcpTransportPlugin.class);
} else {
plugins = Collections.emptyList();
}
TransportClient client = new PreBuiltTransportClient(builder.build(), plugins).addTransportAddresses(transportAddresses);
logger.info("--> Elasticsearch Java TransportClient started");
Exception clientException = null;
try {
ClusterHealthResponse health = client.admin().cluster().prepareHealth().get();
logger.info("--> connected to [{}] cluster which is running [{}] node(s).", health.getClusterName(), health.getNumberOfNodes());
} catch (Exception e) {
clientException = e;
}
assumeNoException("Sounds like your cluster is not running at " + clusterAddresses, clientException);
return client;
}
use of org.elasticsearch.client.transport.TransportClient in project elasticsearch by elastic.
the class PreBuiltTransportClientTests method testPluginInstalled.
@Test
public void testPluginInstalled() {
try (TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)) {
Settings settings = client.settings();
assertEquals(Netty4Plugin.NETTY_TRANSPORT_NAME, NetworkModule.HTTP_DEFAULT_TYPE_SETTING.get(settings));
assertEquals(Netty4Plugin.NETTY_TRANSPORT_NAME, NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.get(settings));
}
}
use of org.elasticsearch.client.transport.TransportClient in project qi4j-sdk by Qi4j.
the class ESClusterSupport method activateElasticSearch.
@Override
protected void activateElasticSearch() throws Exception {
configuration.refresh();
ElasticSearchClusterConfiguration config = configuration.get();
String clusterName = config.clusterName().get() == null ? DEFAULT_CLUSTER_NAME : config.clusterName().get();
index = config.index().get() == null ? DEFAULT_INDEX_NAME : config.index().get();
indexNonAggregatedAssociations = config.indexNonAggregatedAssociations().get();
String[] nodes = config.nodes().get() == null ? new String[] { "localhost:9300" } : config.nodes().get().split(",");
boolean clusterSniff = config.clusterSniff().get();
boolean ignoreClusterName = config.ignoreClusterName().get();
String pingTimeout = config.pingTimeout().get() == null ? "5s" : config.pingTimeout().get();
String samplerInterval = config.samplerInterval().get() == null ? "5s" : config.samplerInterval().get();
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).put("client.transport.sniff", clusterSniff).put("client.transport.ignore_cluster_name", ignoreClusterName).put("client.transport.ping_timeout", pingTimeout).put("client.transport.nodes_sampler_interval", samplerInterval).build();
TransportClient transportClient = new TransportClient(settings);
for (String node : nodes) {
String[] split = node.split(":");
String host = split[0];
int port = Integer.valueOf(split[1]);
transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
}
client = transportClient;
}
use of org.elasticsearch.client.transport.TransportClient in project sonarqube by SonarSource.
the class EsClientProvider method provide.
public EsClient provide(Settings settings) {
if (cache == null) {
TransportClient nativeClient;
org.elasticsearch.common.settings.Settings.Builder esSettings = org.elasticsearch.common.settings.Settings.builder();
// mandatory property defined by bootstrap process
esSettings.put("cluster.name", settings.getString(ProcessProperties.CLUSTER_NAME));
boolean clusterEnabled = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
if (clusterEnabled && settings.getBoolean(ProcessProperties.CLUSTER_SEARCH_DISABLED)) {
esSettings.put("client.transport.sniff", true);
nativeClient = TransportClient.builder().settings(esSettings).build();
Arrays.stream(settings.getStringArray(ProcessProperties.CLUSTER_SEARCH_HOSTS)).map(Host::parse).forEach(h -> h.addTo(nativeClient));
LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
} else {
nativeClient = TransportClient.builder().settings(esSettings).build();
Host host = new Host(settings.getString(ProcessProperties.SEARCH_HOST), settings.getInt(ProcessProperties.SEARCH_PORT));
host.addTo(nativeClient);
LOGGER.info("Connected to local Elasticsearch: [{}]", displayedAddresses(nativeClient));
}
cache = new EsClient(nativeClient);
}
return cache;
}
Aggregations