From c3c11336e2e1b03a2f9a758b1846fe45d7fa8838 Mon Sep 17 00:00:00 2001 From: anilgupta Date: Wed, 3 Apr 2024 10:26:46 +0530 Subject: [PATCH] Issue #LR-766 chore: upgraded the elasticsearch from 6.8.22 to 7.17.13 --- .circleci/config.yml | 4 ++ .../sunbird-util/sunbird-es-utils/pom.xml | 4 +- .../sunbird/common/ElasticSearchHelper.java | 19 +----- .../common/ElasticSearchRestHighImpl.java | 28 ++++----- .../common/ElasticSearchRestHighImplTest.java | 59 +++++++++---------- 5 files changed, 50 insertions(+), 64 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5b87eac39..d05317e14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,10 @@ jobs: build: machine: image: ubuntu-2004:202201-02 + # https://circleci.com/docs/parallelism-faster-jobs/ + # parallelism: 4 + # The resource_class feature allows configuring CPU and RAM resources for each job. Different resource classes are available for different executors. https://circleci.com/docs/2.0/configuration-reference/#resourceclass + resource_class: large steps: - checkout - restore_cache: diff --git a/course-mw/sunbird-util/sunbird-es-utils/pom.xml b/course-mw/sunbird-util/sunbird-es-utils/pom.xml index 6eef4e088..31ea7a318 100644 --- a/course-mw/sunbird-util/sunbird-es-utils/pom.xml +++ b/course-mw/sunbird-util/sunbird-es-utils/pom.xml @@ -18,13 +18,13 @@ org.elasticsearch.client elasticsearch-rest-high-level-client - 6.8.22 + 7.17.13 org.elasticsearch.client transport - 6.8.22 + 7.17.13 io.netty diff --git a/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java b/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java index f65466695..9d8c9858f 100644 --- a/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java +++ b/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java @@ -9,14 +9,7 @@ import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.ExistsQueryBuilder; -import org.elasticsearch.index.query.MatchQueryBuilder; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.RangeQueryBuilder; -import org.elasticsearch.index.query.TermQueryBuilder; -import org.elasticsearch.index.query.TermsQueryBuilder; +import org.elasticsearch.index.query.*; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -33,13 +26,7 @@ import scala.concurrent.Future; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -722,7 +709,7 @@ public static Map getSearchResponseMap( long count = 0; if (response != null) { SearchHits hits = response.getHits(); - count = hits.getTotalHits(); + count = hits.getTotalHits().value; for (SearchHit hit : hits) { esSource.add(hit.getSourceAsMap()); diff --git a/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java b/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java index 4adfb93cf..9a8a6c956 100644 --- a/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java +++ b/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java @@ -1,12 +1,6 @@ package org.sunbird.common; import akka.dispatch.Futures; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -26,6 +20,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.SimpleQueryStringBuilder; @@ -47,6 +42,9 @@ import scala.concurrent.Future; import scala.concurrent.Promise; +import java.util.*; +import java.util.stream.Collectors; + /** * This class will provide all required operation for elastic search. * @@ -130,7 +128,7 @@ public void onFailure(Exception e) { } }; - ConnectionManager.getRestClient().indexAsync(indexRequest, listener); + ConnectionManager.getRestClient().indexAsync(indexRequest, RequestOptions.DEFAULT, listener); return promise.future(); } @@ -186,7 +184,7 @@ public void onFailure(Exception e) { promise.failure(e); } }; - ConnectionManager.getRestClient().updateAsync(updateRequest, listener); + ConnectionManager.getRestClient().updateAsync(updateRequest, RequestOptions.DEFAULT, listener); } else { logger.info(requestContext, @@ -248,7 +246,7 @@ public void onFailure(Exception e) { } }; - ConnectionManager.getRestClient().getAsync(getRequest, listener); + ConnectionManager.getRestClient().getAsync(getRequest, RequestOptions.DEFAULT, listener); } else { logger.info(requestContext, "ElasticSearchRestHighImpl:getDataByIdentifier: " @@ -302,7 +300,7 @@ public void onFailure(Exception e) { } }; - ConnectionManager.getRestClient().deleteAsync(delRequest, listener); + ConnectionManager.getRestClient().deleteAsync(delRequest, RequestOptions.DEFAULT, listener); } else { logger.info(requestContext, "ElasticSearchRestHighImpl:delete: " @@ -435,7 +433,7 @@ public Future> search(RequestContext requestContext, SearchD public void onResponse(SearchResponse response) { logger.debug(requestContext, "ElasticSearchRestHighImpl:search:onResponse response1 = " + response); - if (response.getHits() == null || response.getHits().getTotalHits() == 0) { + if (response.getHits() == null || response.getHits().getTotalHits().value == 0) { Map responseMap = new HashMap<>(); List> esSource = new ArrayList<>(); @@ -467,7 +465,7 @@ public void onFailure(Exception e) { } }; - ConnectionManager.getRestClient().searchAsync(searchRequest, listener); + ConnectionManager.getRestClient().searchAsync(searchRequest, RequestOptions.DEFAULT, listener); return promise.future(); } @@ -499,7 +497,7 @@ public void onFailure(Exception e) { "ElasticSearchRestHighImpl:healthCheck: error " + e.getMessage()); } }; - ConnectionManager.getRestClient().indices().existsAsync(indexRequest, listener); + ConnectionManager.getRestClient().indices().existsAsync(indexRequest, RequestOptions.DEFAULT, listener); return promise.future(); } @@ -554,7 +552,7 @@ public void onFailure(Exception e) { promise.success(false); } }; - ConnectionManager.getRestClient().bulkAsync(request, listener); + ConnectionManager.getRestClient().bulkAsync(request, RequestOptions.DEFAULT, listener); logger.debug(requestContext, "ElasticSearchRestHighImpl:bulkInsert: method end ==" @@ -653,7 +651,7 @@ public void onFailure(Exception e) { promise.failure(e); } }; - ConnectionManager.getRestClient().updateAsync(updateRequest, listener); + ConnectionManager.getRestClient().updateAsync(updateRequest, RequestOptions.DEFAULT, listener); return promise.future(); } else { logger.error(requestContext, diff --git a/course-mw/sunbird-util/sunbird-es-utils/src/test/java/org/sunbird/common/ElasticSearchRestHighImplTest.java b/course-mw/sunbird-util/sunbird-es-utils/src/test/java/org/sunbird/common/ElasticSearchRestHighImplTest.java index 84458c6f9..b949abd26 100644 --- a/course-mw/sunbird-util/sunbird-es-utils/src/test/java/org/sunbird/common/ElasticSearchRestHighImplTest.java +++ b/course-mw/sunbird-util/sunbird-es-utils/src/test/java/org/sunbird/common/ElasticSearchRestHighImplTest.java @@ -1,16 +1,5 @@ package org.sunbird.common; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.doNothing; -import static org.powermock.api.mockito.PowerMockito.mock; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.bulk.BulkItemResponse; @@ -49,6 +38,14 @@ import org.sunbird.helper.ConnectionManager; import scala.concurrent.Future; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.doNothing; +import static org.powermock.api.mockito.PowerMockito.mock; + /** * Test class for Elastic search Rest High level client Impl * @@ -295,13 +292,13 @@ private static void mockRulesForBulk(boolean fail) { new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onResponse(response); return null; } }) .when(client) - .bulkAsync(Mockito.any(), Mockito.any()); + .bulkAsync(Mockito.any(), Mockito.any(), Mockito.any()); } else { doAnswer( @@ -309,13 +306,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onFailure(new NullPointerException()); return null; } }) .when(client) - .bulkAsync(Mockito.any(), Mockito.any()); + .bulkAsync(Mockito.any(), Mockito.any(), Mockito.any()); } } @@ -329,12 +326,12 @@ private static void mockRulesForSave(boolean fail) { new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]).onResponse(ir); + ((ActionListener) invocation.getArguments()[2]).onResponse(ir); return null; } }) .when(client) - .indexAsync(Mockito.any(), Mockito.any()); + .indexAsync(Mockito.any(), Mockito.any(), Mockito.any()); } else { doAnswer( @@ -342,13 +339,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onFailure(new NullPointerException()); return null; } }) .when(client) - .indexAsync(Mockito.any(), Mockito.any()); + .indexAsync(Mockito.any(), Mockito.any(), Mockito.any()); } } @@ -363,13 +360,13 @@ private static void mockRulesForUpdate(boolean fail) { new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onResponse(updateRes); return null; } }) .when(client) - .updateAsync(Mockito.any(), Mockito.any()); + .updateAsync(Mockito.any(), Mockito.any(), Mockito.any()); } else { doAnswer( @@ -378,13 +375,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onFailure(new NullPointerException()); return null; } }) .when(client) - .updateAsync(Mockito.any(), Mockito.any()); + .updateAsync(Mockito.any(), Mockito.any(), Mockito.any()); } } @@ -403,13 +400,13 @@ private static void mockRulesForGet(boolean fail) { @SuppressWarnings("unchecked") @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onResponse(getResponse); return null; } }) .when(client) - .getAsync(Mockito.any(), Mockito.any()); + .getAsync(Mockito.any(), Mockito.any(), Mockito.any()); } else { doAnswer( @@ -417,13 +414,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onFailure(new NullPointerException()); return null; } }) .when(client) - .getAsync(Mockito.any(), Mockito.any()); + .getAsync(Mockito.any(), Mockito.any(), Mockito.any()); } } @@ -439,13 +436,13 @@ private static void mockRulesForDelete(boolean fail, boolean notFound) { new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onResponse(delResponse); return null; } }) .when(client) - .deleteAsync(Mockito.any(), Mockito.any()); + .deleteAsync(Mockito.any(), Mockito.any(), Mockito.any()); } else { doAnswer( @@ -453,13 +450,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ((ActionListener) invocation.getArguments()[1]) + ((ActionListener) invocation.getArguments()[2]) .onFailure(new NullPointerException()); return null; } }) .when(client) - .deleteAsync(Mockito.any(), Mockito.any()); + .deleteAsync(Mockito.any(), Mockito.any(), Mockito.any()); } } }