-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML-DataFrame] Dataframe REST cleanups (#39451)
fix a couple of odd behaviors of data frame transforms REST API's: - check if id from body and id from URL match if both are specified - do not allow a body for delete - allow get and stats without specifying an id
- Loading branch information
Hendrik Muhs
authored
Feb 28, 2019
1 parent
6b5efb8
commit f24fba7
Showing
12 changed files
with
206 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rc/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameGetAndGetStatsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.dataframe.integration; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class DataFrameGetAndGetStatsIT extends DataFrameRestTestCase { | ||
|
||
private static boolean indicesCreated = false; | ||
|
||
// preserve indices in order to reuse source indices in several test cases | ||
@Override | ||
protected boolean preserveIndicesUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Before | ||
public void createIndexes() throws IOException { | ||
|
||
// it's not possible to run it as @BeforeClass as clients aren't initialized then, so we need this little hack | ||
if (indicesCreated) { | ||
return; | ||
} | ||
|
||
createReviewsIndex(); | ||
indicesCreated = true; | ||
} | ||
|
||
public void testGetAndGetStats() throws Exception { | ||
createPivotReviewsTransform("pivot_1", "pivot_reviews_1", null); | ||
createPivotReviewsTransform("pivot_2", "pivot_reviews_2", null); | ||
|
||
startAndWaitForTransform("pivot_1", "pivot_reviews_1"); | ||
startAndWaitForTransform("pivot_2", "pivot_reviews_2"); | ||
|
||
// check all the different ways to retrieve all stats | ||
Map<String, Object> stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "_stats"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", stats)); | ||
stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "_all/_stats"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", stats)); | ||
stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "*/_stats"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", stats)); | ||
|
||
// only pivot_1 | ||
stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "pivot_1/_stats"))); | ||
assertEquals(1, XContentMapValues.extractValue("count", stats)); | ||
|
||
// check all the different ways to retrieve all transforms | ||
Map<String, Object> transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT))); | ||
assertEquals(2, XContentMapValues.extractValue("count", transforms)); | ||
transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "_all"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", transforms)); | ||
transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "*"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", transforms)); | ||
|
||
// only pivot_1 | ||
transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "pivot_1"))); | ||
assertEquals(1, XContentMapValues.extractValue("count", transforms)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...rg/elasticsearch/xpack/dataframe/rest/action/RestDeleteDataFrameTransformActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.dataframe.rest.action; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class RestDeleteDataFrameTransformActionTests extends ESTestCase { | ||
|
||
public void testBodyRejection() throws Exception { | ||
final RestDeleteDataFrameTransformAction handler = new RestDeleteDataFrameTransformAction(Settings.EMPTY, | ||
mock(RestController.class)); | ||
try (XContentBuilder builder = JsonXContent.contentBuilder()) { | ||
builder.startObject(); | ||
{ | ||
builder.field("id", "my_id"); | ||
} | ||
builder.endObject(); | ||
final FakeRestRequest request = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) | ||
.withContent(new BytesArray(builder.toString()), XContentType.JSON) | ||
.build(); | ||
IllegalArgumentException e = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> handler.prepareRequest(request, mock(NodeClient.class))); | ||
assertThat(e.getMessage(), equalTo("delete data frame transforms requests can not have a request body")); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters