Search in sources :

Example 1 with RestActionListener

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

the class RestGetMappingAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
    getMappingsRequest.indices(indices);
    getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
    final TimeValue timeout = request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout());
    getMappingsRequest.masterNodeTimeout(timeout);
    getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
    return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestActionListener<GetMappingsResponse>(channel) {

        @Override
        protected void processResponse(GetMappingsResponse getMappingsResponse) {
            final long startTimeMs = threadPool.relativeTimeInMillis();
            // Process serialization on GENERIC pool since the serialization of the raw mappings to XContent can be too slow to execute
            // on an IO thread
            threadPool.executor(ThreadPool.Names.MANAGEMENT).execute(ActionRunnable.wrap(this, l -> new RestBuilderListener<GetMappingsResponse>(channel) {

                @Override
                public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {
                    if (threadPool.relativeTimeInMillis() - startTimeMs > timeout.millis()) {
                        throw new OpenSearchTimeoutException("Timed out getting mappings");
                    }
                    builder.startObject();
                    response.toXContent(builder, request);
                    builder.endObject();
                    return new BytesRestResponse(RestStatus.OK, builder);
                }
            }.onResponse(getMappingsResponse)));
        }
    });
}
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) ActionRunnable(org.opensearch.action.ActionRunnable) RestRequest(org.opensearch.rest.RestRequest) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) RestStatus(org.opensearch.rest.RestStatus) GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) RestActionListener(org.opensearch.rest.action.RestActionListener) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) BytesRestResponse(org.opensearch.rest.BytesRestResponse) GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) TimeValue(org.opensearch.common.unit.TimeValue) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 2 with RestActionListener

use of org.opensearch.rest.action.RestActionListener 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)

Example 3 with RestActionListener

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

the class RestNodeAttrsAction 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().addMetric(NodesInfoRequest.Metric.PROCESS.metricName());
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {

                @Override
                public RestResponse buildResponse(NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) 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) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) List(java.util.List) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) Map(java.util.Map) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 4 with RestActionListener

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

the class RestNodesAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    if (request.hasParam("local")) {
        deprecationLogger.deprecate("cat_nodes_local_parameter", LOCAL_DEPRECATED_MESSAGE);
    }
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    final boolean fullId = request.paramAsBoolean("full_id", false);
    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.JVM.metricName(), NodesInfoRequest.Metric.OS.metricName(), NodesInfoRequest.Metric.PROCESS.metricName(), NodesInfoRequest.Metric.HTTP.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().indices(true).addMetrics(NodesStatsRequest.Metric.JVM.metricName(), NodesStatsRequest.Metric.OS.metricName(), NodesStatsRequest.Metric.FS.metricName(), NodesStatsRequest.Metric.PROCESS.metricName(), NodesStatsRequest.Metric.SCRIPT.metricName());
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(fullId, request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) SearchStats(org.opensearch.index.search.stats.SearchStats) HttpInfo(org.opensearch.http.HttpInfo) Table(org.opensearch.common.Table) RequestCacheStats(org.opensearch.index.cache.request.RequestCacheStats) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) OsStats(org.opensearch.monitor.os.OsStats) MergeStats(org.opensearch.index.merge.MergeStats) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) RefreshStats(org.opensearch.index.refresh.RefreshStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) Locale(java.util.Locale) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) SegmentsStats(org.opensearch.index.engine.SegmentsStats) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NetworkAddress(org.opensearch.common.network.NetworkAddress) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats) 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) ScriptStats(org.opensearch.script.ScriptStats) FlushStats(org.opensearch.index.flush.FlushStats) IndexingStats(org.opensearch.index.shard.IndexingStats) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) NodeIndicesStats(org.opensearch.indices.NodeIndicesStats) Collectors(java.util.stream.Collectors) GetStats(org.opensearch.index.get.GetStats) RestResponse(org.opensearch.rest.RestResponse) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) TransportAddress(org.opensearch.common.transport.TransportAddress) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) 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) ProcessStats(org.opensearch.monitor.process.ProcessStats) FsInfo(org.opensearch.monitor.fs.FsInfo) 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)

Example 5 with RestActionListener

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

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.timeout(request.param("timeout"));
            nodesInfoRequest.clear().addMetric(NodesInfoRequest.Metric.PLUGINS.metricName());
            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 : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) 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) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) PluginInfo(org.opensearch.plugins.PluginInfo) RestResponse(org.opensearch.rest.RestResponse) Collections.singletonList(java.util.Collections.singletonList) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) List(java.util.List) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) PluginsAndModules(org.opensearch.action.admin.cluster.node.info.PluginsAndModules) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Aggregations

List (java.util.List)8 NodeClient (org.opensearch.client.node.NodeClient)8 RestRequest (org.opensearch.rest.RestRequest)8 GET (org.opensearch.rest.RestRequest.Method.GET)8 RestResponse (org.opensearch.rest.RestResponse)8 RestActionListener (org.opensearch.rest.action.RestActionListener)8 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)7 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)7 Table (org.opensearch.common.Table)7 Strings (org.opensearch.common.Strings)6 RestResponseListener (org.opensearch.rest.action.RestResponseListener)6 Arrays.asList (java.util.Arrays.asList)5 Collections.unmodifiableList (java.util.Collections.unmodifiableList)5 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)5 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)5 NodeInfo (org.opensearch.action.admin.cluster.node.info.NodeInfo)4 NodesInfoRequest (org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)4 NodesInfoResponse (org.opensearch.action.admin.cluster.node.info.NodesInfoResponse)4 Collections.singletonList (java.util.Collections.singletonList)3 Map (java.util.Map)3