From 5fef1669a059d462015a747f6fbf51bcb2220ded Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Mon, 11 Oct 2021 12:49:23 +0200 Subject: [PATCH] [Transform] HLRC cleanups (#78909) removes some "data frame" leftovers in transform code, no functional changes --- .../client/TransformRequestConverters.java | 53 ++++++++----------- .../org/elasticsearch/client/TransformIT.java | 38 +++++++------ .../TransformRequestConvertersTests.java | 32 +++++------ .../TransformDocumentationIT.java | 4 +- ...s.java => StartTransformRequestTests.java} | 2 +- ...java => UpdateTransformResponseTests.java} | 15 +++--- 6 files changed, 71 insertions(+), 73 deletions(-) rename client/rest-high-level/src/test/java/org/elasticsearch/client/transform/{StartDataFrameTransformRequestTests.java => StartTransformRequestTests.java} (94%) rename client/rest-high-level/src/test/java/org/elasticsearch/client/transform/{UpdateDataFrameTransformResponseTests.java => UpdateTransformResponseTests.java} (80%) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java index 84a234578eebb..2f27675a9efe3 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java @@ -38,10 +38,9 @@ final class TransformRequestConverters { private TransformRequestConverters() {} static Request putTransform(PutTransformRequest putRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") - .addPathPart(putRequest.getConfig().getId()) - .build(); + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") + .addPathPart(putRequest.getConfig().getId()) + .build(); Request request = new Request(HttpPut.METHOD_NAME, endpoint); request.setEntity(createEntity(putRequest, REQUEST_BODY_CONTENT_TYPE)); if (putRequest.getDeferValidation() != null) { @@ -50,25 +49,23 @@ static Request putTransform(PutTransformRequest putRequest) throws IOException { return request; } - static Request updateTransform(UpdateTransformRequest updateDataFrameTransformRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") - .addPathPart(updateDataFrameTransformRequest.getId()) + static Request updateTransform(UpdateTransformRequest updateTransformRequest) throws IOException { + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") + .addPathPart(updateTransformRequest.getId()) .addPathPart("_update") .build(); Request request = new Request(HttpPost.METHOD_NAME, endpoint); - request.setEntity(createEntity(updateDataFrameTransformRequest, REQUEST_BODY_CONTENT_TYPE)); - if (updateDataFrameTransformRequest.getDeferValidation() != null) { - request.addParameter(DEFER_VALIDATION, Boolean.toString(updateDataFrameTransformRequest.getDeferValidation())); + request.setEntity(createEntity(updateTransformRequest, REQUEST_BODY_CONTENT_TYPE)); + if (updateTransformRequest.getDeferValidation() != null) { + request.addParameter(DEFER_VALIDATION, Boolean.toString(updateTransformRequest.getDeferValidation())); } return request; } static Request getTransform(GetTransformRequest getRequest) { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") - .addPathPart(Strings.collectionToCommaDelimitedString(getRequest.getId())) - .build(); + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") + .addPathPart(Strings.collectionToCommaDelimitedString(getRequest.getId())) + .build(); Request request = new Request(HttpGet.METHOD_NAME, endpoint); if (getRequest.getPageParams() != null && getRequest.getPageParams().getFrom() != null) { request.addParameter(PageParams.FROM.getPreferredName(), getRequest.getPageParams().getFrom().toString()); @@ -86,10 +83,7 @@ static Request getTransform(GetTransformRequest getRequest) { } static Request deleteTransform(DeleteTransformRequest deleteRequest) { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") - .addPathPart(deleteRequest.getId()) - .build(); + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform").addPathPart(deleteRequest.getId()).build(); Request request = new Request(HttpDelete.METHOD_NAME, endpoint); if (deleteRequest.getForce() != null) { request.addParameter(FORCE, Boolean.toString(deleteRequest.getForce())); @@ -98,11 +92,10 @@ static Request deleteTransform(DeleteTransformRequest deleteRequest) { } static Request startTransform(StartTransformRequest startRequest) { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") - .addPathPart(startRequest.getId()) - .addPathPartAsIs("_start") - .build(); + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") + .addPathPart(startRequest.getId()) + .addPathPartAsIs("_start") + .build(); Request request = new Request(HttpPost.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(); if (startRequest.getTimeout() != null) { @@ -113,8 +106,7 @@ static Request startTransform(StartTransformRequest startRequest) { } static Request stopTransform(StopTransformRequest stopRequest) { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") .addPathPart(stopRequest.getId()) .addPathPartAsIs("_stop") .build(); @@ -151,11 +143,10 @@ static Request previewTransform(PreviewTransformRequest previewRequest) throws I } static Request getTransformStats(GetTransformStatsRequest statsRequest) { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_transform") - .addPathPart(statsRequest.getId()) - .addPathPartAsIs("_stats") - .build(); + String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") + .addPathPart(statsRequest.getId()) + .addPathPartAsIs("_stats") + .build(); Request request = new Request(HttpGet.METHOD_NAME, endpoint); if (statsRequest.getPageParams() != null && statsRequest.getPageParams().getFrom() != null) { request.addParameter(PageParams.FROM.getPreferredName(), statsRequest.getPageParams().getFrom().toString()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformIT.java index 53a5f5154b116..1870367d8e7b3 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformIT.java @@ -178,7 +178,7 @@ public void testCreateDelete() throws IOException { createIndex(sourceIndex); String id = "test-crud"; - TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest"); + TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest"); TransformClient client = highLevelClient().transform(); AcknowledgedResponse ack = execute(new PutTransformRequest(transform), client::putTransform, client::putTransformAsync); @@ -200,7 +200,7 @@ public void testUpdate() throws IOException { createIndex(sourceIndex); String id = "test-update"; - TransformConfig transform = validDataFrameTransformConfigBuilder(id, sourceIndex, "pivot-dest").setSyncConfig( + TransformConfig transform = validTransformConfigBuilder(id, sourceIndex, "pivot-dest").setSyncConfig( TimeSyncConfig.builder().setField("timestamp").setDelay(TimeValue.timeValueSeconds(60)).build() ).build(); @@ -228,7 +228,7 @@ public void testCreateDeleteWithDefer() throws IOException { String sourceIndex = "missing-source-index"; String id = "test-with-defer"; - TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest"); + TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest"); TransformClient client = highLevelClient().transform(); PutTransformRequest request = new PutTransformRequest(transform); request.setDeferValidation(true); @@ -244,7 +244,7 @@ public void testGetTransform() throws IOException { createIndex(sourceIndex); String id = "test-get"; - TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest"); + TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest"); TransformClient client = highLevelClient().transform(); putTransform(transform); @@ -262,10 +262,10 @@ public void testGetAllAndPageTransforms() throws IOException { TransformClient client = highLevelClient().transform(); - TransformConfig transform = validDataFrameTransformConfig("test-get-all-1", sourceIndex, "pivot-dest-1"); + TransformConfig transform = validTransformConfig("test-get-all-1", sourceIndex, "pivot-dest-1"); putTransform(transform); - transform = validDataFrameTransformConfig("test-get-all-2", sourceIndex, "pivot-dest-2"); + transform = validTransformConfig("test-get-all-2", sourceIndex, "pivot-dest-2"); putTransform(transform); GetTransformRequest getRequest = new GetTransformRequest("_all"); @@ -300,7 +300,7 @@ public void testStartStop() throws IOException { createIndex(sourceIndex); String id = "test-stop-start"; - TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest"); + TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest"); TransformClient client = highLevelClient().transform(); putTransform(transform); @@ -342,11 +342,14 @@ public void testPreview() throws IOException { createIndex(sourceIndex); indexData(sourceIndex); - TransformConfig transform = validDataFrameTransformConfig("test-preview", sourceIndex, null); + TransformConfig transform = validTransformConfig("test-preview", sourceIndex, null); TransformClient client = highLevelClient().transform(); - PreviewTransformResponse preview = - execute(new PreviewTransformRequest(transform), client::previewTransform, client::previewTransformAsync); + PreviewTransformResponse preview = execute( + new PreviewTransformRequest(transform), + client::previewTransform, + client::previewTransformAsync + ); assertExpectedPreview(preview); } @@ -356,12 +359,15 @@ public void testPreviewById() throws IOException { indexData(sourceIndex); String transformId = "test-preview-by-id"; - TransformConfig transform = validDataFrameTransformConfig(transformId, sourceIndex, "pivot-dest"); + TransformConfig transform = validTransformConfig(transformId, sourceIndex, "pivot-dest"); putTransform(transform); TransformClient client = highLevelClient().transform(); - PreviewTransformResponse preview = - execute(new PreviewTransformRequest(transformId), client::previewTransform, client::previewTransformAsync); + PreviewTransformResponse preview = execute( + new PreviewTransformRequest(transformId), + client::previewTransform, + client::previewTransformAsync + ); assertExpectedPreview(preview); } @@ -384,11 +390,11 @@ private static void assertExpectedPreview(PreviewTransformResponse preview) { assertThat(fields.get("avg_rating"), equalTo(Collections.singletonMap("type", "double"))); } - private TransformConfig validDataFrameTransformConfig(String id, String source, String destination) { - return validDataFrameTransformConfigBuilder(id, source, destination).build(); + private TransformConfig validTransformConfig(String id, String source, String destination) { + return validTransformConfigBuilder(id, source, destination).build(); } - private TransformConfig.Builder validDataFrameTransformConfigBuilder(String id, String source, String destination) { + private TransformConfig.Builder validTransformConfigBuilder(String id, String source, String destination) { GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder(); aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars")); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformRequestConvertersTests.java index 2bb6c8f6f2858..f877d7946268d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/TransformRequestConvertersTests.java @@ -57,9 +57,8 @@ protected NamedXContentRegistry xContentRegistry() { return new NamedXContentRegistry(namedXContents); } - public void testPutDataFrameTransform() throws IOException { - PutTransformRequest putRequest = new PutTransformRequest( - TransformConfigTests.randomTransformConfig()); + public void testPutTransform() throws IOException { + PutTransformRequest putRequest = new PutTransformRequest(TransformConfigTests.randomTransformConfig()); Request request = TransformRequestConverters.putTransform(putRequest); assertThat(request.getParameters(), not(hasKey("defer_validation"))); assertEquals(HttpPut.METHOD_NAME, request.getMethod()); @@ -74,11 +73,12 @@ public void testPutDataFrameTransform() throws IOException { assertThat(request.getParameters(), hasEntry("defer_validation", Boolean.toString(putRequest.getDeferValidation()))); } - public void testUpdateDataFrameTransform() throws IOException { + public void testUpdateTransform() throws IOException { String transformId = randomAlphaOfLength(10); UpdateTransformRequest updateDataFrameTransformRequest = new UpdateTransformRequest( TransformConfigUpdateTests.randomTransformConfigUpdate(), - transformId); + transformId + ); Request request = TransformRequestConverters.updateTransform(updateDataFrameTransformRequest); assertThat(request.getParameters(), not(hasKey("defer_validation"))); assertEquals(HttpPost.METHOD_NAME, request.getMethod()); @@ -90,11 +90,13 @@ public void testUpdateDataFrameTransform() throws IOException { } updateDataFrameTransformRequest.setDeferValidation(true); request = TransformRequestConverters.updateTransform(updateDataFrameTransformRequest); - assertThat(request.getParameters(), - hasEntry("defer_validation", Boolean.toString(updateDataFrameTransformRequest.getDeferValidation()))); + assertThat( + request.getParameters(), + hasEntry("defer_validation", Boolean.toString(updateDataFrameTransformRequest.getDeferValidation())) + ); } - public void testDeleteDataFrameTransform() { + public void testDeleteTransform() { DeleteTransformRequest deleteRequest = new DeleteTransformRequest("foo"); Request request = TransformRequestConverters.deleteTransform(deleteRequest); @@ -109,7 +111,7 @@ public void testDeleteDataFrameTransform() { assertThat(request.getParameters(), hasEntry("force", "true")); } - public void testStartDataFrameTransform() { + public void testStartTransform() { String id = randomAlphaOfLength(10); TimeValue timeValue = null; if (randomBoolean()) { @@ -129,7 +131,7 @@ public void testStartDataFrameTransform() { } } - public void testStopDataFrameTransform() { + public void testStopTransform() { String id = randomAlphaOfLength(10); Boolean waitForCompletion = null; if (randomBoolean()) { @@ -176,7 +178,7 @@ public void testStopDataFrameTransform() { assertEquals(stopRequest.getAllowNoMatch(), Boolean.parseBoolean(request.getParameters().get(ALLOW_NO_MATCH))); } - public void testPreviewDataFrameTransform() throws IOException { + public void testPreviewTransform() throws IOException { PreviewTransformRequest previewRequest = new PreviewTransformRequest(TransformConfigTests.randomTransformConfig()); Request request = TransformRequestConverters.previewTransform(previewRequest); @@ -189,7 +191,7 @@ public void testPreviewDataFrameTransform() throws IOException { } } - public void testPreviewDataFrameTransformById() throws IOException { + public void testPreviewTransformById() throws IOException { String transformId = randomAlphaOfLengthBetween(1, 10); PreviewTransformRequest previewRequest = new PreviewTransformRequest(transformId); Request request = TransformRequestConverters.previewTransform(previewRequest); @@ -199,7 +201,7 @@ public void testPreviewDataFrameTransformById() throws IOException { assertThat(request.getEntity(), nullValue()); } - public void testGetDataFrameTransformStats() { + public void testGetTransformStats() { GetTransformStatsRequest getStatsRequest = new GetTransformStatsRequest("foo"); Request request = TransformRequestConverters.getTransformStats(getStatsRequest); @@ -229,7 +231,7 @@ public void testGetDataFrameTransformStats() { assertThat(request.getParameters(), hasEntry("allow_no_match", "false")); } - public void testGetDataFrameTransform() { + public void testGetTransform() { GetTransformRequest getRequest = new GetTransformRequest("bar"); Request request = TransformRequestConverters.getTransform(getRequest); @@ -259,7 +261,7 @@ public void testGetDataFrameTransform() { assertThat(request.getParameters(), hasEntry("allow_no_match", "false")); } - public void testGetDataFrameTransform_givenMulitpleIds() { + public void testGetTransform_givenMulitpleIds() { GetTransformRequest getRequest = new GetTransformRequest("foo", "bar", "baz"); Request request = TransformRequestConverters.getTransform(getRequest); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java index 93058e4eb76ab..bd2d0b4f63a4b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TransformDocumentationIT.java @@ -445,7 +445,7 @@ public void onFailure(Exception e) { } } - public void testDeleteDataFrameTransform() throws IOException, InterruptedException { + public void testDeleteTransform() throws IOException, InterruptedException { createIndex("source-data"); RestHighLevelClient client = highLevelClient(); @@ -670,7 +670,7 @@ public void onFailure(Exception e) { } } - public void testGetDataFrameTransform() throws IOException, InterruptedException { + public void testGetTransform() throws IOException, InterruptedException { createIndex("source-data"); GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/StartDataFrameTransformRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/StartTransformRequestTests.java similarity index 94% rename from client/rest-high-level/src/test/java/org/elasticsearch/client/transform/StartDataFrameTransformRequestTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/transform/StartTransformRequestTests.java index 9f04fd4f6c23e..2c8b7c3e795d3 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/StartDataFrameTransformRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/StartTransformRequestTests.java @@ -15,7 +15,7 @@ import static org.hamcrest.Matchers.containsString; -public class StartDataFrameTransformRequestTests extends ESTestCase { +public class StartTransformRequestTests extends ESTestCase { public void testValidate_givenNullId() { StartTransformRequest request = new StartTransformRequest(null, null); Optional validate = request.validate(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/UpdateDataFrameTransformResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/UpdateTransformResponseTests.java similarity index 80% rename from client/rest-high-level/src/test/java/org/elasticsearch/client/transform/UpdateDataFrameTransformResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/transform/UpdateTransformResponseTests.java index 5f8fe055392d9..d07920aab7054 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/UpdateDataFrameTransformResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/UpdateTransformResponseTests.java @@ -21,16 +21,15 @@ import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; -public class UpdateDataFrameTransformResponseTests extends ESTestCase { +public class UpdateTransformResponseTests extends ESTestCase { public void testXContentParser() throws IOException { - xContentTester(this::createParser, - UpdateDataFrameTransformResponseTests::createTestInstance, - UpdateDataFrameTransformResponseTests::toXContent, - UpdateTransformResponse::fromXContent) - .assertToXContentEquivalence(false) - .supportsUnknownFields(false) - .test(); + xContentTester( + this::createParser, + UpdateTransformResponseTests::createTestInstance, + UpdateTransformResponseTests::toXContent, + UpdateTransformResponse::fromXContent + ).assertToXContentEquivalence(false).supportsUnknownFields(false).test(); } private static UpdateTransformResponse createTestInstance() {