use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class RestAllocationAction method doCatRequest.
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes", "data:true"));
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.clear().routingTable(true);
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
@Override
public void processResponse(final ClusterStateResponse state) {
NodesStatsRequest statsRequest = new NodesStatsRequest(nodes);
statsRequest.clear().fs(true).indices(new CommonStatsFlags(CommonStatsFlags.Flag.Store));
client.admin().cluster().nodesStats(statsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
@Override
public RestResponse buildResponse(NodesStatsResponse stats) throws Exception {
Table tab = buildTable(request, state, stats);
return RestTable.buildResponse(tab, channel);
}
});
}
});
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class RestShardsAction method doCatRequest.
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
clusterStateRequest.clear().nodes(true).metaData(true).routingTable(true).indices(indices);
return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
@Override
public void processResponse(final ClusterStateResponse clusterStateResponse) {
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.all();
indicesStatsRequest.indices(indices);
client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {
@Override
public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel);
}
});
}
});
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class SimpleClusterStateIT method testNodes.
public void testNodes() throws Exception {
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().setNodes(true).get();
assertThat(clusterStateResponse.getState().nodes().getNodes().size(), is(cluster().size()));
ClusterStateResponse clusterStateResponseFiltered = client().admin().cluster().prepareState().clear().get();
assertThat(clusterStateResponseFiltered.getState().nodes().getNodes().size(), is(0));
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class SimpleClusterStateIT method testIndicesOptions.
public void testIndicesOptions() throws Exception {
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("f*").get();
assertThat(clusterStateResponse.getState().metaData().indices().size(), is(2));
// close one index
client().admin().indices().close(Requests.closeIndexRequest("fuu")).get();
clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("f*").get();
assertThat(clusterStateResponse.getState().metaData().indices().size(), is(1));
assertThat(clusterStateResponse.getState().metaData().index("foo").getState(), equalTo(IndexMetaData.State.OPEN));
// expand_wildcards_closed should toggle return only closed index fuu
IndicesOptions expandCloseOptions = IndicesOptions.fromOptions(false, true, false, true);
clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("f*").setIndicesOptions(expandCloseOptions).get();
assertThat(clusterStateResponse.getState().metaData().indices().size(), is(1));
assertThat(clusterStateResponse.getState().metaData().index("fuu").getState(), equalTo(IndexMetaData.State.CLOSE));
// ignore_unavailable set to true should not raise exception on fzzbzz
IndicesOptions ignoreUnavailabe = IndicesOptions.fromOptions(true, true, true, false);
clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("fzzbzz").setIndicesOptions(ignoreUnavailabe).get();
assertThat(clusterStateResponse.getState().metaData().indices().isEmpty(), is(true));
// empty wildcard expansion result should work when allowNoIndices is
// turned on
IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false);
clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("a*").setIndicesOptions(allowNoIndices).get();
assertThat(clusterStateResponse.getState().metaData().indices().isEmpty(), is(true));
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class SimpleClusterStateIT method testIndexTemplates.
public void testIndexTemplates() throws Exception {
client().admin().indices().preparePutTemplate("foo_template").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).get();
client().admin().indices().preparePutTemplate("fuu_template").setPatterns(Collections.singletonList("test*")).setOrder(1).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field2").field("type", "text").field("store", false).endObject().endObject().endObject().endObject()).get();
ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().get();
assertThat(clusterStateResponseUnfiltered.getState().metaData().templates().size(), is(greaterThanOrEqualTo(2)));
GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates("foo_template").get();
assertIndexTemplateExists(getIndexTemplatesResponse, "foo_template");
}
Aggregations