Skip to content

Issue #SC-1193 read data from registry if es fails - #45

Open
Hari-stackroute wants to merge 10 commits into
project-sunbird:release-2.2.0-primefrom
Hari-stackroute:SC-1193
Open

Issue #SC-1193 read data from registry if es fails#45
Hari-stackroute wants to merge 10 commits into
project-sunbird:release-2.2.0-primefrom
Hari-stackroute:SC-1193

Conversation

@Hari-stackroute

Copy link
Copy Markdown

When read-api fails to fetch data from elastic-search, request is routed to user-registry for the data.

Comment thread user-org-actor/src/main/java/org/sunbird/user/service/UserServiceImpl.java Outdated
*/
public interface UserJsonKey {

String OSID = "osid";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this constant under Jsonkey file as it will be used across the application not only user related file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must not be hardcoded. Remember we have an env var uuidPropertyName.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is configurable property. Now got this value from DbConnectionInfoMngr bean.

Response response = null;
try {
response = userESDao.getUserById((String) request.getRequest().get(JsonKey.USER_ID));
} catch (Exception e) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add logger in catch block to print sacktrace, to know what went wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try {
response = userESDao.getUserById((String) request.getRequest().get(JsonKey.USER_ID));
} catch (Exception e) {
ProjectLogger.log("Exception occurred while reading user ES.", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger parretn need to be same for all places, we are following "className:methodName message,LoggerEum.Value.name"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

response = userESDao.getUserById((String) request.getRequest().get(JsonKey.USER_ID));
} catch (Exception e) {
ProjectLogger.log("Exception occurred while reading user ES.", e);
userService = new UserServiceImpl();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use service factory , no need to create instance every places,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created factory for service object creation.

* @return response
* @throws BaseException
*/
public Response readUser(JsonNode userId) throws BaseException;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why requested userId is JsonNode , it should be String

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method attribute name incorrect, here we constructed json node with valid input to read method, now attribute name changed

public Response readUser(JsonNode inputNode) throws BaseException {
Response response = new Response();
try {
JsonNode responseNode = registryHelper.readEntity(inputNode,"");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use overide method for readEntity with one and two argument .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be at user-registry, i hope here it is not necessary.

response.putAll(objectMapper.convertValue(responseNode,Map.class));
return response;
} catch (Exception e) {
ProjectLogger.log("Exception occurred while reading user from open saber.", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use same logging format

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

+ "Exception in getting the record from ES : "
+ e.getMessage(),
LoggerEnum.ERROR.name());
ProjectLogger.log("Exception occurred while reading user ES.", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ProjectLogger.log("Exception occurred while reading user ES.", e); because we already have logger above.

try {
response = userESDao.getUserById((String) request.getRequest().get(JsonKey.USER_ID));
} catch (Exception e) {
ProjectLogger.log("Exception occurred while reading user ES.", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


public static Object getService(String serviceName) {
Object serviceObj = null;
if(serviceName.equals(ServiceImplType.USER.getServiceType())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO reverse check to avoid NPE.
serviceName.equals(ServiceImplType.USER.getServiceType()) to ServiceImplType.USER.getServiceType().equals(serviceName)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants