Search in sources :

Example 1 with IndicesSegmentsRequest

use of org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest in project OpenSearch by opensearch-project.

the class RestIndicesSegmentsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(Strings.splitStringByCommaToArray(request.param("index")));
    indicesSegmentsRequest.verbose(request.paramAsBoolean("verbose", false));
    indicesSegmentsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesSegmentsRequest.indicesOptions()));
    return channel -> client.admin().indices().segments(indicesSegmentsRequest, new RestToXContentListener<>(channel));
}
Also used : List(java.util.List) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Arrays.asList(java.util.Arrays.asList) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Strings(org.opensearch.common.Strings) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest)

Example 2 with IndicesSegmentsRequest

use of org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest in project OpenSearch by opensearch-project.

the class IndicesRequestIT method testSegments.

public void testSegments() {
    String segmentsAction = IndicesSegmentsAction.NAME + "[n]";
    interceptTransportActions(segmentsAction);
    IndicesSegmentsRequest segmentsRequest = new IndicesSegmentsRequest(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().segments(segmentsRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(segmentsRequest, segmentsAction);
}
Also used : IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest)

Example 3 with IndicesSegmentsRequest

use of org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest in project OpenSearch by opensearch-project.

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 : ShardSegments(org.opensearch.action.admin.indices.segments.ShardSegments) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments) RestRequest(org.opensearch.rest.RestRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) Table(org.opensearch.common.Table) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Segment(org.opensearch.index.engine.Segment) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) Table(org.opensearch.common.Table) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments)

Aggregations

IndicesSegmentsRequest (org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest)3 Arrays.asList (java.util.Arrays.asList)2 Collections.unmodifiableList (java.util.Collections.unmodifiableList)2 List (java.util.List)2 NodeClient (org.opensearch.client.node.NodeClient)2 Strings (org.opensearch.common.Strings)2 RestRequest (org.opensearch.rest.RestRequest)2 GET (org.opensearch.rest.RestRequest.Method.GET)2 IOException (java.io.IOException)1 Map (java.util.Map)1 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 IndexSegments (org.opensearch.action.admin.indices.segments.IndexSegments)1 IndexShardSegments (org.opensearch.action.admin.indices.segments.IndexShardSegments)1 IndicesSegmentResponse (org.opensearch.action.admin.indices.segments.IndicesSegmentResponse)1 ShardSegments (org.opensearch.action.admin.indices.segments.ShardSegments)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)1 Table (org.opensearch.common.Table)1 Segment (org.opensearch.index.engine.Segment)1