Skip to content

Commit

Permalink
Merge pull request #99 from Sunbird-Lern/release-5.0.0
Browse files Browse the repository at this point in the history
Release 5.0.0 - Merging from release-5.0.0 to master
  • Loading branch information
reshmi-nair authored Nov 4, 2022
2 parents 89593d7 + 9006654 commit d0bf07d
Show file tree
Hide file tree
Showing 46 changed files with 757 additions and 782 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jre-alpine
FROM sunbird/openjdk-java11-alpine:latest
RUN apk update \
&& apk add unzip \
&& apk add curl \
Expand Down
19 changes: 6 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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') {
Expand All @@ -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 ../'
Expand All @@ -51,6 +43,7 @@ node('build-slave') {
archiveArtifacts "metadata.json"
currentBuild.description = "${build_tag}"
}
}
}
}
catch (err) {
Expand Down
12 changes: 6 additions & 6 deletions all-actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>sb-actor</artifactId>
<version>1.0.0</version>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_${scala.major.version}</artifactId>
<version>${akka.x.version}</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
Expand Down Expand Up @@ -44,8 +44,8 @@

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.12</artifactId>
<version>2.6.0-M5</version>
<artifactId>akka-testkit_${scala.major.version}</artifactId>
<version>2.5.22</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -54,7 +54,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<version>${jacoco.maven.plugin.version}</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
Expand Down
1 change: 1 addition & 0 deletions all-actors/src/main/java/org/sunbird/ActorOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
102 changes: 0 additions & 102 deletions all-actors/src/main/java/org/sunbird/Application.java

This file was deleted.

17 changes: 9 additions & 8 deletions all-actors/src/main/java/org/sunbird/BaseActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,9 +26,13 @@ public void onReceive(Object message) throws Throwable {
Request request = (Request) message;
Map<String, Object> trace = new HashMap<>();
if (request.getHeaders().containsKey(JsonKeys.REQUEST_MESSAGE_ID)) {
ArrayList<String> requestIds =
(ArrayList<String>) 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<String> requestIds =
(ArrayList<String>) 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());
Expand Down Expand Up @@ -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());
}

Expand Down
41 changes: 41 additions & 0 deletions all-actors/src/main/java/org/sunbird/RegistryCredential.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 19 additions & 11 deletions all-actors/src/main/java/org/sunbird/actor/CertificationActor.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Loading

0 comments on commit d0bf07d

Please sign in to comment.