diff --git a/.circleci/config.yml b/.circleci/config.yml
index b789ae0..98fede3 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -2,7 +2,7 @@ version: 2.1
jobs:
build:
docker:
- - image: circleci/openjdk:8-jdk
+ - image: circleci/openjdk:11-jdk-buster-node-browsers-legacy
working_directory: ~/project
steps:
- checkout
diff --git a/Dockerfile b/Dockerfile
index 5ee86fe..fd8aa1c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM openjdk:8-jre-alpine
+FROM sunbird/openjdk-java11-alpine:latest
RUN apk update \
&& apk add unzip \
&& apk add curl \
diff --git a/Jenkinsfile b/Jenkinsfile
index 276534f..14bc8e2 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -7,6 +7,7 @@ node('build-slave') {
String ANSI_YELLOW = "\u001B[33m"
ansiColor('xterm') {
+ withEnv(["JAVA_HOME=${JAVA11_HOME}"]) {
stage('Checkout') {
if (!env.hub_org) {
println(ANSI_BOLD + ANSI_RED + "Uh Oh! Please set a Jenkins environment variable named hub_org with value as registery/sunbidrded" + ANSI_NORMAL)
@@ -15,18 +16,9 @@ node('build-slave') {
println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL)
}
cleanWs()
- if (params.github_release_tag == "") {
- checkout scm
- commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
- branch_name = sh(script: 'git name-rev --name-only HEAD | rev | cut -d "/" -f1| rev', returnStdout: true).trim()
- build_tag = branch_name + "" + commit_hash + "" + env.BUILD_NUMBER
- println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag not specified, using the latest commit hash: " + commit_hash + ANSI_NORMAL)
- } else {
- def scmVars = checkout scm
- checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$params.github_release_tag"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]]
- build_tag = params.github_release_tag + "_" + env.BUILD_NUMB
- println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag specified, building from tag: " + params.github_release_tag + ANSI_NORMAL)
- }
+ checkout scm
+ commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
+ build_tag = sh(script: "echo " + params.github_release_tag.split('/')[-1] + "_" + commit_hash + "_" + env.BUILD_NUMBER, returnStdout: true).trim()
echo "build_tag: " + build_tag
stage('Build') {
@@ -39,7 +31,7 @@ node('build-slave') {
sh 'mvn clean install'
}
stage('Package') {
- // Create a deployment package
+ // Create a deployment packageCertificationActor
dir('service') {
sh 'mvn play2:dist'
sh 'cp target/service-1.0.0-SNAPSHOT-dist.zip ../'
@@ -51,6 +43,7 @@ node('build-slave') {
archiveArtifacts "metadata.json"
currentBuild.description = "${build_tag}"
}
+ }
}
}
catch (err) {
diff --git a/all-actors/pom.xml b/all-actors/pom.xml
index 14a7b80..2b30a4d 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
@@ -54,7 +54,7 @@
org.jacoco
jacoco-maven-plugin
- 0.7.5.201505241946
+ ${jacoco.maven.plugin.version}
${basedir}/target/coverage-reports/jacoco-unit.exec
${basedir}/target/coverage-reports/jacoco-unit.exec
diff --git a/all-actors/src/main/java/org/sunbird/ActorOperations.java b/all-actors/src/main/java/org/sunbird/ActorOperations.java
index 79bbdf8..f0a1150 100644
--- a/all-actors/src/main/java/org/sunbird/ActorOperations.java
+++ b/all-actors/src/main/java/org/sunbird/ActorOperations.java
@@ -15,6 +15,7 @@ public enum ActorOperations {
DELETE_CERT_CASSANDRA("delete_cert_cassandra"),
READ("read"),
SEARCH("search"),
+ SEARCHV2("searchV2"),
READ_CERT_META_DATA("readCertMetaData"),
DOWNLOADV2("downloadV2");
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/BaseActor.java b/all-actors/src/main/java/org/sunbird/BaseActor.java
index 4f83b14..6fea037 100644
--- a/all-actors/src/main/java/org/sunbird/BaseActor.java
+++ b/all-actors/src/main/java/org/sunbird/BaseActor.java
@@ -9,10 +9,7 @@
import org.sunbird.request.Request;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
/**
* @author Amit Kumar
@@ -29,9 +26,13 @@ public void onReceive(Object message) throws Throwable {
Request request = (Request) message;
Map trace = new HashMap<>();
if (request.getHeaders().containsKey(JsonKeys.REQUEST_MESSAGE_ID)) {
- ArrayList requestIds =
- (ArrayList) request.getHeaders().get(JsonKeys.REQUEST_MESSAGE_ID);
- trace.put(JsonKeys.REQUEST_MESSAGE_ID, requestIds.get(0));
+ if(request.getHeaders().get(JsonKeys.REQUEST_MESSAGE_ID) instanceof String) {
+ trace.put(JsonKeys.REQUEST_MESSAGE_ID, request.getHeaders().get(JsonKeys.REQUEST_MESSAGE_ID));
+ } else {
+ ArrayList requestIds =
+ (ArrayList) request.getHeaders().get(JsonKeys.REQUEST_MESSAGE_ID);
+ trace.put(JsonKeys.REQUEST_MESSAGE_ID, requestIds.get(0));
+ }
logger.setMDC(trace);
// set mdc for non actors
new BaseLogger().setReqId(logger.getMDC());
@@ -60,7 +61,7 @@ public void onReceive(Object message) throws Throwable {
* @throws Exception
*/
protected void onReceiveException(String callerName, Exception exception) throws Exception {
- logger.error("Exception in message processing for: " + callerName + " :: message: " + exception.getMessage(), exception);
+ logger.error("Exception in message processing for: " + callerName + " :: message: " + exception, exception);
sender().tell(exception, self());
}
diff --git a/all-actors/src/main/java/org/sunbird/RegistryCredential.java b/all-actors/src/main/java/org/sunbird/RegistryCredential.java
new file mode 100644
index 0000000..de6dcf8
--- /dev/null
+++ b/all-actors/src/main/java/org/sunbird/RegistryCredential.java
@@ -0,0 +1,41 @@
+package org.sunbird;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * this class will help in getting the env values for calling the cert service
+ * @author anmolgupta
+ */
+public class RegistryCredential {
+
+ private static Logger logger= LoggerFactory.getLogger(RegistryCredential.class);
+ private static final String SERVICE_BASE_URL = getPropsFromEnvs(JsonKeys.REGISTRY_CREDENTIAL_SERVICE_BASE_URL);
+ private static final String CERTIFICATE_TYPE = getPropsFromEnvs(JsonKeys.RC_ENTITY);
+ private static final String API = "/api/v1/%s";
+
+ public static String getSERVICE_BASE_URL() {
+ if(StringUtils.isBlank(SERVICE_BASE_URL)){
+ logger.error("RegistryCredential:getPropsFromEnvs:no suitable host found");
+ System.exit(-1);
+ }
+ return SERVICE_BASE_URL;
+ }
+ public static String getDOWNLOAD_URI() {
+ return String.format(API, CERTIFICATE_TYPE);
+ }
+
+ private static String getPropsFromEnvs(String props){
+ String propValue = System.getenv(props);
+ return propValue;
+ }
+
+
+ public static String getRCSearchUri(){
+ String apiUrl = String.format(API, CERTIFICATE_TYPE);
+ String rcSearchApi = String.format("%s/%s/search", getSERVICE_BASE_URL().split(",")[0], apiUrl);
+ logger.info("RegistryCredential:getRCSearchUri:es uri formed: "+rcSearchApi);
+ return rcSearchApi;
+ }
+}
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..d656654 100644
--- a/all-actors/src/main/java/org/sunbird/actor/CertificationActor.java
+++ b/all-actors/src/main/java/org/sunbird/actor/CertificationActor.java
@@ -1,32 +1,33 @@
package org.sunbird.actor;
+import akka.actor.ActorRef;
+import com.fasterxml.jackson.core.JsonProcessingException;
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;
+import java.util.concurrent.ExecutionException;
-@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();
}
@Override
- public void onReceive(Request request) throws BaseException {
+ public void onReceive(Request request) throws BaseException, InterruptedException, ExecutionException, JsonProcessingException {
logger.info("CertificationActor:onReceive:request arrived with operation" + request.getOperation());
String operation = request.getOperation();
switch (operation) {
@@ -57,13 +58,16 @@ public void onReceive(Request request) throws BaseException {
case "downloadV2" :
downloadV2(request);
break;
+ case "searchV2":
+ searchV2(request);
+ break;
default:
onReceiveUnsupportedMessage("CertificationActor");
}
}
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());
@@ -93,6 +97,10 @@ private void read(Request request) throws BaseException {
private void search(Request request) throws BaseException{
sender().tell(certService.search(request),self());
}
+
+ private void searchV2(Request request) throws BaseException{
+ sender().tell(certService.searchV2(request),self());
+ }
private void downloadV2(Request request) throws BaseException {
sender().tell(certService.downloadV2(request), 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..5639693 100644
--- a/all-actors/src/main/java/org/sunbird/service/ICertService.java
+++ b/all-actors/src/main/java/org/sunbird/service/ICertService.java
@@ -1,10 +1,14 @@
package org.sunbird.service;
+import akka.actor.ActorRef;
+import com.fasterxml.jackson.core.JsonProcessingException;
import org.sunbird.BaseException;
import org.sunbird.request.Request;
import org.sunbird.response.Response;
+import java.util.concurrent.ExecutionException;
+
/**
* this is an interface class for implementing certificate related operations
* @author anmolgupta
@@ -12,9 +16,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;
@@ -29,5 +33,7 @@ public interface ICertService{
Response read(Request request) throws BaseException;
Response search(Request request) throws BaseException;
+
+ Response searchV2(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..1c00c83 100644
--- a/all-actors/src/main/java/org/sunbird/serviceimpl/CertsServiceImpl.java
+++ b/all-actors/src/main/java/org/sunbird/serviceimpl/CertsServiceImpl.java
@@ -1,7 +1,9 @@
package org.sunbird.serviceimpl;
+import akka.actor.ActorRef;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import org.apache.commons.collections.CollectionUtils;
@@ -14,6 +16,7 @@
import org.sunbird.BaseException;
import org.sunbird.CertVars;
import org.sunbird.JsonKeys;
+import org.sunbird.RegistryCredential;
import org.sunbird.builders.Certificate;
import org.sunbird.builders.Recipient;
import org.sunbird.message.IResponseMessage;
@@ -29,10 +32,8 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -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()
@@ -204,7 +205,7 @@ public Response download(Request request) throws BaseException {
String signedUrl=jsonResponse.getBody().getObject().getJSONObject(JsonKeys.RESULT).getString(JsonKeys.SIGNED_URL);
response.put(JsonKeys.SIGNED_URL,signedUrl);
} else {
- throw new BaseException(IResponseMessage.INVALID_REQUESTED_DATA, MessageFormat.format(getLocalizedMessage(IResponseMessage.INVALID_PROVIDED_URL,null),(String)request.getRequest().get(JsonKeys.PDF_URL)), ResponseCode.CLIENT_ERROR.getCode());
+ throw new BaseException(IResponseMessage.INVALID_REQUESTED_DATA, MessageFormat.format(getLocalizedMessage(IResponseMessage.INVALID_PROVIDED_URL, null), (String) request.getRequest().get(JsonKeys.PDF_URL)), ResponseCode.CLIENT_ERROR.getCode());
}
} catch (Exception e) {
@@ -221,11 +222,11 @@ public Response downloadV2(Request request) throws BaseException {
Response certData = CertificateUtil.getCertRecordByID(certId);
Response response = new Response();
List