From fd4dca8e14cd70faf02f75df9d3cd24ab749e326 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Mon, 11 Oct 2021 12:22:56 +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 | 42 ++++++++------- .../TransformRequestConvertersTests.java | 36 +++++++------ .../TransformDocumentationIT.java | 6 +-- ...s.java => StartTransformRequestTests.java} | 2 +- ...java => UpdateTransformResponseTests.java} | 19 ++++--- 6 files changed, 78 insertions(+), 80 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} (79%) 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 5dce41530c838..5a492c6f39672 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 @@ -44,8 +44,6 @@ import org.elasticsearch.client.transform.transforms.pivot.PivotConfig; import org.elasticsearch.client.transform.transforms.pivot.TermsGroupSource; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHit; @@ -53,6 +51,8 @@ import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.SortOrder; +import org.elasticsearch.xcontent.XContentBuilder; +import org.elasticsearch.xcontent.XContentType; import org.junit.After; import java.io.IOException; @@ -177,7 +177,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); @@ -199,7 +199,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(); @@ -227,7 +227,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); @@ -243,7 +243,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); @@ -261,10 +261,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"); @@ -299,7 +299,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); @@ -341,11 +341,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); } @@ -355,12 +358,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); } @@ -383,11 +389,11 @@ private static void assertExpectedPreview(PreviewTransformResponse preview) { assertThat(fields.get("avg_rating"), equalTo(Map.of("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 69c15c56b4a79..98f99ccb2b89b 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 @@ -29,11 +29,11 @@ import org.elasticsearch.client.transform.transforms.TransformConfigUpdateTests; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.search.SearchModule; +import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.json.JsonXContent; -import org.elasticsearch.search.SearchModule; -import org.elasticsearch.test.ESTestCase; import java.io.IOException; import java.util.Collections; @@ -58,9 +58,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()); @@ -75,11 +74,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()); @@ -91,11 +91,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); @@ -110,7 +112,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()) { @@ -130,7 +132,7 @@ public void testStartDataFrameTransform() { } } - public void testStopDataFrameTransform() { + public void testStopTransform() { String id = randomAlphaOfLength(10); Boolean waitForCompletion = null; if (randomBoolean()) { @@ -177,7 +179,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); @@ -190,7 +192,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); @@ -200,7 +202,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); @@ -230,7 +232,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); @@ -260,7 +262,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 f5cc765f4cc24..1261ecfb59acb 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 @@ -50,10 +50,10 @@ import org.elasticsearch.client.transform.transforms.pivot.PivotConfig; import org.elasticsearch.client.transform.transforms.pivot.TermsGroupSource; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregatorFactories; +import org.elasticsearch.xcontent.XContentBuilder; import org.junit.After; import java.io.IOException; @@ -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 79% 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 1ae24640165e7..64303e1e4e40a 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 @@ -10,10 +10,10 @@ import org.elasticsearch.client.transform.transforms.TransformConfigTests; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xcontent.NamedXContentRegistry; -import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.search.SearchModule; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xcontent.NamedXContentRegistry; +import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; import java.util.Collections; @@ -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() {