Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions core/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
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.ClearNodesUsageAction;
import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageAction;
import org.elasticsearch.action.admin.cluster.node.usage.TransportClearNodesUsageAction;
import org.elasticsearch.action.admin.cluster.node.usage.TransportNodesUsageAction;
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction;
import org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction;
import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction;
Expand Down Expand Up @@ -211,6 +215,7 @@
import org.elasticsearch.rest.action.RestFieldStatsAction;
import org.elasticsearch.rest.action.RestMainAction;
import org.elasticsearch.rest.action.admin.cluster.RestCancelTasksAction;
import org.elasticsearch.rest.action.admin.cluster.RestClearNodesUsageAction;
import org.elasticsearch.rest.action.admin.cluster.RestClusterAllocationExplainAction;
import org.elasticsearch.rest.action.admin.cluster.RestClusterGetSettingsAction;
import org.elasticsearch.rest.action.admin.cluster.RestClusterHealthAction;
Expand All @@ -231,6 +236,7 @@
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;
Expand Down Expand Up @@ -309,6 +315,7 @@
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
import org.elasticsearch.rest.action.search.RestSuggestAction;
import org.elasticsearch.usage.UsageService;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
Expand All @@ -328,7 +335,7 @@ public class ActionModule extends AbstractModule {
private final RestController restController;

public ActionModule(boolean ingestEnabled, boolean transportClient, Settings settings, IndexNameExpressionResolver resolver,
ClusterSettings clusterSettings, List<ActionPlugin> actionPlugins) {
ClusterSettings clusterSettings, List<ActionPlugin> actionPlugins, UsageService usageService) {
this.transportClient = transportClient;
this.settings = settings;
this.actionPlugins = actionPlugins;
Expand All @@ -337,7 +344,7 @@ public ActionModule(boolean ingestEnabled, boolean transportClient, Settings set
autoCreateIndex = transportClient ? null : new AutoCreateIndex(settings, clusterSettings, resolver);
destructiveOperations = new DestructiveOperations(settings, clusterSettings);
Set<String> headers = actionPlugins.stream().flatMap(p -> p.getRestHeaders().stream()).collect(Collectors.toSet());
restController = new RestController(settings, headers);
restController = new RestController(settings, headers, usageService);
}

public Map<String, ActionHandler<?, ?>> getActions() {
Expand Down Expand Up @@ -366,6 +373,8 @@ public <Request extends ActionRequest<Request>, Response extends ActionResponse>
actions.register(MainAction.INSTANCE, TransportMainAction.class);
actions.register(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class);
actions.register(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class);
actions.register(NodesUsageAction.INSTANCE, TransportNodesUsageAction.class);
actions.register(ClearNodesUsageAction.INSTANCE, TransportClearNodesUsageAction.class);
actions.register(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class);
actions.register(ListTasksAction.INSTANCE, TransportListTasksAction.class);
actions.register(GetTaskAction.INSTANCE, TransportGetTaskAction.class);
Expand Down Expand Up @@ -480,6 +489,8 @@ static Set<Class<? extends RestHandler>> setupRestHandlers(List<ActionPlugin> ac
registerRestHandler(handlers, RestMainAction.class);
registerRestHandler(handlers, RestNodesInfoAction.class);
registerRestHandler(handlers, RestNodesStatsAction.class);
registerRestHandler(handlers, RestNodesUsageAction.class);
registerRestHandler(handlers, RestClearNodesUsageAction.class);
registerRestHandler(handlers, RestNodesHotThreadsAction.class);
registerRestHandler(handlers, RestClusterAllocationExplainAction.class);
registerRestHandler(handlers, RestClusterStatsAction.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;

public class ClearNodeUsageResponse extends BaseNodeResponse implements ToXContent {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("acknowledged", true);
return builder;
}

public static ClearNodeUsageResponse readNodeStats(StreamInput in) throws IOException {
ClearNodeUsageResponse noderesponse = new ClearNodeUsageResponse();
noderesponse.readFrom(in);
return noderesponse;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 ClearNodesUsageAction extends Action<ClearNodesUsageRequest, ClearNodesUsageResponse, ClearNodesUsageRequestBuilder> {

public static final ClearNodesUsageAction INSTANCE = new ClearNodesUsageAction();
public static final String NAME = "cluster:monitor/nodes/usage/clear";

protected ClearNodesUsageAction() {
super(NAME);
}

@Override
public ClearNodesUsageRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new ClearNodesUsageRequestBuilder(client, this);
}

@Override
public ClearNodesUsageResponse newResponse() {
return new ClearNodesUsageResponse();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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;

public class ClearNodesUsageRequest extends BaseNodesRequest<ClearNodesUsageRequest> {

public ClearNodesUsageRequest() {
super();
}

/**
* Get usage from nodes based on the nodes ids specified. If none are
* passed, usage for all nodes will be returned.
*/
public ClearNodesUsageRequest(String... nodesIds) {
super(nodesIds);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.action.support.nodes.NodesOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;

public class ClearNodesUsageRequestBuilder
extends NodesOperationRequestBuilder<ClearNodesUsageRequest, ClearNodesUsageResponse, ClearNodesUsageRequestBuilder> {

public ClearNodesUsageRequestBuilder(ElasticsearchClient client,
Action<ClearNodesUsageRequest, ClearNodesUsageResponse, ClearNodesUsageRequestBuilder> action) {
super(client, action, new ClearNodesUsageRequest());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 java.io.IOException;
import java.util.List;

public class ClearNodesUsageResponse extends BaseNodesResponse<ClearNodeUsageResponse> implements ToXContent {

ClearNodesUsageResponse() {
super();
}

public ClearNodesUsageResponse(ClusterName clusterName, List<ClearNodeUsageResponse> nodes, List<FailedNodeException> failures) {
super(clusterName, nodes, failures);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder;
}

@Override
protected List<ClearNodeUsageResponse> readNodesFrom(StreamInput in) throws IOException {
return in.readList(ClearNodeUsageResponse::readNodeStats);
}

@Override
protected void writeNodesTo(StreamOutput out, List<ClearNodeUsageResponse> nodes) throws IOException {
out.writeStreamableList(nodes);
}

}
Loading