Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class ElasticSearchRestHighImpl implements ElasticSearchService {

private static final String ERROR = "ERROR";
private static final LoggerUtil logger = new LoggerUtil(ElasticSearchRestHighImpl.class);
private static final int MAX_ES_RESULT_SIZE = 10000;
private static final int DEFAULT_ES_RESULT_SIZE = 200;


/**
Expand All @@ -75,7 +77,7 @@ public Future<String> save(String index, String identifier, Map<String, Object>
long startTime = System.currentTimeMillis();
Promise<String> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:save: method started at ==" + startTime + " for Index " + index);
logger.debug(requestContext, "ElasticSearchRestHighImpl:save: method started at =={} for Index {}", startTime, index);

if (StringUtils.isBlank(identifier) || StringUtils.isBlank(index)) {
logger.info(requestContext, "ElasticSearchRestHighImpl:save: Identifier or Index value is null or empty, identifier : "
Expand All @@ -92,14 +94,14 @@ public Future<String> save(String index, String identifier, Map<String, Object>
ActionListener<IndexResponse> listener = new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
logger.info(requestContext, "ElasticSearchRestHighImpl:save: Success for index : " + index + ", identifier :" + identifier);
logger.info(requestContext, "ElasticSearchRestHighImpl:save: Success for index : {}, identifier :{}", index, identifier);
promise.success(indexResponse.getId());
logEndTime(startTime, index, requestContext);
}

@Override
public void onFailure(Exception e) {
logger.error(requestContext, "ElasticSearchRestHighImpl:save: Error while saving " + index + " id : " + identifier, e);
logger.error(requestContext, "ElasticSearchRestHighImpl:save: Error while saving {} id : {}", index, identifier, e);
promise.failure(e);
logEndTime(startTime, index, requestContext);
}
Expand Down Expand Up @@ -131,11 +133,11 @@ public Future<Boolean> update(String index, String identifier, Map<String, Objec
long startTime = System.currentTimeMillis();
Promise<Boolean> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:update: method started at ==" + startTime + " for Index " + index);
logger.debug(requestContext, "ElasticSearchRestHighImpl:update: method started at =={} for Index {}", startTime, index);

if (StringUtils.isBlank(index) || StringUtils.isBlank(identifier) || data == null) {
logger.info(requestContext, "ElasticSearchRestHighImpl:update: Invalid parameters - index: " + index
+ ", identifier: " + identifier + ", data: " + (data == null ? "null" : "present"));
logger.info(requestContext, "ElasticSearchRestHighImpl:update: Invalid parameters - index: {}, identifier: {}, data: {}",
index, identifier, (data == null ? "null" : "present"));
promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData));
return promise.future();
}
Expand All @@ -147,8 +149,7 @@ public Future<Boolean> update(String index, String identifier, Map<String, Objec
ActionListener<UpdateResponse> listener = new ActionListener<UpdateResponse>() {
@Override
public void onResponse(UpdateResponse updateResponse) {
logger.info(requestContext, "ElasticSearchRestHighImpl:update: Success with " + updateResponse.getResult()
+ " response from Elasticsearch for index: " + index + ", identifier: " + identifier);
logger.info(requestContext, "ElasticSearchRestHighImpl:update: Success with {} response from Elasticsearch for index: {}, identifier: {}", updateResponse.getResult(), index, identifier);
promise.success(true);
logUpdateEndTime(startTime, index, requestContext);
}
Expand Down Expand Up @@ -187,12 +188,11 @@ public Future<Map<String, Object>> getDataByIdentifier(String index, String iden
long startTime = System.currentTimeMillis();
Promise<Map<String, Object>> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:getDataByIdentifier: method started at ==" + startTime
+ " for Index " + index);
logger.debug(requestContext, "ElasticSearchRestHighImpl:getDataByIdentifier: method started at =={} for Index {}", startTime, index);

if (StringUtils.isBlank(index) || StringUtils.isBlank(identifier)) {
logger.info(requestContext, "ElasticSearchRestHighImpl:getDataByIdentifier: Invalid parameters - index: "
+ index + ", identifier: " + identifier);
logger.info(requestContext, "ElasticSearchRestHighImpl:getDataByIdentifier: Invalid parameters - index: {}, identifier: {}",
index, identifier);
promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData));
return promise.future();
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public Future<Boolean> delete(String index, String identifier, RequestContext re
long startTime = System.currentTimeMillis();
Promise<Boolean> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:delete: method started at ==" + startTime);
logger.debug(requestContext, "ElasticSearchRestHighImpl:delete: method started at =={}", startTime);

if (StringUtils.isBlank(index) || StringUtils.isBlank(identifier)) {
logger.info(requestContext, "ElasticSearchRestHighImpl:delete: Invalid parameters - index: "
Expand Down Expand Up @@ -319,7 +319,7 @@ public Future<Map<String, Object>> search(SearchDTO searchDTO, String index, Req
long startTime = System.currentTimeMillis();
Promise<Map<String, Object>> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:search: method started at ==" + startTime);
logger.debug(requestContext, "ElasticSearchRestHighImpl:search: method started at =={}", startTime);

try {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand Down Expand Up @@ -378,10 +378,10 @@ public Future<Map<String, Object>> search(SearchDTO searchDTO, String index, Req
searchSourceBuilder.from(searchDTO.getOffset());
}

// Set limit
if (searchDTO.getLimit() != null) {
searchSourceBuilder.size(searchDTO.getLimit());
}
// Set limit with bounds checking
int requestedSize = (searchDTO.getLimit() != null && searchDTO.getLimit() > 0)
? searchDTO.getLimit() : DEFAULT_ES_RESULT_SIZE;
searchSourceBuilder.size(Math.min(requestedSize, MAX_ES_RESULT_SIZE));

// Apply additional properties
if (searchDTO.getAdditionalProperties() != null && !searchDTO.getAdditionalProperties().isEmpty()) {
Expand All @@ -405,7 +405,7 @@ public Future<Map<String, Object>> search(SearchDTO searchDTO, String index, Req
searchSourceBuilder = addAggregations(searchSourceBuilder, searchDTO.getFacets(), requestContext);
}

logger.info(requestContext, "ElasticSearchRestHighImpl:search: calling search for index " + index
logger.info(requestContext, "ElasticSearchRestHighImpl:search: calling search for index {}
+ ", with query = " + searchSourceBuilder.toString());

searchRequest.source(searchSourceBuilder);
Expand All @@ -429,7 +429,7 @@ public void onResponse(SearchResponse response) {

@Override
public void onFailure(Exception e) {
logger.error(requestContext, "ElasticSearchRestHighImpl:search: Search failed for index: " + index, e);
logger.error(requestContext, "ElasticSearchRestHighImpl:search: Search failed for index: {}", index, e);
promise.failure(e);
logSearchEndTime(startTime, index, requestContext);
}
Expand All @@ -438,7 +438,7 @@ public void onFailure(Exception e) {
ConnectionManager.getRestClient().searchAsync(searchRequest, RequestOptions.DEFAULT, listener);

} catch (Exception e) {
logger.error(requestContext, "ElasticSearchRestHighImpl:search: Failed to prepare/submit search request for index: " + index, e);
logger.error(requestContext, "ElasticSearchRestHighImpl:search: Failed to prepare/submit search request for index: {}", index, e);
promise.failure(e);
logSearchEndTime(startTime, index, requestContext);
}
Expand All @@ -464,7 +464,7 @@ public Future<Boolean> healthCheck() {
@Override
public void onResponse(Boolean getResponse) {
promise.success(getResponse != null ? getResponse : false);
logger.info("ElasticSearchRestHighImpl:healthCheck: Health check successful, index exists: " + getResponse);
logger.info("ElasticSearchRestHighImpl:healthCheck: Health check successful, index exists: {}", getResponse);
}

@Override
Expand Down Expand Up @@ -497,11 +497,11 @@ public Future<Boolean> bulkInsert(String index, List<Map<String, Object>> dataLi
long startTime = System.currentTimeMillis();
Promise<Boolean> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:bulkInsert: method started at ==" + startTime + " for Index " + index);
logger.debug(requestContext, "ElasticSearchRestHighImpl:bulkInsert: method started at =={} for Index {}", startTime, index);

if (StringUtils.isBlank(index) || dataList == null || dataList.isEmpty()) {
logger.info(requestContext, "ElasticSearchRestHighImpl:bulkInsert: Invalid parameters - index: " + index
+ ", dataList size: " + (dataList == null ? "null" : dataList.size()));
logger.info(requestContext, "ElasticSearchRestHighImpl:bulkInsert: Invalid parameters - index: {}, dataList size: {}",
index, (dataList == null ? "null" : dataList.size()));
promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData));
return promise.future();
}
Expand Down Expand Up @@ -545,7 +545,7 @@ public void onResponse(BulkResponse bulkResponse) {

@Override
public void onFailure(Exception e) {
logger.error(requestContext, "ElasticSearchRestHighImpl:bulkInsert: Bulk upload failed for index: " + index, e);
logger.error(requestContext, "ElasticSearchRestHighImpl:bulkInsert: Bulk upload failed for index: {}", index, e);
promise.success(false);
logBulkInsertEndTime(startTime, index, requestContext);
}
Expand All @@ -554,7 +554,7 @@ public void onFailure(Exception e) {
ConnectionManager.getRestClient().bulkAsync(request, RequestOptions.DEFAULT, listener);

} catch (Exception e) {
logger.error(requestContext, "ElasticSearchRestHighImpl:bulkInsert: Failed to prepare/submit bulk request for index: " + index, e);
logger.error(requestContext, "ElasticSearchRestHighImpl:bulkInsert: Failed to prepare/submit bulk request for index: {}", index, e);
promise.success(false);
logBulkInsertEndTime(startTime, index, requestContext);
}
Expand All @@ -575,7 +575,7 @@ private static SearchSourceBuilder addAggregations(SearchSourceBuilder searchSou
List<Map<String, String>> facets,
RequestContext requestContext) {
long startTime = System.currentTimeMillis();
logger.debug(requestContext, "ElasticSearchRestHighImpl:addAggregations: method started at ==" + startTime);
logger.debug(requestContext, "ElasticSearchRestHighImpl:addAggregations: method started at =={}", startTime);

if (CollectionUtils.isNotEmpty(facets)) {
Map<String, String> map = facets.get(0);
Expand Down Expand Up @@ -614,11 +614,11 @@ public Future<Boolean> upsert(String index, String identifier, Map<String, Objec
long startTime = System.currentTimeMillis();
Promise<Boolean> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:upsert: method started at ==" + startTime + " for Index " + index);
logger.debug(requestContext, "ElasticSearchRestHighImpl:upsert: method started at =={} for Index {}", startTime, index);

if (StringUtils.isBlank(index) || StringUtils.isBlank(identifier) || data == null || data.isEmpty()) {
logger.info(requestContext, "ElasticSearchRestHighImpl:upsert: Invalid parameters - index: " + index
+ ", identifier: " + identifier + ", data: " + (data == null ? "null" : "size=" + data.size()));
logger.info(requestContext, "ElasticSearchRestHighImpl:upsert: Invalid parameters - index: {}, identifier: {}, data: {}",
index, identifier, (data == null ? "null" : "size=" + data.size()));
promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData));
return promise.future();
}
Expand Down Expand Up @@ -672,7 +672,7 @@ public Future<Map<String, Map<String, Object>>> getEsResultByListOfIds(List<Stri
String index, RequestContext requestContext) {
Promise<Map<String, Map<String, Object>>> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: method started for index " + index);
logger.debug(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: method started for index {}", index);

if (ids == null || ids.isEmpty() || StringUtils.isBlank(index)) {
logger.info(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: Invalid parameters - index: " + index
Expand Down Expand Up @@ -704,11 +704,11 @@ public Future<Map<String, Map<String, Object>>> getEsResultByListOfIds(List<Stri
+ resultMap.size() + " documents for index " + index);
} else {
promise.success(new HashMap<>());
logger.info(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: No documents found for index " + index);
logger.info(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: No documents found for index {}", index);
}

} catch (Exception e) {
logger.error(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: Failed to retrieve documents for index: " + index, e);
logger.error(requestContext, "ElasticSearchRestHighImpl:getEsResultByListOfIds: Failed to retrieve documents for index: {}", index, e);
promise.success(new HashMap<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sunbird.actorutil.InterServiceCommunication;
import org.sunbird.actorutil.InterServiceCommunicationFactory;
import org.sunbird.actorutil.systemsettings.SystemSettingClient;
import org.sunbird.exception.ProjectCommonException;
import org.sunbird.response.Response;
import org.sunbird.operations.lms.ActorOperations;
import org.sunbird.keys.JsonKey;
import org.sunbird.logging.LoggerEnum;
import org.sunbird.logging.ProjectLogger;
import org.sunbird.request.Request;
import org.sunbird.response.ResponseCode;
import org.sunbird.models.systemsetting.SystemSetting;

public class SystemSettingClientImpl implements SystemSettingClient {
private static final Logger logger = LoggerFactory.getLogger(SystemSettingClientImpl.class);

private static InterServiceCommunication interServiceCommunication =
InterServiceCommunicationFactory.getInstance();
Expand All @@ -33,7 +34,7 @@ public static SystemSettingClient getInstance() {

@Override
public SystemSetting getSystemSettingByField(ActorRef actorRef, String field) {
ProjectLogger.log("SystemSettingClientImpl:getSystemSettingByField: field is " + field, LoggerEnum.INFO.name());
logger.info("SystemSettingClientImpl:getSystemSettingByField: field is {}", field);
SystemSetting systemSetting = getSystemSetting(actorRef, JsonKey.FIELD, field);
return systemSetting;
}
Expand All @@ -53,17 +54,15 @@ public <T> T getSystemSettingByFieldAndKey(
}
return (T)objectMapper.convertValue(valueMap.get(keys[numKeys - 1]), typeReference);
} catch (Exception e) {
ProjectLogger.log(
"SystemSettingClientImpl:getSystemSettingByFieldAndKey: Exception occurred with error message = "
+ e.getMessage(),
LoggerEnum.ERROR.name());
logger.error("SystemSettingClientImpl:getSystemSettingByFieldAndKey: Exception occurred with error message = {}",
e.getMessage(), e);
}
}
return null;
}

private SystemSetting getSystemSetting(ActorRef actorRef, String param, Object value) {
ProjectLogger.log("SystemSettingClientImpl: getSystemSetting called", LoggerEnum.DEBUG);
logger.debug("SystemSettingClientImpl: getSystemSetting called");
Request request = new Request();
Map<String, Object> map = new HashMap<>();
map.put(param, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.sunbird.common.factory.EsClientFactory;
import org.sunbird.common.inf.ElasticSearchService;
import org.sunbird.response.Response;
import org.sunbird.logging.ProjectLogger;
import org.sunbird.logging.LoggerEnum;
import org.sunbird.keys.JsonKey;
import org.sunbird.common.ProjectUtil;
import org.sunbird.operations.lms.ActorOperations;
import org.sunbird.request.Request;
import org.sunbird.response.ResponseCode;
import org.sunbird.dto.SearchDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.Future;

import java.text.MessageFormat;
Expand All @@ -28,18 +28,19 @@

public class UserClientImpl implements UserClient {

private static final Logger logger = LoggerFactory.getLogger(UserClientImpl.class);
private static InterServiceCommunication interServiceCommunication = InterServiceCommunicationFactory.getInstance();
private ElasticSearchService esUtil = EsClientFactory.getInstance();

@Override
public String createUser(ActorRef actorRef, Map<String, Object> userMap) {
ProjectLogger.log("UserClientImpl: createUser called", LoggerEnum.INFO);
logger.info("UserClientImpl: createUser called");
return upsertUser(actorRef, userMap, ActorOperations.CREATE_USER.getValue());
}

@Override
public void updateUser(ActorRef actorRef, Map<String, Object> userMap) {
ProjectLogger.log("UserClientImpl: updateUser called", LoggerEnum.INFO);
logger.info("UserClientImpl: updateUser called");
upsertUser(actorRef, userMap, ActorOperations.UPDATE_USER.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.sunbird.keys.JsonKey;
import org.sunbird.logging.LoggerEnum;
import org.sunbird.logging.LoggerUtil;
import org.sunbird.logging.ProjectLogger;
import org.sunbird.request.Request;
import org.sunbird.response.ResponseCode;

Expand All @@ -17,8 +16,8 @@ public class CacheManagementActor extends BaseActor {

@Override
public void onReceive(Request request) throws Throwable {
System.out.println(
"Actor dispatcher parent=>" + getContext().getParent().path() + ", self=>" + self().path());
logger.debug(request.getRequestContext(), "Actor dispatcher parent=>{}, self=>{}",
getContext().getParent().path(), self().path());
if (request.getOperation().equalsIgnoreCase(ActorOperations.CLEAR_CACHE.getValue())) {
clearCache(request);
} else {
Expand All @@ -28,7 +27,7 @@ public void onReceive(Request request) throws Throwable {

private void clearCache(Request request) {
String mapName = (String) request.getContext().get(JsonKey.MAP_NAME);
logger.info(request.getRequestContext(), "CacheManagementActor:clearCache: mapName = " + mapName);
logger.info(request.getRequestContext(), "CacheManagementActor:clearCache: mapName = {}", mapName);
try {
if (!JsonKey.ALL.equals(mapName)) {
cache.clear(mapName);
Expand All @@ -41,8 +40,8 @@ private void clearCache(Request request) {

sender().tell(response, self());
} catch (Exception e) {
logger.error(request.getRequestContext(), "CacheManagementActor:clearCache: Error occurred for mapName = "
+ mapName + " error = " + e.getMessage(), e);
logger.error(request.getRequestContext(), "CacheManagementActor:clearCache: Error occurred for mapName = {} error = {}",
mapName, e.getMessage(), e);
sender().tell(e, self());
}
}
Expand Down
Loading