From 89647c14f624320a26e30e04af865c9471189008 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:59:55 -0700 Subject: [PATCH] Removing old datasources model test (#2594) (#2596) (cherry picked from commit e153609ebcb4621d66aa08234ee0cd0524e94f5f) Signed-off-by: Vamsi Manohar Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- ...enSearchDataSourceMetadataStorageTest.java | 38 +++++++++++++++++++ .../sql/datasource/DataSourceAPIsIT.java | 36 ------------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java index f9c62599ec..886e84298d 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.datasources.storage; +import static org.opensearch.sql.datasource.model.DataSourceStatus.ACTIVE; import static org.opensearch.sql.datasources.storage.OpenSearchDataSourceMetadataStorage.DATASOURCE_INDEX_NAME; import com.fasterxml.jackson.core.JsonProcessingException; @@ -103,6 +104,39 @@ public void testGetDataSourceMetadata() { "basicauth", dataSourceMetadata.getProperties().get("prometheus.auth.type")); } + @SneakyThrows + @Test + public void testGetOldDataSourceMetadata() { + Mockito.when(clusterService.state().routingTable().hasIndex(DATASOURCE_INDEX_NAME)) + .thenReturn(true); + Mockito.when(client.search(ArgumentMatchers.any())).thenReturn(searchResponseActionFuture); + Mockito.when(searchResponseActionFuture.actionGet()).thenReturn(searchResponse); + Mockito.when(searchResponse.status()).thenReturn(RestStatus.OK); + Mockito.when(searchResponse.getHits()) + .thenReturn( + new SearchHits( + new SearchHit[] {searchHit}, new TotalHits(21, TotalHits.Relation.EQUAL_TO), 1.0F)); + Mockito.when(searchHit.getSourceAsString()) + .thenReturn(getOldDataSourceMetadataStringWithOutStatusEnum()); + Mockito.when(encryptor.decrypt("password")).thenReturn("password"); + Mockito.when(encryptor.decrypt("username")).thenReturn("username"); + + Optional dataSourceMetadataOptional = + openSearchDataSourceMetadataStorage.getDataSourceMetadata(TEST_DATASOURCE_INDEX_NAME); + + Assertions.assertFalse(dataSourceMetadataOptional.isEmpty()); + DataSourceMetadata dataSourceMetadata = dataSourceMetadataOptional.get(); + Assertions.assertEquals(TEST_DATASOURCE_INDEX_NAME, dataSourceMetadata.getName()); + Assertions.assertEquals(DataSourceType.PROMETHEUS, dataSourceMetadata.getConnector()); + Assertions.assertEquals( + "password", dataSourceMetadata.getProperties().get("prometheus.auth.password")); + Assertions.assertEquals( + "username", dataSourceMetadata.getProperties().get("prometheus.auth.username")); + Assertions.assertEquals( + "basicauth", dataSourceMetadata.getProperties().get("prometheus.auth.type")); + Assertions.assertEquals(ACTIVE, dataSourceMetadata.getStatus()); + } + @SneakyThrows @Test public void testGetDataSourceMetadataWith404SearchResponse() { @@ -615,6 +649,10 @@ private String getBasicDataSourceMetadataString() throws JsonProcessingException return objectMapper.writeValueAsString(dataSourceMetadata); } + private String getOldDataSourceMetadataStringWithOutStatusEnum() { + return "{\"name\":\"testDS\",\"description\":\"\",\"connector\":\"PROMETHEUS\",\"allowedRoles\":[\"prometheus_access\"],\"properties\":{\"prometheus.auth.password\":\"password\",\"prometheus.auth.username\":\"username\",\"prometheus.auth.uri\":\"https://localhost:9090\",\"prometheus.auth.type\":\"basicauth\"},\"resultIndex\":\"query_execution_result_testds\"}"; + } + private String getAWSSigv4DataSourceMetadataString() throws JsonProcessingException { Map properties = new HashMap<>(); properties.put("prometheus.auth.type", "awssigv4"); diff --git a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java index 70bece480a..05e19f8285 100644 --- a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java @@ -11,10 +11,7 @@ import static org.opensearch.sql.datasources.utils.XContentParserUtils.DESCRIPTION_FIELD; import static org.opensearch.sql.datasources.utils.XContentParserUtils.NAME_FIELD; import static org.opensearch.sql.datasources.utils.XContentParserUtils.STATUS_FIELD; -import static org.opensearch.sql.legacy.TestUtils.createIndexByRestClient; import static org.opensearch.sql.legacy.TestUtils.getResponseBody; -import static org.opensearch.sql.legacy.TestUtils.isIndexExist; -import static org.opensearch.sql.legacy.TestUtils.loadDataByRestClient; import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; @@ -70,10 +67,6 @@ protected static void deleteDataSourcesCreated() throws IOException { deleteRequest = getDeleteDataSourceRequest("patch_prometheus"); deleteResponse = client().performRequest(deleteRequest); Assert.assertEquals(204, deleteResponse.getStatusLine().getStatusCode()); - - deleteRequest = getDeleteDataSourceRequest("old_prometheus"); - deleteResponse = client().performRequest(deleteRequest); - Assert.assertEquals(204, deleteResponse.getStatusLine().getStatusCode()); } @SneakyThrows @@ -392,35 +385,6 @@ public void patchDataSourceAPITest() { Assert.assertEquals("test", dataSourceMetadata.getDescription()); } - @SneakyThrows - @Test - public void testOldDataSourceModelLoadingThroughGetDataSourcesAPI() { - Index index = Index.DATASOURCES; - String indexName = index.getName(); - String mapping = index.getMapping(); - String dataSet = index.getDataSet(); - if (!isIndexExist(client(), indexName)) { - createIndexByRestClient(client(), indexName, mapping); - } - loadDataByRestClient(client(), indexName, dataSet); - // waiting for loaded indices. - Thread.sleep(1000); - // get datasource to validate the creation. - Request getRequest = getFetchDataSourceRequest(null); - Response getResponse = client().performRequest(getRequest); - Assert.assertEquals(200, getResponse.getStatusLine().getStatusCode()); - String getResponseString = getResponseBody(getResponse); - Type listType = new TypeToken>() {}.getType(); - List dataSourceMetadataList = - new Gson().fromJson(getResponseString, listType); - Assert.assertTrue( - dataSourceMetadataList.stream() - .anyMatch( - dataSourceMetadata -> - dataSourceMetadata.getName().equals("old_prometheus") - && dataSourceMetadata.getStatus().equals(ACTIVE))); - } - public DataSourceMetadata mockDataSourceMetadata(String name) { return new DataSourceMetadata.Builder() .setName(name)