Skip to content

Commit

Permalink
Issue# SB-18727 feat:merging release-1.2.0 to master (Sunbird-Lern#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMIT KUMAR authored Apr 6, 2020
1 parent fd04b1b commit 3c8a777
Show file tree
Hide file tree
Showing 78 changed files with 5,461 additions and 557 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
paths: ~/.m2
- run:
name: Analyze on SonarCloud
command: mvn verify sonar:sonar -Dsonar.projectKey=project-sunbird_certificate-registry -Dsonar.organization=project-sunbird -Dsonar.host.url=https://sonarcloud.io -Dsonar.coverage.jacoco.xmlReportPaths=/home/circleci/project/service/target/site/jacoco/jacoco.xml
command: mvn verify sonar:sonar -Dsonar.projectKey=project-sunbird_certificate-registry -Dsonar.organization=project-sunbird -Dsonar.host.url=https://sonarcloud.io -Dsonar.coverage.jacoco.xmlReportPaths=/home/circleci/project/service/target/site/jacoco/jacoco.xml,/home/circleci/project/all-actors/target/site/jacoco/jacoco.xml,/home/circleci/project/cassandra-utils/target/site/jacoco/jacoco.xml

workflows:
version: 2.1
Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ node('build-slave') {
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
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
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)
}
echo "build_tag: " + build_tag
Expand Down
45 changes: 42 additions & 3 deletions all-actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<parent>
<artifactId>certification-service</artifactId>
<groupId>org.sunbird</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>all-actors</artifactId>

<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>sb-actor</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
Expand All @@ -25,10 +25,49 @@
<artifactId>sb-utils</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>cassandra-utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.12</artifactId>
<version>2.6.0-M5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
6 changes: 5 additions & 1 deletion all-actors/src/main/java/org/sunbird/ActorOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ public enum ActorOperations {
VALIDATE("validate"),
DOWNLOAD("download"),
GENERATE("generate"),
VERIFY("verify");
VERIFY("verify"),
ADD_CERT_ES("add_cert_es"),
DELETE_CERT_CASSANDRA("delete_cert_cassandra"),
READ("read"),
SEARCH("search");

private String operation;

Expand Down
60 changes: 59 additions & 1 deletion all-actors/src/main/java/org/sunbird/Application.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package org.sunbird;

import akka.actor.ActorRef;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
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.
Expand All @@ -14,6 +22,9 @@
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 = Logger.getLogger(Application.class);


// private constructor restricted to this class itself
private Application() {
Expand All @@ -25,10 +36,11 @@ public static Application getInstance() {
}

// instantiate actor system and actors
public void init() {
public void init() throws BaseException {
List<String> actorClassPaths = new ArrayList<>();
actorClassPaths.add("org.sunbird");
ActorService.getInstance().init(actorSystemName, actorClassPaths);
createCassandraConnection(JsonKeys.SUNBIRD);
}


Expand All @@ -40,4 +52,50 @@ public void init() {
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);
}
}
5 changes: 4 additions & 1 deletion all-actors/src/main/java/org/sunbird/BaseActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import akka.actor.UntypedAbstractActor;
import org.apache.log4j.Logger;
import org.sunbird.common.factory.EsClientFactory;
import org.sunbird.common.inf.ElasticSearchService;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.Localizer;
import org.sunbird.message.ResponseCode;
import org.sunbird.request.Request;
import org.sunbird.service.ICertService;
import org.sunbird.serviceimpl.CertsServiceImpl;

import java.util.Locale;

/**
* @author Amit Kumar
*/
public abstract class BaseActor extends UntypedAbstractActor {

private Logger logger = Logger.getLogger(BaseActor.class);
public abstract void onReceive(Request request) throws Throwable;
protected Localizer localizer = Localizer.getInstance();
Expand Down
8 changes: 8 additions & 0 deletions all-actors/src/main/java/org/sunbird/CertVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class CertVars {
private static final String DOWNLOAD_URI= "/v1/user/certs/download";
private static final String GENERATE_URI="/v1/certs/generate";
private static final String VERIFY_URI="/v1/certs/verify";
public static final String SUNBIRD_ES_IP = "sunbird_es_host";


public static String getVerifyUri() { return VERIFY_URI; }
Expand All @@ -37,4 +38,11 @@ private static String getPropsFromEnvs(String props){
String propValue=System.getenv(props);
return propValue;
}


public static String getEsSearchUri(){
String esApi=String.format("http://%s:9200/%s/_search",getPropsFromEnvs(SUNBIRD_ES_IP).split(",")[0],JsonKeys.CERT_ALIAS);
logger.info("CertVars:getEsSearchUri:es uri formed:"+esApi);
return esApi;
}
}
68 changes: 0 additions & 68 deletions all-actors/src/main/java/org/sunbird/Certification.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.sunbird.actor;

import org.apache.log4j.Logger;
import org.sunbird.BaseActor;
import org.sunbird.BaseException;
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.Map;

@ActorConfig(
tasks = {"add_cert_es","delete_cert_cassandra"},
dispatcher = "",
asyncTasks = {}
)
public class CertBackgroundActor extends BaseActor {
static Logger logger = Logger.getLogger(CertBackgroundActor.class);
private ElasticSearchService elasticSearchService = getESService();
private CassandraOperation cassandraOperation = getCassandraOperation();
private static CassandraOperation getCassandraOperation(){
return ServiceFactory.getInstance();
}

private static ElasticSearchService getESService(){
return EsClientFactory.getInstance();
}
@Override
public void onReceive(Request request) throws Throwable {
logger.info("CertificationActor:onReceive:request arrived with operation" + request.getOperation());
String operation = request.getOperation();
switch (operation) {
case "add_cert_es":
add(request);
break;

case "delete_cert_cassandra":
delete(request);
break;

default:
onReceiveUnsupportedMessage("CertificationActor");
}
}

private void delete(Request request) throws BaseException {
String id = (String) request.getRequest().get(JsonKeys.ID);
try {
cassandraOperation.deleteRecord(JsonKeys.SUNBIRD, JsonKeys.CERT_REGISTRY, id);
logger.info("Data deleted from cassandra for id " + id);
}catch (Exception ex){
logger.error("Exception occurred while deleting data from cert_registry for id : "+id,ex);
}
}


private void add(Request request) {
Map<String,Object> certAddReqMap = (Map<String, Object>) request.getRequest().get(JsonKeys.REQUEST);
String id = (String)ElasticSearchHelper.getResponseFromFuture(elasticSearchService.save(JsonKeys.CERT_ALIAS,(String)certAddReqMap.get(JsonKeys.ID),certAddReqMap));
logger.info("ES save response for id "+id);
}
}
Loading

0 comments on commit 3c8a777

Please sign in to comment.