Skip to content

Commit bef1e45

Browse files
authored
Apply spotless formatting to more sub-projects (#73989) (#73996)
1 parent 6035916 commit bef1e45

File tree

21 files changed

+800
-358
lines changed

21 files changed

+800
-358
lines changed

build-tools-internal/src/main/groovy/elasticsearch.formatting.gradle

-6
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ def projectPathsToExclude = [
106106
':test:fixtures:azure-fixture',
107107
':test:fixtures:gcs-fixture',
108108
':test:fixtures:geoip-fixture',
109-
':test:fixtures:hdfs-fixture',
110109
':test:fixtures:krb5kdc-fixture',
111-
':test:fixtures:minio-fixture',
112110
':test:fixtures:old-elasticsearch',
113-
':test:fixtures:s3-fixture',
114-
':test:fixtures:url-fixture',
115111
':test:framework',
116112
':test:logger-usage',
117113
':x-pack:license-tools',
@@ -134,7 +130,6 @@ def projectPathsToExclude = [
134130
':x-pack:plugin:eql:qa:rest',
135131
':x-pack:plugin:eql:qa:security',
136132
':x-pack:plugin:fleet:qa:rest',
137-
':x-pack:plugin:frozen-indices',
138133
':x-pack:plugin:graph',
139134
':x-pack:plugin:graph:qa:with-security',
140135
':x-pack:plugin:identity-provider',
@@ -159,7 +154,6 @@ def projectPathsToExclude = [
159154
':x-pack:plugin:rollup',
160155
':x-pack:plugin:rollup:qa:rest',
161156
':x-pack:plugin:search-business-rules',
162-
':x-pack:plugin:searchable-snapshots:qa:rest',
163157
':x-pack:plugin:security',
164158
':x-pack:plugin:security:cli',
165159
':x-pack:plugin:security:qa:basic-enable-security',

test/fixtures/azure-fixture/src/main/java/fixture/azure/AzureHttpHandler.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void handle(final HttpExchange exchange) throws IOException {
9898
} else {
9999
blobs.put(exchange.getRequestURI().getPath(), Streams.readFully(exchange.getRequestBody()));
100100
}
101-
exchange.getResponseHeaders().add("x-ms-request-server-encrypted", "false");
101+
exchange.getResponseHeaders().add("x-ms-request-server-encrypted", "false");
102102
exchange.sendResponseHeaders(RestStatus.CREATED.getStatus(), -1);
103103

104104
} else if (Regex.simpleMatch("HEAD /" + account + "/" + container + "/*", request)) {
@@ -222,8 +222,11 @@ public static void sendError(final HttpExchange exchange, final RestStatus statu
222222
if ("HEAD".equals(exchange.getRequestMethod())) {
223223
exchange.sendResponseHeaders(status.getStatus(), -1L);
224224
} else {
225-
final byte[] response = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>" + errorCode + "</Code><Message>"
226-
+ status + "</Message></Error>").getBytes(StandardCharsets.UTF_8);
225+
final byte[] response = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>"
226+
+ errorCode
227+
+ "</Code><Message>"
228+
+ status
229+
+ "</Message></Error>").getBytes(StandardCharsets.UTF_8);
227230
exchange.sendResponseHeaders(status.getStatus(), response.length);
228231
exchange.getResponseBody().write(response);
229232
}

test/fixtures/gcs-fixture/src/main/java/fixture/gcs/FakeOAuth2HttpHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class FakeOAuth2HttpHandler implements HttpHandler {
2424
@Override
2525
public void handle(final HttpExchange exchange) throws IOException {
2626
try {
27-
while (exchange.getRequestBody().read(BUFFER) >= 0) ;
27+
while (exchange.getRequestBody().read(BUFFER) >= 0) {
28+
}
2829
byte[] response = ("{\"access_token\":\"foo\",\"token_type\":\"Bearer\",\"expires_in\":3600}").getBytes(UTF_8);
2930
exchange.getResponseHeaders().add("Content-Type", "application/json");
3031
exchange.getResponseHeaders().add("Metadata-Flavor", "Google");

test/fixtures/gcs-fixture/src/main/java/fixture/gcs/FakeProjectIdHttpHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class FakeProjectIdHttpHandler implements HttpHandler {
2525
@Override
2626
public void handle(final HttpExchange exchange) throws IOException {
2727
try {
28-
while (exchange.getRequestBody().read(BUFFER) >= 0) ;
28+
while (exchange.getRequestBody().read(BUFFER) >= 0) {
29+
}
2930
byte[] response = ("some-project-id").getBytes(UTF_8);
3031
exchange.getResponseHeaders().add("Content-Type", "application/json");
3132
exchange.getResponseHeaders().add("Metadata-Flavor", "Google");

test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpFixture.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class GoogleCloudStorageHttpFixture {
1717

1818
private final HttpServer server;
1919

20-
private GoogleCloudStorageHttpFixture(final String address, final int port,
21-
final String bucket, final String token) throws IOException {
20+
private GoogleCloudStorageHttpFixture(final String address, final int port, final String bucket, final String token)
21+
throws IOException {
2222
this.server = HttpServer.create(new InetSocketAddress(InetAddress.getByName(address), port), 0);
2323
server.createContext("/" + token, new FakeOAuth2HttpHandler());
2424
server.createContext("/computeMetadata/v1/project/project-id", new FakeProjectIdHttpHandler());

test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpHandler.java

+59-28
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public void handle(final HttpExchange exchange) throws IOException {
8080
try {
8181
// Request body is closed in the finally block
8282
final BytesReference requestBody = Streams.readFully(Streams.noCloseStream(exchange.getRequestBody()));
83-
if (request.equals("GET /") &&
84-
"Google".equals(exchange.getRequestHeaders().getFirst("Metadata-Flavor"))) {
83+
if (request.equals("GET /") && "Google".equals(exchange.getRequestHeaders().getFirst("Metadata-Flavor"))) {
8584
// the SDK checks this endpoint to determine if it's running within Google Compute Engine
8685
exchange.getResponseHeaders().add("Metadata-Flavor", "Google");
8786
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), 0);
@@ -118,11 +117,11 @@ public void handle(final HttpExchange exchange) throws IOException {
118117
}
119118
}
120119

121-
byte[] response = ("{\"kind\":\"storage#objects\",\"items\":[" +
122-
String.join(",", listOfBlobs) +
123-
"],\"prefixes\":[" +
124-
String.join(",", prefixes) +
125-
"]}").getBytes(UTF_8);
120+
byte[] response = ("{\"kind\":\"storage#objects\",\"items\":["
121+
+ String.join(",", listOfBlobs)
122+
+ "],\"prefixes\":["
123+
+ String.join(",", prefixes)
124+
+ "]}").getBytes(UTF_8);
126125

127126
exchange.getResponseHeaders().add("Content-Type", "application/json; charset=utf-8");
128127
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), response.length);
@@ -194,8 +193,13 @@ public void handle(final HttpExchange exchange) throws IOException {
194193
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), response.length);
195194
exchange.getResponseBody().write(response);
196195
} else {
197-
throw new AssertionError("Could not read multi-part request to [" + request + "] with headers ["
198-
+ new HashMap<>(exchange.getRequestHeaders()) + "]");
196+
throw new AssertionError(
197+
"Could not read multi-part request to ["
198+
+ request
199+
+ "] with headers ["
200+
+ new HashMap<>(exchange.getRequestHeaders())
201+
+ "]"
202+
);
199203
}
200204

201205
} else if (Regex.simpleMatch("POST /upload/storage/v1/b/" + bucket + "/*uploadType=resumable*", request)) {
@@ -208,14 +212,23 @@ public void handle(final HttpExchange exchange) throws IOException {
208212
byte[] response = requestBody.utf8ToString().getBytes(UTF_8);
209213
if (Paths.get(blobName).getFileName().toString().startsWith(BlobStoreRepository.UPLOADED_DATA_BLOB_PREFIX) == false) {
210214
final Map<String, Object> parsedBody = XContentHelper.convertToMap(requestBody, false, XContentType.JSON).v2();
211-
assert parsedBody.get("md5Hash") != null :
212-
"file [" + blobName + "] is not a data blob but did not come with a md5 checksum";
215+
assert parsedBody.get("md5Hash") != null
216+
: "file [" + blobName + "] is not a data blob but did not come with a md5 checksum";
213217
}
214218
exchange.getResponseHeaders().add("Content-Type", "application/json");
215-
exchange.getResponseHeaders().add("Location", httpServerUrl(exchange) + "/upload/storage/v1/b/" + bucket + "/o?"
216-
+ "uploadType=resumable"
217-
+ "&upload_id=" + UUIDs.randomBase64UUID()
218-
+ "&test_blob_name=" + blobName); // not a Google Storage parameter, but it allows to pass the blob name
219+
exchange.getResponseHeaders()
220+
.add(
221+
"Location",
222+
httpServerUrl(exchange)
223+
+ "/upload/storage/v1/b/"
224+
+ bucket
225+
+ "/o?"
226+
+ "uploadType=resumable"
227+
+ "&upload_id="
228+
+ UUIDs.randomBase64UUID()
229+
+ "&test_blob_name="
230+
+ blobName
231+
); // not a Google Storage parameter, but it allows to pass the blob name
219232
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), response.length);
220233
exchange.getResponseBody().write(response);
221234

@@ -260,10 +273,18 @@ public void handle(final HttpExchange exchange) throws IOException {
260273

261274
private String buildBlobInfoJson(String blobName, int size) {
262275
return "{\"kind\":\"storage#object\","
263-
+ "\"bucket\":\"" + bucket + "\","
264-
+ "\"name\":\"" + blobName + "\","
265-
+ "\"id\":\"" + blobName + "\","
266-
+ "\"size\":\"" + size + "\""
276+
+ "\"bucket\":\""
277+
+ bucket
278+
+ "\","
279+
+ "\"name\":\""
280+
+ blobName
281+
+ "\","
282+
+ "\"id\":\""
283+
+ blobName
284+
+ "\","
285+
+ "\"size\":\""
286+
+ size
287+
+ "\""
267288
+ "}";
268289
}
269290

@@ -307,7 +328,9 @@ public static Optional<Tuple<String, BytesReference>> parseMultipartRequestBody(
307328
} else if (start.startsWith(bucketPrefix)) {
308329
markAndContinue = true;
309330
final String line = fullRequestBody.slice(
310-
startPos + bucketPrefix.length(), endPos - startPos - bucketPrefix.length()).utf8ToString();
331+
startPos + bucketPrefix.length(),
332+
endPos - startPos - bucketPrefix.length()
333+
).utf8ToString();
311334
Matcher matcher = NAME_PATTERN.matcher(line);
312335
if (matcher.find()) {
313336
name = matcher.group(1);
@@ -326,8 +349,12 @@ public static Optional<Tuple<String, BytesReference>> parseMultipartRequestBody(
326349
}
327350
if (content == null) {
328351
final InputStream stream = fullRequestBody.streamInput();
329-
logger.warn(() -> new ParameterizedMessage("Failed to find multi-part upload in [{}]", new BufferedReader(
330-
new InputStreamReader(stream)).lines().collect(Collectors.joining("\n"))));
352+
logger.warn(
353+
() -> new ParameterizedMessage(
354+
"Failed to find multi-part upload in [{}]",
355+
new BufferedReader(new InputStreamReader(stream)).lines().collect(Collectors.joining("\n"))
356+
)
357+
);
331358
}
332359
return Optional.ofNullable(content);
333360
}
@@ -360,14 +387,18 @@ public static Integer getContentRangeLimit(final String contentRange) {
360387
}
361388

362389
public static int getContentRangeStart(final String contentRange) {
363-
return parse(PATTERN_CONTENT_RANGE, contentRange,
364-
(bytes, limit) -> parse(PATTERN_CONTENT_RANGE_BYTES, bytes,
365-
(start, end) -> Integer.parseInt(start)));
390+
return parse(
391+
PATTERN_CONTENT_RANGE,
392+
contentRange,
393+
(bytes, limit) -> parse(PATTERN_CONTENT_RANGE_BYTES, bytes, (start, end) -> Integer.parseInt(start))
394+
);
366395
}
367396

368397
public static int getContentRangeEnd(final String contentRange) {
369-
return parse(PATTERN_CONTENT_RANGE, contentRange,
370-
(bytes, limit) -> parse(PATTERN_CONTENT_RANGE_BYTES, bytes,
371-
(start, end) -> Integer.parseInt(end)));
398+
return parse(
399+
PATTERN_CONTENT_RANGE,
400+
contentRange,
401+
(bytes, limit) -> parse(PATTERN_CONTENT_RANGE_BYTES, bytes, (start, end) -> Integer.parseInt(end))
402+
);
372403
}
373404
}

test/fixtures/hdfs-fixture/src/main/java/hdfs/MiniHDFS.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public class MiniHDFS {
4545

4646
public static void main(String[] args) throws Exception {
4747
if (args.length != 1 && args.length != 3) {
48-
throw new IllegalArgumentException("Expected: MiniHDFS <baseDirectory> [<kerberosPrincipal> <kerberosKeytab>], " +
49-
"got: " + Arrays.toString(args));
48+
throw new IllegalArgumentException(
49+
"Expected: MiniHDFS <baseDirectory> [<kerberosPrincipal> <kerberosKeytab>], got: " + Arrays.toString(args)
50+
);
5051
}
5152
boolean secure = args.length == 3;
5253

@@ -89,7 +90,7 @@ public static void main(String[] args) throws Exception {
8990

9091
MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(cfg);
9192
String explicitPort = System.getProperty("hdfs.config.port");
92-
if(explicitPort != null) {
93+
if (explicitPort != null) {
9394
builder.nameNodePort(Integer.parseInt(explicitPort));
9495
} else {
9596
if (secure) {
@@ -142,7 +143,9 @@ public static void main(String[] args) throws Exception {
142143
FileUtils.copyURLToFile(readOnlyRepositoryArchiveURL, readOnlyRepositoryArchive);
143144
FileUtil.unTar(readOnlyRepositoryArchive, tempDirectory.toFile());
144145

145-
fs.copyFromLocalFile(true, true,
146+
fs.copyFromLocalFile(
147+
true,
148+
true,
146149
new org.apache.hadoop.fs.Path(tempDirectory.resolve(directoryName).toAbsolutePath().toUri()),
147150
esUserPath.suffix("/existing/" + directoryName)
148151
);

test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpFixtureWithEC2.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,23 @@ protected HttpHandler createHandler(final String[] args) {
6565

6666
protected String buildCredentialResponse(final String ec2AccessKey, final String ec2SessionToken) {
6767
return "{"
68-
+ "\"AccessKeyId\": \"" + ec2AccessKey + "\","
69-
+ "\"Expiration\": \"" + ZonedDateTime.now().plusDays(1L).format(DateTimeFormatter.ISO_DATE_TIME) + "\","
70-
+ "\"RoleArn\": \"arn\","
68+
+ "\"AccessKeyId\": \""
69+
+ ec2AccessKey
70+
+ "\",\"Expiration\": \""
71+
+ ZonedDateTime.now().plusDays(1L).format(DateTimeFormatter.ISO_DATE_TIME)
72+
+ "\",\"RoleArn\": \"arn\","
7173
+ "\"SecretAccessKey\": \"secret_access_key\","
72-
+ "\"Token\": \"" + ec2SessionToken + "\""
74+
+ "\"Token\": \""
75+
+ ec2SessionToken
76+
+ "\""
7377
+ "}";
7478
}
7579

7680
public static void main(final String[] args) throws Exception {
7781
if (args == null || args.length < 6) {
78-
throw new IllegalArgumentException("S3HttpFixtureWithEC2 expects 6 arguments " +
79-
"[address, port, bucket, base path, ec2 access id, ec2 session token]");
82+
throw new IllegalArgumentException(
83+
"S3HttpFixtureWithEC2 expects 6 arguments " + "[address, port, bucket, base path, ec2 access id, ec2 session token]"
84+
);
8085
}
8186
final S3HttpFixtureWithEC2 fixture = new S3HttpFixtureWithEC2(args);
8287
fixture.start();

test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpFixtureWithECS.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ protected HttpHandler createHandler(final String[] args) {
4141

4242
public static void main(final String[] args) throws Exception {
4343
if (args == null || args.length < 6) {
44-
throw new IllegalArgumentException("S3HttpFixtureWithECS expects 6 arguments " +
45-
"[address, port, bucket, base path, ecs access id, ecs session token]");
44+
throw new IllegalArgumentException(
45+
"S3HttpFixtureWithECS expects 6 arguments [address, port, bucket, base path, ecs access id, ecs session token]"
46+
);
4647
}
4748
final S3HttpFixtureWithECS fixture = new S3HttpFixtureWithECS(args);
4849
fixture.start();

test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpFixtureWithSessionToken.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ protected HttpHandler createHandler(final String[] args) {
4040

4141
public static void main(final String[] args) throws Exception {
4242
if (args == null || args.length < 6) {
43-
throw new IllegalArgumentException("S3HttpFixtureWithSessionToken expects 6 arguments " +
44-
"[address, port, bucket, base path, access key, session token]");
43+
throw new IllegalArgumentException(
44+
"S3HttpFixtureWithSessionToken expects 6 arguments [address, port, bucket, base path, access key, session token]"
45+
);
4546
}
4647
final S3HttpFixtureWithSessionToken fixture = new S3HttpFixtureWithSessionToken(args);
4748
fixture.start();

0 commit comments

Comments
 (0)