Search in sources :

Example 36 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class RestPluginsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(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 clusterStateResponse) throws Exception {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().plugins(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {

                @Override
                public RestResponse buildResponse(final NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
Also used : PluginInfo(org.elasticsearch.plugins.PluginInfo) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 37 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class RestTemplatesAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    final String matchPattern = request.hasParam("name") ? request.param("name") : null;
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().metaData(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestResponseListener<ClusterStateResponse>(channel) {

        @Override
        public RestResponse buildResponse(ClusterStateResponse clusterStateResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, clusterStateResponse, matchPattern), channel);
        }
    });
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Regex(org.elasticsearch.common.regex.Regex) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)

Example 38 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class RestSegmentsAction method doCatRequest.

@Override
protected 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).routingTable(true).indices(indices);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {

                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
Also used : IndicesSegmentResponse(org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) GET(org.elasticsearch.rest.RestRequest.Method.GET) IndicesSegmentsRequest(org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest) RestResponse(org.elasticsearch.rest.RestResponse) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) Segment(org.elasticsearch.index.engine.Segment) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments) Map(java.util.Map) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) Table(org.elasticsearch.common.Table) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) IndicesSegmentResponse(org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse) IndicesSegmentsRequest(org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments)

Example 39 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class IndicesLifecycleListenerIT method testBeforeIndexAddedToCluster.

public void testBeforeIndexAddedToCluster() throws Exception {
    String node1 = internalCluster().startNode();
    String node2 = internalCluster().startNode();
    String node3 = internalCluster().startNode();
    final AtomicInteger beforeAddedCount = new AtomicInteger(0);
    final AtomicInteger allCreatedCount = new AtomicInteger(0);
    IndexEventListener listener = new IndexEventListener() {

        @Override
        public void beforeIndexAddedToCluster(Index index, Settings indexSettings) {
            beforeAddedCount.incrementAndGet();
            if (MockIndexEventListener.TestPlugin.INDEX_FAIL.get(indexSettings)) {
                throw new ElasticsearchException("failing on purpose");
            }
        }

        @Override
        public void beforeIndexCreated(Index index, Settings indexSettings) {
            allCreatedCount.incrementAndGet();
        }
    };
    internalCluster().getInstance(MockIndexEventListener.TestEventListener.class, node1).setNewDelegate(listener);
    internalCluster().getInstance(MockIndexEventListener.TestEventListener.class, node2).setNewDelegate(listener);
    internalCluster().getInstance(MockIndexEventListener.TestEventListener.class, node3).setNewDelegate(listener);
    client().admin().indices().prepareCreate("test").setSettings(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3, IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).get();
    ensureGreen("test");
    assertThat("beforeIndexAddedToCluster called only once", beforeAddedCount.get(), equalTo(1));
    assertThat("beforeIndexCreated called on each data node", allCreatedCount.get(), greaterThanOrEqualTo(3));
    try {
        client().admin().indices().prepareCreate("failed").setSettings("index.fail", true).get();
        fail("should have thrown an exception during creation");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("failing on purpose"));
        ClusterStateResponse resp = client().admin().cluster().prepareState().get();
        assertFalse(resp.getState().routingTable().indicesRouting().keys().contains("failed"));
    }
}
Also used : MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) Index(org.elasticsearch.index.Index) ElasticsearchException(org.elasticsearch.ElasticsearchException) Settings(org.elasticsearch.common.settings.Settings) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 40 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class GetClusterStateTests method testSizeDerivedFromFullClusterState.

public void testSizeDerivedFromFullClusterState() {
    ClusterStateResponse response = client().admin().cluster().prepareState().get();
    final ClusterState clusterState = response.getState();
    final long totalCompressedSize = response.getTotalCompressedSize().getBytes();
    // exclude the nodes from being returned, the total size returned should still be
    // the same as when no filtering was applied to the cluster state retrieved
    response = client().admin().cluster().prepareState().setNodes(false).get();
    assertEquals(totalCompressedSize, response.getTotalCompressedSize().getBytes());
    assertNotEquals(clusterState, response.getState());
    assertEquals(0, response.getState().nodes().getSize());
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Aggregations

ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)52 Settings (org.elasticsearch.common.settings.Settings)20 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)18 NodeClient (org.elasticsearch.client.node.NodeClient)12 RestController (org.elasticsearch.rest.RestController)12 RestRequest (org.elasticsearch.rest.RestRequest)12 RestResponse (org.elasticsearch.rest.RestResponse)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)10 Table (org.elasticsearch.common.Table)10 GET (org.elasticsearch.rest.RestRequest.Method.GET)10 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)10 ClusterState (org.elasticsearch.cluster.ClusterState)9 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)8 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)8 RestActionListener (org.elasticsearch.rest.action.RestActionListener)8 Strings (org.elasticsearch.common.Strings)7 MetaData (org.elasticsearch.cluster.metadata.MetaData)6 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)6 IOException (java.io.IOException)5