-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SB#14597 initial play seeder addition (#3)
* issue #SB-14597 feat: setup new microservice for notification * issue #SB-14597 feat: removing submodule call * Issue #SB-14597 feat: removing .pom.xml.swap file
- Loading branch information
Showing
51 changed files
with
2,959 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ./notification-service-1.0.0-dist.zip /home/sunbird/ | ||
RUN unzip /home/sunbird/notification-service-1.0.0-dist.zip -d /home/sunbird/ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 user-org service | ||
sh 'mvn clean install' | ||
} | ||
stage('Package') { | ||
// Create a deployment package | ||
dir('play-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}" | ||
} | ||
} | ||
} | ||
catch (err) { | ||
currentBuild.result = "FAILURE" | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# sunbird-notification-service | ||
Microservice for sending notifications via different channels | ||
## service-seed-without-router | ||
Play, Akka seed project without router implementation. | ||
|
||
Use this for creating a play-based service that leverages all internal actors. By default, runs http on port 9000. | ||
|
||
|
||
### Note | ||
1.In this Application , throw only org.sunbird.BaseException | ||
|
||
### Build | ||
|
||
1. Execute clean install `mvn clean install` | ||
|
||
|
||
### Run | ||
1. For debug mode, <br> | ||
`cd notification-service/service` <br> | ||
`mvn play2:dist` <br> | ||
`mvn play2:run` | ||
|
||
2. For run mode, | ||
`cd notification-service/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":[]}}}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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>notification-play-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-utils</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "notificationActorSystem"; | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
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(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())); | ||
} 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(); | ||
} | ||
|
||
/** | ||
* This method we used to print the logs of starting time of methods | ||
* | ||
* @param tag | ||
*/ | ||
public void startTrace(String tag) { | ||
logger.info(String.format("%s:%s:started at %s", this.getClass().getSimpleName(), tag, getTimeStamp())); | ||
} | ||
|
||
/** | ||
* This method we used to print the logs of ending time of methods | ||
* | ||
* @param tag | ||
*/ | ||
public void endTrace(String tag) { | ||
logger.info(String.format("%s:%s:ended at %s", this.getClass().getSimpleName(), tag, getTimeStamp())); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
all-actors/src/main/java/org/sunbird/health/actor/HealthActor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* | ||
*/ | ||
package org.sunbird.health.actor; | ||
|
||
import org.sunbird.BaseActor; | ||
import org.sunbird.actor.core.ActorConfig; | ||
import org.sunbird.request.Request; | ||
import org.sunbird.response.Response; | ||
/** | ||
* @author manzarul | ||
* | ||
*/ | ||
@ActorConfig( | ||
tasks = {"health"}, | ||
asyncTasks = {} | ||
) | ||
public class HealthActor extends BaseActor{ | ||
|
||
@Override | ||
public void onReceive(Request request) throws Throwable { | ||
Response response = new Response(); | ||
response.getResult().put("response", "Success"); | ||
sender().tell(response, getSelf()); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
all-actors/src/main/java/org/sunbird/notification/actor/NotificationActor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* | ||
*/ | ||
package org.sunbird.notification.actor; | ||
|
||
import org.apache.log4j.LogManager; | ||
import org.apache.log4j.Logger; | ||
import org.sunbird.BaseActor; | ||
import org.sunbird.actor.core.ActorConfig; | ||
import org.sunbird.request.Request; | ||
import org.sunbird.response.Response; | ||
|
||
/** | ||
* @author manzarul | ||
* | ||
*/ | ||
|
||
@ActorConfig( | ||
tasks = {"notification"}, | ||
asyncTasks = {} | ||
) | ||
public class NotificationActor extends BaseActor { | ||
Logger logger = LogManager.getLogger(NotificationActor.class); | ||
private static final String NOTIFICATION = "notification"; | ||
|
||
@Override | ||
public void onReceive(Request request) throws Throwable { | ||
String operation = request.getOperation(); | ||
logger.info("onReceive method call start for operation " + operation); | ||
if (NOTIFICATION.equalsIgnoreCase(operation)) { | ||
notify(request); | ||
} else { | ||
onReceiveUnsupportedMessage(request.getOperation()); | ||
} | ||
|
||
logger.info("onReceive method call End"); | ||
} | ||
|
||
public void notify(Request request) { | ||
System.out.println("Success"); | ||
Response response = new Response(); | ||
response.getResult().put("response", "SUCCESS"); | ||
sender().tell(response, getSelf()); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.