From 47577613cb54559fe8db890c6ad74f9883771935 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 27 Apr 2016 17:02:35 -0400 Subject: [PATCH] Wrap tasks code at 140 columns Switch something from an explicit toString to Strings.toString which is the same thing but with more code reuse. Also renamed a constant to be CONSTANT_CASE. --- .../resources/checkstyle_suppressions.xml | 7 ---- .../node/tasks/list/ListTasksResponse.java | 15 +++----- .../tasks/list/TransportListTasksAction.java | 9 +++-- .../support/tasks/TasksRequestBuilder.java | 7 ++-- .../node/tasks/CancellableTasksTests.java | 2 +- .../node/tasks/TaskManagerTestCase.java | 8 ++--- .../node/tasks/TransportTasksActionTests.java | 35 ++++++++++++------- 7 files changed, 42 insertions(+), 41 deletions(-) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index 2cdb0f74f6d..8394e430777 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -30,8 +30,6 @@ - - @@ -233,8 +231,6 @@ - - @@ -803,7 +799,6 @@ - @@ -1467,7 +1462,6 @@ - @@ -1476,6 +1470,5 @@ - diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java index f8ecd7a506f..446ae3affb7 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java @@ -23,11 +23,11 @@ import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.TaskOperationFailure; import org.elasticsearch.action.support.tasks.BaseTasksResponse; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.Strings; 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 org.elasticsearch.tasks.TaskId; import java.io.IOException; @@ -54,7 +54,8 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent { public ListTasksResponse() { } - public ListTasksResponse(List tasks, List taskFailures, List nodeFailures) { + public ListTasksResponse(List tasks, List taskFailures, + List nodeFailures) { super(taskFailures, nodeFailures); this.tasks = tasks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(tasks)); } @@ -205,14 +206,6 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent { @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() + "\"}"; - } + return Strings.toString(this); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TransportListTasksAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TransportListTasksAction.java index e6ea002a794..b05049f6776 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TransportListTasksAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TransportListTasksAction.java @@ -51,12 +51,15 @@ public class TransportListTasksAction extends TransportTasksAction tasks, List taskOperationFailures, List failedNodeExceptions) { + protected ListTasksResponse newResponse(ListTasksRequest request, List tasks, + List taskOperationFailures, List failedNodeExceptions) { return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions); } diff --git a/core/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java index a510a847c62..78a2de20a89 100644 --- a/core/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java @@ -26,8 +26,11 @@ import org.elasticsearch.common.unit.TimeValue; /** * Builder for task-based requests */ -public class TasksRequestBuilder , Response extends BaseTasksResponse, RequestBuilder extends TasksRequestBuilder> - extends ActionRequestBuilder { +public class TasksRequestBuilder< + Request extends BaseTasksRequest, + Response extends BaseTasksResponse, + RequestBuilder extends TasksRequestBuilder + > extends ActionRequestBuilder { protected TasksRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java index fdbc16916ce..d96531b2f6c 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java @@ -202,7 +202,7 @@ public class CancellableTasksTests extends TaskManagerTestCase { for (int i = 0; i < testNodes.length; i++) { boolean shouldBlock = blockOnNodes.contains(testNodes[i]); logger.info("The action in the node [{}] should block: [{}]", testNodes[i].discoveryNode.getId(), shouldBlock); - actions[i] = new CancellableTestNodesAction(Settings.EMPTY, "testAction", clusterName, threadPool, testNodes[i] + actions[i] = new CancellableTestNodesAction(Settings.EMPTY, "testAction", CLUSTER_NAME, threadPool, testNodes[i] .clusterService, testNodes[i].transportService, shouldBlock, actionLatch); } Task task = actions[0].execute(request, listener); diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java index 9153e659d0b..0490dfd96aa 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java @@ -68,7 +68,7 @@ import static org.elasticsearch.cluster.service.ClusterServiceUtils.setState; public abstract class TaskManagerTestCase extends ESTestCase { protected static ThreadPool threadPool; - public static final ClusterName clusterName = new ClusterName("test-cluster"); + public static final ClusterName CLUSTER_NAME = new ClusterName("test-cluster"); protected TestNode[] testNodes; protected int nodesCount; @@ -203,10 +203,10 @@ public abstract class TaskManagerTestCase extends ESTestCase { emptyMap(), emptySet(), Version.CURRENT); IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(settings); ActionFilters actionFilters = new ActionFilters(emptySet()); - transportListTasksAction = new TransportListTasksAction(settings, clusterName, threadPool, clusterService, transportService, - actionFilters, indexNameExpressionResolver); - transportCancelTasksAction = new TransportCancelTasksAction(settings, clusterName, threadPool, clusterService, transportService, + transportListTasksAction = new TransportListTasksAction(settings, CLUSTER_NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver); + transportCancelTasksAction = new TransportCancelTasksAction(settings, CLUSTER_NAME, threadPool, clusterService, + transportService, actionFilters, indexNameExpressionResolver); transportService.acceptIncomingRequests(); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index 6e0bf27e642..3e996421441 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -221,7 +221,8 @@ public class TransportTasksActionTests extends TaskManagerTestCase { } - public TestTasksResponse(List tasks, List taskFailures, List nodeFailures) { + public TestTasksResponse(List tasks, List taskFailures, + List nodeFailures) { super(taskFailures, nodeFailures); this.tasks = tasks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(tasks)); } @@ -252,14 +253,16 @@ public class TransportTasksActionTests extends TaskManagerTestCase { */ static abstract class TestTasksAction extends TransportTasksAction { - protected TestTasksAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, ClusterService clusterService, - TransportService transportService) { - super(settings, actionName, clusterName, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), - TestTasksRequest::new, TestTasksResponse::new, ThreadPool.Names.MANAGEMENT); + protected TestTasksAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, + ClusterService clusterService, TransportService transportService) { + super(settings, actionName, clusterName, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), + new IndexNameExpressionResolver(Settings.EMPTY), TestTasksRequest::new, TestTasksResponse::new, + ThreadPool.Names.MANAGEMENT); } @Override - protected TestTasksResponse newResponse(TestTasksRequest request, List tasks, List taskOperationFailures, List failedNodeExceptions) { + protected TestTasksResponse newResponse(TestTasksRequest request, List tasks, + List taskOperationFailures, List failedNodeExceptions) { return new TestTasksResponse(tasks, taskOperationFailures, failedNodeExceptions); } @@ -278,22 +281,26 @@ public class TransportTasksActionTests extends TaskManagerTestCase { return startBlockingTestNodesAction(checkLatch, new NodesRequest("Test Request")); } - private ActionFuture startBlockingTestNodesAction(CountDownLatch checkLatch, NodesRequest request) throws InterruptedException { + private ActionFuture startBlockingTestNodesAction(CountDownLatch checkLatch, NodesRequest request) + throws InterruptedException { PlainActionFuture future = newFuture(); startBlockingTestNodesAction(checkLatch, request, future); return future; } - private Task startBlockingTestNodesAction(CountDownLatch checkLatch, ActionListener listener) throws InterruptedException { + private Task startBlockingTestNodesAction(CountDownLatch checkLatch, ActionListener listener) + throws InterruptedException { return startBlockingTestNodesAction(checkLatch, new NodesRequest("Test Request"), listener); } - private Task startBlockingTestNodesAction(CountDownLatch checkLatch, NodesRequest request, ActionListener listener) throws InterruptedException { + private Task startBlockingTestNodesAction(CountDownLatch checkLatch, NodesRequest request, ActionListener listener) + throws InterruptedException { CountDownLatch actionLatch = new CountDownLatch(nodesCount); TestNodesAction[] actions = new TestNodesAction[nodesCount]; for (int i = 0; i < testNodes.length; i++) { final int node = i; - actions[i] = new TestNodesAction(Settings.EMPTY, "testAction", clusterName, threadPool, testNodes[i].clusterService, testNodes[i].transportService) { + actions[i] = new TestNodesAction(Settings.EMPTY, "testAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, + testNodes[i].transportService) { @Override protected NodeResponse nodeOperation(NodeRequest request) { logger.info("Action on node {}", node); @@ -577,7 +584,8 @@ public class TransportTasksActionTests extends TaskManagerTestCase { RecordingTaskManagerListener[] listeners = setupListeners(testNodes, "testAction*"); for (int i = 0; i < testNodes.length; i++) { final int node = i; - actions[i] = new TestNodesAction(Settings.EMPTY, "testAction", clusterName, threadPool, testNodes[i].clusterService, testNodes[i].transportService) { + actions[i] = new TestNodesAction(Settings.EMPTY, "testAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, + testNodes[i].transportService) { @Override protected NodeResponse nodeOperation(NodeRequest request) { logger.info("Action on node {}", node); @@ -616,7 +624,8 @@ public class TransportTasksActionTests extends TaskManagerTestCase { for (int i = 0; i < testNodes.length; i++) { final int node = i; // Simulate task action that fails on one of the tasks on one of the nodes - tasksActions[i] = new TestTasksAction(Settings.EMPTY, "testTasksAction", clusterName, threadPool, testNodes[i].clusterService, testNodes[i].transportService) { + tasksActions[i] = new TestTasksAction(Settings.EMPTY, "testTasksAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, + testNodes[i].transportService) { @Override protected TestTaskResponse taskOperation(TestTasksRequest request, Task task) { logger.info("Task action on node {}", node); @@ -673,7 +682,7 @@ public class TransportTasksActionTests extends TaskManagerTestCase { final int node = i; // Simulate a task action that works on all nodes except nodes listed in filterNodes. // We are testing that it works. - tasksActions[i] = new TestTasksAction(Settings.EMPTY, "testTasksAction", clusterName, threadPool, + tasksActions[i] = new TestTasksAction(Settings.EMPTY, "testTasksAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, testNodes[i].transportService) { @Override