Skip to content

Commit

Permalink
Issue #LR-766 chore: upgraded the elasticsearch from 6.8.22 to 7.17.13
Browse files Browse the repository at this point in the history
  • Loading branch information
AmiableAnil committed Apr 3, 2024
1 parent ff095ea commit c3c1133
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 64 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions course-mw/sunbird-util/sunbird-es-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.8.22</version>
<version>7.17.13</version>
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.8.22</version>
<version>7.17.13</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -722,7 +709,7 @@ public static Map<String, Object> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -130,7 +128,7 @@ public void onFailure(Exception e) {
}
};

ConnectionManager.getRestClient().indexAsync(indexRequest, listener);
ConnectionManager.getRestClient().indexAsync(indexRequest, RequestOptions.DEFAULT, listener);

return promise.future();
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: "
Expand Down Expand Up @@ -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: "
Expand Down Expand Up @@ -435,7 +433,7 @@ public Future<Map<String, Object>> 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<String, Object> responseMap = new HashMap<>();
List<Map<String, Object>> esSource = new ArrayList<>();
Expand Down Expand Up @@ -467,7 +465,7 @@ public void onFailure(Exception e) {
}
};

ConnectionManager.getRestClient().searchAsync(searchRequest, listener);
ConnectionManager.getRestClient().searchAsync(searchRequest, RequestOptions.DEFAULT, listener);
return promise.future();
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 =="
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -295,27 +292,27 @@ private static void mockRulesForBulk(boolean fail) {
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ActionListener<BulkResponse>) invocation.getArguments()[1])
((ActionListener<BulkResponse>) invocation.getArguments()[2])
.onResponse(response);
return null;
}
})
.when(client)
.bulkAsync(Mockito.any(), Mockito.any());
.bulkAsync(Mockito.any(), Mockito.any(), Mockito.any());
} else {

doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {

((ActionListener<BulkResponse>) invocation.getArguments()[1])
((ActionListener<BulkResponse>) invocation.getArguments()[2])
.onFailure(new NullPointerException());
return null;
}
})
.when(client)
.bulkAsync(Mockito.any(), Mockito.any());
.bulkAsync(Mockito.any(), Mockito.any(), Mockito.any());
}
}

Expand All @@ -329,26 +326,26 @@ private static void mockRulesForSave(boolean fail) {
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ActionListener<IndexResponse>) invocation.getArguments()[1]).onResponse(ir);
((ActionListener<IndexResponse>) invocation.getArguments()[2]).onResponse(ir);
return null;
}
})
.when(client)
.indexAsync(Mockito.any(), Mockito.any());
.indexAsync(Mockito.any(), Mockito.any(), Mockito.any());
} else {

doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {

((ActionListener<IndexResponse>) invocation.getArguments()[1])
((ActionListener<IndexResponse>) invocation.getArguments()[2])
.onFailure(new NullPointerException());
return null;
}
})
.when(client)
.indexAsync(Mockito.any(), Mockito.any());
.indexAsync(Mockito.any(), Mockito.any(), Mockito.any());
}
}

Expand All @@ -363,13 +360,13 @@ private static void mockRulesForUpdate(boolean fail) {
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ActionListener<UpdateResponse>) invocation.getArguments()[1])
((ActionListener<UpdateResponse>) invocation.getArguments()[2])
.onResponse(updateRes);
return null;
}
})
.when(client)
.updateAsync(Mockito.any(), Mockito.any());
.updateAsync(Mockito.any(), Mockito.any(), Mockito.any());
} else {

doAnswer(
Expand All @@ -378,13 +375,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {

((ActionListener<UpdateResponse>) invocation.getArguments()[1])
((ActionListener<UpdateResponse>) invocation.getArguments()[2])
.onFailure(new NullPointerException());
return null;
}
})
.when(client)
.updateAsync(Mockito.any(), Mockito.any());
.updateAsync(Mockito.any(), Mockito.any(), Mockito.any());
}
}

Expand All @@ -403,27 +400,27 @@ private static void mockRulesForGet(boolean fail) {
@SuppressWarnings("unchecked")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ActionListener<GetResponse>) invocation.getArguments()[1])
((ActionListener<GetResponse>) invocation.getArguments()[2])
.onResponse(getResponse);
return null;
}
})
.when(client)
.getAsync(Mockito.any(), Mockito.any());
.getAsync(Mockito.any(), Mockito.any(), Mockito.any());
} else {

doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {

((ActionListener<GetResponse>) invocation.getArguments()[1])
((ActionListener<GetResponse>) invocation.getArguments()[2])
.onFailure(new NullPointerException());
return null;
}
})
.when(client)
.getAsync(Mockito.any(), Mockito.any());
.getAsync(Mockito.any(), Mockito.any(), Mockito.any());
}
}

Expand All @@ -439,27 +436,27 @@ private static void mockRulesForDelete(boolean fail, boolean notFound) {
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ActionListener<DeleteResponse>) invocation.getArguments()[1])
((ActionListener<DeleteResponse>) invocation.getArguments()[2])
.onResponse(delResponse);
return null;
}
})
.when(client)
.deleteAsync(Mockito.any(), Mockito.any());
.deleteAsync(Mockito.any(), Mockito.any(), Mockito.any());
} else {

doAnswer(
new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {

((ActionListener<DeleteResponse>) invocation.getArguments()[1])
((ActionListener<DeleteResponse>) invocation.getArguments()[2])
.onFailure(new NullPointerException());
return null;
}
})
.when(client)
.deleteAsync(Mockito.any(), Mockito.any());
.deleteAsync(Mockito.any(), Mockito.any(), Mockito.any());
}
}
}

0 comments on commit c3c1133

Please sign in to comment.