Adds nodes usage API to monitor usages of actions (#24169)

* Adds nodes usage API to monitor usages of actions

The nodes usage API has 2 main endpoints

/_nodes/usage and /_nodes/{nodeIds}/usage return the usage statistics
for all nodes and the specified node(s) respectively.

At the moment only one type of usage statistics is available, the REST
actions usage. This records the number of times each REST action class is
called and when the nodes usage api is called will return a map of rest
action class name to long representing the number of times each of the action
classes has been called.

Still to do:

* [x] Create usage service to store usage statistics
* [x] Record usage in REST layer
* [x] Add Transport Actions
* [x] Add REST Actions
* [x] Tests
* [x] Documentation

* Rafactors UsageService so counts are done by the handlers

* Fixing up docs tests

* Adds a name to all rest actions

* Addresses review comments
This commit is contained in:
Colin Goodheart-Smithe 2017-06-02 08:46:38 +01:00 committed by GitHub
parent 528bd25fa7
commit 779fb9a1c0
146 changed files with 1788 additions and 27 deletions

View File

@ -57,6 +57,11 @@ public class RestNoopBulkAction extends BaseRestHandler {
controller.registerHandler(PUT, "/{index}/{type}/_noop_bulk", this);
}
@Override
public String getName() {
return "noop_bulk_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
BulkRequest bulkRequest = Requests.bulkRequest();

View File

@ -42,6 +42,11 @@ public class RestNoopSearchAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/{type}/_noop_search", this);
}
@Override
public String getName() {
return "noop_search_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
SearchRequest searchRequest = new SearchRequest();

View File

@ -37,6 +37,8 @@ import org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskAction;
import org.elasticsearch.action.admin.cluster.node.tasks.get.TransportGetTaskAction;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
import org.elasticsearch.action.admin.cluster.node.tasks.list.TransportListTasksAction;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageAction;
import org.elasticsearch.action.admin.cluster.node.usage.TransportNodesUsageAction;
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoAction;
import org.elasticsearch.action.admin.cluster.remote.TransportRemoteInfoAction;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction;
@ -234,6 +236,7 @@ import org.elasticsearch.rest.action.admin.cluster.RestListTasksAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesHotThreadsAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesInfoAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesStatsAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction;
import org.elasticsearch.rest.action.admin.cluster.RestPendingClusterTasksAction;
import org.elasticsearch.rest.action.admin.cluster.RestPutRepositoryAction;
import org.elasticsearch.rest.action.admin.cluster.RestPutStoredScriptAction;
@ -310,6 +313,7 @@ import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.usage.UsageService;
import java.util.ArrayList;
import java.util.List;
@ -346,7 +350,7 @@ public class ActionModule extends AbstractModule {
public ActionModule(boolean transportClient, Settings settings, IndexNameExpressionResolver indexNameExpressionResolver,
IndexScopedSettings indexScopedSettings, ClusterSettings clusterSettings, SettingsFilter settingsFilter,
ThreadPool threadPool, List<ActionPlugin> actionPlugins, NodeClient nodeClient,
CircuitBreakerService circuitBreakerService) {
CircuitBreakerService circuitBreakerService, UsageService usageService) {
this.transportClient = transportClient;
this.settings = settings;
this.indexNameExpressionResolver = indexNameExpressionResolver;
@ -373,7 +377,7 @@ public class ActionModule extends AbstractModule {
if (transportClient) {
restController = null;
} else {
restController = new RestController(settings, headers, restWrapper, nodeClient, circuitBreakerService);
restController = new RestController(settings, headers, restWrapper, nodeClient, circuitBreakerService, usageService);
}
}
@ -405,6 +409,7 @@ public class ActionModule extends AbstractModule {
actions.register(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class);
actions.register(RemoteInfoAction.INSTANCE, TransportRemoteInfoAction.class);
actions.register(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class);
actions.register(NodesUsageAction.INSTANCE, TransportNodesUsageAction.class);
actions.register(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class);
actions.register(ListTasksAction.INSTANCE, TransportListTasksAction.class);
actions.register(GetTaskAction.INSTANCE, TransportGetTaskAction.class);
@ -515,6 +520,7 @@ public class ActionModule extends AbstractModule {
registerHandler.accept(new RestNodesInfoAction(settings, restController, settingsFilter));
registerHandler.accept(new RestRemoteClusterInfoAction(settings, restController));
registerHandler.accept(new RestNodesStatsAction(settings, restController));
registerHandler.accept(new RestNodesUsageAction(settings, restController));
registerHandler.accept(new RestNodesHotThreadsAction(settings, restController));
registerHandler.accept(new RestClusterAllocationExplainAction(settings, restController));
registerHandler.accept(new RestClusterStatsAction(settings, restController));

View File

@ -0,0 +1,115 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.usage;
import org.elasticsearch.action.support.nodes.BaseNodeResponse;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Map;
public class NodeUsage extends BaseNodeResponse implements ToXContent {
private long timestamp;
private long sinceTime;
private Map<String, Long> restUsage;
NodeUsage() {
}
public static NodeUsage readNodeStats(StreamInput in) throws IOException {
NodeUsage nodeInfo = new NodeUsage();
nodeInfo.readFrom(in);
return nodeInfo;
}
/**
* @param node
* the node these statistics were collected from
* @param timestamp
* the timestamp for when these statistics were collected
* @param sinceTime
* the timestamp for when the collection of these statistics
* started
* @param restUsage
* a map containing the counts of the number of times each REST
* endpoint has been called
*/
public NodeUsage(DiscoveryNode node, long timestamp, long sinceTime, Map<String, Long> restUsage) {
super(node);
this.timestamp = timestamp;
this.sinceTime = sinceTime;
this.restUsage = restUsage;
}
/**
* @return the timestamp for when these statistics were collected
*/
public long getTimestamp() {
return timestamp;
}
/**
* @return the timestamp for when the collection of these statistics started
*/
public long getSinceTime() {
return sinceTime;
}
/**
* @return a map containing the counts of the number of times each REST
* endpoint has been called
*/
public Map<String, Long> getRestUsage() {
return restUsage;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("since", sinceTime);
if (restUsage != null) {
builder.field("rest_actions");
builder.map(restUsage);
}
return builder;
}
@SuppressWarnings("unchecked")
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
timestamp = in.readLong();
sinceTime = in.readLong();
restUsage = (Map<String, Long>) in.readGenericValue();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeLong(timestamp);
out.writeLong(sinceTime);
out.writeGenericValue(restUsage);
}
}

View File

@ -0,0 +1,44 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.usage;
import org.elasticsearch.action.Action;
import org.elasticsearch.client.ElasticsearchClient;
public class NodesUsageAction extends Action<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> {
public static final NodesUsageAction INSTANCE = new NodesUsageAction();
public static final String NAME = "cluster:monitor/nodes/usage";
protected NodesUsageAction() {
super(NAME);
}
@Override
public NodesUsageRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new NodesUsageRequestBuilder(client, this);
}
@Override
public NodesUsageResponse newResponse() {
return new NodesUsageResponse();
}
}

View File

@ -0,0 +1,86 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.usage;
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
public class NodesUsageRequest extends BaseNodesRequest<NodesUsageRequest> {
private boolean restActions;
public NodesUsageRequest() {
super();
}
/**
* Get usage from nodes based on the nodes ids specified. If none are
* passed, usage for all nodes will be returned.
*/
public NodesUsageRequest(String... nodesIds) {
super(nodesIds);
}
/**
* Sets all the request flags.
*/
public NodesUsageRequest all() {
this.restActions = true;
return this;
}
/**
* Clears all the request flags.
*/
public NodesUsageRequest clear() {
this.restActions = false;
return this;
}
/**
* Should the node rest actions usage statistics be returned.
*/
public boolean restActions() {
return this.restActions;
}
/**
* Should the node rest actions usage statistics be returned.
*/
public NodesUsageRequest restActions(boolean restActions) {
this.restActions = restActions;
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
this.restActions = in.readBoolean();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(restActions);
}
}

View File

@ -17,8 +17,18 @@
* under the License.
*/
/**
* Infrastructure for actions that modify documents based on the results of a scrolling query
* like reindex, update by query or delete by query.
*/
package org.elasticsearch.index.reindex;
package org.elasticsearch.action.admin.cluster.node.usage;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
public class NodesUsageRequestBuilder
extends NodesOperationRequestBuilder<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> {
public NodesUsageRequestBuilder(ElasticsearchClient client,
Action<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> action) {
super(client, action, new NodesUsageRequest());
}
}

View File

@ -0,0 +1,85 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.usage;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import java.io.IOException;
import java.util.List;
/**
* The response for the nodes usage api which contains the individual usage
* statistics for all nodes queried.
*/
public class NodesUsageResponse extends BaseNodesResponse<NodeUsage> implements ToXContent {
NodesUsageResponse() {
}
public NodesUsageResponse(ClusterName clusterName, List<NodeUsage> nodes, List<FailedNodeException> failures) {
super(clusterName, nodes, failures);
}
@Override
protected List<NodeUsage> readNodesFrom(StreamInput in) throws IOException {
return in.readList(NodeUsage::readNodeStats);
}
@Override
protected void writeNodesTo(StreamOutput out, List<NodeUsage> nodes) throws IOException {
out.writeStreamableList(nodes);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("nodes");
for (NodeUsage nodeUsage : getNodes()) {
builder.startObject(nodeUsage.getNode().getId());
builder.field("timestamp", nodeUsage.getTimestamp());
nodeUsage.toXContent(builder, params);
builder.endObject();
}
builder.endObject();
return builder;
}
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return builder.string();
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
}

View File

@ -0,0 +1,104 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.usage;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.nodes.BaseNodeRequest;
import org.elasticsearch.action.support.nodes.TransportNodesAction;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.usage.UsageService;
import java.io.IOException;
import java.util.List;
public class TransportNodesUsageAction
extends TransportNodesAction<NodesUsageRequest, NodesUsageResponse, TransportNodesUsageAction.NodeUsageRequest, NodeUsage> {
private UsageService usageService;
@Inject
public TransportNodesUsageAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
TransportService transportService, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, UsageService usageService) {
super(settings, NodesUsageAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
NodesUsageRequest::new, NodeUsageRequest::new, ThreadPool.Names.MANAGEMENT, NodeUsage.class);
this.usageService = usageService;
}
@Override
protected NodesUsageResponse newResponse(NodesUsageRequest request, List<NodeUsage> responses, List<FailedNodeException> failures) {
return new NodesUsageResponse(clusterService.getClusterName(), responses, failures);
}
@Override
protected NodeUsageRequest newNodeRequest(String nodeId, NodesUsageRequest request) {
return new NodeUsageRequest(nodeId, request);
}
@Override
protected NodeUsage newNodeResponse() {
return new NodeUsage();
}
@Override
protected NodeUsage nodeOperation(NodeUsageRequest nodeUsageRequest) {
NodesUsageRequest request = nodeUsageRequest.request;
return usageService.getUsageStats(clusterService.localNode(), request.restActions());
}
@Override
protected boolean accumulateExceptions() {
return false;
}
public static class NodeUsageRequest extends BaseNodeRequest {
NodesUsageRequest request;
public NodeUsageRequest() {
}
NodeUsageRequest(String nodeId, NodesUsageRequest request) {
super(nodeId);
this.request = request;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
request = new NodesUsageRequest();
request.readFrom(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
request.writeTo(out);
}
}
}

View File

@ -45,6 +45,9 @@ import org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequestBuilder;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequest;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequestBuilder;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageResponse;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequestBuilder;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse;
@ -265,8 +268,37 @@ public interface ClusterAdminClient extends ElasticsearchClient {
NodesStatsRequestBuilder prepareNodesStats(String... nodesIds);
/**
* Returns top N hot-threads samples per node. The hot-threads are only sampled
* for the node ids specified in the request.
* Returns top N hot-threads samples per node. The hot-threads are only
* sampled for the node ids specified in the request. Nodes usage of the
* cluster.
*
* @param request
* The nodes usage request
* @return The result future
* @see org.elasticsearch.client.Requests#nodesUsageRequest(String...)
*/
ActionFuture<NodesUsageResponse> nodesUsage(NodesUsageRequest request);
/**
* Nodes usage of the cluster.
*
* @param request
* The nodes usage request
* @param listener
* A listener to be notified with a result
* @see org.elasticsearch.client.Requests#nodesUsageRequest(String...)
*/
void nodesUsage(NodesUsageRequest request, ActionListener<NodesUsageResponse> listener);
/**
* Nodes usage of the cluster.
*/
NodesUsageRequestBuilder prepareNodesUsage(String... nodesIds);
/**
* Returns top N hot-threads samples per node. The hot-threads are only
* sampled for the node ids specified in the request.
*
*/
ActionFuture<NodesHotThreadsResponse> nodesHotThreads(NodesHotThreadsRequest request);

View File

@ -25,6 +25,7 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequest;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest;
import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest;
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
@ -387,6 +388,19 @@ public class Requests {
return new NodesStatsRequest(nodesIds);
}
/**
* Creates a nodes usage request against one or more nodes. Pass
* <tt>null</tt> or an empty array for all nodes.
*
* @param nodesIds
* The nodes ids to get the usage for
* @return The nodes usage request
* @see org.elasticsearch.client.ClusterAdminClient#nodesUsage(org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequest)
*/
public static NodesUsageRequest nodesUsageRequest(String... nodesIds) {
return new NodesUsageRequest(nodesIds);
}
/**
* Creates a cluster stats request.
*

View File

@ -57,6 +57,10 @@ import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequestBuilder;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageAction;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequest;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequestBuilder;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageResponse;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequestBuilder;
@ -828,6 +832,21 @@ public abstract class AbstractClient extends AbstractComponent implements Client
return new NodesStatsRequestBuilder(this, NodesStatsAction.INSTANCE).setNodesIds(nodesIds);
}
@Override
public ActionFuture<NodesUsageResponse> nodesUsage(final NodesUsageRequest request) {
return execute(NodesUsageAction.INSTANCE, request);
}
@Override
public void nodesUsage(final NodesUsageRequest request, final ActionListener<NodesUsageResponse> listener) {
execute(NodesUsageAction.INSTANCE, request, listener);
}
@Override
public NodesUsageRequestBuilder prepareNodesUsage(String... nodesIds) {
return new NodesUsageRequestBuilder(this, NodesUsageAction.INSTANCE).setNodesIds(nodesIds);
}
@Override
public ActionFuture<ClusterStatsResponse> clusterStats(ClusterStatsRequest request) {
return execute(ClusterStatsAction.INSTANCE, request);

View File

@ -45,8 +45,8 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.InternalSettingsPreparer;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.NetworkPlugin;
import org.elasticsearch.plugins.Plugin;
@ -159,7 +159,7 @@ public abstract class TransportClient extends AbstractClient {
modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool));
ActionModule actionModule = new ActionModule(true, settings, null, settingsModule.getIndexScopedSettings(),
settingsModule.getClusterSettings(), settingsModule.getSettingsFilter(), threadPool,
pluginsService.filterPlugins(ActionPlugin.class), null, null);
pluginsService.filterPlugins(ActionPlugin.class), null, null, null);
modules.add(actionModule);
CircuitBreakerService circuitBreakerService = Node.createCircuitBreakerService(settingsModule.getSettings(),

View File

@ -132,6 +132,7 @@ import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportInterceptor;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.tribe.TribeService;
import org.elasticsearch.usage.UsageService;
import org.elasticsearch.watcher.ResourceWatcherService;
import java.io.BufferedWriter;
@ -340,6 +341,7 @@ public class Node implements Closeable {
final IngestService ingestService = new IngestService(clusterService.getClusterSettings(), settings, threadPool, this.environment,
scriptModule.getScriptService(), analysisModule.getAnalysisRegistry(), pluginsService.filterPlugins(IngestPlugin.class));
final ClusterInfoService clusterInfoService = newClusterInfoService(settings, clusterService, threadPool, client);
final UsageService usageService = new UsageService(settings);
ModulesBuilder modules = new ModulesBuilder();
// plugin modules must be added here, before others or we can get crazy injection errors...
@ -360,7 +362,7 @@ public class Node implements Closeable {
resourcesToClose.add(circuitBreakerService);
ActionModule actionModule = new ActionModule(false, settings, clusterModule.getIndexNameExpressionResolver(),
settingsModule.getIndexScopedSettings(), settingsModule.getClusterSettings(), settingsModule.getSettingsFilter(),
threadPool, pluginsService.filterPlugins(ActionPlugin.class), client, circuitBreakerService);
threadPool, pluginsService.filterPlugins(ActionPlugin.class), client, circuitBreakerService, usageService);
modules.add(actionModule);
modules.add(new GatewayModule());
@ -455,6 +457,7 @@ public class Node implements Closeable {
b.bind(ScriptService.class).toInstance(scriptModule.getScriptService());
b.bind(AnalysisRegistry.class).toInstance(analysisModule.getAnalysisRegistry());
b.bind(IngestService.class).toInstance(ingestService);
b.bind(UsageService.class).toInstance(usageService);
b.bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);
b.bind(MetaDataUpgrader.class).toInstance(metaDataUpgrader);
b.bind(MetaStateService.class).toInstance(metaStateService);

View File

@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction;
import java.io.IOException;
import java.util.ArrayList;
@ -39,6 +40,7 @@ import java.util.Locale;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.Collectors;
/**
@ -54,10 +56,24 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH
public static final Setting<Boolean> MULTI_ALLOW_EXPLICIT_INDEX =
Setting.boolSetting("rest.action.multi.allow_explicit_index", true, Property.NodeScope);
private final LongAdder usageCount = new LongAdder();
protected BaseRestHandler(Settings settings) {
super(settings);
}
public final long getUsageCount() {
return usageCount.sum();
}
/**
* @return the name of this handler. The name should be human readable and
* should describe the action that will performed when this API is
* called. This name is used in the response to the
* {@link RestNodesUsageAction}.
*/
public abstract String getName();
@Override
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
// prepare the request for execution; has the side effect of touching the request parameters
@ -76,6 +92,7 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH
throw new IllegalArgumentException(unrecognized(request, unconsumedParams, candidateParams, "parameter"));
}
usageCount.increment();
// execute the action
action.accept(channel);
}

View File

@ -37,6 +37,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.usage.UsageService;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -72,11 +73,13 @@ public class RestController extends AbstractComponent implements HttpServerTrans
/** Rest headers that are copied to internal requests made during a rest request. */
private final Set<String> headersToCopy;
private UsageService usageService;
public RestController(Settings settings, Set<String> headersToCopy, UnaryOperator<RestHandler> handlerWrapper,
NodeClient client, CircuitBreakerService circuitBreakerService) {
NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService) {
super(settings);
this.headersToCopy = headersToCopy;
this.usageService = usageService;
if (handlerWrapper == null) {
handlerWrapper = h -> h; // passthrough if no wrapper set
}
@ -148,6 +151,9 @@ public class RestController extends AbstractComponent implements HttpServerTrans
PathTrie<RestHandler> handlers = getHandlersForMethod(method);
if (handlers != null) {
handlers.insert(path, handler);
if (handler instanceof BaseRestHandler) {
usageService.addRestHandler((BaseRestHandler) handler);
}
} else {
throw new IllegalArgumentException("Can't handle [" + method + "] for path [" + path + "]");
}

View File

@ -38,7 +38,6 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestFieldCapabilitiesAction extends BaseRestHandler {
@ -50,6 +49,11 @@ public class RestFieldCapabilitiesAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/_field_caps", this);
}
@Override
public String getName() {
return "field_capabilities_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request,
final NodeClient client) throws IOException {

View File

@ -60,6 +60,11 @@ public class RestFieldStatsAction extends BaseRestHandler {
"run a min/max aggregations on the desired fields.";
}
@Override
public String getName() {
return "field_stats_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request,
final NodeClient client) throws IOException {

View File

@ -44,6 +44,11 @@ public class RestMainAction extends BaseRestHandler {
controller.registerHandler(HEAD, "/", this);
}
@Override
public String getName() {
return "main_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
return channel -> client.execute(MainAction.INSTANCE, new MainRequest(), new RestBuilderListener<MainResponse>(channel) {

View File

@ -46,6 +46,11 @@ public class RestCancelTasksAction extends BaseRestHandler {
controller.registerHandler(POST, "/_tasks/{task_id}/_cancel", this);
}
@Override
public String getName() {
return "cancel_tasks_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodes"));

View File

@ -46,6 +46,11 @@ public class RestClusterAllocationExplainAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/_cluster/allocation/explain", this);
}
@Override
public String getName() {
return "cluster_allocation_explain_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterAllocationExplainRequest req;

View File

@ -53,6 +53,11 @@ public class RestClusterGetSettingsAction extends BaseRestHandler {
this.settingsFilter = settingsFilter;
}
@Override
public String getName() {
return "cluster_get_settings_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()

View File

@ -46,6 +46,11 @@ public class RestClusterHealthAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.GET, "/_cluster/health/{index}", this);
}
@Override
public String getName() {
return "cluster_health_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -63,6 +63,11 @@ public class RestClusterRerouteAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/_cluster/reroute", this);
}
@Override
public String getName() {
return "cluster_reroute_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterRerouteRequest clusterRerouteRequest = createRequest(request);

View File

@ -44,6 +44,11 @@ public class RestClusterSearchShardsAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/_search_shards", this);
}
@Override
public String getName() {
return "cluster_search_shards_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -56,6 +56,11 @@ public class RestClusterStateAction extends BaseRestHandler {
this.settingsFilter = settingsFilter;
}
@Override
public String getName() {
return "cluster_state_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();

View File

@ -36,6 +36,11 @@ public class RestClusterStatsAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.GET, "/_cluster/stats/nodes/{nodeId}", this);
}
@Override
public String getName() {
return "cluster_stats_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterStatsRequest clusterStatsRequest = new ClusterStatsRequest().nodesIds(request.paramAsStringArray("nodeId", null));

View File

@ -41,6 +41,11 @@ public class RestClusterUpdateSettingsAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.PUT, "/_cluster/settings", this);
}
@Override
public String getName() {
return "cluster_update_settings_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = Requests.clusterUpdateSettingsRequest();

View File

@ -43,6 +43,11 @@ public class RestCreateSnapshotAction extends BaseRestHandler {
controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}", this);
}
@Override
public String getName() {
return "create_snapshot_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
CreateSnapshotRequest createSnapshotRequest = createSnapshotRequest(request.param("repository"), request.param("snapshot"));

View File

@ -41,6 +41,11 @@ public class RestDeleteRepositoryAction extends BaseRestHandler {
controller.registerHandler(DELETE, "/_snapshot/{repository}", this);
}
@Override
public String getName() {
return "delete_repository_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteRepositoryRequest deleteRepositoryRequest = deleteRepositoryRequest(request.param("repository"));

View File

@ -41,6 +41,11 @@ public class RestDeleteSnapshotAction extends BaseRestHandler {
controller.registerHandler(DELETE, "/_snapshot/{repository}/{snapshot}", this);
}
@Override
public String getName() {
return "delete_snapshot_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteSnapshotRequest deleteSnapshotRequest = deleteSnapshotRequest(request.param("repository"), request.param("snapshot"));

View File

@ -42,6 +42,11 @@ public class RestDeleteStoredScriptAction extends BaseRestHandler {
controller.registerHandler(DELETE, "/_scripts/{lang}/{id}", this);
}
@Override
public String getName() {
return "delete_stored_script_action";
}
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String id = request.param("id");

View File

@ -56,6 +56,11 @@ public class RestGetRepositoriesAction extends BaseRestHandler {
this.settingsFilter = settingsFilter;
}
@Override
public String getName() {
return "get_respositories_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);

View File

@ -42,6 +42,11 @@ public class RestGetSnapshotsAction extends BaseRestHandler {
controller.registerHandler(GET, "/_snapshot/{repository}/{snapshot}", this);
}
@Override
public String getName() {
return "get_snapshots_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String repository = request.param("repository");

View File

@ -53,6 +53,11 @@ public class RestGetStoredScriptAction extends BaseRestHandler {
controller.registerHandler(GET, "/_scripts/{lang}/{id}", this);
}
@Override
public String getName() {
return "get_stored_scripts_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, NodeClient client) throws IOException {
String id;

View File

@ -39,6 +39,11 @@ public class RestGetTaskAction extends BaseRestHandler {
controller.registerHandler(GET, "/_tasks/{taskId}", this);
}
@Override
public String getName() {
return "get_task_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
TaskId taskId = new TaskId(request.param("taskId"));

View File

@ -55,6 +55,11 @@ public class RestListTasksAction extends BaseRestHandler {
controller.registerHandler(GET, "/_tasks", this);
}
@Override
public String getName() {
return "list_tasks_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ListTasksRequest listTasksRequest = generateListTasksRequest(request);

View File

@ -51,6 +51,11 @@ public class RestNodesHotThreadsAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/hot_threads", this);
}
@Override
public String getName() {
return "nodes_hot_threads_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));

View File

@ -62,6 +62,11 @@ public class RestNodesInfoAction extends BaseRestHandler {
this.settingsFilter = settingsFilter;
}
@Override
public String getName() {
return "nodes_info_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] nodeIds;

View File

@ -84,6 +84,11 @@ public class RestNodesStatsAction extends BaseRestHandler {
FLAGS = Collections.unmodifiableMap(flags);
}
@Override
public String getName() {
return "nodes_stats_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));

View File

@ -0,0 +1,98 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest.action.admin.cluster;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageRequest;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.rest.action.RestBuilderListener;
import java.io.IOException;
import java.util.Locale;
import java.util.Set;
import static org.elasticsearch.rest.RestRequest.Method.GET;
public class RestNodesUsageAction extends BaseRestHandler {
@Inject
public RestNodesUsageAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_nodes/usage", this);
controller.registerHandler(GET, "/_nodes/{nodeId}/usage", this);
controller.registerHandler(GET, "/_nodes/usage/{metric}", this);
controller.registerHandler(GET, "/_nodes/{nodeId}/usage/{metric}", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all"));
NodesUsageRequest nodesUsageRequest = new NodesUsageRequest(nodesIds);
nodesUsageRequest.timeout(request.param("timeout"));
if (metrics.size() == 1 && metrics.contains("_all")) {
nodesUsageRequest.all();
} else if (metrics.contains("_all")) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "request [%s] contains _all and individual metrics [%s]",
request.path(), request.param("metric")));
} else {
nodesUsageRequest.clear();
nodesUsageRequest.restActions(metrics.contains("rest_actions"));
}
return channel -> client.admin().cluster().nodesUsage(nodesUsageRequest, new RestBuilderListener<NodesUsageResponse>(channel) {
@Override
public RestResponse buildResponse(NodesUsageResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
RestActions.buildNodesHeader(builder, channel.request(), response);
builder.field("cluster_name", response.getClusterName().value());
response.toXContent(builder, channel.request());
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
});
}
@Override
public String getName() {
return "nodes_usage_action";
}
@Override
public boolean canTripCircuitBreaker() {
return false;
}
}

View File

@ -35,6 +35,11 @@ public class RestPendingClusterTasksAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.GET, "/_cluster/pending_tasks", this);
}
@Override
public String getName() {
return "pending_cluster_tasks_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();

View File

@ -44,6 +44,10 @@ public class RestPutRepositoryAction extends BaseRestHandler {
controller.registerHandler(POST, "/_snapshot/{repository}", this);
}
@Override
public String getName() {
return "put_repository_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {

View File

@ -46,6 +46,11 @@ public class RestPutStoredScriptAction extends BaseRestHandler {
controller.registerHandler(PUT, "/_scripts/{lang}/{id}", this);
}
@Override
public String getName() {
return "put_stored_script_action";
}
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String id = request.param("id");

View File

@ -44,6 +44,11 @@ public final class RestRemoteClusterInfoAction extends BaseRestHandler {
controller.registerHandler(GET, "_remote/info", this);
}
@Override
public String getName() {
return "remote_cluster_info_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client)
throws IOException {

View File

@ -41,6 +41,11 @@ public class RestRestoreSnapshotAction extends BaseRestHandler {
controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}/_restore", this);
}
@Override
public String getName() {
return "restore_snapshot_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
RestoreSnapshotRequest restoreSnapshotRequest = restoreSnapshotRequest(request.param("repository"), request.param("snapshot"));

View File

@ -44,6 +44,11 @@ public class RestSnapshotsStatusAction extends BaseRestHandler {
controller.registerHandler(GET, "/_snapshot/_status", this);
}
@Override
public String getName() {
return "snapshot_status_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String repository = request.param("repository", "_all");

View File

@ -38,6 +38,11 @@ public class RestVerifyRepositoryAction extends BaseRestHandler {
controller.registerHandler(POST, "/_snapshot/{repository}/_verify", this);
}
@Override
public String getName() {
return "verify_repository_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
VerifyRepositoryRequest verifyRepositoryRequest = verifyRepositoryRequest(request.param("repository"));

View File

@ -56,6 +56,11 @@ public class RestAnalyzeAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/_analyze", this);
}
@Override
public String getName() {
return "analyze_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {

View File

@ -52,6 +52,11 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_cache/clear", this);
}
@Override
public String getName() {
return "clear_indices_cache_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(

View File

@ -38,6 +38,11 @@ public class RestCloseIndexAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/{index}/_close", this);
}
@Override
public String getName() {
return "close_index_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -38,6 +38,11 @@ public class RestCreateIndexAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.PUT, "/{index}", this);
}
@Override
public String getName() {
return "create_index_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));

View File

@ -38,6 +38,11 @@ public class RestDeleteIndexAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.DELETE, "/{index}", this);
}
@Override
public String getName() {
return "delete_index_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -34,6 +34,11 @@ public class RestDeleteIndexTemplateAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.DELETE, "/_template/{name}", this);
}
@Override
public String getName() {
return "delete_index_template_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteIndexTemplateRequest deleteIndexTemplateRequest = new DeleteIndexTemplateRequest(request.param("name"));

View File

@ -50,6 +50,11 @@ public class RestFlushAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_flush", this);
}
@Override
public String getName() {
return "flush_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
FlushRequest flushRequest = new FlushRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -46,6 +46,11 @@ public class RestForceMergeAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/_forcemerge", this);
}
@Override
public String getName() {
return "force_merge_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -20,6 +20,7 @@
package org.elasticsearch.rest.action.admin.indices;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
import org.elasticsearch.action.support.IndicesOptions;
@ -60,6 +61,11 @@ public class RestGetAliasesAction extends BaseRestHandler {
controller.registerHandler(HEAD, "/{index}/_alias/{name}", this);
}
@Override
public String getName() {
return "get_aliases_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name");

View File

@ -52,6 +52,11 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_mapping/{type}/field/{fields}", this);
}
@Override
public String getName() {
return "get_field_mapping_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -50,6 +50,11 @@ public class RestGetIndexTemplateAction extends BaseRestHandler {
controller.registerHandler(HEAD, "/_template/{name}", this);
}
@Override
public String getName() {
return "get_index_template_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = Strings.splitStringByCommaToArray(request.param("name"));

View File

@ -71,6 +71,11 @@ public class RestGetIndicesAction extends BaseRestHandler {
this.settingsFilter = settingsFilter;
}
@Override
public String getName() {
return "get_indices_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -53,6 +53,11 @@ public class RestGetMappingAction extends BaseRestHandler {
controller.registerHandler(GET, "/_mapping/{type}", this);
}
@Override
public String getName() {
return "get_mapping_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -57,6 +57,11 @@ public class RestGetSettingsAction extends BaseRestHandler {
this.settingsFilter = settingsFilter;
}
@Override
public String getName() {
return "get_settings_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");

View File

@ -39,6 +39,11 @@ public class RestIndexDeleteAliasesAction extends BaseRestHandler {
controller.registerHandler(DELETE, "/{index}/_aliases/{name}", this);
}
@Override
public String getName() {
return "index_delete_aliases_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -53,6 +53,11 @@ public class RestIndexPutAliasAction extends BaseRestHandler {
//we cannot add POST for "/_aliases" because this is the _aliases api already defined in RestIndicesAliasesAction
}
@Override
public String getName() {
return "index_put_alias_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -45,6 +45,11 @@ public class RestIndicesAliasesAction extends BaseRestHandler {
}, AliasActions.PARSER, new ParseField("actions"));
}
@Override
public String getName() {
return "indices_aliases_action";
}
public RestIndicesAliasesAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_aliases", this);

View File

@ -46,6 +46,11 @@ public class RestIndicesSegmentsAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_segments", this);
}
@Override
public String getName() {
return "indices_segments_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(

View File

@ -49,6 +49,11 @@ public class RestIndicesShardStoresAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_shard_stores", this);
}
@Override
public String getName() {
return "indices_shard_stores_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesShardStoresRequest indicesShardStoresRequest = new IndicesShardStoresRequest(

View File

@ -55,6 +55,11 @@ public class RestIndicesStatsAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_stats/{metric}", this);
}
@Override
public String getName() {
return "indices_stats_action";
}
static final Map<String, Consumer<IndicesStatsRequest>> METRICS;
static {

View File

@ -39,6 +39,11 @@ public class RestOpenIndexAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/{index}/_open", this);
}
@Override
public String getName() {
return "open_index_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
OpenIndexRequest openIndexRequest = new OpenIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -44,6 +44,11 @@ public class RestPutIndexTemplateAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/_template/{name}", this);
}
@Override
public String getName() {
return "put_index_template_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));

View File

@ -60,6 +60,11 @@ public class RestPutMappingAction extends BaseRestHandler {
controller.registerHandler(POST, "/_mappings/{type}", this);
}
@Override
public String getName() {
return "put_mapping_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -48,6 +48,11 @@ public class RestRecoveryAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_recovery", this);
}
@Override
public String getName() {
return "recovery_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {

View File

@ -37,7 +37,6 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader;
public class RestRefreshAction extends BaseRestHandler {
@ -50,6 +49,11 @@ public class RestRefreshAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_refresh", this);
}
@Override
public String getName() {
return "refresh_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -37,6 +37,11 @@ public class RestRolloverIndexAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover/{new_index}", this);
}
@Override
public String getName() {
return "rollover_index_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index"));

View File

@ -39,6 +39,11 @@ public class RestShrinkIndexAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.POST, "/{index}/_shrink/{target}", this);
}
@Override
public String getName() {
return "shrink_index_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
if (request.param("target") == null) {

View File

@ -48,6 +48,11 @@ public class RestSyncedFlushAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_flush/synced", this);
}
@Override
public String getName() {
return "synced_flush_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, IndicesOptions.lenientExpandOpen());

View File

@ -49,6 +49,11 @@ public class RestTypesExistsAction extends BaseRestHandler {
HEAD, "/{index}/{type}", deprecationLogger);
}
@Override
public String getName() {
return "types_exists_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
TypesExistsRequest typesExistsRequest = new TypesExistsRequest(

View File

@ -45,6 +45,11 @@ public class RestUpdateSettingsAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.PUT, "/_settings", this);
}
@Override
public String getName() {
return "update_settings_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
UpdateSettingsRequest updateSettingsRequest = updateSettingsRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -55,6 +55,11 @@ public class RestUpgradeAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/_upgrade", this);
}
@Override
public String getName() {
return "upgrade_action";
}
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (request.method().equals(RestRequest.Method.GET)) {

View File

@ -55,6 +55,11 @@ public class RestValidateQueryAction extends BaseRestHandler {
controller.registerHandler(POST, "/{index}/{type}/_validate/query", this);
}
@Override
public String getName() {
return "validate_query_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));

View File

@ -43,6 +43,11 @@ public class RestAliasAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/aliases/{alias}", this);
}
@Override
public String getName() {
return "cat_alias_action";
}
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ?

View File

@ -50,6 +50,11 @@ public class RestAllocationAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/allocation/{nodes}", this);
}
@Override
public String getName() {
return "cat_allocation_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/allocation\n");

View File

@ -51,6 +51,11 @@ public class RestCatAction extends BaseRestHandler {
HELP = sb.toString();
}
@Override
public String getName() {
return "cat_action";
}
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, HELP));

View File

@ -45,6 +45,11 @@ public class RestCountAction extends AbstractCatAction {
restController.registerHandler(GET, "/_cat/count/{index}", this);
}
@Override
public String getName() {
return "cat_count_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/count\n");

View File

@ -45,6 +45,11 @@ public class RestFielddataAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/fielddata/{fields}", this);
}
@Override
public String getName() {
return "cat_fielddata_action";
}
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");

View File

@ -39,6 +39,11 @@ public class RestHealthAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/health", this);
}
@Override
public String getName() {
return "cat_health_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/health\n");

View File

@ -66,6 +66,11 @@ public class RestIndicesAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/indices/{index}", this);
}
@Override
public String getName() {
return "cat_indices_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/indices\n");

View File

@ -39,6 +39,11 @@ public class RestMasterAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/master", this);
}
@Override
public String getName() {
return "cat_master_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/master\n");

View File

@ -46,6 +46,11 @@ public class RestNodeAttrsAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/nodeattrs", this);
}
@Override
public String getName() {
return "cat_node_attrs_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/nodeattrs\n");

View File

@ -71,6 +71,11 @@ public class RestNodesAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/nodes", this);
}
@Override
public String getName() {
return "cat_nodes_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/nodes\n");

View File

@ -38,6 +38,11 @@ public class RestPendingClusterTasksAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/pending_tasks", this);
}
@Override
public String getName() {
return "cat_pending_cluster_tasks_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/pending_tasks\n");

View File

@ -44,6 +44,11 @@ public class RestPluginsAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/plugins", this);
}
@Override
public String getName() {
return "cat_plugins_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/plugins\n");

