Skip to content

Commit

Permalink
issues #SB-00 fix: adding logs
Browse files Browse the repository at this point in the history
  • Loading branch information
John Doe committed May 4, 2018
2 parents de8e38f + 5f46b74 commit aedface
Show file tree
Hide file tree
Showing 34 changed files with 2,679 additions and 160 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node('build-slave') {

try {
cleanWs()
stage('Checkout'){
stage('Checkout'){
checkout scm
}

Expand All @@ -24,7 +24,7 @@ node('build-slave') {
sh 'ls -al ~/'
sh('chmod 777 ./dockerPushToRepo.sh')
sh 'ARTIFACT_LABEL=bronze ./dockerPushToRepo.sh'
sh './metadata.sh > metadata.json'
sh './metadata.sh > metadata.json'
sh 'cat metadata.json'
archive includes: "metadata.json"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void onReceive(Object message) throws Throwable {
if (message instanceof Request) {
Request request = (Request) message;
String callerName = request.getOperation();
ProjectLogger.log("BaseActor onReceive called for operation : " + callerName);
try {
onReceive(request);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sunbird.actor.core.service;

import org.sunbird.common.request.Request;

/** Created by arvind on 24/4/18. */
public interface InterServiceCommunication {

public Object getResponse(Request request, String operation);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.sunbird.actor.core.service;

import java.util.HashMap;
import java.util.Map;
import org.sunbird.actor.core.service.impl.InterServiceCommunicationImpl;

/** Created by arvind on 24/4/18. */
public class InterServiceCommunicationFactory {

private static InterServiceCommunicationFactory factory;
private static Map<String, InterServiceCommunication> modes = new HashMap<>();

private InterServiceCommunicationFactory() {}

public static InterServiceCommunicationFactory getInstance() {
if (null == factory) {
synchronized (InterServiceCommunicationFactory.class) {
if (null == factory) {
factory = new InterServiceCommunicationFactory();
}
}
}
return factory;
}

public InterServiceCommunication getCommunicationPath(String mode) {
if ("actorCommunication".equalsIgnoreCase(mode)) {
return getActorCommunicationMode();
}
return null;
}

public InterServiceCommunication getActorCommunicationMode() {

if (modes.get("actorCommunication") != null) {
return modes.get("actorCommunication");
} else {
synchronized (InterServiceCommunicationFactory.class) {
if (modes.get("actorCommunication") == null) {
InterServiceCommunication communication = new InterServiceCommunicationImpl();
modes.put("actorCommunication", communication);
}
}
}
return modes.get("actorCommunication");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.sunbird.actor.core.service.impl;

import static akka.pattern.PatternsCS.ask;

import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import akka.util.Timeout;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import org.sunbird.actor.core.service.InterServiceCommunication;
import org.sunbird.actor.router.RequestRouter;
import org.sunbird.actor.service.BaseMWService;
import org.sunbird.common.models.util.LoggerEnum;
import org.sunbird.common.models.util.ProjectLogger;
import org.sunbird.common.request.Request;
import scala.concurrent.duration.Duration;

/** Created by arvind on 24/4/18. */
public class InterServiceCommunicationImpl extends BaseMWService
implements InterServiceCommunication {

private Integer WAIT_TIME = 10;

@Override
public Object getResponse(Request request, String operation) {
ActorRef actor = RequestRouter.getActor(operation);
Timeout t = new Timeout(Duration.create(WAIT_TIME, TimeUnit.SECONDS));
request.setOperation(operation);
Object obj = null;
if (null == actor) {
ActorSelection select = getRemoteRouter(RequestRouter.class.getSimpleName());
CompletionStage<ActorRef> futureActor =
select.resolveOneCS(Duration.create(WAIT_TIME, "seconds"));
try {
actor = futureActor.toCompletableFuture().get();
} catch (Exception e) {
ProjectLogger.log(
"InterServiceCommunicationImpl : getResponse - unable to get actorref from actorselection "
+ e.getMessage(),
e);
}
}
if (null == actor) {
ProjectLogger.log(
"InterServiceCommunicationImpl : getResponse - actorRef is null ", LoggerEnum.INFO);
return obj;
}
ProjectLogger.log(
"Operation " + operation + " with request type " + (request instanceof Request));
CompletableFuture<Object> future = ask(actor, request, t).toCompletableFuture();
try {
obj = future.get(WAIT_TIME + 2, TimeUnit.SECONDS);
} catch (Exception e) {
ProjectLogger.log("Interservice communication error " + e.getMessage(), e);
}
return obj;
}
}
Loading

0 comments on commit aedface

Please sign in to comment.