From 1e3b3512041edd2ffc07cd6407ef747ee982974c Mon Sep 17 00:00:00 2001
From: Aishwarya <42641684+aishwa8141@users.noreply.github.com>
Date: Tue, 6 Oct 2020 13:41:23 +0530
Subject: [PATCH 01/39] SC-2049: upgrade Play Framework to 2.7.2 (#63)
* SC-2049: upgrade Play Framework to 2.7.2
* SC-2049: Using Play-Guice module for initialising and injecting the AKKA actors
* SC-2049: Using Play-Guice module for initialising and injecting the AKKA actors
* SC-2049 : exclude netty dependency from cassandra-unit
---
all-actors/pom.xml | 10 +-
.../main/java/org/sunbird/Application.java | 102 -------------
.../sunbird/actor/CertBackgroundActor.java | 9 --
.../org/sunbird/actor/CertificationActor.java | 19 ++-
.../org/sunbird/service/ICertService.java | 5 +-
.../sunbird/serviceimpl/CertsServiceImpl.java | 19 +--
.../sunbird/utilities/CertificateUtil.java | 13 +-
.../src/main/resources/application.conf | 129 -----------------
.../sunbird/actor/CertificationActorTest.java | 2 +-
cassandra-utils/pom.xml | 12 ++
pom.xml | 8 +-
sb-actor/pom.xml | 33 -----
.../org/sunbird/actor/core/ActorCache.java | 35 -----
.../org/sunbird/actor/core/ActorConfig.java | 23 ---
.../org/sunbird/actor/core/ActorService.java | 114 ---------------
sb-es-utils/pom.xml | 2 +-
service/app/controllers/BaseController.java | 9 +-
.../controllers/CertificateController.java | 41 ++++--
service/app/controllers/RequestHandler.java | 12 +-
.../controllers/health/HealthController.java | 18 +--
service/app/utils/ApplicationStart.java | 82 +++++++++--
service/app/utils/module/ACTOR_NAMES.java | 26 ++++
.../app/utils/module/ActorStartModule.java | 24 +++
service/conf/application.conf | 137 +++++++++++++++---
service/conf/routes | 20 +--
service/pom.xml | 26 +++-
.../test/controllers/BaseApplicationTest.java | 80 +++-------
.../test/controllers/BaseControllerTest.java | 45 ------
.../CertificateControllerTest.java | 7 +-
service/test/controllers/TestHelper.java | 13 +-
.../health/HealthControllerTest.java | 42 ++----
31 files changed, 405 insertions(+), 712 deletions(-)
delete mode 100644 all-actors/src/main/java/org/sunbird/Application.java
delete mode 100644 all-actors/src/main/resources/application.conf
delete mode 100644 sb-actor/pom.xml
delete mode 100644 sb-actor/src/main/java/org/sunbird/actor/core/ActorCache.java
delete mode 100644 sb-actor/src/main/java/org/sunbird/actor/core/ActorConfig.java
delete mode 100644 sb-actor/src/main/java/org/sunbird/actor/core/ActorService.java
create mode 100644 service/app/utils/module/ACTOR_NAMES.java
create mode 100644 service/app/utils/module/ActorStartModule.java
delete mode 100644 service/test/controllers/BaseControllerTest.java
diff --git a/all-actors/pom.xml b/all-actors/pom.xml
index 14a7b80..d7b41f9 100644
--- a/all-actors/pom.xml
+++ b/all-actors/pom.xml
@@ -11,9 +11,9 @@
1.0.0
- org.sunbird
- sb-actor
- 1.0.0
+ com.typesafe.akka
+ akka-actor_${scala.major.version}
+ ${akka.x.version}
org.sunbird
@@ -44,8 +44,8 @@
com.typesafe.akka
- akka-testkit_2.12
- 2.6.0-M5
+ akka-testkit_${scala.major.version}
+ 2.5.22
test
diff --git a/all-actors/src/main/java/org/sunbird/Application.java b/all-actors/src/main/java/org/sunbird/Application.java
deleted file mode 100644
index 593a298..0000000
--- a/all-actors/src/main/java/org/sunbird/Application.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package org.sunbird;
-
-import akka.actor.ActorRef;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sunbird.actor.core.ActorCache;
-import org.sunbird.actor.core.ActorService;
-import org.sunbird.helper.CassandraConnectionManager;
-import org.sunbird.helper.CassandraConnectionMngrFactory;
-import org.sunbird.message.IResponseMessage;
-import org.sunbird.message.Localizer;
-import org.sunbird.message.ResponseCode;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * this class is used to instantiate the actor system and open saber.
- * @author Amit Kumar
- */
-public class Application {
- private final static String actorSystemName = "certActorSystem";
- private static Application instance = new Application();
- private static Localizer localizer = Localizer.getInstance();
- private static Logger logger = LoggerFactory.getLogger(Application.class);
-
-
- // private constructor restricted to this class itself
- private Application() {
- }
-
- // static method to create instance of ActorService class
- public static Application getInstance() {
- return instance;
- }
-
- // instantiate actor system and actors
- public void init() throws BaseException {
- List actorClassPaths = new ArrayList<>();
- actorClassPaths.add("org.sunbird");
- ActorService.getInstance().init(actorSystemName, actorClassPaths);
- createCassandraConnection(JsonKeys.SUNBIRD);
- }
-
-
- /**
- * this method is used to get the reference of actor from in memory cache.
- * @param operation
- * @return
- */
- public ActorRef getActorRef(String operation) {
- return ActorCache.getActorRef(operation);
- }
-
- /**
- * This method will read the configuration from System variable.
- *
- * @return boolean
- */
- public static boolean createCassandraConnection(String keyspace) throws BaseException {
- boolean response = false;
- String ips = System.getenv(JsonKeys.SUNBIRD_CASSANDRA_IP);
- String envPort = System.getenv(JsonKeys.SUNBIRD_CASSANDRA_PORT);
- CassandraConnectionManager cassandraConnectionManager =
- CassandraConnectionMngrFactory.getObject(JsonKeys.STANDALONE_MODE);
-
- if (StringUtils.isBlank(ips) || StringUtils.isBlank(envPort)) {
- logger.info("Configuration value is not coming form System variable.");
- return false;
- }
- String[] portList = envPort.split(",");
- String userName = System.getenv(JsonKeys.SUNBIRD_CASSANDRA_USER_NAME);
- String password = System.getenv(JsonKeys.SUNBIRD_CASSANDRA_PASSWORD);
- try {
- boolean result =
- cassandraConnectionManager.createConnection(ips, portList[0], userName, password, keyspace);
- if (result) {
- response = true;
- logger.info(
- "CONNECTION CREATED SUCCESSFULLY FOR IP's: " + ips + " : KEYSPACE :" + keyspace);
- } else {
- logger.info(
- "CONNECTION CREATION FAILED FOR IP: " + ips + " : KEYSPACE :" + keyspace);
- }
- } catch (BaseException ex) {
- logger.error("Application:createCassandraConnection: Exception occurred with message = " + ex.getMessage());
- }
- if (!response) {
- throw new BaseException(
- IResponseMessage.INVALID_CONFIGURATION,
- getLocalizedMessage(IResponseMessage.INVALID_CONFIGURATION,null),
- ResponseCode.SERVER_ERROR.hashCode());
- }
- return response;
- }
-
- private static String getLocalizedMessage(String key, Locale locale){
- return localizer.getMessage(key, locale);
- }
-}
diff --git a/all-actors/src/main/java/org/sunbird/actor/CertBackgroundActor.java b/all-actors/src/main/java/org/sunbird/actor/CertBackgroundActor.java
index 6ff4335..88f44a2 100644
--- a/all-actors/src/main/java/org/sunbird/actor/CertBackgroundActor.java
+++ b/all-actors/src/main/java/org/sunbird/actor/CertBackgroundActor.java
@@ -2,24 +2,15 @@
import org.sunbird.BaseActor;
import org.sunbird.BaseException;
-import org.sunbird.BaseLogger;
import org.sunbird.JsonKeys;
-import org.sunbird.actor.core.ActorConfig;
import org.sunbird.cassandra.CassandraOperation;
import org.sunbird.common.ElasticSearchHelper;
import org.sunbird.common.factory.EsClientFactory;
import org.sunbird.common.inf.ElasticSearchService;
import org.sunbird.helper.ServiceFactory;
import org.sunbird.request.Request;
-
-import java.util.HashMap;
import java.util.Map;
-@ActorConfig(
- tasks = {"add_cert_es","delete_cert_cassandra"},
- dispatcher = "",
- asyncTasks = {}
-)
public class CertBackgroundActor extends BaseActor {
private ElasticSearchService elasticSearchService = getESService();
private CassandraOperation cassandraOperation = getCassandraOperation();
diff --git a/all-actors/src/main/java/org/sunbird/actor/CertificationActor.java b/all-actors/src/main/java/org/sunbird/actor/CertificationActor.java
index a541a70..536e9c6 100644
--- a/all-actors/src/main/java/org/sunbird/actor/CertificationActor.java
+++ b/all-actors/src/main/java/org/sunbird/actor/CertificationActor.java
@@ -1,26 +1,25 @@
package org.sunbird.actor;
+import akka.actor.ActorRef;
import org.sunbird.BaseActor;
import org.sunbird.BaseException;
-import org.sunbird.BaseLogger;
import org.sunbird.JsonKeys;
-import org.sunbird.actor.core.ActorConfig;
import org.sunbird.request.Request;
import org.sunbird.response.Response;
import org.sunbird.service.ICertService;
import org.sunbird.serviceimpl.CertsServiceImpl;
-import java.util.HashMap;
-import java.util.Map;
+import javax.inject.Inject;
+import javax.inject.Named;
-@ActorConfig(
- tasks = {"add","validate","download","generate","verify","search","read", "addV2", "downloadV2"},
- dispatcher = "",
- asyncTasks = {}
-)
public class CertificationActor extends BaseActor {
private ICertService certService = getCertServiceImpl();
+ @Inject
+ @Named("certificate_background_actor")
+ private ActorRef certBackgroundActorRef;
+
+
private ICertService getCertServiceImpl(){
return new CertsServiceImpl();
}
@@ -63,7 +62,7 @@ public void onReceive(Request request) throws BaseException {
}
private void add(Request request) throws BaseException {
- String id = certService.add(request);
+ String id = certService.add(request, certBackgroundActorRef);
Response response = new Response();
response.put(JsonKeys.ID, id);
sender().tell(response, self());
diff --git a/all-actors/src/main/java/org/sunbird/service/ICertService.java b/all-actors/src/main/java/org/sunbird/service/ICertService.java
index 6b0abd6..f39a9aa 100644
--- a/all-actors/src/main/java/org/sunbird/service/ICertService.java
+++ b/all-actors/src/main/java/org/sunbird/service/ICertService.java
@@ -1,6 +1,7 @@
package org.sunbird.service;
+import akka.actor.ActorRef;
import org.sunbird.BaseException;
import org.sunbird.request.Request;
import org.sunbird.response.Response;
@@ -12,9 +13,9 @@
*/
public interface ICertService{
- Response delete(Request request) throws BaseException;
+ Response delete(Request request, ActorRef certBackgroundActorRef) throws BaseException;
- String add(Request request) throws BaseException;
+ String add(Request request, ActorRef certBackgroundActorRef) throws BaseException;
Response validate(Request request) throws BaseException;
diff --git a/all-actors/src/main/java/org/sunbird/serviceimpl/CertsServiceImpl.java b/all-actors/src/main/java/org/sunbird/serviceimpl/CertsServiceImpl.java
index 8e20b17..094b605 100644
--- a/all-actors/src/main/java/org/sunbird/serviceimpl/CertsServiceImpl.java
+++ b/all-actors/src/main/java/org/sunbird/serviceimpl/CertsServiceImpl.java
@@ -1,5 +1,6 @@
package org.sunbird.serviceimpl;
+import akka.actor.ActorRef;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashape.unirest.http.HttpResponse;
@@ -50,11 +51,11 @@ public class CertsServiceImpl implements ICertService {
}
@Override
- public Response delete(Request request) throws BaseException {
+ public Response delete(Request request, ActorRef certBackgroundActorRef) throws BaseException {
Map certAddReqMap = request.getRequest();
Response response = new Response();
if(StringUtils.isNotBlank((String)certAddReqMap.get(JsonKeys.OLD_ID))){
- boolean bool = CertificateUtil.deleteRecord((String)certAddReqMap.get(JsonKeys.OLD_ID));
+ boolean bool = CertificateUtil.deleteRecord((String)certAddReqMap.get(JsonKeys.OLD_ID), certBackgroundActorRef);
response.getResult().put(JsonKeys.RESPONSE,bool);
logger.info("CertsServiceImpl:delete Deleted the record from cert_registry table for id "+certAddReqMap.get(JsonKeys.OLD_ID));
}
@@ -62,21 +63,21 @@ public Response delete(Request request) throws BaseException {
}
@Override
- public String add(Request request) throws BaseException {
+ public String add(Request request, ActorRef certBackgroundActorRef) throws BaseException {
Map reqMap = request.getRequest();
if(isPresentRecipientIdAndCertId(request)){
validateCertAndRecipientId(reqMap);
- deleteOldCertificate((String) reqMap.get(JsonKeys.OLD_ID));
+ deleteOldCertificate((String) reqMap.get(JsonKeys.OLD_ID),certBackgroundActorRef);
}
Map certAddReqMap = request.getRequest();
assureUniqueCertId((String) certAddReqMap.get(JsonKeys.ID));
- processRecord(certAddReqMap,(String) request.getContext().get(JsonKeys.VERSION));
+ processRecord(certAddReqMap,(String) request.getContext().get(JsonKeys.VERSION), certBackgroundActorRef);
logger.info("CertsServiceImpl:add:record successfully processed with request:"+certAddReqMap.get(JsonKeys.ID));
return (String)certAddReqMap.get(JsonKeys.ID);
}
- private void deleteOldCertificate(String oldCertId) throws BaseException {
- CertificateUtil.deleteRecord(oldCertId);
+ private void deleteOldCertificate(String oldCertId, ActorRef certBackgroundActorRef) throws BaseException {
+ CertificateUtil.deleteRecord(oldCertId, certBackgroundActorRef);
}
private void validateCertAndRecipientId(Map reqMap) throws BaseException {
@@ -117,13 +118,13 @@ private void assureUniqueCertId(String certificatedId) throws BaseException {
}
- private Response processRecord(Map certReqAddMap, String version) throws BaseException {
+ private Response processRecord(Map certReqAddMap, String version, ActorRef certBackgroundActorRef) throws BaseException {
Certificate certificate=getCertificate(certReqAddMap);
if(version.equalsIgnoreCase(JsonKeys.VERSION_1)) {
certificate.setPdfUrl((String)certReqAddMap.get(JsonKeys.PDF_URL));
}
MaprecordMap= requestMapper.convertValue(certificate,Map.class);
- return CertificateUtil.insertRecord(recordMap);
+ return CertificateUtil.insertRecord(recordMap, certBackgroundActorRef);
}
private Certificate getCertificate(Map certReqAddMap) {
Certificate certificate = new Certificate.Builder()
diff --git a/all-actors/src/main/java/org/sunbird/utilities/CertificateUtil.java b/all-actors/src/main/java/org/sunbird/utilities/CertificateUtil.java
index 0d97959..d88d292 100644
--- a/all-actors/src/main/java/org/sunbird/utilities/CertificateUtil.java
+++ b/all-actors/src/main/java/org/sunbird/utilities/CertificateUtil.java
@@ -10,7 +10,6 @@
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.sunbird.ActorOperations;
-import org.sunbird.Application;
import org.sunbird.BaseException;
import org.sunbird.JsonKeys;
import org.sunbird.cassandra.CassandraOperation;
@@ -26,7 +25,9 @@
import org.sunbird.response.Response;
import java.sql.Timestamp;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
import java.util.concurrent.Future;
@@ -60,7 +61,7 @@ public static Response getCertRecordByID(String id) throws BaseException {
return cassandraOperation.getRecordById(JsonKeys.SUNBIRD,JsonKeys.CERT_REGISTRY,id);
}
- public static Boolean deleteRecord(String id) throws BaseException {
+ public static Boolean deleteRecord(String id, ActorRef certBackgroundActorRef) throws BaseException {
Boolean bool = (Boolean)ElasticSearchHelper.getResponseFromFuture(elasticSearchService.delete(JsonKeys.CERT_ALIAS,id));
logger.info("Data deleted from ES for id "+id);
//Delete the data from cassandra
@@ -70,11 +71,11 @@ public static Boolean deleteRecord(String id) throws BaseException {
RequestParams params = new RequestParams();
params.setMsgid(MDC.get(JsonKeys.REQUEST_MESSAGE_ID));
req.setParams(params);
- Application.getInstance().getActorRef(ActorOperations.DELETE_CERT_CASSANDRA.getOperation()).tell(req, ActorRef.noSender());
+ certBackgroundActorRef.tell(req, ActorRef.noSender());
return bool;
}
- public static Response insertRecord(MapcertAddReqMap) throws BaseException {
+ public static Response insertRecord(MapcertAddReqMap, ActorRef certBackgroundActorRef) throws BaseException {
MapcertMap = new HashMap<>();
long createdAt = System.currentTimeMillis();
certAddReqMap.put(JsonKeys.CREATED_AT,createdAt);
@@ -106,7 +107,7 @@ public static Response insertRecord(MapcertAddReqMap) throws Base
req.setParams(params);
req.setOperation(ActorOperations.ADD_CERT_ES.getOperation());
req.getRequest().put(JsonKeys.REQUEST,certAddReqMap);
- Application.getInstance().getActorRef(ActorOperations.ADD_CERT_ES.getOperation()).tell(req, ActorRef.noSender());
+ certBackgroundActorRef.tell(req, ActorRef.noSender());
return response;
}
diff --git a/all-actors/src/main/resources/application.conf b/all-actors/src/main/resources/application.conf
deleted file mode 100644
index 3b6fcd0..0000000
--- a/all-actors/src/main/resources/application.conf
+++ /dev/null
@@ -1,129 +0,0 @@
-certActorSystem {
- default-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 8
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
- router-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 8
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
- supervisor-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 8
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
- user-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 8
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
- search-read-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 12
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
- org-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 8
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
-
- akka {
-
- loggers = ["akka.event.slf4j.Slf4jLogger"]
- loglevel = "INFO"
- stdout-loglevel = "DEBUG"
- logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
-
-
- actor {
- akka.actor.allow-java-serialization = off
- debug {
- # enable DEBUG logging of all AutoReceiveMessages (Kill, PoisonPill etc.)
- autoreceive = on
- # enable DEBUG logging of actor lifecycle changes
- lifecycle = on
- # enable DEBUG logging of unhandled messages
- unhandled = on
- # enable DEBUG logging of all LoggingFSMs for events, transitions and timers
- fsm = on
- # enable DEBUG logging of subscription changes on the eventStream
- event-stream = on
- }
-
- default-dispatcher {
- type = "Dispatcher"
- executor = "fork-join-executor"
- fork-join-executor {
- parallelism-min = 8
- parallelism-factor = 32.0
- parallelism-max = 64
- }
- # Throughput for default Dispatcher, set to 1 for as fair as possible
- throughput = 1
- }
- deployment {
- /CertificationActor
- {
- router = smallest-mailbox-pool
- nr-of-instances = 5
- dispatcher = user-dispatcher
- }
- /CertBackgroundActor
- {
- router = smallest-mailbox-pool
- nr-of-instances = 5
- dispatcher = user-dispatcher
- }
- }
- }
- remote {
- maximum-payload-bytes = 30000000 bytes
- netty.tcp {
- port = 8088
- message-frame-size = 30000000b
- send-buffer-size = 30000000b
- receive-buffer-size = 30000000b
- maximum-frame-size = 30000000b
- }
- }
- }
-}
diff --git a/all-actors/src/test/java/org/sunbird/actor/CertificationActorTest.java b/all-actors/src/test/java/org/sunbird/actor/CertificationActorTest.java
index c78a060..4f3c741 100644
--- a/all-actors/src/test/java/org/sunbird/actor/CertificationActorTest.java
+++ b/all-actors/src/test/java/org/sunbird/actor/CertificationActorTest.java
@@ -90,7 +90,7 @@ public void beforeTestSetUp() throws Exception {
when(CertificateUtil.isIdPresent(Mockito.anyString())).thenReturn(false);
CertsServiceImpl certsService = PowerMockito.mock(CertsServiceImpl.class);
PowerMockito.whenNew(CertsServiceImpl.class).withNoArguments().thenReturn(certsService);
- when(certsService.add(Mockito.any(Request.class))).thenReturn("id");
+ when(certsService.add(Mockito.any(Request.class), Mockito.any(ActorRef.class))).thenReturn("id");
when(certsService.validate(Mockito.any(Request.class))).thenReturn(getValidateCertResponse());
Map map = new HashMap<>();
diff --git a/cassandra-utils/pom.xml b/cassandra-utils/pom.xml
index f0193f4..5180a06 100644
--- a/cassandra-utils/pom.xml
+++ b/cassandra-utils/pom.xml
@@ -20,6 +20,12 @@
org.cassandraunit
cassandra-unit
3.11.2.0
+
+
+ io.netty
+ *
+
+
com.datastax.cassandra
@@ -39,6 +45,12 @@
com.datastax.cassandra
cassandra-driver-mapping
${cassandra.driver.version}
+
+
+ com.datastax.cassandra
+ cassandra-driver-core
+
+
com.fasterxml.jackson.core
diff --git a/pom.xml b/pom.xml
index 12fd31d..bd532ef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
1.8
1.8
2.9.10
- 2.6.0-M2
+ 2.5.22
4.12
2.3.1
@@ -24,8 +24,9 @@
1.0.7
UTF-8
- 2.6.5
- 2.12.8
+ 2.7.2
+ 2.11.8
+ 2.11
1.6.5
4.5.1
@@ -35,7 +36,6 @@
cassandra-utils
sb-es-utils
all-actors
- sb-actor
service
diff --git a/sb-actor/pom.xml b/sb-actor/pom.xml
deleted file mode 100644
index 0502b37..0000000
--- a/sb-actor/pom.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
- certification-service
- org.sunbird
- 1.2.0
-
- 4.0.0
-
- sb-actor
- 1.0.0
-
-
- com.typesafe.akka
- akka-actor_2.12
- ${akka.x.version}
-
-
- org.reflections
- reflections
- 0.9.10
-
-
- org.apache.commons
- commons-lang3
- 3.9
-
-
-
-
-
diff --git a/sb-actor/src/main/java/org/sunbird/actor/core/ActorCache.java b/sb-actor/src/main/java/org/sunbird/actor/core/ActorCache.java
deleted file mode 100644
index 7b733e9..0000000
--- a/sb-actor/src/main/java/org/sunbird/actor/core/ActorCache.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.sunbird.actor.core;
-
-import akka.actor.ActorRef;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * This class will maintain the cache of actor reference.
- * NOTE:: Today does not handle remote actor references
- * @author Amit Kumar
- */
-public class ActorCache {
-
- private ActorCache(){}
-
- private static Map actorRefCache = new HashMap<>();
-
- /**
- * This method will return the map of actor operation and actor reference.
- * @return Map of string and actor reference
- */
- public static Map getActorCache() {
- return actorRefCache;
- }
-
- /**
- * This method will return the actor reference based on actor operation
- * @param actorOperation operation performed by actor
- * @return ActorRef actor reference
- */
- public static ActorRef getActorRef(String actorOperation){
- return actorRefCache.get(actorOperation);
- }
-}
diff --git a/sb-actor/src/main/java/org/sunbird/actor/core/ActorConfig.java b/sb-actor/src/main/java/org/sunbird/actor/core/ActorConfig.java
deleted file mode 100644
index 5ec3f15..0000000
--- a/sb-actor/src/main/java/org/sunbird/actor/core/ActorConfig.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.sunbird.actor.core;
-
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * @author Amit Kumar
- */
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Inherited
-public @interface ActorConfig {
- String[] tasks();
-
- String[] asyncTasks();
-
- String dispatcher() default "";
-}
diff --git a/sb-actor/src/main/java/org/sunbird/actor/core/ActorService.java b/sb-actor/src/main/java/org/sunbird/actor/core/ActorService.java
deleted file mode 100644
index cb9e1b3..0000000
--- a/sb-actor/src/main/java/org/sunbird/actor/core/ActorService.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.sunbird.actor.core;
-
-import akka.actor.ActorRef;
-import akka.actor.ActorSystem;
-import akka.actor.Props;
-import akka.routing.FromConfig;
-import com.typesafe.config.Config;
-import com.typesafe.config.ConfigFactory;
-import org.apache.commons.lang3.StringUtils;
-import org.reflections.Reflections;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * This class contains method to instantiate actor system and actors.
- * @author Amit Kumar
- */
-public class ActorService {
-
- private static ActorSystem system;
- private static Config config =
- ConfigFactory.systemEnvironment().withFallback(ConfigFactory.load());
- private static Map actorRefCache = ActorCache.getActorCache();
-
- // static variable instance of type ActorService
- private static ActorService instance = null;
-
- // private constructor restricted to this class itself
- private ActorService() { }
-
- // static method to create instance of ActorService class
- public static ActorService getInstance()
- {
- if (instance == null)
- instance = new ActorService();
-
- return instance;
- }
-
- // instantiate actor system and actors
- public void init(String actorSystemName, List actorsClassPathList) {
-
- getActorSystem(actorSystemName);
- initActors(actorsClassPathList);
-
- }
-
- /**
- * This method will instantiate actor system
- * @return actor system
- */
- private ActorSystem getActorSystem(String actorSystemName) {
-
- if (null == system) {
- Config conf = config.getConfig(actorSystemName);
- system = ActorSystem.create(actorSystemName, conf);
- }
-
- return system;
-
- }
-
- /**
- * initialize the actors
- */
- private void initActors(List actorsClassPathList) {
- Set> actors = getActors(actorsClassPathList);
- for (Class> actor : actors) {
- ActorConfig routerDetails = actor.getAnnotation(ActorConfig.class);
- if (null != routerDetails) {
- String[] operations = routerDetails.tasks();
- String dispatcher = (StringUtils.isNotBlank(routerDetails.dispatcher())) ? routerDetails.dispatcher() : "default-dispatcher";
- createActor(actor,operations, dispatcher);
- }
- }
- }
-
-
- private Set> getActors(List actorsClassPathList) {
- synchronized (ActorService.class) {
- Reflections reflections = null;
- Set> actors = new HashSet<>();
- for(String classpath : actorsClassPathList){
- reflections = new Reflections(classpath);
- actors.addAll(reflections.getTypesAnnotatedWith(ActorConfig.class));
- }
- return actors;
- }
- }
-
-
- private void createActor(Class actor,
- String[] operations,
- String dispatcher) {
-
- if (null != operations && operations.length > 0) {
- Props props;
- if (StringUtils.isNotBlank(dispatcher)) {
- props = Props.create(actor).withDispatcher(dispatcher);
- } else {
- props = Props.create(actor);
- }
- ActorRef actorRef =
- system.actorOf(FromConfig.getInstance().props(props), actor.getSimpleName());
- for (String operation : operations) {
- actorRefCache.put(operation, actorRef);
- }
- }
- }
-
-}
diff --git a/sb-es-utils/pom.xml b/sb-es-utils/pom.xml
index 1a21a81..d02a911 100755
--- a/sb-es-utils/pom.xml
+++ b/sb-es-utils/pom.xml
@@ -53,7 +53,7 @@
com.typesafe.akka
- akka-actor_2.12
+ akka-actor_${scala.major.version}
${akka.x.version}
compile
diff --git a/service/app/controllers/BaseController.java b/service/app/controllers/BaseController.java
index 6baceb7..77f8305 100644
--- a/service/app/controllers/BaseController.java
+++ b/service/app/controllers/BaseController.java
@@ -10,7 +10,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sunbird.Application;
import org.sunbird.BaseException;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.Localizer;
@@ -83,10 +82,6 @@ public void endTrace(String tag) {
logger.info("Method call ended.");
}
- protected ActorRef getActorRef(String operation) throws BaseException {
- return Application.getInstance().getActorRef(operation);
- }
-
/**
* this method will take play.mv.http request and a validation function and
* lastly operation(Actor operation) this method is validating the request and ,
@@ -99,7 +94,7 @@ protected ActorRef getActorRef(String operation) throws BaseException {
* @param operation
* @return
*/
- public CompletionStage handleRequest(play.mvc.Http.Request req, RequestValidatorFunction validatorFunction,
+ public CompletionStage handleRequest(ActorRef actorRef, play.mvc.Http.Request req, RequestValidatorFunction validatorFunction,
String operation) {
try {
Request request = new Request();
@@ -109,7 +104,7 @@ public CompletionStage handleRequest(play.mvc.Http.Request req, RequestV
if (validatorFunction != null) {
validatorFunction.apply(request);
}
- return new RequestHandler().handleRequest(request, operation,req);
+ return new RequestHandler().handleRequest(request, actorRef, operation, req);
} catch (Exception ex) {
return CompletableFuture.supplyAsync(() -> {
return RequestHandler.handleFailureResponse(ex,req);
diff --git a/service/app/controllers/CertificateController.java b/service/app/controllers/CertificateController.java
index 22b172e..d644d76 100644
--- a/service/app/controllers/CertificateController.java
+++ b/service/app/controllers/CertificateController.java
@@ -1,10 +1,14 @@
package controllers;
+import akka.actor.ActorRef;
import org.sunbird.JsonKeys;
import org.sunbird.request.Request;
+import play.mvc.Http;
import play.mvc.Result;
import validators.*;
+import javax.inject.Inject;
+import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletionStage;
@@ -15,14 +19,19 @@
*/
public class CertificateController extends BaseController {
+
+ @Inject
+ @Named("certification_actor")
+ private ActorRef certificationActorRef;
+
/**
* this action method will be called for adding certificate
* @return CompletionStage of Result
*/
- public CompletionStage add()
+ public CompletionStage add(Http.Request httpRequest)
{
IRequestValidator requestValidator=new CertAddRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
Map context = new HashMap<>();
@@ -37,10 +46,10 @@ public CompletionStage add()
* this action method will be called for adding certificate
* @return CompletionStage of Result
*/
- public CompletionStage addV2()
+ public CompletionStage addV2(Http.Request httpRequest)
{
IRequestValidator requestValidator=new CertAddRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
Map context = new HashMap<>();
@@ -55,10 +64,10 @@ public CompletionStage addV2()
* this action method will be called for verifying certificate
* @return CompletionStage of Result
*/
- public CompletionStage validate()
+ public CompletionStage validate(Http.Request httpRequest)
{
IRequestValidator requestValidator=new CertValidateRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
requestValidator.validate(req);
@@ -70,10 +79,10 @@ public CompletionStage validate()
* this action method will be called for downloading certificate
* @return CompletionStage of Result
*/
- public CompletionStage download()
+ public CompletionStage download(Http.Request httpRequest)
{
IRequestValidator requestValidator=new CertDownloadRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
requestValidator.validate(req);
@@ -87,9 +96,9 @@ public CompletionStage download()
*
* @return CompletionStage of Result
*/
- public CompletionStage downloadV2(String id) {
+ public CompletionStage downloadV2(String id, Http.Request httpRequest) {
IRequestValidator requestValidator = new CertDownloadV2RequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
req.getRequest().put(JsonKeys.ID, id);
@@ -102,10 +111,10 @@ public CompletionStage downloadV2(String id) {
* this action method will be called for verify certificate
* @return CompletionStage of Result
*/
- public CompletionStage verify()
+ public CompletionStage verify(Http.Request httpRequest)
{
IRequestValidator requestValidator=new CertVerifyRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
requestValidator.validate(req);
@@ -117,9 +126,9 @@ public CompletionStage verify()
* this action method will be called for reading certificate with id
* @return CompletionStage of Result
*/
- public CompletionStage read(String id) {
+ public CompletionStage read(String id, Http.Request httpRequest) {
IRequestValidator requestValidator = new CertReadRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
req.getRequest().put(JsonKeys.ID, id);
@@ -131,10 +140,10 @@ public CompletionStage read(String id) {
}
- public CompletionStage search()
+ public CompletionStage search(Http.Request httpRequest)
{
IRequestValidator requestValidator=new CertSearchRequestValidator();
- return handleRequest(request(),
+ return handleRequest(certificationActorRef, httpRequest,
request -> {
Request req = (Request) request;
requestValidator.validate(req);
diff --git a/service/app/controllers/RequestHandler.java b/service/app/controllers/RequestHandler.java
index 0ace81d..f8ba711 100644
--- a/service/app/controllers/RequestHandler.java
+++ b/service/app/controllers/RequestHandler.java
@@ -1,5 +1,7 @@
package controllers;
+import akka.actor.ActorRef;
+import akka.actor.ActorSelection;
import akka.pattern.Patterns;
import akka.util.Timeout;
import java.util.concurrent.CompletionStage;
@@ -7,7 +9,6 @@
import java.util.function.Function;
import org.apache.commons.lang3.StringUtils;
import org.sunbird.BaseException;
-import org.sunbird.JsonKeys;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.ResponseCode;
import org.sunbird.request.Request;
@@ -35,11 +36,16 @@ public class RequestHandler extends BaseController {
* @return CompletionStage
* @throws Exception
*/
- public CompletionStage handleRequest(Request request, String operation, play.mvc.Http.Request req) throws Exception {
+ public CompletionStage handleRequest(Request request, Object actorRef, String operation, play.mvc.Http.Request req) throws Exception {
request.setOperation(operation);
Function