diff --git a/.gitmodules b/.gitmodules
index c8dd41149d..67e9f8925d 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,4 @@
[submodule "actors/sunbird-lms-mw"]
path = actors/sunbird-lms-mw
url = https://github.com/project-sunbird/sunbird-lms-mw.git
- branch = master
+ branch = master
diff --git a/Dockerfile b/Dockerfile
index 43b1e8c110..8522ff90f1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,4 +12,4 @@ USER sunbird
COPY ./service/target/learning-service-1.0-SNAPSHOT-dist.zip /home/sunbird/learner/
RUN unzip /home/sunbird/learner/learning-service-1.0-SNAPSHOT-dist.zip -d /home/sunbird/learner/
WORKDIR /home/sunbird/learner/
-CMD java -cp '/home/sunbird/learner/learning-service-1.0-SNAPSHOT/lib/*' play.core.server.ProdServerStart /home/sunbird/learner/learning-service-1.0-SNAPSHOT
+CMD java -XX:+PrintFlagsFinal $JAVA_OPTIONS -cp '/home/sunbird/learner/learning-service-1.0-SNAPSHOT/lib/*' play.core.server.ProdServerStart /home/sunbird/learner/learning-service-1.0-SNAPSHOT
diff --git a/auto_build_deploy b/auto_build_deploy
new file mode 100644
index 0000000000..9731316431
--- /dev/null
+++ b/auto_build_deploy
@@ -0,0 +1,63 @@
+@Library('deploy-conf') _
+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') {
+ tag_name = env.JOB_NAME.split("/")[-1]
+ pre_checks()
+ 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()
+ def scmVars = checkout scm
+ checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$tag_name"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]]
+ build_tag = tag_name + "_" + env.BUILD_NUMBER
+ commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
+ artifact_version = tag_name + "_" + commit_hash
+ echo "build_tag: " + build_tag
+
+ // stage Build
+ env.NODE_ENV = "build"
+ print "Environment will be : ${env.NODE_ENV}"
+ sh('git submodule update --init')
+ sh('git submodule update --init --recursive --remote')
+ sh 'git log -1'
+ sh 'cat service/conf/routes | grep v2'
+ sh 'mvn clean install -U -DskipTests=true '
+
+
+ // stage Unit Tests
+ sh "mvn test '-Dtest=!%regex[io.opensaber.registry.client.*]' -DfailIfNoTests=false"
+
+ // stage Package
+ dir('service') {
+ sh 'mvn play2:dist'
+ }
+ sh('chmod 777 ./build.sh')
+ sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
+
+ // stage ArchiveArtifacts
+ archiveArtifacts "metadata.json"
+ currentBuild.description = "${build_tag}"
+ }
+ currentBuild.result = "SUCCESS"
+ slack_notify(currentBuild.result, tag_name)
+ email_notify()
+ auto_build_deploy()
+ }
+ catch (err) {
+ currentBuild.result = "FAILURE"
+ slack_notify(currentBuild.result, tag_name)
+ email_notify()
+ throw err
+ }
+}
diff --git a/pom.xml b/pom.xml
index 09d3b82f7e..d60616c0d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,4 +15,15 @@
actors/sunbird-lms-mw
service
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.1.1
+
+
+
+
diff --git a/service/app/controllers/BaseController.java b/service/app/controllers/BaseController.java
index 7c3515dc0a..02dda98045 100644
--- a/service/app/controllers/BaseController.java
+++ b/service/app/controllers/BaseController.java
@@ -13,12 +13,16 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
import modules.ApplicationStart;
import modules.OnRequestHandler;
import org.apache.commons.lang3.StringUtils;
import org.sunbird.actor.service.SunbirdMWService;
import org.sunbird.common.exception.ProjectCommonException;
+import org.sunbird.common.models.response.ClientErrorResponse;
import org.sunbird.common.models.response.Response;
import org.sunbird.common.models.response.ResponseParams;
import org.sunbird.common.models.util.ActorOperations;
@@ -39,10 +43,6 @@
import play.mvc.Results;
import util.AuthenticationHelper;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.function.Function;
-
/**
* This controller we can use for writing some common method.
*
@@ -65,9 +65,10 @@ public class BaseController extends Controller {
}
private org.sunbird.common.request.Request initRequest(
- org.sunbird.common.request.Request request, String operation, Request httpRequest) {
+ org.sunbird.common.request.Request request, String operation, Request httpRequest) {
request.setOperation(operation);
- request.setRequestId(ExecutionContext.getRequestId());
+ request.setRequestId(httpRequest.flash().get(JsonKey.REQUEST_ID));
+ request.getParams().setMsgid(httpRequest.flash().get(JsonKey.REQUEST_ID));
request.setEnv(getEnvironment());
request.getContext().put(JsonKey.REQUESTED_BY, httpRequest.flash().get(JsonKey.USER_ID));
request = transformUserId(request);
@@ -84,7 +85,7 @@ private org.sunbird.common.request.Request initRequest(
* instance.
*/
protected org.sunbird.common.request.Request createAndInitRequest(
- String operation, JsonNode requestBodyJson, Request httpRequest) {
+ String operation, JsonNode requestBodyJson, Request httpRequest) {
org.sunbird.common.request.Request request =
(org.sunbird.common.request.Request)
mapper.RequestMapper.mapRequest(
@@ -100,7 +101,8 @@ protected org.sunbird.common.request.Request createAndInitRequest(
* @return Created and initialised Request (@see {@link org.sunbird.common.request.Request})
* instance.
*/
- protected org.sunbird.common.request.Request createAndInitRequest(String operation, Request httpRequest) {
+ protected org.sunbird.common.request.Request createAndInitRequest(
+ String operation, Request httpRequest) {
org.sunbird.common.request.Request request = new org.sunbird.common.request.Request();
return initRequest(request, operation, httpRequest);
}
@@ -109,7 +111,8 @@ protected CompletionStage handleRequest(String operation, Http.Request h
return handleRequest(operation, null, null, null, null, false, httpRequest);
}
- protected CompletionStage handleRequest(String operation, JsonNode requestBodyJson, Request httpRequest) {
+ protected CompletionStage handleRequest(
+ String operation, JsonNode requestBodyJson, Request httpRequest) {
return handleRequest(operation, requestBodyJson, null, null, null, true, httpRequest);
}
@@ -119,41 +122,56 @@ protected CompletionStage handleRequest(
}
protected CompletionStage handleRequest(
- String operation, JsonNode requestBodyJson, Function requestValidatorFn, Request httpRequest) {
- return handleRequest(operation, requestBodyJson, requestValidatorFn, null, null, true, httpRequest);
+ String operation,
+ JsonNode requestBodyJson,
+ Function requestValidatorFn,
+ Request httpRequest) {
+ return handleRequest(
+ operation, requestBodyJson, requestValidatorFn, null, null, true, httpRequest);
}
- protected CompletionStage handleRequest(String operation, String pathId, String pathVariable, Request httpRequest) {
+ protected CompletionStage handleRequest(
+ String operation, String pathId, String pathVariable, Request httpRequest) {
return handleRequest(operation, null, null, pathId, pathVariable, false, httpRequest);
}
protected CompletionStage handleRequest(
- String operation, String pathId, String pathVariable, boolean isJsonBodyRequired, Request httpRequest) {
- return handleRequest(operation, null, null, pathId, pathVariable, isJsonBodyRequired, httpRequest);
+ String operation,
+ String pathId,
+ String pathVariable,
+ boolean isJsonBodyRequired,
+ Request httpRequest) {
+ return handleRequest(
+ operation, null, null, pathId, pathVariable, isJsonBodyRequired, httpRequest);
}
protected CompletionStage handleRequest(
- String operation,
- JsonNode requestBodyJson,
- Function requestValidatorFn,
- Map headers, Request httpRequest) {
- return handleRequest(operation, requestBodyJson, requestValidatorFn, null, null, headers, true, httpRequest);
+ String operation,
+ JsonNode requestBodyJson,
+ Function requestValidatorFn,
+ Map headers,
+ Request httpRequest) {
+ return handleRequest(
+ operation, requestBodyJson, requestValidatorFn, null, null, headers, true, httpRequest);
}
protected CompletionStage handleRequest(
- String operation,
- Function requestValidatorFn,
- String pathId,
- String pathVariable, Request httpRequest) {
- return handleRequest(operation, null, requestValidatorFn, pathId, pathVariable, false, httpRequest);
+ String operation,
+ Function requestValidatorFn,
+ String pathId,
+ String pathVariable,
+ Request httpRequest) {
+ return handleRequest(
+ operation, null, requestValidatorFn, pathId, pathVariable, false, httpRequest);
}
protected CompletionStage handleRequest(
- String operation,
- JsonNode requestBodyJson,
- Function requestValidatorFn,
- String pathId,
- String pathVariable, Request httpRequest) {
+ String operation,
+ JsonNode requestBodyJson,
+ Function requestValidatorFn,
+ String pathId,
+ String pathVariable,
+ Request httpRequest) {
return handleRequest(
operation, requestBodyJson, requestValidatorFn, pathId, pathVariable, true, httpRequest);
}
@@ -174,17 +192,18 @@ protected CompletionStage handleRequest(
pathVariable,
null,
isJsonBodyRequired,
- httpRequest);
+ httpRequest);
}
protected CompletionStage handleRequest(
- String operation,
- JsonNode requestBodyJson,
- Function requestValidatorFn,
- String pathId,
- String pathVariable,
- Map headers,
- boolean isJsonBodyRequired, Request httpRequest) {
+ String operation,
+ JsonNode requestBodyJson,
+ Function requestValidatorFn,
+ String pathId,
+ String pathVariable,
+ Map headers,
+ boolean isJsonBodyRequired,
+ Request httpRequest) {
try {
org.sunbird.common.request.Request request = null;
if (!isJsonBodyRequired) {
@@ -199,23 +218,33 @@ protected CompletionStage handleRequest(
if (requestValidatorFn != null) requestValidatorFn.apply(request);
if (headers != null) request.getContext().put(JsonKey.HEADER, headers);
+ ProjectLogger.log(
+ "BaseController:handleRequest for operation: "
+ + operation
+ + " requestId: "
+ + request.getRequestId(),
+ LoggerEnum.INFO.name());
return actorResponseHandler(getActorRef(), request, timeout, null, httpRequest);
} catch (Exception e) {
ProjectLogger.log(
- "BaseController:handleRequest: Exception occurred with error message = " + e.getMessage(),
+ "BaseController:handleRequest for operation: "
+ + operation
+ + " Exception occurred with error message = "
+ + e.getMessage(),
e);
return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
}
}
protected CompletionStage handleSearchRequest(
- String operation,
- JsonNode requestBodyJson,
- Function requestValidatorFn,
- String pathId,
- String pathVariable,
- Map headers,
- String esObjectType, Request httpRequest) {
+ String operation,
+ JsonNode requestBodyJson,
+ Function requestValidatorFn,
+ String pathId,
+ String pathVariable,
+ Map headers,
+ String esObjectType,
+ Request httpRequest) {
try {
org.sunbird.common.request.Request request = null;
if (null != requestBodyJson) {
@@ -327,7 +356,7 @@ public static Result createSuccessResponse(Request request, Response response) {
}
return Results.ok(Json.toJson(response))
- .withHeader(HeaderParam.X_Response_Length.getName(), value);
+ .withHeader(HeaderParam.X_Response_Length.getName(), value);
}
/**
@@ -423,32 +452,33 @@ public Result createCommonResponse(Object response, String key, Request request)
params.put(JsonKey.DURATION, calculateApiTimeTaken(startTime));
removeFields(params, JsonKey.START_TIME);
params.put(
- JsonKey.STATUS, String.valueOf(((Response) response).getResponseCode().getResponseCode()));
+ JsonKey.STATUS,
+ String.valueOf(((Response) response).getResponseCode().getResponseCode()));
params.put(JsonKey.LOG_LEVEL, JsonKey.INFO);
req.setRequest(
- generateTelemetryRequestForController(
- TelemetryEvents.LOG.getName(),
- params,
- (Map) requestInfo.get(JsonKey.CONTEXT)));
+ generateTelemetryRequestForController(
+ TelemetryEvents.LOG.getName(),
+ params,
+ (Map) requestInfo.get(JsonKey.CONTEXT)));
// if any request is coming form /v1/telemetry/save then don't generate the telemetry log
// for it.
lmaxWriter.submitMessage(req);
} catch (Exception ex) {
ProjectLogger.log(
- "BaseController:createCommonResponse Exception in writing telemetry for request "
- + requestId,
- ex);
+ "BaseController:createCommonResponse Exception in writing telemetry for request "
+ + requestId,
+ ex);
} finally {
// remove request info from map
OnRequestHandler.requestInfo.remove(requestId);
ProjectLogger.log(
- "BaseController:createCommonResponse removed details for messageId=" + requestId,
- LoggerEnum.INFO);
+ "BaseController:createCommonResponse removed details for messageId=" + requestId,
+ LoggerEnum.INFO);
}
} else {
ProjectLogger.log(
- "BaseController:createCommonResponse request details not found requestId=" + requestId,
- LoggerEnum.ERROR);
+ "BaseController:createCommonResponse request details not found requestId=" + requestId,
+ LoggerEnum.ERROR);
}
Response courseResponse = (Response) response;
if (!StringUtils.isBlank(key)) {
@@ -465,8 +495,8 @@ public Result createCommonResponse(Object response, String key, Request request)
*/
public Result createFileDownloadResponse(File file) {
return Results.ok(file)
- .withHeader("Content-Type", "application/x-download")
- .withHeader("Content-disposition", "attachment; filename=" + file.getName());
+ .withHeader("Content-Type", "application/x-download")
+ .withHeader("Content-disposition", "attachment; filename=" + file.getName());
}
private void removeFields(Map params, String... properties) {
@@ -515,35 +545,40 @@ public Result createCommonExceptionResponse(Exception e, Request request) {
ResponseCode.internalError.getErrorMessage(),
ResponseCode.SERVER_ERROR.getResponseCode());
}
- try {
- Map requestInfo = OnRequestHandler.requestInfo.get(request.flash().get(JsonKey.REQUEST_ID));
- org.sunbird.common.request.Request reqForTelemetry = new org.sunbird.common.request.Request();
- Map params = (Map) requestInfo.get(JsonKey.ADDITIONAL_INFO);
- params.put(JsonKey.LOG_TYPE, JsonKey.API_ACCESS);
- params.put(JsonKey.MESSAGE, "");
- params.put(JsonKey.METHOD, request.method());
- // calculate the total time consume
- long startTime = (Long) params.get(JsonKey.START_TIME);
- params.put(JsonKey.DURATION, calculateApiTimeTaken(startTime));
- removeFields(params, JsonKey.START_TIME);
- params.put(JsonKey.STATUS, String.valueOf(exception.getResponseCode()));
- params.put(JsonKey.LOG_LEVEL, "error");
- params.put(JsonKey.STACKTRACE, generateStackTrace(exception.getStackTrace()));
- reqForTelemetry.setRequest(
- generateTelemetryRequestForController(
- TelemetryEvents.ERROR.getName(),
- params,
- (Map) requestInfo.get(JsonKey.CONTEXT)));
- lmaxWriter.submitMessage(reqForTelemetry);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ generateExceptionTelemetry(request, exception);
// cleaning request info ...
return Results.status(
exception.getResponseCode(),
Json.toJson(BaseController.createResponseOnException(req, exception)));
}
+ private void generateExceptionTelemetry(Request request, ProjectCommonException exception) {
+ try {
+ Map requestInfo =
+ OnRequestHandler.requestInfo.get(request.flash().get(JsonKey.REQUEST_ID));
+ org.sunbird.common.request.Request reqForTelemetry = new org.sunbird.common.request.Request();
+ Map params = (Map) requestInfo.get(JsonKey.ADDITIONAL_INFO);
+ params.put(JsonKey.LOG_TYPE, JsonKey.API_ACCESS);
+ params.put(JsonKey.MESSAGE, "");
+ params.put(JsonKey.METHOD, request.method());
+ // calculate the total time consume
+ long startTime = (Long) params.get(JsonKey.START_TIME);
+ params.put(JsonKey.DURATION, calculateApiTimeTaken(startTime));
+ removeFields(params, JsonKey.START_TIME);
+ params.put(JsonKey.STATUS, String.valueOf(exception.getResponseCode()));
+ params.put(JsonKey.LOG_LEVEL, "error");
+ params.put(JsonKey.STACKTRACE, generateStackTrace(exception.getStackTrace()));
+ reqForTelemetry.setRequest(
+ generateTelemetryRequestForController(
+ TelemetryEvents.ERROR.getName(),
+ params,
+ (Map) requestInfo.get(JsonKey.CONTEXT)));
+ lmaxWriter.submitMessage(reqForTelemetry);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
private long calculateApiTimeTaken(Long startTime) {
Long timeConsumed = null;
@@ -569,24 +604,21 @@ public CompletionStage actorResponseHandler(
Timeout timeout,
String responseKey,
Request httpReq) {
-
- String operation = request.getOperation();
-
- // set header to request object , setting actor type and channel headers value
- // ...
setChannelAndActorInfo(httpReq, request);
-
Function