Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SB-25677 #60

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
version: 2.1
jobs:
build:
docker:
- image: circleci/openjdk:8-jdk
working_directory: ~/project
machine:
image: ubuntu-2004:202008-01
steps:
- checkout
- restore_cache:
Expand All @@ -21,4 +20,4 @@ workflows:
version: 2.1
workflow:
jobs:
- build
- build
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jre-alpine
FROM adoptopenjdk/openjdk11:alpine-slim
RUN apk update \
&& apk add unzip \
&& apk add curl \
Expand All @@ -10,4 +10,4 @@ RUN chown -R sunbird:sunbird /home/sunbird
USER sunbird
EXPOSE 9000
WORKDIR /home/sunbird/
CMD java -cp '/home/sunbird/notification-service-1.0.0/lib/*' play.core.server.ProdServerStart /home/sunbird/notification-service-1.0.0
CMD java -XX:+PrintFlagsFinal $JAVA_OPTIONS -Dplay.server.http.idleTimeout=180s -cp '/home/sunbird/notification-service-1.0.0/lib/*' play.core.server.ProdServerStart /home/sunbird/notification-service-1.0.0
76 changes: 34 additions & 42 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,46 @@ node('build-slave') {
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 == "") {
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)
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()
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
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') {
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 user-org service
sh 'mvn clean install'
}
stage('Package') {
// Create a deployment package
dir('service') {
sh 'mvn play2:dist'
sh 'cp target/notification-service-1.0.0-dist.zip ../'
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 user-org service
sh 'mvn clean install'
}
stage('Package') {
// Create a deployment package
dir('service') {
sh 'mvn play2:dist'
sh 'cp target/notification-service-1.0.0-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}"
}
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) {
} catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}
}
10 changes: 5 additions & 5 deletions all-actors/src/main/java/org/sunbird/BaseActor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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.LoggerUtil;
import org.sunbird.request.Request;

import java.util.Locale;
Expand All @@ -14,7 +14,7 @@
*/
public abstract class BaseActor extends UntypedAbstractActor {

private Logger logger = Logger.getLogger(BaseActor.class);
private static LoggerUtil logger = new LoggerUtil(BaseActor.class);
public abstract void onReceive(Request request) throws Throwable;
protected Localizer localizer = Localizer.getInstance();

Expand All @@ -23,11 +23,11 @@ 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);
logger.info(request.getRequestContext(),"BaseActor:onReceive called for operation:" + operation);
try {
logger.info(String.format("%s:%s:method started at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
logger.info(request.getRequestContext(),String.format("%s:%s:method started at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
onReceive(request);
logger.info(String.format("%s:%s:method ended at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
logger.info(request.getRequestContext(),String.format("%s:%s:method ended at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
} catch (Exception e) {
onReceiveException(operation, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.ResponseCode;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.LoggerUtil;

public class NotificationRequestMapper {

private static ObjectMapper mapper = new ObjectMapper();

private static Logger logger = LogManager.getLogger(NotificationRequestMapper.class);
private static LoggerUtil logger = new LoggerUtil(NotificationRequestMapper.class);

/**
* maps request to notification request
Expand Down Expand Up @@ -44,7 +43,6 @@ private static NotificationRequest getNotificationRequest(Map<String, Object> da
try {
NotificationRequest notificationRequest =
mapper.convertValue(data, NotificationRequest.class);
logger.info("Notification request , " + notificationRequest.toString());
return notificationRequest;
} catch (Exception e) {
throw new BaseException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.sunbird.ActorServiceException;
import org.sunbird.BaseActor;
import org.sunbird.BaseException;
Expand All @@ -19,42 +17,40 @@
import org.sunbird.message.IUserResponseMessage;
import org.sunbird.message.ResponseCode;
import org.sunbird.notification.beans.OTPRequest;
import org.sunbird.notification.dispatcher.INotificationDispatcher;
import org.sunbird.notification.dispatcher.NotificationRouter;
import org.sunbird.notification.dispatcher.impl.FCMNotificationDispatcher;
import org.sunbird.notification.utils.NotificationConstant;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.LoggerUtil;
import org.sunbird.request.Request;
import org.sunbird.response.Response;
import org.sunbird.util.validator.OtpRequestValidator;

/** @author manzarul */
@ActorConfig(
tasks = {JsonKey.NOTIFICATION, JsonKey.VERIFY_OTP},
asyncTasks = {}
asyncTasks = {},
dispatcher= "notification-dispatcher"
)
public class NotificationActor extends BaseActor {
Logger logger = LogManager.getLogger(NotificationActor.class);
private static final String NOTIFICATION = JsonKey.NOTIFICATION;
INotificationDispatcher Dispatcher = new FCMNotificationDispatcher();
private static LoggerUtil logger = new LoggerUtil(NotificationActor.class);

@Override
public void onReceive(Request request) throws Throwable {
String operation = request.getOperation();
if (NOTIFICATION.equalsIgnoreCase(operation)) {
if (JsonKey.NOTIFICATION.equalsIgnoreCase(operation)) {
notify(request);
} else if (JsonKey.VERIFY_OTP.equalsIgnoreCase(operation)) {
verifyOtp(request);

} else {
onReceiveUnsupportedMessage(request.getOperation());
}
logger.info("onReceive method call End");
logger.info(request.getRequestContext(),"onReceive method call End");
}

public void notify(Request request) throws BaseException {
boolean isSyncDelivery = false;
logger.info("Call started for notify method");
logger.info(request.getRequestContext(),"Call started for notify method");
List<NotificationRequest> notificationRequestList =
NotificationRequestMapper.toList(
(List<Map<String, Object>>) request.getRequest().get(JsonKey.NOTIFICATIONS));
Expand All @@ -71,13 +67,13 @@ public void notify(Request request) throws BaseException {
if (StringUtils.isNotBlank(deliveryMode) && "sync".equalsIgnoreCase(deliveryMode)) {
isSyncDelivery = true;
}
Response response = routes.route(notificationRequestList, false, isSyncDelivery);
logger.info("response got from notification service " + response);
Response response = routes.route(notificationRequestList, false, isSyncDelivery, request.getRequestContext());
logger.info(request.getRequestContext(),"response got from notification service " + response);
sender().tell(response, getSelf());
}

public void verifyOtp(Request request) throws BaseException {
logger.info("call started for verify otp method");
logger.info(request.getRequestContext(),"call started for verify otp method");
Map<String, Object> requestMap = request.getRequest();
boolean response =
OtpRequestValidator.isOtpVerifyRequestValid(
Expand All @@ -99,8 +95,8 @@ public void verifyOtp(Request request) throws BaseException {
0,
null,
(String) request.get(NotificationConstant.VALUE));
Response responseData = routes.verifyOtp(otpRequest);
logger.info("response got from notification service " + response);
Response responseData = routes.verifyOtp(otpRequest, request.getRequestContext());
logger.info(request.getRequestContext(),"response got from notification service " + response);
sender().tell(responseData, getSelf());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import org.sunbird.notification.utils.FCMResponse;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.RequestContext;

/**
* This interface is responsible for handling different mode of notification
Expand All @@ -11,5 +12,5 @@
*/
public interface INotificationDispatcher {

public FCMResponse dispatch(NotificationRequest data, boolean isDryRun, boolean isSync);
public FCMResponse dispatch(NotificationRequest data, boolean isDryRun, boolean isSync, RequestContext context);
}
Loading