use of org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder in project sonarqube by SonarSource.
the class ProxyClusterStateRequestBuilderTest method trace_logs.
@Test
public void trace_logs() {
logTester.setLevel(LoggerLevel.TRACE);
ClusterStateRequestBuilder requestBuilder = esTester.client().prepareState();
requestBuilder.get();
assertThat(logTester.logs()).hasSize(1);
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder in project pentaho-kettle by pentaho.
the class ElasticSearchBulkDialog method test.
private void test(TestType testType) {
// Save off the thread's context class loader to restore after the test
ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
// Now ensure that the thread's context class loader is the plugin's classloader
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
Client client = null;
Node node = null;
try {
ElasticSearchBulkMeta tempMeta = new ElasticSearchBulkMeta();
toModel(tempMeta);
Settings.Builder settingsBuilder = Settings.settingsBuilder();
// keep default classloader
settingsBuilder.put(Settings.Builder.EMPTY_SETTINGS);
settingsBuilder.put(tempMeta.getSettingsMap());
TransportClient.Builder tClientBuilder = TransportClient.builder().settings(settingsBuilder);
if (!tempMeta.getServers().isEmpty()) {
node = null;
TransportClient tClient = tClientBuilder.build();
for (ElasticSearchBulkMeta.Server s : tempMeta.getServers()) {
tClient.addTransportAddress(s.getAddr());
}
client = tClient;
} else {
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();
nodeBuilder.settings(settingsBuilder);
node = nodeBuilder.client(true).node();
client = node.client();
node.start();
}
AdminClient admin = client.admin();
switch(testType) {
case INDEX:
if (StringUtils.isBlank(tempMeta.getIndex())) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulk.Error.NoIndex"));
break;
}
// First check to see if the index exists
IndicesExistsRequestBuilder indicesExistBld = admin.indices().prepareExists(tempMeta.getIndex());
IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get();
if (!indicesExistResponse.isExists()) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoIndex"));
return;
}
RecoveryRequestBuilder indicesBld = admin.indices().prepareRecoveries(tempMeta.getIndex());
ListenableActionFuture<RecoveryResponse> lafInd = indicesBld.execute();
String shards = "" + lafInd.get().getSuccessfulShards() + "/" + lafInd.get().getTotalShards();
showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", shards));
break;
case CLUSTER:
ClusterStateRequestBuilder clusterBld = admin.cluster().prepareState();
ListenableActionFuture<ClusterStateResponse> lafClu = clusterBld.execute();
ClusterStateResponse cluResp = lafClu.actionGet();
String name = cluResp.getClusterName().value();
ClusterState cluState = cluResp.getState();
int numNodes = cluState.getNodes().size();
showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestCluster.TestOK", name, numNodes));
break;
default:
break;
}
} catch (NoNodeAvailableException e) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
} catch (MasterNotDiscoveredException e) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
} catch (Exception e) {
showError(e.getLocalizedMessage());
} finally {
if (client != null) {
client.close();
}
if (node != null) {
node.close();
}
}
// Restore the original classloader
Thread.currentThread().setContextClassLoader(originalClassloader);
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder in project sonarqube by SonarSource.
the class ProxyClusterStateRequestBuilderTest method state.
@Test
public void state() {
ClusterStateRequestBuilder requestBuilder = esTester.client().prepareState();
requestBuilder.get();
}
Aggregations