Skip to content

Commit

Permalink
[Transform] HLRC cleanups (#78909) (#78912)
Browse files Browse the repository at this point in the history
removes some "data frame" leftovers in transform code, no functional changes
  • Loading branch information
Hendrik Muhs authored Oct 11, 2021
1 parent c4cda1c commit 68eaec2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
Expand All @@ -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()));
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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);

Expand All @@ -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()) {
Expand All @@ -129,7 +131,7 @@ public void testStartDataFrameTransform() {
}
}

public void testStopDataFrameTransform() {
public void testStopTransform() {
String id = randomAlphaOfLength(10);
Boolean waitForCompletion = null;
if (randomBoolean()) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationException> validate = request.validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 68eaec2

Please sign in to comment.