Permalink
Browse files

Cluster Nodes hot_threads API, closes #2134.

  • Loading branch information...
kimchy committed Aug 2, 2012
1 parent e26a56e commit 8be5c7220052c59bbb445db56b8579f12ca01b2b
@@ -22,6 +22,8 @@
import com.google.common.collect.Maps;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction;
+import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction;
+import org.elasticsearch.action.admin.cluster.node.hotthreads.TransportNodesHotThreadsAction;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartAction;
@@ -159,6 +161,7 @@ protected void configure() {
registerAction(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class);
registerAction(NodesShutdownAction.INSTANCE, TransportNodesShutdownAction.class);
registerAction(NodesRestartAction.INSTANCE, TransportNodesRestartAction.class);
+ registerAction(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class);
registerAction(ClusterStateAction.INSTANCE, TransportClusterStateAction.class);
registerAction(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class);
@@ -0,0 +1,64 @@
+/*
+ * Licensed to ElasticSearch and Shay Banon 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.hotthreads;
+
+import org.elasticsearch.action.support.nodes.NodeOperationResponse;
+import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.io.stream.StreamOutput;
+
+import java.io.IOException;
+
+/**
+ */
+public class NodeHotThreads extends NodeOperationResponse {
+
+ private String hotThreads;
+
+ NodeHotThreads() {
+ }
+
+ public NodeHotThreads(DiscoveryNode node, String hotThreads) {
+ super(node);
+ this.hotThreads = hotThreads;
+ }
+
+ public String hotThreads() {
+ return this.hotThreads;
+ }
+
+ public static NodeHotThreads readNodeHotThreads(StreamInput in) throws IOException {
+ NodeHotThreads node = new NodeHotThreads();
+ node.readFrom(in);
+ return node;
+ }
+
+ @Override
+ public void readFrom(StreamInput in) throws IOException {
+ super.readFrom(in);
+ hotThreads = in.readString();
+ }
+
+ @Override
+ public void writeTo(StreamOutput out) throws IOException {
+ super.writeTo(out);
+ out.writeString(hotThreads);
+ }
+}
@@ -0,0 +1,45 @@
+/*
+ * Licensed to ElasticSearch and Shay Banon 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.hotthreads;
+
+import org.elasticsearch.action.admin.cluster.ClusterAction;
+import org.elasticsearch.client.ClusterAdminClient;
+
+/**
+ */
+public class NodesHotThreadsAction extends ClusterAction<NodesHotThreadsRequest, NodesHotThreadsResponse, NodesHotThreadsRequestBuilder> {
+
+ public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction();
+ public static final String NAME = "cluster/nodes/hot_threads";
+
+ private NodesHotThreadsAction() {
+ super(NAME);
+ }
+
+ @Override
+ public NodesHotThreadsResponse newResponse() {
+ return new NodesHotThreadsResponse();
+ }
+
+ @Override
+ public NodesHotThreadsRequestBuilder newRequestBuilder(ClusterAdminClient client) {
+ return new NodesHotThreadsRequestBuilder(client);
+ }
+}
@@ -0,0 +1,88 @@
+/*
+ * Licensed to ElasticSearch and Shay Banon 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.hotthreads;
+
+import org.elasticsearch.action.support.nodes.NodesOperationRequest;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.unit.TimeValue;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ */
+public class NodesHotThreadsRequest extends NodesOperationRequest {
+
+ int threads = 3;
+ String type = "cpu";
+ TimeValue interval = new TimeValue(500, TimeUnit.MILLISECONDS);
+
+ /**
+ * Get hot threads from nodes based on the nodes ids specified. If none are passed, hot
+ * threads for all nodes is used.
+ */
+ public NodesHotThreadsRequest(String... nodesIds) {
+ super(nodesIds);
+ }
+
+ public int threads() {
+ return this.threads;
+ }
+
+ public NodesHotThreadsRequest threads(int threads) {
+ this.threads = threads;
+ return this;
+ }
+
+ public NodesHotThreadsRequest type(String type) {
+ this.type = type;
+ return this;
+ }
+
+ public String type() {
+ return this.type;
+ }
+
+ public NodesHotThreadsRequest interval(TimeValue interval) {
+ this.interval = interval;
+ return this;
+ }
+
+ public TimeValue interval() {
+ return this.interval;
+ }
+
+ @Override
+ public void readFrom(StreamInput in) throws IOException {
+ super.readFrom(in);
+ threads = in.readInt();
+ type = in.readString();
+ interval = TimeValue.readTimeValue(in);
+ }
+
+ @Override
+ public void writeTo(StreamOutput out) throws IOException {
+ super.writeTo(out);
+ out.writeInt(threads);
+ out.writeString(type);
+ interval.writeTo(out);
+ }
+}
@@ -0,0 +1,59 @@
+/*
+ * Licensed to ElasticSearch and Shay Banon 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.hotthreads;
+
+import org.elasticsearch.action.ActionListener;
+import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
+import org.elasticsearch.client.ClusterAdminClient;
+import org.elasticsearch.common.unit.TimeValue;
+
+/**
+ */
+public class NodesHotThreadsRequestBuilder extends BaseClusterRequestBuilder<NodesHotThreadsRequest, NodesHotThreadsResponse> {
+
+ public NodesHotThreadsRequestBuilder(ClusterAdminClient clusterClient) {
+ super(clusterClient, new NodesHotThreadsRequest());
+ }
+
+ public NodesHotThreadsRequestBuilder setNodesIds(String... nodesIds) {
+ request.nodesIds(nodesIds);
+ return this;
+ }
+
+ public NodesHotThreadsRequestBuilder setThreads(int threads) {
+ request.threads(threads);
+ return this;
+ }
+
+ public NodesHotThreadsRequestBuilder setType(String type) {
+ request.type(type);
+ return this;
+ }
+
+ public NodesHotThreadsRequestBuilder setInterval(TimeValue interval) {
+ request.interval(interval);
+ return this;
+ }
+
+ @Override
+ protected void doExecute(ActionListener<NodesHotThreadsResponse> listener) {
+ client.nodesHotThreads(request, listener);
+ }
+}
@@ -0,0 +1,58 @@
+/*
+ * Licensed to ElasticSearch and Shay Banon 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.hotthreads;
+
+import org.elasticsearch.action.support.nodes.NodesOperationResponse;
+import org.elasticsearch.cluster.ClusterName;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.io.stream.StreamOutput;
+
+import java.io.IOException;
+
+/**
+ */
+public class NodesHotThreadsResponse extends NodesOperationResponse<NodeHotThreads> {
+
+ NodesHotThreadsResponse() {
+ }
+
+ public NodesHotThreadsResponse(ClusterName clusterName, NodeHotThreads[] nodes) {
+ super(clusterName, nodes);
+ }
+
+ @Override
+ public void readFrom(StreamInput in) throws IOException {
+ super.readFrom(in);
+ nodes = new NodeHotThreads[in.readVInt()];
+ for (int i = 0; i < nodes.length; i++) {
+ nodes[i] = NodeHotThreads.readNodeHotThreads(in);
+ }
+ }
+
+ @Override
+ public void writeTo(StreamOutput out) throws IOException {
+ super.writeTo(out);
+ out.writeVInt(nodes.length);
+ for (NodeHotThreads node : nodes) {
+ node.writeTo(out);
+ }
+ }
+
+}
Oops, something went wrong.

0 comments on commit 8be5c72

Please sign in to comment.