View File

@ -54,6 +54,11 @@ public class RestRecoveryAction extends AbstractCatAction {
restController.registerHandler(GET, "/_cat/recovery/{index}", this);
}
@Override
public String getName() {
return "cat_recovery_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/recovery\n");

View File

@ -58,6 +58,11 @@ public class RestRepositoriesAction extends AbstractCatAction {
});
}
@Override
public String getName() {
return "cat_repositories_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/repositories\n");

View File

@ -50,6 +50,11 @@ public class RestSegmentsAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/segments/{index}", this);
}
@Override
public String getName() {
return "cat_segments_action";
}
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

View File

@ -52,6 +52,11 @@ public class RestShardsAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/shards/{index}", this);
}
@Override
public String getName() {
return "cat_shards_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/shards\n");

View File

@ -49,6 +49,11 @@ public class RestSnapshotAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/snapshots/{repository}", this);
}
@Override
public String getName() {
return "cat_snapshot_action";
}
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest()

View File

@ -55,6 +55,11 @@ public class RestTasksAction extends AbstractCatAction {
this.nodesInCluster = nodesInCluster;
}
@Override
public String getName() {
return "cat_tasks_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/tasks\n");

View File

@ -43,6 +43,11 @@ public class RestTemplatesAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/templates/{name}", this);
}
@Override
public String getName() {
return "cat_templates_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/templates\n");

View File

@ -57,6 +57,11 @@ public class RestThreadPoolAction extends AbstractCatAction {
controller.registerHandler(GET, "/_cat/thread_pool/{thread_pool_patterns}", this);
}
@Override
public String getName() {
return "cat_threadpool_action";
}
@Override
protected void documentation(StringBuilder sb) {
sb.append("/_cat/thread_pool\n");

Some files were not shown because too many files have changed in this diff Show More