diff --git a/build.gradle b/build.gradle index e5b95739f..ad262a6fd 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ import java.util.concurrent.Callable import org.opensearch.gradle.test.RestIntegTestTask +import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask buildscript { ext { @@ -185,6 +186,12 @@ integTest { } } + if (System.getProperty("tests.rest.bwcsuite") == null) { + filter { + excludeTestsMatching "org.opensearch.ad.bwc.*IT" + } + } + // The 'doFirst' delays till execution time. doFirst { // Tell the test JVM if the cluster JVM is running under a debugger so that tests can @@ -260,6 +267,180 @@ testClusters.integTest { } } +String bwcVersion = "1.13.0.0"; +String baseName = "adBwcCluster" +String bwcFilePath = "src/test/resources/org/opensearch/ad/bwc/" + +testClusters { + "${baseName}" { + testDistribution = "ARCHIVE" + versions = ["7.10.2","1.0.0"] + numberOfNodes = 3 + plugin(provider(new Callable(){ + @Override + RegularFile call() throws Exception { + return new RegularFile() { + @Override + File getAsFile() { + return fileTree(bwcFilePath + "job-scheduler/" + bwcVersion).getSingleFile() + } + } + } + })) + plugin(provider(new Callable(){ + @Override + RegularFile call() throws Exception { + return new RegularFile() { + @Override + File getAsFile() { + return fileTree(bwcFilePath + "anomaly-detection/" + bwcVersion).getSingleFile() + } + } + } + })) + setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" + setting 'http.content_type.required', 'true' + } +} + +List> plugins = [ + provider(new Callable(){ + @Override + RegularFile call() throws Exception { + return new RegularFile() { + @Override + File getAsFile() { + return fileTree(bwcFilePath + "job-scheduler/" + project.version).getSingleFile() + } + } + } + }), + provider(new Callable(){ + @Override + RegularFile call() throws Exception { + return new RegularFile() { + @Override + File getAsFile() { + return fileTree(bwcFilePath + "anomaly-detection/" + project.version).getSingleFile() + } + } + } + }) + ] + +// Creates a test cluster with 3 nodes of the old version. +task "${baseName}#oldVersionClusterTask"(type: StandaloneRestIntegTestTask) { + useCluster testClusters."${baseName}" + if (System.getProperty("mixedCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInAMixedCluster") + } + } + if (System.getProperty("rollingUpgradeCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") + } + } + if (System.getProperty("fullRestartCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInAnUpgradedCluster") + } + } + systemProperty 'tests.rest.bwcsuite', 'old_cluster' + systemProperty 'tests.rest.bwcsuite_round', 'old' + systemProperty 'tests.plugin_bwc_version', bwcVersion + nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}") + nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}") +} + +// Upgrades one node of the old cluster to new OpenSearch version with upgraded plugin version +// This results in a mixed cluster with 2 nodes on the old version and 1 upgraded node. +// This is also used as a one third upgraded cluster for a rolling upgrade. +task "${baseName}#mixedClusterTask"(type: StandaloneRestIntegTestTask) { + dependsOn "${baseName}#oldVersionClusterTask" + useCluster testClusters."${baseName}" + doFirst { + testClusters."${baseName}".upgradeNodeAndPluginToNextVersion(plugins) + } + if (System.getProperty("mixedCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInAMixedCluster") + } + } + if (System.getProperty("rollingUpgradeCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") + } + } + systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' + systemProperty 'tests.rest.bwcsuite_round', 'first' + systemProperty 'tests.plugin_bwc_version', bwcVersion + nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}") + nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}") +} + +// Upgrades the second node to new OpenSearch version with upgraded plugin version after the first node is upgraded. +// This results in a mixed cluster with 1 node on the old version and 2 upgraded nodes. +// This is used for rolling upgrade. +task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTask) { + dependsOn "${baseName}#mixedClusterTask" + useCluster testClusters."${baseName}" + doFirst { + testClusters."${baseName}".upgradeNodeAndPluginToNextVersion(plugins) + } + if (System.getProperty("rollingUpgradeCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") + } + } + systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' + systemProperty 'tests.rest.bwcsuite_round', 'second' + systemProperty 'tests.plugin_bwc_version', bwcVersion + nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}") + nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}") +} + +// Upgrades the third node to new OpenSearch version with upgraded plugin version after the second node is upgraded. +// This results in a fully upgraded cluster. +// This is used for rolling upgrade. +task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask) { + dependsOn "${baseName}#twoThirdsUpgradedClusterTask" + useCluster testClusters."${baseName}" + doFirst { + testClusters."${baseName}".upgradeNodeAndPluginToNextVersion(plugins) + } + if (System.getProperty("rollingUpgradeCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInARollingUpgradedCluster") + } + } + systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' + systemProperty 'tests.rest.bwcsuite_round', 'third' + systemProperty 'tests.plugin_bwc_version', bwcVersion + nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}") + nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}") +} + +// Upgrades all the nodes of the old cluster to new OpenSearch version with upgraded plugin version +// at the same time resulting in a fully upgraded cluster. +tasks.register("${baseName}#fullRestartClusterTask", StandaloneRestIntegTestTask) { + dependsOn "${baseName}#oldVersionClusterTask" + useCluster testClusters."${baseName}" + doFirst { + testClusters."${baseName}".upgradeAllNodesAndPluginsToNextVersion(plugins) + } + if (System.getProperty("fullRestartCluster") != null) { + filter { + includeTest("org.opensearch.ad.bwc.ADBackwardsCompatibilityIT", "testPluginUpgradeInAnUpgradedCluster") + } + } + systemProperty 'tests.rest.bwcsuite', 'upgraded_cluster' + systemProperty 'tests.plugin_bwc_version', bwcVersion + nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}") + nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}") +} + + run { doFirst { // There seems to be an issue when running multi node run or integ tasks with unicast_hosts diff --git a/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java b/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java index 33700659e..17e3a0f91 100644 --- a/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java +++ b/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java @@ -26,7 +26,6 @@ package org.opensearch.ad; -import static org.apache.http.entity.ContentType.APPLICATION_JSON; import static org.opensearch.common.xcontent.json.JsonXContent.jsonXContent; import java.io.IOException; @@ -35,9 +34,7 @@ import java.util.ArrayList; import java.util.Map; -import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; -import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHeader; import org.opensearch.ad.model.ADTask; import org.opensearch.ad.model.AnomalyDetector; @@ -52,7 +49,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.NamedXContentRegistry; -import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContent; import org.opensearch.common.xcontent.XContentBuilder; @@ -115,7 +111,7 @@ protected AnomalyDetector createRandomAnomalyDetector( "POST", "/" + detector.getIndices().get(0) + "/_doc/" + randomAlphaOfLength(5) + "?refresh=true", ImmutableMap.of(), - toHttpEntity("{\"name\": \"test\"}"), + TestHelpers.toHttpEntity("{\"name\": \"test\"}"), null, false ); @@ -142,8 +138,8 @@ protected AnomalyDetector createRandomAnomalyDetector( protected AnomalyDetector createAnomalyDetector(AnomalyDetector detector, Boolean refresh, RestClient client) throws IOException { Response response = TestHelpers - .makeRequest(client, "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), toHttpEntity(detector), null); - assertEquals("Create anomaly detector failed", RestStatus.CREATED, restStatus(response)); + .makeRequest(client, "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null); + assertEquals("Create anomaly detector failed", RestStatus.CREATED, TestHelpers.restStatus(response)); Map detectorJson = jsonXContent .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getEntity().getContent()) @@ -176,7 +172,7 @@ protected Response startAnomalyDetector(String detectorId, DetectionDateRange da "POST", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detectorId + "/_start", ImmutableMap.of(), - dateRange == null ? null : toHttpEntity(dateRange), + dateRange == null ? null : TestHelpers.toHttpEntity(dateRange), null ); } @@ -198,7 +194,7 @@ protected Response previewAnomalyDetector(String detectorId, RestClient client, "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null ); } @@ -215,7 +211,7 @@ public Response updateAnomalyDetector(String detectorId, AnomalyDetector newDete "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detectorId, null, - toJsonString(newDetector), + TestHelpers.toJsonString(newDetector), ImmutableList.of(header) ); } @@ -245,7 +241,7 @@ public ToXContentObject[] getAnomalyDetector( "", ImmutableList.of(header) ); - assertEquals("Unable to get anomaly detector " + detectorId, RestStatus.OK, restStatus(response)); + assertEquals("Unable to get anomaly detector " + detectorId, RestStatus.OK, TestHelpers.restStatus(response)); XContentParser parser = createAdParser(XContentType.JSON.xContent(), response.getEntity().getContent()); parser.nextToken(); XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); @@ -301,23 +297,6 @@ public ToXContentObject[] getAnomalyDetector( adTask }; } - protected HttpEntity toHttpEntity(ToXContentObject object) throws IOException { - return new StringEntity(toJsonString(object), APPLICATION_JSON); - } - - protected HttpEntity toHttpEntity(String jsonString) throws IOException { - return new StringEntity(jsonString, APPLICATION_JSON); - } - - protected String toJsonString(ToXContentObject object) throws IOException { - XContentBuilder builder = XContentFactory.jsonBuilder(); - return TestHelpers.xContentBuilderToString(shuffleXContent(object.toXContent(builder, ToXContent.EMPTY_PARAMS))); - } - - protected RestStatus restStatus(Response response) { - return RestStatus.fromCode(response.getStatusLine().getStatusCode()); - } - protected final XContentParser createAdParser(XContent xContent, InputStream data) throws IOException { return xContent.createParser(TestHelpers.xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data); } @@ -391,17 +370,18 @@ public Response createUser(String name, String password, ArrayList backe "PUT", "/_opendistro/_security/api/internalusers/" + name, null, - toHttpEntity( - " {\n" - + "\"password\": \"" - + password - + "\",\n" - + "\"backend_roles\": " - + backendRolesString - + ",\n" - + "\"attributes\": {\n" - + "}} " - ), + TestHelpers + .toHttpEntity( + " {\n" + + "\"password\": \"" + + password + + "\",\n" + + "\"backend_roles\": " + + backendRolesString + + ",\n" + + "\"attributes\": {\n" + + "}} " + ), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); } @@ -417,9 +397,10 @@ public Response createRoleMapping(String role, ArrayList users) throws I "PUT", "/_opendistro/_security/api/rolesmapping/" + role, null, - toHttpEntity( - "{\n" + " \"backend_roles\" : [ ],\n" + " \"hosts\" : [ ],\n" + " \"users\" : " + usersString + "\n" + "}" - ), + TestHelpers + .toHttpEntity( + "{\n" + " \"backend_roles\" : [ ],\n" + " \"hosts\" : [ ],\n" + " \"users\" : " + usersString + "\n" + "}" + ), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); } @@ -431,29 +412,30 @@ public Response createIndexRole(String role, String index) throws IOException { "PUT", "/_opendistro/_security/api/roles/" + role, null, - toHttpEntity( - "{\n" - + "\"cluster_permissions\": [\n" - + "],\n" - + "\"index_permissions\": [\n" - + "{\n" - + "\"index_patterns\": [\n" - + "\"" - + index - + "\"\n" - + "],\n" - + "\"dls\": \"\",\n" - + "\"fls\": [],\n" - + "\"masked_fields\": [],\n" - + "\"allowed_actions\": [\n" - + "\"crud\",\n" - + "\"indices:admin/create\"\n" - + "]\n" - + "}\n" - + "],\n" - + "\"tenant_permissions\": []\n" - + "}" - ), + TestHelpers + .toHttpEntity( + "{\n" + + "\"cluster_permissions\": [\n" + + "],\n" + + "\"index_permissions\": [\n" + + "{\n" + + "\"index_patterns\": [\n" + + "\"" + + index + + "\"\n" + + "],\n" + + "\"dls\": \"\",\n" + + "\"fls\": [],\n" + + "\"masked_fields\": [],\n" + + "\"allowed_actions\": [\n" + + "\"crud\",\n" + + "\"indices:admin/create\"\n" + + "]\n" + + "}\n" + + "],\n" + + "\"tenant_permissions\": []\n" + + "}" + ), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); } @@ -489,13 +471,14 @@ public Response enableFilterBy() throws IOException { "PUT", "_cluster/settings", null, - toHttpEntity( - "{\n" - + " \"persistent\": {\n" - + " \"opendistro.anomaly_detection.filter_by_backend_roles\" : \"true\"\n" - + " }\n" - + "}" - ), + TestHelpers + .toHttpEntity( + "{\n" + + " \"persistent\": {\n" + + " \"opendistro.anomaly_detection.filter_by_backend_roles\" : \"true\"\n" + + " }\n" + + "}" + ), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); } @@ -507,13 +490,14 @@ public Response disableFilterBy() throws IOException { "PUT", "_cluster/settings", null, - toHttpEntity( - "{\n" - + " \"persistent\": {\n" - + " \"opendistro.anomaly_detection.filter_by_backend_roles\" : \"false\"\n" - + " }\n" - + "}" - ), + TestHelpers + .toHttpEntity( + "{\n" + + " \"persistent\": {\n" + + " \"opendistro.anomaly_detection.filter_by_backend_roles\" : \"false\"\n" + + " }\n" + + "}" + ), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); } diff --git a/src/test/java/org/opensearch/ad/HistoricalAnalysisRestTestCase.java b/src/test/java/org/opensearch/ad/HistoricalAnalysisRestTestCase.java index 59393d31e..86329208d 100644 --- a/src/test/java/org/opensearch/ad/HistoricalAnalysisRestTestCase.java +++ b/src/test/java/org/opensearch/ad/HistoricalAnalysisRestTestCase.java @@ -100,12 +100,12 @@ public Response ingestSimpleMockLog( "PUT", indexName, null, - toHttpEntity(MockSimpleLog.INDEX_MAPPING), + TestHelpers.toHttpEntity(MockSimpleLog.INDEX_MAPPING), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); Response statsResponse = TestHelpers.makeRequest(client(), "GET", indexName, ImmutableMap.of(), "", null); - assertEquals(RestStatus.OK, restStatus(statsResponse)); + assertEquals(RestStatus.OK, TestHelpers.restStatus(statsResponse)); String result = EntityUtils.toString(statsResponse.getEntity()); assertTrue(result.contains(indexName)); @@ -130,7 +130,7 @@ public Response ingestSimpleMockLog( "POST", "_bulk?refresh=true", null, - toHttpEntity(bulkRequestBuilder.toString()), + TestHelpers.toHttpEntity(bulkRequestBuilder.toString()), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana")) ); return bulkResponse; diff --git a/src/test/java/org/opensearch/ad/TestHelpers.java b/src/test/java/org/opensearch/ad/TestHelpers.java index 7d7ed205d..7c76639a0 100644 --- a/src/test/java/org/opensearch/ad/TestHelpers.java +++ b/src/test/java/org/opensearch/ad/TestHelpers.java @@ -135,6 +135,7 @@ import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.QueryBuilder; import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.rest.RestStatus; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.search.SearchModule; @@ -967,6 +968,10 @@ public static String toJsonString(ToXContentObject object) throws IOException { return TestHelpers.xContentBuilderToString(object.toXContent(builder, ToXContent.EMPTY_PARAMS)); } + public static RestStatus restStatus(Response response) { + return RestStatus.fromCode(response.getStatusLine().getStatusCode()); + } + public static SearchHits createSearchHits(int totalHits) { List hitList = new ArrayList<>(); IntStream.range(0, totalHits).forEach(i -> hitList.add(new SearchHit(i))); diff --git a/src/test/java/org/opensearch/ad/bwc/ADBackwardsCompatibilityIT.java b/src/test/java/org/opensearch/ad/bwc/ADBackwardsCompatibilityIT.java new file mode 100644 index 000000000..a78d33a55 --- /dev/null +++ b/src/test/java/org/opensearch/ad/bwc/ADBackwardsCompatibilityIT.java @@ -0,0 +1,153 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ +package org.opensearch.ad.bwc; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.junit.Assert; +import org.opensearch.ad.TestHelpers; +import org.opensearch.ad.model.AnomalyDetector; +import org.opensearch.ad.util.RestHandlerUtils; +import org.opensearch.client.Response; +import org.opensearch.common.settings.Settings; +import org.opensearch.rest.RestStatus; +import org.opensearch.test.rest.OpenSearchRestTestCase; + +import com.google.common.collect.ImmutableMap; + +public class ADBackwardsCompatibilityIT extends OpenSearchRestTestCase { + + private static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.bwcsuite")); + private static final String CLUSTER_NAME = System.getProperty("tests.clustername"); + + @Override + protected final boolean preserveIndicesUponCompletion() { + return true; + } + + @Override + protected final boolean preserveReposUponCompletion() { + return true; + } + + @Override + protected boolean preserveTemplatesUponCompletion() { + return true; + } + + @Override + protected final Settings restClientSettings() { + return Settings + .builder() + .put(super.restClientSettings()) + // increase the timeout here to 90 seconds to handle long waits for a green + // cluster health. the waits for green need to be longer than a minute to + // account for delayed shards + .put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s") + .build(); + } + + public void testPluginUpgradeInAMixedCluster() throws Exception { + assertPluginUpgrade("_nodes/" + CLUSTER_NAME + "-0/plugins"); + } + + public void testPluginUpgradeInAnUpgradedCluster() throws Exception { + assertPluginUpgrade("_nodes/plugins"); + } + + public void testPluginUpgradeInARollingUpgradedCluster() throws Exception { + String round = System.getProperty("tests.rest.bwcsuite_round"); + if (round.equals("first") || round.equals("old")) { + assertPluginUpgrade("_nodes/" + CLUSTER_NAME + "-0/plugins"); + } else if (round.equals("second")) { + assertPluginUpgrade("_nodes/" + CLUSTER_NAME + "-1/plugins"); + } else if (round.equals("third")) { + assertPluginUpgrade("_nodes/" + CLUSTER_NAME + "-2/plugins"); + } + } + + private enum ClusterType { + OLD, + MIXED, + UPGRADED; + + public static ClusterType parse(String value) { + switch (value) { + case "old_cluster": + return OLD; + case "mixed_cluster": + return MIXED; + case "upgraded_cluster": + return UPGRADED; + default: + throw new AssertionError("unknown cluster type: " + value); + } + } + } + + @SuppressWarnings("unchecked") + private void assertPluginUpgrade(String uri) throws Exception { + Map> responseMap = (Map>) getAsMap(uri).get("nodes"); + for (Map response : responseMap.values()) { + List> plugins = (List>) response.get("plugins"); + Set pluginNames = plugins.stream().map(map -> map.get("name")).collect(Collectors.toSet()); + switch (CLUSTER_TYPE) { + case OLD: + Assert.assertTrue(pluginNames.contains("opendistro-anomaly-detection")); + Assert.assertTrue(pluginNames.contains("opendistro-job-scheduler")); + createBasicAnomalyDetector(); + break; + case MIXED: + Assert.assertTrue(pluginNames.contains("opensearch-anomaly-detection")); + Assert.assertTrue(pluginNames.contains("opensearch-job-scheduler")); + verifyAnomalyDetector(TestHelpers.LEGACY_OPENDISTRO_AD_BASE_DETECTORS_URI); + break; + case UPGRADED: + Assert.assertTrue(pluginNames.contains("opensearch-anomaly-detection")); + Assert.assertTrue(pluginNames.contains("opensearch-job-scheduler")); + verifyAnomalyDetector(TestHelpers.AD_BASE_DETECTORS_URI); + break; + } + break; + } + } + + private void createBasicAnomalyDetector() throws Exception { + AnomalyDetector detector = TestHelpers.randomAnomalyDetector(TestHelpers.randomUiMetadata(), null); + String indexName = detector.getIndices().get(0); + TestHelpers.createIndex(client(), indexName, TestHelpers.toHttpEntity("{\"name\": \"test\"}")); + + Response response = TestHelpers + .makeRequest( + client(), + "POST", + TestHelpers.LEGACY_OPENDISTRO_AD_BASE_DETECTORS_URI, + ImmutableMap.of(), + TestHelpers.toHttpEntity(detector), + null + ); + // verify that the detector is created + assertEquals("Create anomaly detector failed", RestStatus.CREATED, TestHelpers.restStatus(response)); + Map responseMap = entityAsMap(response); + String id = (String) responseMap.get("_id"); + int version = (int) responseMap.get("_version"); + assertNotEquals("response is missing Id", AnomalyDetector.NO_ID, id); + assertTrue("incorrect version", version > 0); + } + + private void verifyAnomalyDetector(String uri) throws Exception { + Response response = TestHelpers.makeRequest(client(), "GET", uri + "/" + RestHandlerUtils.COUNT, null, "", null); + Map responseMap = entityAsMap(response); + Integer count = (Integer) responseMap.get("count"); + assertEquals(1, (long) count); + } + +} diff --git a/src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java b/src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java index 679a63bac..ee63eaa78 100644 --- a/src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java +++ b/src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java @@ -69,7 +69,14 @@ public void testCreateAnomalyDetectorWithNotExistingIndices() throws Exception { ResponseException.class, "index_not_found_exception", () -> TestHelpers - .makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), toHttpEntity(detector), null) + .makeRequest( + client(), + "POST", + TestHelpers.AD_BASE_DETECTORS_URI, + ImmutableMap.of(), + TestHelpers.toHttpEntity(detector), + null + ) ); } @@ -81,7 +88,10 @@ public void testCreateAnomalyDetectorWithEmptyIndices() throws Exception { "PUT", "/" + detector.getIndices().get(0), ImmutableMap.of(), - toHttpEntity("{\"settings\":{\"number_of_shards\":1},\"mappings\":{\"properties\":" + "{\"field1\":{\"type\":\"text\"}}}}"), + TestHelpers + .toHttpEntity( + "{\"settings\":{\"number_of_shards\":1}," + " \"mappings\":{\"properties\":" + "{\"field1\":{\"type\":\"text\"}}}}" + ), null ); @@ -90,7 +100,14 @@ public void testCreateAnomalyDetectorWithEmptyIndices() throws Exception { ResponseException.class, "Can't create anomaly detector as no document found in indices", () -> TestHelpers - .makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), toHttpEntity(detector), null) + .makeRequest( + client(), + "POST", + TestHelpers.AD_BASE_DETECTORS_URI, + ImmutableMap.of(), + TestHelpers.toHttpEntity(detector), + null + ) ); } @@ -126,7 +143,7 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception { "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), - toHttpEntity(detectorDuplicateName), + TestHelpers.toHttpEntity(detectorDuplicateName), null ) ); @@ -135,21 +152,28 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception { public void testCreateAnomalyDetector() throws Exception { AnomalyDetector detector = TestHelpers.randomAnomalyDetector(TestHelpers.randomUiMetadata(), null); String indexName = detector.getIndices().get(0); - TestHelpers.createIndex(client(), indexName, toHttpEntity("{\"name\": \"test\"}")); + TestHelpers.createIndex(client(), indexName, TestHelpers.toHttpEntity("{\"name\": \"test\"}")); updateClusterSettings(EnabledSetting.AD_PLUGIN_ENABLED, false); Exception ex = expectThrows( ResponseException.class, () -> TestHelpers - .makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), toHttpEntity(detector), null) + .makeRequest( + client(), + "POST", + TestHelpers.AD_BASE_DETECTORS_URI, + ImmutableMap.of(), + TestHelpers.toHttpEntity(detector), + null + ) ); assertThat(ex.getMessage(), containsString(CommonErrorMessages.DISABLED_ERR_MSG)); updateClusterSettings(EnabledSetting.AD_PLUGIN_ENABLED, true); Response response = TestHelpers - .makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), toHttpEntity(detector), null); - assertEquals("Create anomaly detector failed", RestStatus.CREATED, restStatus(response)); + .makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null); + assertEquals("Create anomaly detector failed", RestStatus.CREATED, TestHelpers.restStatus(response)); Map responseMap = entityAsMap(response); String id = (String) responseMap.get("_id"); int version = (int) responseMap.get("_version"); @@ -210,7 +234,7 @@ public void testUpdateAnomalyDetectorA() throws Exception { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detector.getDetectorId() + "?refresh=true", ImmutableMap.of(), - toHttpEntity(newDetector), + TestHelpers.toHttpEntity(newDetector), null ) ); @@ -224,11 +248,11 @@ public void testUpdateAnomalyDetectorA() throws Exception { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detector.getDetectorId() + "?refresh=true", ImmutableMap.of(), - toHttpEntity(newDetector), + TestHelpers.toHttpEntity(newDetector), null ); - assertEquals("Update anomaly detector failed", RestStatus.OK, restStatus(updateResponse)); + assertEquals("Update anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(updateResponse)); Map responseBody = entityAsMap(updateResponse); assertEquals("Updated anomaly detector id doesn't match", detector.getDetectorId(), responseBody.get("_id")); assertEquals("Version not incremented", (detector.getVersion().intValue() + 1), (int) responseBody.get("_version")); @@ -272,7 +296,7 @@ public void testUpdateAnomalyDetectorNameToExisting() throws Exception { "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), - toHttpEntity(newDetector1WithDetector2Name), + TestHelpers.toHttpEntity(newDetector1WithDetector2Name), null ) ); @@ -306,7 +330,7 @@ public void testUpdateAnomalyDetectorNameToNew() throws Exception { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detector.getDetectorId() + "?refresh=true", ImmutableMap.of(), - toHttpEntity(detectorWithNewName), + TestHelpers.toHttpEntity(detectorWithNewName), null ); @@ -356,7 +380,7 @@ public void testUpdateAnomalyDetectorWithNotExistingIndex() throws Exception { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detector.getDetectorId(), ImmutableMap.of(), - toHttpEntity(newDetector), + TestHelpers.toHttpEntity(newDetector), null ) ); @@ -393,7 +417,7 @@ public void testSearchAnomalyDetector() throws Exception { new NStringEntity(search.toString(), ContentType.APPLICATION_JSON), null ); - assertEquals("Search anomaly detector failed", RestStatus.OK, restStatus(searchResponse)); + assertEquals("Search anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(searchResponse)); } public void testStatsAnomalyDetector() throws Exception { @@ -409,7 +433,7 @@ public void testStatsAnomalyDetector() throws Exception { Response statsResponse = TestHelpers .makeRequest(client(), "GET", AnomalyDetectorPlugin.LEGACY_AD_BASE + "/stats", ImmutableMap.of(), "", null); - assertEquals("Get stats failed", RestStatus.OK, restStatus(statsResponse)); + assertEquals("Get stats failed", RestStatus.OK, TestHelpers.restStatus(statsResponse)); } public void testPreviewAnomalyDetector() throws Exception { @@ -431,7 +455,7 @@ public void testPreviewAnomalyDetector() throws Exception { "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null ) ); @@ -445,10 +469,10 @@ public void testPreviewAnomalyDetector() throws Exception { "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null ); - assertEquals("Execute anomaly detector failed", RestStatus.OK, restStatus(response)); + assertEquals("Execute anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(response)); } public void testPreviewAnomalyDetectorWhichNotExist() throws Exception { @@ -468,7 +492,7 @@ public void testPreviewAnomalyDetectorWhichNotExist() throws Exception { "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null ) ); @@ -490,7 +514,7 @@ public void testExecuteAnomalyDetectorWithNullDetectorId() throws Exception { "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null ) ); @@ -510,11 +534,11 @@ public void testPreviewAnomalyDetectorWithDetector() throws Exception { "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null, false ); - assertEquals("Execute anomaly detector failed", RestStatus.OK, restStatus(response)); + assertEquals("Execute anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(response)); } public void testPreviewAnomalyDetectorWithDetectorAndNoFeatures() throws Exception { @@ -535,7 +559,7 @@ public void testPreviewAnomalyDetectorWithDetectorAndNoFeatures() throws Excepti "POST", String.format(TestHelpers.AD_BASE_PREVIEW_URI, input.getDetectorId()), ImmutableMap.of(), - toHttpEntity(input), + TestHelpers.toHttpEntity(input), null ) ); @@ -549,11 +573,11 @@ public void testSearchAnomalyResult() throws Exception { "POST", "/.opendistro-anomaly-results/_doc/" + UUIDs.base64UUID(), ImmutableMap.of(), - toHttpEntity(anomalyResult), + TestHelpers.toHttpEntity(anomalyResult), null, false ); - assertEquals("Post anomaly result failed", RestStatus.CREATED, restStatus(response)); + assertEquals("Post anomaly result failed", RestStatus.CREATED, TestHelpers.restStatus(response)); SearchSourceBuilder search = (new SearchSourceBuilder()) .query(QueryBuilders.termQuery("detector_id", anomalyResult.getDetectorId())); @@ -585,7 +609,7 @@ public void testSearchAnomalyResult() throws Exception { new NStringEntity(search.toString(), ContentType.APPLICATION_JSON), null ); - assertEquals("Search anomaly result failed", RestStatus.OK, restStatus(searchResponse)); + assertEquals("Search anomaly result failed", RestStatus.OK, TestHelpers.restStatus(searchResponse)); SearchSourceBuilder searchAll = SearchSourceBuilder.fromXContent(TestHelpers.parser("{\"query\":{\"match_all\":{}}}")); Response searchAllResponse = TestHelpers @@ -597,7 +621,7 @@ public void testSearchAnomalyResult() throws Exception { new NStringEntity(searchAll.toString(), ContentType.APPLICATION_JSON), null ); - assertEquals("Search anomaly result failed", RestStatus.OK, restStatus(searchAllResponse)); + assertEquals("Search anomaly result failed", RestStatus.OK, TestHelpers.restStatus(searchAllResponse)); } public void testDeleteAnomalyDetector() throws Exception { @@ -630,7 +654,7 @@ public void testDeleteAnomalyDetector() throws Exception { "", null ); - assertEquals("Delete anomaly detector failed", RestStatus.OK, restStatus(response)); + assertEquals("Delete anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(response)); } public void testDeleteAnomalyDetectorWhichNotExist() throws Exception { @@ -660,7 +684,7 @@ public void testDeleteAnomalyDetectorWithNoAdJob() throws Exception { "", null ); - assertEquals("Delete anomaly detector failed", RestStatus.OK, restStatus(response)); + assertEquals("Delete anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(response)); } public void testDeleteAnomalyDetectorWithRunningAdJob() throws Exception { @@ -676,7 +700,7 @@ public void testDeleteAnomalyDetectorWithRunningAdJob() throws Exception { null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); TestHelpers .assertFailWith( @@ -707,7 +731,7 @@ public void testUpdateAnomalyDetectorWithRunningAdJob() throws Exception { null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); String newDescription = randomAlphaOfLength(5); @@ -740,7 +764,7 @@ public void testUpdateAnomalyDetectorWithRunningAdJob() throws Exception { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detector.getDetectorId(), ImmutableMap.of(), - toHttpEntity(newDetector), + TestHelpers.toHttpEntity(newDetector), null ) ); @@ -759,7 +783,7 @@ public void testGetDetectorWithAdJob() throws IOException { null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); ToXContentObject[] results = getAnomalyDetector(detector.getDetectorId(), true, client()); assertEquals("Incorrect Location header", detector, results[0]); @@ -802,7 +826,7 @@ public void testStartAdJobWithExistingDetector() throws Exception { null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); startAdJobResponse = TestHelpers .makeRequest( @@ -814,7 +838,7 @@ public void testStartAdJobWithExistingDetector() throws Exception { null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); } public void testStartAdJobWithNonexistingDetectorIndex() throws Exception { @@ -864,7 +888,7 @@ public void testStopAdJob() throws Exception { "", null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); updateClusterSettings(EnabledSetting.AD_PLUGIN_ENABLED, false); @@ -893,7 +917,7 @@ public void testStopAdJob() throws Exception { "", null ); - assertEquals("Fail to stop AD job", RestStatus.OK, restStatus(stopAdJobResponse)); + assertEquals("Fail to stop AD job", RestStatus.OK, TestHelpers.restStatus(stopAdJobResponse)); stopAdJobResponse = TestHelpers .makeRequest( @@ -904,7 +928,7 @@ public void testStopAdJob() throws Exception { "", null ); - assertEquals("Fail to stop AD job", RestStatus.OK, restStatus(stopAdJobResponse)); + assertEquals("Fail to stop AD job", RestStatus.OK, TestHelpers.restStatus(stopAdJobResponse)); } public void testStopNonExistingAdJobIndex() throws Exception { @@ -936,7 +960,7 @@ public void testStopNonExistingAdJob() throws Exception { "", null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); TestHelpers .assertFailWith( @@ -965,7 +989,7 @@ public void testStartDisabledAdjob() throws IOException { "", null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); Response stopAdJobResponse = TestHelpers .makeRequest( @@ -976,7 +1000,7 @@ public void testStartDisabledAdjob() throws IOException { "", null ); - assertEquals("Fail to stop AD job", RestStatus.OK, restStatus(stopAdJobResponse)); + assertEquals("Fail to stop AD job", RestStatus.OK, TestHelpers.restStatus(stopAdJobResponse)); startAdJobResponse = TestHelpers .makeRequest( @@ -988,13 +1012,13 @@ public void testStartDisabledAdjob() throws IOException { null ); - assertEquals("Fail to start AD job", RestStatus.OK, restStatus(startAdJobResponse)); + assertEquals("Fail to start AD job", RestStatus.OK, TestHelpers.restStatus(startAdJobResponse)); } public void testStartAdjobWithNullFeatures() throws Exception { AnomalyDetector detectorWithoutFeature = TestHelpers.randomAnomalyDetector(null, null, Instant.now()); String indexName = detectorWithoutFeature.getIndices().get(0); - TestHelpers.createIndex(client(), indexName, toHttpEntity("{\"name\": \"test\"}")); + TestHelpers.createIndex(client(), indexName, TestHelpers.toHttpEntity("{\"name\": \"test\"}")); AnomalyDetector detector = createAnomalyDetector(detectorWithoutFeature, true, client()); TestHelpers .assertFailWith( @@ -1015,7 +1039,7 @@ public void testStartAdjobWithNullFeatures() throws Exception { public void testStartAdjobWithEmptyFeatures() throws Exception { AnomalyDetector detectorWithoutFeature = TestHelpers.randomAnomalyDetector(ImmutableList.of(), null, Instant.now()); String indexName = detectorWithoutFeature.getIndices().get(0); - TestHelpers.createIndex(client(), indexName, toHttpEntity("{\"name\": \"test\"}")); + TestHelpers.createIndex(client(), indexName, TestHelpers.toHttpEntity("{\"name\": \"test\"}")); AnomalyDetector detector = createAnomalyDetector(detectorWithoutFeature, true, client()); TestHelpers .assertFailWith( @@ -1044,7 +1068,7 @@ public void testDefaultProfileAnomalyDetector() throws Exception { updateClusterSettings(EnabledSetting.AD_PLUGIN_ENABLED, true); Response profileResponse = getDetectorProfile(detector.getDetectorId()); - assertEquals("Incorrect profile status", RestStatus.OK, restStatus(profileResponse)); + assertEquals("Incorrect profile status", RestStatus.OK, TestHelpers.restStatus(profileResponse)); } @Ignore @@ -1052,7 +1076,7 @@ public void testAllProfileAnomalyDetector() throws Exception { AnomalyDetector detector = createRandomAnomalyDetector(true, true, client()); Response profileResponse = getDetectorProfile(detector.getDetectorId(), true); - assertEquals("Incorrect profile status", RestStatus.OK, restStatus(profileResponse)); + assertEquals("Incorrect profile status", RestStatus.OK, TestHelpers.restStatus(profileResponse)); } @Ignore @@ -1060,7 +1084,7 @@ public void testCustomizedProfileAnomalyDetector() throws Exception { AnomalyDetector detector = createRandomAnomalyDetector(true, true, client()); Response profileResponse = getDetectorProfile(detector.getDetectorId(), true, "/models/", client()); - assertEquals("Incorrect profile status", RestStatus.OK, restStatus(profileResponse)); + assertEquals("Incorrect profile status", RestStatus.OK, TestHelpers.restStatus(profileResponse)); } public void testSearchAnomalyDetectorCountNoIndex() throws Exception { @@ -1133,7 +1157,7 @@ public void testBackwardCompatibilityWithOpenDistro() throws IOException { // Create a detector AnomalyDetector detector = TestHelpers.randomAnomalyDetector(TestHelpers.randomUiMetadata(), null); String indexName = detector.getIndices().get(0); - TestHelpers.createIndex(client(), indexName, toHttpEntity("{\"name\": \"test\"}")); + TestHelpers.createIndex(client(), indexName, TestHelpers.toHttpEntity("{\"name\": \"test\"}")); // Verify the detector is created using legacy _opendistro API Response response = TestHelpers @@ -1142,10 +1166,10 @@ public void testBackwardCompatibilityWithOpenDistro() throws IOException { "POST", TestHelpers.LEGACY_OPENDISTRO_AD_BASE_DETECTORS_URI, ImmutableMap.of(), - toHttpEntity(detector), + TestHelpers.toHttpEntity(detector), null ); - assertEquals("Create anomaly detector failed", RestStatus.CREATED, restStatus(response)); + assertEquals("Create anomaly detector failed", RestStatus.CREATED, TestHelpers.restStatus(response)); Map responseMap = entityAsMap(response); String id = (String) responseMap.get("_id"); int version = (int) responseMap.get("_version"); @@ -1166,7 +1190,7 @@ public void testBackwardCompatibilityWithOpenDistro() throws IOException { "", null ); - assertEquals("Delete anomaly detector failed", RestStatus.OK, restStatus(response)); + assertEquals("Delete anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(response)); } } diff --git a/src/test/java/org/opensearch/ad/rest/HistoricalAnalysisRestApiIT.java b/src/test/java/org/opensearch/ad/rest/HistoricalAnalysisRestApiIT.java index 140c7a81c..3e37b1b7b 100644 --- a/src/test/java/org/opensearch/ad/rest/HistoricalAnalysisRestApiIT.java +++ b/src/test/java/org/opensearch/ad/rest/HistoricalAnalysisRestApiIT.java @@ -121,7 +121,7 @@ public void testStopHistoricalAnalysis() throws Exception { // stop historical detector Response stopDetectorResponse = stopAnomalyDetector(detectorId, client()); - assertEquals(RestStatus.OK, restStatus(stopDetectorResponse)); + assertEquals(RestStatus.OK, TestHelpers.restStatus(stopDetectorResponse)); // get task profile ADTaskProfile stoppedAdTaskProfile = waitUntilTaskFinished(detectorId); @@ -159,7 +159,7 @@ public void testUpdateHistoricalAnalysis() throws IOException { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detectorId + "?refresh=true", ImmutableMap.of(), - toHttpEntity(newDetector), + TestHelpers.toHttpEntity(newDetector), null ); Map responseBody = entityAsMap(updateResponse); @@ -194,7 +194,7 @@ public void testUpdateRunningHistoricalAnalysis() throws Exception { "PUT", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detectorId + "?refresh=true", ImmutableMap.of(), - toHttpEntity(newDetector), + TestHelpers.toHttpEntity(newDetector), null ) ); @@ -211,7 +211,7 @@ public void testDeleteHistoricalAnalysis() throws IOException { // delete detector Response response = TestHelpers .makeRequest(client(), "DELETE", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detectorId, ImmutableMap.of(), "", null); - assertEquals(RestStatus.OK, restStatus(response)); + assertEquals(RestStatus.OK, TestHelpers.restStatus(response)); } // TODO: fix delete diff --git a/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java b/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java index a508a40c1..5f1180bf2 100644 --- a/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java +++ b/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java @@ -37,6 +37,7 @@ import org.junit.Assert; import org.junit.Before; import org.opensearch.ad.AnomalyDetectorRestTestCase; +import org.opensearch.ad.TestHelpers; import org.opensearch.ad.model.AnomalyDetector; import org.opensearch.ad.model.AnomalyDetectorExecutionInput; import org.opensearch.ad.model.DetectionDateRange; @@ -299,7 +300,7 @@ public void testPreviewAnomalyDetectorWithWriteAccess() throws IOException { null ); Response response = previewAnomalyDetector(aliceDetector.getDetectorId(), aliceClient, input); - Assert.assertEquals(RestStatus.OK, restStatus(response)); + Assert.assertEquals(RestStatus.OK, TestHelpers.restStatus(response)); } public void testPreviewAnomalyDetectorWithReadAccess() throws IOException { diff --git a/src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.13.0.0/opendistro-anomaly-detection-1.13.0.0.zip b/src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.13.0.0/opendistro-anomaly-detection-1.13.0.0.zip new file mode 100644 index 000000000..a68b74704 Binary files /dev/null and b/src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.13.0.0/opendistro-anomaly-detection-1.13.0.0.zip differ diff --git a/src/test/resources/org/opensearch/ad/bwc/job-scheduler/1.13.0.0/opendistro-job-scheduler-1.13.0.0.zip b/src/test/resources/org/opensearch/ad/bwc/job-scheduler/1.13.0.0/opendistro-job-scheduler-1.13.0.0.zip new file mode 100644 index 000000000..daf3b8f73 Binary files /dev/null and b/src/test/resources/org/opensearch/ad/bwc/job-scheduler/1.13.0.0/opendistro-job-scheduler-1.13.0.0.zip differ