diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexDefinition.java b/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexDefinition.java index 62d880c6be3..41cbb5567f4 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexDefinition.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexDefinition.java @@ -76,9 +76,6 @@ public class ElasticSearchIndexDefinition { ENTITY_REPORT_DATA, "entity_report_data_index", "/elasticsearch/entity_report_data_index.json"), TEST_CASE_SEARCH_INDEX( Entity.TEST_CASE, "test_case_search_index", "/elasticsearch/%s/test_case_index_mapping.json"), - - TEST_SUITE_SEARCH_INDEX( - Entity.TEST_SUITE, "test_suite_search_index", "/elasticsearch/%s/test_suite_index_mapping.json"), WEB_ANALYTIC_ENTITY_VIEW_REPORT_DATA_INDEX( Entity.WEB_ANALYTIC_EVENT, "web_analytic_entity_view_report_data_index", @@ -174,10 +171,8 @@ public class ElasticSearchIndexDefinition { return ElasticSearchIndexType.CONTAINER_SEARCH_INDEX; } else if (type.equalsIgnoreCase(Entity.QUERY)) { return ElasticSearchIndexType.QUERY_SEARCH_INDEX; - } else if (type.equalsIgnoreCase(Entity.TEST_CASE)) { + } else if (type.equalsIgnoreCase(Entity.TEST_SUITE) || type.equalsIgnoreCase(Entity.TEST_CASE)) { return ElasticSearchIndexType.TEST_CASE_SEARCH_INDEX; - } else if (type.equalsIgnoreCase(Entity.TEST_SUITE)) { - return ElasticSearchIndexType.TEST_SUITE_SEARCH_INDEX; } throw new EventPublisherException("Failed to find index doc for type " + type); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexFactory.java b/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexFactory.java index dba25d5c1ef..305ee6e21ea 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexFactory.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/ElasticSearchIndexFactory.java @@ -13,7 +13,6 @@ import org.openmetadata.schema.entity.data.Topic; import org.openmetadata.schema.entity.teams.Team; import org.openmetadata.schema.entity.teams.User; import org.openmetadata.schema.tests.TestCase; -import org.openmetadata.schema.tests.TestSuite; import org.openmetadata.service.Entity; import org.openmetadata.service.elasticsearch.indexes.ContainerIndex; import org.openmetadata.service.elasticsearch.indexes.DashboardIndex; @@ -25,7 +24,6 @@ import org.openmetadata.service.elasticsearch.indexes.QueryIndex; import org.openmetadata.service.elasticsearch.indexes.TableIndex; import org.openmetadata.service.elasticsearch.indexes.TagIndex; import org.openmetadata.service.elasticsearch.indexes.TeamIndex; -import org.openmetadata.service.elasticsearch.indexes.TestSuiteIndex; import org.openmetadata.service.elasticsearch.indexes.TopicIndex; import org.openmetadata.service.elasticsearch.indexes.UserIndex; @@ -58,9 +56,8 @@ public class ElasticSearchIndexFactory { case Entity.CONTAINER: return new ContainerIndex((Container) entity); case Entity.TEST_CASE: - return new TestCaseIndex((TestCase) entity); case Entity.TEST_SUITE: - return new TestSuiteIndex((TestSuite) entity); + return new TestCaseIndex((TestCase) entity); default: LOG.warn("Ignoring Entity Type {}", entityType); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/indexes/TestSuiteIndex.java b/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/indexes/TestSuiteIndex.java deleted file mode 100644 index d3f95670f9c..00000000000 --- a/openmetadata-service/src/main/java/org/openmetadata/service/elasticsearch/indexes/TestSuiteIndex.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.openmetadata.service.elasticsearch.indexes; - -import java.util.Map; -import org.openmetadata.schema.tests.TestSuite; -import org.openmetadata.service.util.JsonUtils; - -public class TestSuiteIndex implements ElasticSearchIndex { - TestSuite testSuite; - - public TestSuiteIndex(TestSuite testSuite) { - this.testSuite = testSuite; - } - - public Map buildESDoc() { - Map doc = JsonUtils.getMap(testSuite); - return doc; - } -} diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticSearch/ElasticSearchClientImpl.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticSearch/ElasticSearchClientImpl.java index a2b4c40dab2..90ccfb77d77 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticSearch/ElasticSearchClientImpl.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticSearch/ElasticSearchClientImpl.java @@ -133,7 +133,6 @@ import org.openmetadata.service.elasticsearch.indexes.ElasticSearchIndex; import org.openmetadata.service.elasticsearch.indexes.GlossaryTermIndex; import org.openmetadata.service.elasticsearch.indexes.TagIndex; import org.openmetadata.service.elasticsearch.indexes.TeamIndex; -import org.openmetadata.service.elasticsearch.indexes.TestSuiteIndex; import org.openmetadata.service.elasticsearch.indexes.UserIndex; import org.openmetadata.service.jdbi3.CollectionDAO; import org.openmetadata.service.jdbi3.DataInsightChartRepository; @@ -280,7 +279,6 @@ public class ElasticSearchClientImpl implements SearchClient { searchSourceBuilder = buildQuerySearchBuilder(request.getQuery(), request.getFrom(), request.getSize()); break; case "test_case_search_index": - case "test_suite_search_index": searchSourceBuilder = buildTestCaseSearch(request.getQuery(), request.getFrom(), request.getSize()); break; default: @@ -1180,33 +1178,26 @@ public class ElasticSearchClientImpl implements SearchClient { @Override public void updateTestSuite(ChangeEvent event) throws IOException { ElasticSearchIndexDefinition.ElasticSearchIndexType indexType = - ElasticSearchIndexDefinition.getIndexMappingByEntityType(Entity.TEST_SUITE); + ElasticSearchIndexDefinition.getIndexMappingByEntityType(Entity.TEST_CASE); TestSuite testSuite = (TestSuite) event.getEntity(); UUID testSuiteId = testSuite.getId(); - UpdateRequest updateRequest = new UpdateRequest(indexType.indexName, testSuiteId.toString()); - TestSuiteIndex testSuiteIndex; - - switch (event.getEventType()) { - case ENTITY_CREATED: - testSuiteIndex = new TestSuiteIndex((TestSuite) event.getEntity()); - updateRequest.doc(JsonUtils.pojoToJson(testSuiteIndex.buildESDoc()), XContentType.JSON); - updateRequest.docAsUpsert(true); - updateElasticSearch(updateRequest); - break; - case ENTITY_UPDATED: - testSuiteIndex = new TestSuiteIndex((TestSuite) event.getEntity()); - scriptedUpsert(testSuiteIndex.buildESDoc(), updateRequest); - updateElasticSearch(updateRequest); - break; - case ENTITY_SOFT_DELETED: - softDeleteEntity(updateRequest); - updateElasticSearch(updateRequest); - break; - case ENTITY_DELETED: - DeleteRequest deleteRequest = new DeleteRequest(indexType.indexName, event.getEntityId().toString()); - deleteEntityFromElasticSearch(deleteRequest); - break; + if (event.getEventType() == ENTITY_DELETED) { + if (testSuite.getExecutable()) { + DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(indexType.indexName); + deleteByQueryRequest.setQuery(new MatchQueryBuilder("testSuites.id", testSuiteId.toString())); + deleteEntityFromElasticSearchByQuery(deleteByQueryRequest); + } else { + UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest(indexType.indexName); + updateByQueryRequest.setQuery(new MatchQueryBuilder("testSuites.id", testSuiteId.toString())); + String scriptTxt = + "for (int i = 0; i < ctx._source.testSuites.length; i++) { if (ctx._source.testSuites[i].id == '%s') { ctx._source.testSuites.remove(i) }}"; + Script script = + new Script( + ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, String.format(scriptTxt, testSuiteId), new HashMap<>()); + updateByQueryRequest.setScript(script); + updateElasticSearchByQuery(updateByQueryRequest); + } } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/openSearch/OpenSearchClientImpl.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/openSearch/OpenSearchClientImpl.java index 4ae1747b3ea..7395982413f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/openSearch/OpenSearchClientImpl.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/openSearch/OpenSearchClientImpl.java @@ -68,7 +68,6 @@ import org.openmetadata.service.elasticsearch.indexes.ElasticSearchIndex; import org.openmetadata.service.elasticsearch.indexes.GlossaryTermIndex; import org.openmetadata.service.elasticsearch.indexes.TagIndex; import org.openmetadata.service.elasticsearch.indexes.TeamIndex; -import org.openmetadata.service.elasticsearch.indexes.TestSuiteIndex; import org.openmetadata.service.elasticsearch.indexes.UserIndex; import org.openmetadata.service.jdbi3.CollectionDAO; import org.openmetadata.service.jdbi3.DataInsightChartRepository; @@ -280,7 +279,6 @@ public class OpenSearchClientImpl implements SearchClient { searchSourceBuilder = buildQuerySearchBuilder(request.getQuery(), request.getFrom(), request.getSize()); break; case "test_case_search_index": - case "test_suite_search_index": searchSourceBuilder = buildTestCaseSearch(request.getQuery(), request.getFrom(), request.getSize()); break; default: @@ -1174,33 +1172,26 @@ public class OpenSearchClientImpl implements SearchClient { @Override public void updateTestSuite(ChangeEvent event) throws IOException { ElasticSearchIndexDefinition.ElasticSearchIndexType indexType = - ElasticSearchIndexDefinition.getIndexMappingByEntityType(Entity.TEST_SUITE); + ElasticSearchIndexDefinition.getIndexMappingByEntityType(Entity.TEST_CASE); TestSuite testSuite = (TestSuite) event.getEntity(); UUID testSuiteId = testSuite.getId(); - UpdateRequest updateRequest = new UpdateRequest(indexType.indexName, testSuiteId.toString()); - TestSuiteIndex testSuiteIndex; - - switch (event.getEventType()) { - case ENTITY_CREATED: - testSuiteIndex = new TestSuiteIndex((TestSuite) event.getEntity()); - updateRequest.doc(JsonUtils.pojoToJson(testSuiteIndex.buildESDoc()), XContentType.JSON); - updateRequest.docAsUpsert(true); - updateElasticSearch(updateRequest); - break; - case ENTITY_UPDATED: - testSuiteIndex = new TestSuiteIndex((TestSuite) event.getEntity()); - scriptedUpsert(testSuiteIndex.buildESDoc(), updateRequest); - updateElasticSearch(updateRequest); - break; - case ENTITY_SOFT_DELETED: - softDeleteEntity(updateRequest); - updateElasticSearch(updateRequest); - break; - case ENTITY_DELETED: - DeleteRequest deleteRequest = new DeleteRequest(indexType.indexName, event.getEntityId().toString()); - deleteEntityFromElasticSearch(deleteRequest); - break; + if (event.getEventType() == ENTITY_DELETED) { + if (Boolean.TRUE.equals(testSuite.getExecutable())) { + DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(indexType.indexName); + deleteByQueryRequest.setQuery(new MatchQueryBuilder("testSuites.id", testSuiteId.toString())); + deleteEntityFromElasticSearchByQuery(deleteByQueryRequest); + } else { + UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest(indexType.indexName); + updateByQueryRequest.setQuery(new MatchQueryBuilder("testSuites.id", testSuiteId.toString())); + String scriptTxt = + "for (int i = 0; i < ctx._source.testSuites.length; i++) { if (ctx._source.testSuites[i].id == '%s') { ctx._source.testSuites.remove(i) }}"; + Script script = + new Script( + ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, String.format(scriptTxt, testSuiteId), new HashMap<>()); + updateByQueryRequest.setScript(script); + updateElasticSearchByQuery(updateByQueryRequest); + } } } diff --git a/openmetadata-service/src/main/resources/elasticsearch/en/test_suite_index_mapping.json b/openmetadata-service/src/main/resources/elasticsearch/en/test_suite_index_mapping.json deleted file mode 100644 index acf63fef3b3..00000000000 --- a/openmetadata-service/src/main/resources/elasticsearch/en/test_suite_index_mapping.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "settings": { - "analysis": { - "normalizer": { - "lowercase_normalizer": { - "type": "custom", - "char_filter": [], - "filter": [ - "lowercase" - ] - } - }, - "analyzer": { - "om_analyzer": { - "tokenizer": "letter", - "filter": [ - "lowercase", - "om_stemmer" - ] - }, - "om_ngram": { - "tokenizer": "ngram", - "min_gram": 2, - "max_gram": 3, - "filter": [ - "lowercase" - ] - } - }, - "filter": { - "om_stemmer": { - "type": "stemmer", - "name": "english" - } - } - } - }, - "mappings": { - "properties": { - "id": { - "type": "keyword" - }, - "name": { - "type": "text", - "analyzer": "om_analyzer", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - }, - "ngram": { - "type": "text", - "analyzer": "om_ngram" - } - } - }, - "fullyQualifiedName": { - "type": "keyword", - "normalizer": "lowercase_normalizer" - }, - "description": { - "type": "text", - "analyzer": "om_analyzer", - "fields": { - "ngram": { - "type": "text", - "analyzer": "om_ngram" - } - } - }, - "displayName": { - "type": "text", - "analyzer": "om_analyzer", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "deleted": { - "type": "text" - }, - "href": { - "type": "text" - }, - "executable": { - "type": "text" - } - } - } -} \ No newline at end of file diff --git a/openmetadata-service/src/main/resources/elasticsearch/jp/test_suite_index_mapping.json b/openmetadata-service/src/main/resources/elasticsearch/jp/test_suite_index_mapping.json deleted file mode 100644 index 2d76b02ce97..00000000000 --- a/openmetadata-service/src/main/resources/elasticsearch/jp/test_suite_index_mapping.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "settings": { - "analysis": { - "normalizer": { - "lowercase_normalizer": { - "type": "custom", - "char_filter": [], - "filter": [ - "lowercase" - ] - } - }, - "analyzer": { - "om_analyzer": { - "tokenizer": "letter", - "filter": [ - "lowercase", - "om_stemmer" - ] - }, - "om_analyzer_jp" : { - "tokenizer" : "kuromoji_tokenizer", - "type" : "custom", - "filter" : [ - "kuromoji_baseform", - "kuromoji_part_of_speech", - "kuromoji_number", - "kuromoji_stemmer" - ] - }, - "om_ngram": { - "tokenizer": "ngram", - "min_gram": 1, - "max_gram": 2, - "filter": [ - "lowercase" - ] - } - }, - "filter": { - "om_stemmer": { - "type": "stemmer", - "name": "english" - } - } - } - }, - "mappings": { - "properties": { - "id": { - "type": "keyword" - }, - "name": { - "type": "text", - "analyzer": "om_analyzer_jp", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - }, - "ngram": { - "type": "text", - "analyzer": "om_ngram" - } - } - }, - "fullyQualifiedName": { - "type": "keyword", - "normalizer": "lowercase_normalizer" - }, - "description": { - "type": "text", - "analyzer": "om_analyzer_jp", - "fields": { - "ngram": { - "type": "text", - "analyzer": "om_ngram" - } - } - }, - "displayName": { - "type": "text", - "analyzer": "om_analyzer_jp", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "deleted": { - "type": "text" - }, - "href": { - "type": "text" - }, - "executable": { - "type": "text" - } - } - } -} \ No newline at end of file diff --git a/openmetadata-service/src/main/resources/elasticsearch/zh/test_suite_index_mapping.json b/openmetadata-service/src/main/resources/elasticsearch/zh/test_suite_index_mapping.json deleted file mode 100644 index cb5466c171a..00000000000 --- a/openmetadata-service/src/main/resources/elasticsearch/zh/test_suite_index_mapping.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "settings": { - "analysis": { - "normalizer": { - "lowercase_normalizer": { - "type": "custom", - "char_filter": [], - "filter": [ - "lowercase" - ] - } - }, - "analyzer": { - "om_analyzer": { - "tokenizer": "letter", - "filter": [ - "lowercase", - "om_stemmer" - ] - }, - "om_ngram": { - "tokenizer": "ngram", - "min_gram": 2, - "max_gram": 3, - "filter": [ - "lowercase" - ] - } - }, - "filter": { - "om_stemmer": { - "type": "stemmer", - "name": "english" - } - } - } - }, - "mappings": { - "properties": { - "id": { - "type": "keyword" - }, - "name": { - "type": "text", - "analyzer": "ik_max_word", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - }, - "ngram": { - "type": "text", - "analyzer": "om_ngram" - } - } - }, - "fullyQualifiedName": { - "type": "keyword", - "normalizer": "lowercase_normalizer" - }, - "description": { - "type": "text", - "analyzer": "ik_max_word", - "fields": { - "ngram": { - "type": "text", - "analyzer": "om_ngram" - } - } - }, - "displayName": { - "type": "text", - "analyzer": "ik_max_word", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "deleted": { - "type": "text" - }, - "href": { - "type": "text" - }, - "executable": { - "type": "text" - } - } - } -} \ No newline at end of file