Search in sources :

Example 1 with RestResponseListener

use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.

the class RestNodesHotThreadsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    NodesHotThreadsRequest nodesHotThreadsRequest = new NodesHotThreadsRequest(nodesIds);
    nodesHotThreadsRequest.threads(request.paramAsInt("threads", nodesHotThreadsRequest.threads()));
    nodesHotThreadsRequest.ignoreIdleThreads(request.paramAsBoolean("ignore_idle_threads", nodesHotThreadsRequest.ignoreIdleThreads()));
    nodesHotThreadsRequest.type(request.param("type", nodesHotThreadsRequest.type()));
    nodesHotThreadsRequest.interval(TimeValue.parseTimeValue(request.param("interval"), nodesHotThreadsRequest.interval(), "interval"));
    nodesHotThreadsRequest.snapshots(request.paramAsInt("snapshots", nodesHotThreadsRequest.snapshots()));
    nodesHotThreadsRequest.timeout(request.param("timeout"));
    return channel -> client.admin().cluster().nodesHotThreads(nodesHotThreadsRequest, new RestResponseListener<NodesHotThreadsResponse>(channel) {

        @Override
        public RestResponse buildResponse(NodesHotThreadsResponse response) throws Exception {
            StringBuilder sb = new StringBuilder();
            for (NodeHotThreads node : response.getNodes()) {
                sb.append("::: ").append(node.getNode().toString()).append("\n");
                Strings.spaceify(3, node.getHotThreads(), sb);
                sb.append('\n');
            }
            return new BytesRestResponse(RestStatus.OK, sb.toString());
        }
    });
}
Also used : TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) NodesHotThreadsRequest(org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest) GET(org.opensearch.rest.RestRequest.Method.GET) NodesHotThreadsResponse(org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) NodeHotThreads(org.opensearch.action.admin.cluster.node.hotthreads.NodeHotThreads) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) List(java.util.List) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) BaseRestHandler(org.opensearch.rest.BaseRestHandler) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NodesHotThreadsRequest(org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) BytesRestResponse(org.opensearch.rest.BytesRestResponse) NodeHotThreads(org.opensearch.action.admin.cluster.node.hotthreads.NodeHotThreads) NodesHotThreadsResponse(org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse) IOException(java.io.IOException)

Example 2 with RestResponseListener

use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.

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 : IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) NodeClient(org.opensearch.client.node.NodeClient) Metadata(org.opensearch.cluster.metadata.Metadata) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) Regex(org.opensearch.common.regex.Regex) RestResponse(org.opensearch.rest.RestResponse) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Map(java.util.Map) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest)

Example 3 with RestResponseListener

use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.

the class RestPendingClusterTasksAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
    pendingClusterTasksRequest.masterNodeTimeout(request.paramAsTime("master_timeout", pendingClusterTasksRequest.masterNodeTimeout()));
    pendingClusterTasksRequest.local(request.paramAsBoolean("local", pendingClusterTasksRequest.local()));
    return channel -> client.admin().cluster().pendingClusterTasks(pendingClusterTasksRequest, new RestResponseListener<PendingClusterTasksResponse>(channel) {

        @Override
        public RestResponse buildResponse(PendingClusterTasksResponse pendingClusterTasks) throws Exception {
            Table tab = buildTable(request, pendingClusterTasks);
            return RestTable.buildResponse(tab, channel);
        }
    });
}
Also used : PendingClusterTasksResponse(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksResponse) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) PendingClusterTasksRequest(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksRequest) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Table(org.opensearch.common.Table) PendingClusterTask(org.opensearch.cluster.service.PendingClusterTask) RestResponse(org.opensearch.rest.RestResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) Collections.singletonList(java.util.Collections.singletonList) Table(org.opensearch.common.Table) PendingClusterTasksResponse(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksResponse) RestResponse(org.opensearch.rest.RestResponse) PendingClusterTasksRequest(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksRequest)

Example 4 with RestResponseListener

use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.

the class RestSnapshotAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest().repository(request.param("repository")).snapshots(new String[] { GetSnapshotsRequest.ALL_SNAPSHOTS });
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
        }
    });
}
Also used : TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) Table(org.opensearch.common.Table) SnapshotState(org.opensearch.snapshots.SnapshotState) Instant(java.time.Instant) RestResponse(org.opensearch.rest.RestResponse) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Arrays.asList(java.util.Arrays.asList) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) ZoneOffset(java.time.ZoneOffset) DateFormatter(org.opensearch.common.time.DateFormatter) RestResponseListener(org.opensearch.rest.action.RestResponseListener) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestResponse(org.opensearch.rest.RestResponse)

Example 5 with RestResponseListener

use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.

the class RestThreadPoolAction 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) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.timeout(request.param("timeout"));
            nodesInfoRequest.clear().addMetrics(NodesInfoRequest.Metric.PROCESS.metricName(), NodesInfoRequest.Metric.THREAD_POOL.metricName());
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {

                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.timeout(request.param("timeout"));
                    nodesStatsRequest.clear().addMetric(NodesStatsRequest.Metric.THREAD_POOL.metricName());
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Collections.unmodifiableList(java.util.Collections.unmodifiableList) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) Table(org.opensearch.common.Table) HashMap(java.util.HashMap) Regex(org.opensearch.common.regex.Regex) HashSet(java.util.HashSet) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ThreadPoolInfo(org.opensearch.threadpool.ThreadPoolInfo) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest) Set(java.util.Set) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) RestResponse(org.opensearch.rest.RestResponse) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) TreeMap(java.util.TreeMap) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) NodesStatsRequest(org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest) Collections(java.util.Collections) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) NodesStatsRequest(org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Aggregations

List (java.util.List)18 NodeClient (org.opensearch.client.node.NodeClient)18 RestRequest (org.opensearch.rest.RestRequest)18 GET (org.opensearch.rest.RestRequest.Method.GET)18 RestResponse (org.opensearch.rest.RestResponse)18 RestResponseListener (org.opensearch.rest.action.RestResponseListener)18 Table (org.opensearch.common.Table)17 Arrays.asList (java.util.Arrays.asList)12 Collections.unmodifiableList (java.util.Collections.unmodifiableList)12 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)10 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)10 Strings (org.opensearch.common.Strings)9 Collections.singletonList (java.util.Collections.singletonList)6 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)6 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)6 RestActionListener (org.opensearch.rest.action.RestActionListener)6 Locale (java.util.Locale)5 Map (java.util.Map)5 TimeValue (org.opensearch.common.unit.TimeValue)5 NodeInfo (org.opensearch.action.admin.cluster.node.info.NodeInfo)4