diff --git a/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java b/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java index c462ac430..0e5359795 100644 --- a/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java +++ b/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java @@ -69,12 +69,11 @@ public class ElasticSearchRestHighImpl implements ElasticSearchService { @Override public Future save(String index, String identifier, Map data, RequestContext context) { long startTime = System.currentTimeMillis(); - Promise promise = Futures.promise(); - logger.debug(context, - "ElasticSearchUtilRest:save: method started at ==" + startTime + " for Index " + index); + Promise promise = (Promise) (Promise) Futures.promise(); + + logger.debug(context, "ElasticSearchUtilRest:save: method started at ==" + startTime + " for Index " + index); if (StringUtils.isBlank(identifier) || StringUtils.isBlank(index)) { - logger.info(context, - "ElasticSearchRestHighImpl:save: " + logger.info(context, "ElasticSearchRestHighImpl:save: " + "Identifier or Index value is null or empty, identifier : " + identifier + ",index: " + index + ",not able to save data."); promise.success(ERROR); @@ -88,13 +87,11 @@ public Future save(String index, String identifier, Map new ActionListener() { @Override public void onResponse(IndexResponse indexResponse) { - logger.info(context, - "ElasticSearchRestHighImpl:save: Success for index : " + index + logger.info(context, "ElasticSearchRestHighImpl:save: Success for index : " + index + ", identifier :" + identifier); promise.success(indexResponse.getId()); - logger.debug(context, - "ElasticSearchRestHighImpl:save: method end at ==" + System.currentTimeMillis() + logger.debug(context, "ElasticSearchRestHighImpl:save: method end at ==" + System.currentTimeMillis() + " for Index " + index + " ,Total time elapsed = " + calculateEndTime(startTime)); } @@ -102,12 +99,10 @@ public void onResponse(IndexResponse indexResponse) { @Override public void onFailure(Exception e) { promise.failure(e); - logger.error(context, - "ElasticSearchRestHighImpl:save: " + logger.error(context, "ElasticSearchRestHighImpl:save: " + "Error while saving " + index + " id : " + identifier, e); - logger.debug(context, - "ElasticSearchRestHighImpl:save: method end at ==" + System.currentTimeMillis() + logger.debug(context, "ElasticSearchRestHighImpl:save: method end at ==" + System.currentTimeMillis() + " for INdex " + index + " ,Total time elapsed = " + calculateEndTime(startTime)); } @@ -130,10 +125,9 @@ public void onFailure(Exception e) { @Override public Future update(String index, String documentId, Map document, RequestContext context) { long startTime = System.currentTimeMillis(); - logger.debug(context, - "ElasticSearchRestHighImpl:update: method started at ==" + startTime + logger.debug(context, "ElasticSearchRestHighImpl:update: method started at ==" + startTime + " for Index " + index); - Promise promise = Futures.promise(); + Promise promise = (Promise) (Promise) Futures.promise(); document.put("identifier", documentId); if (!StringUtils.isBlank(index) && !StringUtils.isBlank(documentId)) { @@ -146,12 +140,10 @@ public Future update(String index, String documentId, Map sourceAsMap = getResponse.getSourceAsMap(); if (MapUtils.isNotEmpty(sourceAsMap)) { promise.success(sourceAsMap); - logger.debug(context, - "ElasticSearchRestHighImpl:getDataByIdentifier: method end ==" - + " for Index " + index + logger.debug(context, "ElasticSearchRestHighImpl:getDataByIdentifier: method end == for Index " + index + " ,Total time elapsed = " + calculateEndTime(startTime)); } else { promise.success(new HashMap<>()); @@ -220,8 +208,7 @@ public void onFailure(Exception e) { ConnectionManager.getRestClient().getAsync(getRequest, RequestOptions.DEFAULT, listener); } else { - logger.info(context, - "ElasticSearchRestHighImpl:getDataByIdentifier: " + logger.info(context, "ElasticSearchRestHighImpl:getDataByIdentifier: " + "provided index or identifier is null, index = " + index + ", identifier = " + identifier); promise.failure(ProjectUtil.createClientException(ResponseCode.invalidRequestData)); @@ -241,7 +228,7 @@ public void onFailure(Exception e) { public Future delete(String index, String identifier, RequestContext context) { long startTime = System.currentTimeMillis(); logger.debug(context, "ElasticSearchRestHighImpl:delete: method started at ==" + startTime); - Promise promise = Futures.promise(); + Promise promise = (Promise) (Promise) Futures.promise(); if (StringUtils.isNotEmpty(identifier) && StringUtils.isNotEmpty(index)) { DeleteRequest delRequest = new DeleteRequest(index, _DOC, identifier); ActionListener listener = @@ -267,15 +254,13 @@ public void onFailure(Exception e) { ConnectionManager.getRestClient().deleteAsync(delRequest, RequestOptions.DEFAULT, listener); } else { - logger.info(context, - "ElasticSearchRestHighImpl:delete: " + logger.info(context, "ElasticSearchRestHighImpl:delete: " + "provided index or identifier is null, index = " + index + ", identifier = " + identifier); promise.failure(ProjectUtil.createClientException(ResponseCode.invalidRequestData)); } - logger.debug(context, - "ElasticSearchRestHighImpl:delete: method end ==" + logger.debug(context, "ElasticSearchRestHighImpl:delete: method end ==" + " ,Total time elapsed = " + calculateEndTime(startTime)); return promise.future(); } @@ -380,12 +365,11 @@ public Future> search(SearchDTO searchDTO, String index, Req if (null != searchDTO.getFacets() && !searchDTO.getFacets().isEmpty()) { searchSourceBuilder = addAggregations(searchSourceBuilder, searchDTO.getFacets()); } - logger.info(context, - "ElasticSearchRestHighImpl:search: calling search for index " + index + logger.info(context, "ElasticSearchRestHighImpl:search: calling search for index " + index + ", with query = " + searchSourceBuilder.toString()); searchRequest.source(searchSourceBuilder); - Promise> promise = Futures.promise(); + Promise> promise = (Promise>) (Promise) Futures.promise(); ActionListener listener = new ActionListener() { @@ -401,8 +385,7 @@ public void onResponse(SearchResponse response) { promise.success(responseMap); } else { Map responseMap = ElasticSearchHelper.getSearchResponseMap(response, searchDTO, finalFacetList); - logger.debug(context, - "ElasticSearchRestHighImpl:search: method end " + logger.debug(context, "ElasticSearchRestHighImpl:search: method end " + " ,Total time elapsed = " + calculateEndTime(startTime)); promise.success(responseMap); } @@ -412,8 +395,7 @@ public void onResponse(SearchResponse response) { public void onFailure(Exception e) { promise.failure(e); - logger.debug(context, - "ElasticSearchRestHighImpl:search: method end for Index " + index + logger.debug(context, "ElasticSearchRestHighImpl:search: method end for Index " + index + " ,Total time elapsed = " + calculateEndTime(startTime)); logger.error(context, "ElasticSearchRestHighImpl:search: method Failed with error :", e); } @@ -431,7 +413,7 @@ public void onFailure(Exception e) { @Override public Future healthCheck() { GetIndexRequest indexRequest = new GetIndexRequest().indices(ProjectUtil.EsType.user.getTypeName()); - Promise promise = Futures.promise(); + Promise promise = (Promise) (Promise) Futures.promise(); ActionListener listener = new ActionListener() { @Override @@ -465,11 +447,10 @@ public void onFailure(Exception e) { @Override public Future bulkInsert(String index, List> dataList, RequestContext context) { long startTime = System.currentTimeMillis(); - logger.debug(context, - "ElasticSearchRestHighImpl:bulkInsert: method started at ==" + startTime + logger.debug(context, "ElasticSearchRestHighImpl:bulkInsert: method started at ==" + startTime + " for Index " + index); BulkRequest request = new BulkRequest(); - Promise promise = Futures.promise(); + Promise promise = (Promise) (Promise) Futures.promise(); for (Map data : dataList) { data.put("identifier", data.get(JsonKey.ID)); request.add(new IndexRequest(index, _DOC, (String) data.get(JsonKey.ID)).source(data)); @@ -486,8 +467,7 @@ public void onResponse(BulkResponse bulkResponse) { BulkItemResponse bResponse = responseItr.next(); if (bResponse.isFailed()) { - logger.info(context, - "ElasticSearchRestHighImpl:bulkinsert: api response===" + bResponse.getId() + logger.info(context, "ElasticSearchRestHighImpl:bulkinsert: api response===" + bResponse.getId() + " " + bResponse.getFailureMessage()); } } @@ -502,9 +482,7 @@ public void onFailure(Exception e) { }; ConnectionManager.getRestClient().bulkAsync(request, RequestOptions.DEFAULT, listener); - logger.debug(context, - "ElasticSearchRestHighImpl:bulkInsert: method end ==" - + " for Index " + index + logger.debug(context, "ElasticSearchRestHighImpl:bulkInsert: method end == for Index " + index + " ,Total time elapsed = " + calculateEndTime(startTime)); return promise.future(); } @@ -531,8 +509,7 @@ private static SearchSourceBuilder addAggregations(SearchSourceBuilder searchSou AggregationBuilders.terms(key).field(key + ElasticSearchHelper.RAW_APPEND)); } } - logger.debug(null, - "ElasticSearchRestHighImpl:addAggregations: method end ==" + logger.debug(null, "ElasticSearchRestHighImpl:addAggregations: method end ==" + " ,Total time elapsed = " + calculateEndTime(startTime)); return searchSourceBuilder; } @@ -550,9 +527,8 @@ private static SearchSourceBuilder addAggregations(SearchSourceBuilder searchSou @Override public Future upsert(String index, String identifier, Map data, RequestContext context) { long startTime = System.currentTimeMillis(); - Promise promise = Futures.promise(); - logger.debug(context, - "ElasticSearchRestHighImpl:upsert: method started at ==" + startTime + Promise promise = (Promise) (Promise) Futures.promise(); + logger.debug(context, "ElasticSearchRestHighImpl:upsert: method started at ==" + startTime + " for INdex " + index); if (!StringUtils.isBlank(index) && !StringUtils.isBlank(identifier) @@ -568,13 +544,10 @@ public Future upsert(String index, String identifier, Map