From 11fa8d37440403169a50b37dcc4a6d751e10ae69 Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Fri, 26 Oct 2018 16:14:04 -0500 Subject: [PATCH] Enforce 140 char line lengths for packages action.bulk/delete/explain/get/index (#34885) part of #34884 --- .../resources/checkstyle_suppressions.xml | 16 --------- .../action/bulk/BackoffPolicy.java | 3 +- .../action/bulk/BulkProcessor.java | 8 +++-- .../action/bulk/BulkRequest.java | 13 +++++--- .../action/bulk/BulkResponse.java | 3 +- .../action/bulk/TransportBulkAction.java | 33 ++++++++++++------- .../action/delete/DeleteRequest.java | 6 ++-- .../explain/TransportExplainAction.java | 9 +++-- .../elasticsearch/action/get/GetRequest.java | 4 +-- .../action/get/MultiGetRequest.java | 14 +++++--- .../action/get/TransportGetAction.java | 3 +- .../get/TransportShardMultiGetAction.java | 4 +-- .../action/index/IndexRequest.java | 12 ++++--- .../action/bulk/BulkRequestTests.java | 6 ++-- .../elasticsearch/action/bulk/RetryTests.java | 3 +- .../action/get/MultiGetShardRequestTests.java | 3 +- 16 files changed, 81 insertions(+), 59 deletions(-) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index 1da4c0f9fbd..fbc4b82e32b 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -78,19 +78,6 @@ - - - - - - - - - - - - - @@ -291,9 +278,6 @@ - - - diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BackoffPolicy.java b/server/src/main/java/org/elasticsearch/action/bulk/BackoffPolicy.java index 81084e22377..00462df4d89 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BackoffPolicy.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BackoffPolicy.java @@ -34,7 +34,8 @@ import java.util.NoSuchElementException; * semantics: * *
    - *
  • #hasNext() determines whether the progression has more elements. Return true for infinite progressions
  • + *
  • #hasNext() determines whether the progression has more elements. Return true for infinite progressions + *
  • *
  • #next() determines the next element in the progression, i.e. the next wait time period
  • *
* diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java index f8f9d154b14..a2cae6b7bec 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java @@ -217,12 +217,13 @@ public class BulkProcessor implements Closeable { * Closes the processor. If flushing by time is enabled, then it's shutdown. Any remaining bulk actions are flushed. *

* If concurrent requests are not enabled, returns {@code true} immediately. - * If concurrent requests are enabled, waits for up to the specified timeout for all bulk requests to complete then returns {@code true}, + * If concurrent requests are enabled, waits for up to the specified timeout for all bulk requests to complete then returns {@code true} * If the specified waiting time elapses before all bulk requests complete, {@code false} is returned. * * @param timeout The maximum time to wait for the bulk requests to complete * @param unit The time unit of the {@code timeout} argument - * @return {@code true} if all bulk requests completed and {@code false} if the waiting time elapsed before all the bulk requests completed + * @return {@code true} if all bulk requests completed and {@code false} if the waiting time elapsed before all the bulk requests + * completed * @throws InterruptedException If the current thread is interrupted */ public synchronized boolean awaitClose(long timeout, TimeUnit unit) throws InterruptedException { @@ -298,7 +299,8 @@ public class BulkProcessor implements Closeable { * Adds the data from the bytes to be processed by the bulk processor */ public synchronized BulkProcessor add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, - @Nullable String defaultPipeline, @Nullable Object payload, XContentType xContentType) throws Exception { + @Nullable String defaultPipeline, @Nullable Object payload, + XContentType xContentType) throws Exception { bulkRequest.add(data, defaultIndex, defaultType, null, null, defaultPipeline, payload, true, xContentType); executeIfNeeded(); return this; diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index 6698aa4b62a..c10dcc02082 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -369,20 +369,23 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques } else if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) { fetchSourceContext = FetchSourceContext.fromXContent(parser); } else { - throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]"); + throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + + currentFieldName + "]"); } } else if (token == XContentParser.Token.START_ARRAY) { throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); - } else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName, parser.getDeprecationHandler())) { + } else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName, + parser.getDeprecationHandler())) { fetchSourceContext = FetchSourceContext.fromXContent(parser); } else if (token != XContentParser.Token.VALUE_NULL) { - throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); + throw new IllegalArgumentException("Malformed action/metadata line [" + line + + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); } } } else if (token != XContentParser.Token.END_OBJECT) { - throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected " + XContentParser.Token.START_OBJECT - + " or " + XContentParser.Token.END_OBJECT + " but found [" + token + "]"); + throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected " + + XContentParser.Token.START_OBJECT + " or " + XContentParser.Token.END_OBJECT + " but found [" + token + "]"); } if ("delete".equals(action)) { diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java index 30bf2dc1477..d474dcee363 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java @@ -109,7 +109,8 @@ public class BulkResponse extends ActionResponse implements Iterable responses, int idx, DocWriteRequest request, String index, Exception e) { + private boolean setResponseFailureIfIndexMatches(AtomicArray responses, int idx, DocWriteRequest request, + String index, Exception e) { if (index.equals(request.index())) { - responses.set(idx, new BulkItemResponse(idx, request.opType(), new BulkItemResponse.Failure(request.index(), request.type(), request.id(), e))); + responses.set(idx, new BulkItemResponse(idx, request.opType(), new BulkItemResponse.Failure(request.index(), request.type(), + request.id(), e))); return true; } return false; @@ -327,19 +329,22 @@ public class TransportBulkAction extends HandledTransportAction shardRequests = requestsByShard.computeIfAbsent(shardId, shard -> new ArrayList<>()); shardRequests.add(new BulkItemRequest(i, request)); } if (requestsByShard.isEmpty()) { - listener.onResponse(new BulkResponse(responses.toArray(new BulkItemResponse[responses.length()]), buildTookInMillis(startTimeNanos))); + listener.onResponse(new BulkResponse(responses.toArray(new BulkItemResponse[responses.length()]), + buildTookInMillis(startTimeNanos))); return; } @@ -407,7 +414,8 @@ public class TransportBulkAction extends HandledTransportAction actionListener = bulkRequestModifier.wrapActionListenerIfNeeded(ingestTookInMillis, listener); + ActionListener actionListener = bulkRequestModifier.wrapActionListenerIfNeeded(ingestTookInMillis, + listener); if (bulkRequest.requests().isEmpty()) { // at this stage, the transport bulk action can't deal with a bulk request with no requests, // so we stop and send an empty response back to the client. @@ -628,7 +637,8 @@ public class TransportBulkAction extends HandledTransportAction itemResponses; private final ActionListener actionListener; - IngestBulkResponseListener(long ingestTookInMillis, int[] originalSlots, List itemResponses, ActionListener actionListener) { + IngestBulkResponseListener(long ingestTookInMillis, int[] originalSlots, List itemResponses, + ActionListener actionListener) { this.ingestTookInMillis = ingestTookInMillis; this.itemResponses = itemResponses; this.actionListener = actionListener; diff --git a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java index 879e8e665cd..ee9c863c011 100644 --- a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java +++ b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java @@ -46,7 +46,8 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; * @see org.elasticsearch.client.Client#delete(DeleteRequest) * @see org.elasticsearch.client.Requests#deleteRequest(String) */ -public class DeleteRequest extends ReplicatedWriteRequest implements DocWriteRequest, CompositeIndicesRequest { +public class DeleteRequest extends ReplicatedWriteRequest + implements DocWriteRequest, CompositeIndicesRequest { private String type; private String id; @@ -89,7 +90,8 @@ public class DeleteRequest extends ReplicatedWriteRequest impleme validationException = addValidationError("id is missing", validationException); } if (!versionType.validateVersionForWrites(version)) { - validationException = addValidationError("illegal version value [" + version + "] for version type [" + versionType.name() + "]", validationException); + validationException = addValidationError("illegal version value [" + version + "] for version type [" + + versionType.name() + "]", validationException); } if (versionType == VersionType.FORCE) { validationException = addValidationError("version type [force] may no longer be used", validationException); diff --git a/server/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java b/server/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java index c1695e13864..aff9594ff13 100644 --- a/server/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java +++ b/server/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java @@ -90,7 +90,8 @@ public class TransportExplainAction extends TransportSingleShardAction listener) throws IOException { + protected void asyncShardOperation(ExplainRequest request, ShardId shardId, + ActionListener listener) throws IOException { IndexService indexService = searchService.getIndicesService().indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); indexShard.awaitShardSearchActive(b -> { @@ -129,7 +130,8 @@ public class TransportExplainAction extends TransportSingleShardAction implements Realti validationException = ValidateActions.addValidationError("id is missing", validationException); } if (!versionType.validateVersionForReads(version)) { - validationException = ValidateActions.addValidationError("illegal version value [" + version + "] for version type [" + versionType.name() + "]", - validationException); + validationException = ValidateActions.addValidationError("illegal version value [" + version + "] for version type [" + + versionType.name() + "]", validationException); } if (versionType == VersionType.FORCE) { validationException = ValidateActions.addValidationError("version type [force] may no longer be used", validationException); diff --git a/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java b/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java index 875015f8a98..df23bad10bc 100644 --- a/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java +++ b/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java @@ -360,7 +360,8 @@ public class MultiGetRequest extends ActionRequest currentFieldName = parser.currentName(); } else if (token == Token.START_ARRAY) { if ("docs".equals(currentFieldName)) { - parseDocuments(parser, this.items, defaultIndex, defaultType, defaultFields, defaultFetchSource, defaultRouting, allowExplicitIndex); + parseDocuments(parser, this.items, defaultIndex, defaultType, defaultFields, defaultFetchSource, defaultRouting, + allowExplicitIndex); } else if ("ids".equals(currentFieldName)) { parseIds(parser, this.items, defaultIndex, defaultType, defaultFields, defaultFetchSource, defaultRouting); } else { @@ -384,7 +385,9 @@ public class MultiGetRequest extends ActionRequest return this; } - private static void parseDocuments(XContentParser parser, List items, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, @Nullable String defaultRouting, boolean allowExplicitIndex) throws IOException { + private static void parseDocuments(XContentParser parser, List items, @Nullable String defaultIndex, @Nullable String defaultType, + @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, + @Nullable String defaultRouting, boolean allowExplicitIndex) throws IOException { String currentFieldName = null; Token token; while ((token = parser.nextToken()) != Token.END_ARRAY) { @@ -499,13 +502,16 @@ public class MultiGetRequest extends ActionRequest } } - public static void parseIds(XContentParser parser, List items, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, @Nullable String defaultRouting) throws IOException { + public static void parseIds(XContentParser parser, List items, @Nullable String defaultIndex, @Nullable String defaultType, + @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, + @Nullable String defaultRouting) throws IOException { Token token; while ((token = parser.nextToken()) != Token.END_ARRAY) { if (!token.isValue()) { throw new IllegalArgumentException("ids array element should only contain ids"); } - items.add(new Item(defaultIndex, defaultType, parser.text()).storedFields(defaultFields).fetchSourceContext(defaultFetchSource).routing(defaultRouting)); + items.add(new Item(defaultIndex, defaultType, parser.text()).storedFields(defaultFields).fetchSourceContext(defaultFetchSource) + .routing(defaultRouting)); } } diff --git a/server/src/main/java/org/elasticsearch/action/get/TransportGetAction.java b/server/src/main/java/org/elasticsearch/action/get/TransportGetAction.java index 69753bdd979..fcdece29e1b 100644 --- a/server/src/main/java/org/elasticsearch/action/get/TransportGetAction.java +++ b/server/src/main/java/org/elasticsearch/action/get/TransportGetAction.java @@ -63,7 +63,8 @@ public class TransportGetAction extends TransportSingleShardAction implement final long resolvedVersion = resolveVersionDefaults(); if (opType() == OpType.CREATE) { if (versionType != VersionType.INTERNAL) { - validationException = addValidationError("create operations only support internal versioning. use index instead", validationException); + validationException = addValidationError("create operations only support internal versioning. use index instead", + validationException); return validationException; } if (resolvedVersion != Versions.MATCH_DELETED) { - validationException = addValidationError("create operations do not support explicit versions. use index instead", validationException); + validationException = addValidationError("create operations do not support explicit versions. use index instead", + validationException); return validationException; } } @@ -169,7 +171,8 @@ public class IndexRequest extends ReplicatedWriteRequest implement } if (!versionType.validateVersionForWrites(resolvedVersion)) { - validationException = addValidationError("illegal version value [" + resolvedVersion + "] for version type [" + versionType.name() + "]", validationException); + validationException = addValidationError("illegal version value [" + resolvedVersion + "] for version type [" + + versionType.name() + "]", validationException); } if (versionType == VersionType.FORCE) { @@ -347,7 +350,8 @@ public class IndexRequest extends ReplicatedWriteRequest implement throw new IllegalArgumentException("The number of object passed must be even but was [" + source.length + "]"); } if (source.length == 2 && source[0] instanceof BytesReference && source[1] instanceof Boolean) { - throw new IllegalArgumentException("you are using the removed method for source with bytes and unsafe flag, the unsafe flag was removed, please just use source(BytesReference)"); + throw new IllegalArgumentException("you are using the removed method for source with bytes and unsafe flag, the unsafe flag" + + " was removed, please just use source(BytesReference)"); } try { XContentBuilder builder = XContentFactory.contentBuilder(xContentType); diff --git a/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java b/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java index 1b2c238098e..65935bea96e 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java @@ -165,7 +165,8 @@ public class BulkRequestTests extends ESTestCase { BulkRequest bulkRequest = new BulkRequest(); IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON)); - assertThat(exc.getMessage(), containsString("Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [START_ARRAY]")); + assertThat(exc.getMessage(), + containsString("Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [START_ARRAY]")); } public void testSimpleBulk10() throws Exception { @@ -207,7 +208,8 @@ public class BulkRequestTests extends ESTestCase { BulkRequest bulkRequest = new BulkRequest(); IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON)); - assertThat(exc.getMessage(), containsString("Malformed action/metadata line [" + emptyLine + "], expected FIELD_NAME but found [END_OBJECT]")); + assertThat(exc.getMessage(), containsString("Malformed action/metadata line [" + + emptyLine + "], expected FIELD_NAME but found [END_OBJECT]")); } // issue 7361 diff --git a/server/src/test/java/org/elasticsearch/action/bulk/RetryTests.java b/server/src/test/java/org/elasticsearch/action/bulk/RetryTests.java index f9cdfa092ae..decee8ceab7 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/RetryTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/RetryTests.java @@ -230,7 +230,8 @@ public class RetryTests extends ESTestCase { } private BulkItemResponse failedResponse() { - return new BulkItemResponse(1, OpType.INDEX, new BulkItemResponse.Failure("test", "test", "1", new EsRejectedExecutionException("pool full"))); + return new BulkItemResponse(1, OpType.INDEX, new BulkItemResponse.Failure("test", "test", "1", + new EsRejectedExecutionException("pool full"))); } } } diff --git a/server/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java b/server/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java index a130f10d659..782edb517cb 100644 --- a/server/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java @@ -45,7 +45,8 @@ public class MultiGetShardRequestTests extends ESTestCase { MultiGetShardRequest multiGetShardRequest = new MultiGetShardRequest(multiGetRequest, "index", 0); int numItems = iterations(10, 30); for (int i = 0; i < numItems; i++) { - MultiGetRequest.Item item = new MultiGetRequest.Item("alias-" + randomAlphaOfLength(randomIntBetween(1, 10)), "type", "id-" + i); + MultiGetRequest.Item item = new MultiGetRequest.Item("alias-" + randomAlphaOfLength(randomIntBetween(1, 10)), + "type", "id-" + i); if (randomBoolean()) { int numFields = randomIntBetween(1, 5); String[] fields = new String[numFields];