Skip to content

Commit

Permalink
Sb 15165 (Sunbird-Lern#1)
Browse files Browse the repository at this point in the history
* certification-service all APIs completed

* changed the setip.sh file

* Issue#SB-15165 PR comments resolved

* Issue#SB-15165 changed es mapping rawData to data

* Issue#SB-15165 added java doc on public classes

* Issue#SB-15165 log messages changed

* logs removed
  • Loading branch information
anmol2302 authored and manzarul committed Oct 10, 2019
1 parent 89fe826 commit 41c4cdb
Show file tree
Hide file tree
Showing 76 changed files with 6,348 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/target/
project/project
project/target
target
tmp
.history
dist
/.idea
/*.iml
*.iml
*.log
RUNNING_PID
/out
/.idea_modules
/.classpath
/.project
/.settings
/.target/
/bin/
/logs
*.zip
.idea/*
all-actors/all-actors.iml
play-seed-wo-router.iml
sb-actor/sb-actor.iml
sb-utils/sb-utils.iml
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM openjdk:8-jre-alpine
RUN apk update \
&& apk add unzip \
&& apk add curl \
&& adduser -u 1001 -h /home/sunbird/ -D sunbird \
&& mkdir -p /home/sunbird/
ADD ./service-1.0.0-SNAPSHOT-dist.zip /home/sunbird/
RUN unzip /home/sunbird/service-1.0.0-SNAPSHOT-dist.zip -d /home/sunbird/
RUN chown -R sunbird:sunbird /home/sunbird
USER sunbird
EXPOSE 9000
WORKDIR /home/sunbird/
CMD java -cp '/home/sunbird/service-1.0.0-SNAPSHOT/lib/*' play.core.server.ProdServerStart /home/sunbird/service-1.0.0-SNAPSHOT
61 changes: 61 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
node('build-slave') {
try {
String ANSI_GREEN = "\u001B[32m"
String ANSI_NORMAL = "\u001B[0m"
String ANSI_BOLD = "\u001B[1m"
String ANSI_RED = "\u001B[31m"
String ANSI_YELLOW = "\u001B[33m"

ansiColor('xterm') {
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)
error 'Please resolve the errors and rerun..'
} else
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
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
println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag specified, building from tag: " + params.github_release_tag + ANSI_NORMAL)
}
echo "build_tag: " + build_tag

stage('Build') {
currentDir = sh(returnStdout: true, script: 'pwd').trim()
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
sh 'git log -1'

sh "cd $currentDir"
// Build the dependencies for sunbird certification-service
sh 'mvn clean install'
}
stage('Package') {
// Create a deployment package
dir('service') {
sh 'mvn play2:dist'
sh 'cp target/service-1.0.0-SNAPSHOT-dist.zip ../'
}
sh('chmod 777 ./build.sh')
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
}
stage('ArchiveArtifacts') {
archiveArtifacts "metadata.json"
currentBuild.description = "${build_tag}"
}
}
}
catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Certification-Service

1.In this Application , throw only org.sunbird.BaseException

### Build

1. Execute clean install `mvn clean install`


### Run
1. For debug mode, <br>
`cd play-service` <br>
`mvn play2:dist` <br>
`mvn play2:run`

2. For run mode,
`cd play-service` <br>
`mvn play2:dist` <br>
`mvn play2:start`

### Verify running status

Hit the following Health check curl command

`curl -X GET \
http://localhost:9000/health \
-H 'Postman-Token: 6a5e0eb0-910a-42d1-9077-c46f6f85397d' \
-H 'cache-control: no-cache'`

And, a successful response must be like this:

`{"id":"api.200ok","ver":"v1","ts":"2019-01-17 16:53:26:286+0530","params":{"resmsgid":null,"msgid":"8e27cbf5-e299-43b0-bca7-8347f7ejk5abcf","err":null,"status":"success","errmsg":null},"responseCode":"OK","result":{"response":{"response":"SUCCESS","errors":[]}}}`
34 changes: 34 additions & 0 deletions all-actors/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>certification-service</artifactId>
<groupId>org.sunbird</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>all-actors</artifactId>

<dependencies>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>sb-actor</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>sb-es-utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>sb-utils</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
</dependencies>
</project>
24 changes: 24 additions & 0 deletions all-actors/src/main/java/org/sunbird/ActorOperations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.sunbird;

/**
* this is an actor operation class
* @author anmolgupta
*/
public enum ActorOperations {

ADD("add"),
VALIDATE("validate"),
DOWNLOAD("download"),
GENERATE("generate");

private String operation;

ActorOperations(String operation) {
this.operation = operation;
}

public String getOperation() {
return operation;
}
}

43 changes: 43 additions & 0 deletions all-actors/src/main/java/org/sunbird/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.sunbird;

import akka.actor.ActorRef;
import org.sunbird.actor.core.ActorCache;
import org.sunbird.actor.core.ActorService;

import java.util.ArrayList;
import java.util.List;

/**
* 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 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() {
List<String> actorClassPaths = new ArrayList<>();
actorClassPaths.add("org.sunbird");
ActorService.getInstance().init(actorSystemName, actorClassPaths);
}


/**
* 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);
}
}
89 changes: 89 additions & 0 deletions all-actors/src/main/java/org/sunbird/BaseActor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.sunbird;

import akka.actor.UntypedAbstractActor;
import org.apache.log4j.Logger;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.Localizer;
import org.sunbird.message.ResponseCode;
import org.sunbird.request.Request;

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();

@Override
public void onReceive(Object message) throws Throwable {
if (message instanceof Request) {
Request request = (Request) message;
String operation = request.getOperation();
logger.info("BaseActor:onReceive called for operation:" + operation);
try {
logger.info("BaseActor:onReceive:method started at"+System.currentTimeMillis());
onReceive(request);
logger.info("BaseActor:onReceive:method ended at"+System.currentTimeMillis());
} catch (Exception e) {
onReceiveException(operation, e);
}
} else {
logger.info("BaseActor: onReceive called with invalid type of request.");
}
}

/**
* this method will handle the exception
* @param callerName
* @param exception
* @throws Exception
*/
protected void onReceiveException(String callerName, Exception exception) throws Exception {
logger.error("Exception in message processing for: " + callerName + " :: message: " + exception.getMessage(), exception);
sender().tell(exception, self());
}


/**
* this message will handle the unsupported actor operation
* @param callerName
*/
protected void onReceiveUnsupportedMessage(String callerName) {
logger.info(callerName + ": unsupported operation");
/**
* TODO Need to replace null reference from getLocalized method and replace with requested local.
*/
BaseException exception =
new ActorServiceException.InvalidOperationName(
IResponseMessage.INVALID_OPERATION_NAME,
getLocalizedMessage(IResponseMessage.INVALID_OPERATION_NAME,null),
ResponseCode.CLIENT_ERROR.getCode());
sender().tell(exception, self());
}


/**
* this is method is used get message in different different locales
* @param key
* @param locale
* @return
*/

protected String getLocalizedMessage(String key, Locale locale){
return localizer.getMessage(key, locale);
}

/**
* This method will return the current timestamp.
*
* @return long
*/
public long getTimeStamp() {
return System.currentTimeMillis();
}

}
43 changes: 43 additions & 0 deletions all-actors/src/main/java/org/sunbird/CertVars.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.sunbird;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

/**
* this class will help in getting the env values for calling the cert service
* @author anmolgupta
*/
public class CertVars {

public static final String CERT_SERVICE_BASE_URL= "cert_service_base_url";
private static Logger logger=Logger.getLogger(CertVars.class);
private static final String SERVICE_BASE_URL=getPropsFromEnvs(CERT_SERVICE_BASE_URL);
private static final String DOWNLOAD_URI= "/v1/user/certs/download";
private static final String GENERATE_URI="/v1/certs/generate";


public static String getGenerateUri() {
return GENERATE_URI;
}


public static String getSERVICE_BASE_URL() {
if(StringUtils.isBlank(SERVICE_BASE_URL)){
logger.error("CertVars:getPropsFromEnvs:no suitable host found for downloadUri");
System.exit(-1);
}
return SERVICE_BASE_URL;

}

public static String getDOWNLOAD_URI() {
return DOWNLOAD_URI;
}


private static String getPropsFromEnvs(String props){
String propValue=System.getenv(props);
return propValue;
}

}
Loading

0 comments on commit 41c4cdb

Please sign in to comment.