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

Telemetry fixes 4.8.4 #60

Open
wants to merge 4 commits into
base: dev-4.8.4
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public final class SunbirdKey {
public static final String COLLECTION = "collection";
public static final String EVENT_SET = "eventSet";
public static final String OBJECT_TYPE = "objectType";

public static final String ROOT_ORG_ID = "rootOrgId";
private SunbirdKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
val courseId: String = request.getOrDefault(JsonKey.COURSE_ID, "").asInstanceOf[String]
val batchId: String = request.getOrDefault(JsonKey.BATCH_ID, "").asInstanceOf[String]
val filters = Map[String, AnyRef]("userid"-> userId, "courseid"-> courseId, "batchid"-> batchId).asJava
val rootOrgId: String = request.getOrDefault(JsonKey.ROOT_ORG_ID, "").asInstanceOf[String]
val result = cassandraOperation
.getRecords(request.getRequestContext, enrolmentDBInfo.getKeySpace, enrolmentDBInfo.getTableName, filters,
null)
Expand All @@ -431,7 +432,7 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
.asInstanceOf[java.util.List[java.util.Map[String, AnyRef]]]
val response = {
if (CollectionUtils.isNotEmpty(resp)) {
pushEnrolmentSyncEvent(userId, courseId, batchId)
pushEnrolmentSyncEvent(userId, courseId, batchId, rootOrgId)
successResponse()
} else {
new ProjectCommonException(ResponseCode.invalidRequestData.getErrorCode,
Expand All @@ -441,13 +442,13 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
sender().tell(response, self)
}

def pushEnrolmentSyncEvent(userId: String, courseId: String, batchId: String) = {
def pushEnrolmentSyncEvent(userId: String, courseId: String, batchId: String, rootOrgId: String) = {
val now = System.currentTimeMillis()
val event =
s"""{"eid":"BE_JOB_REQUEST","ets":$now,"mid":"LP.$now.${UUID.randomUUID()}"
s"""{"eid":"AUDIT","ets":$now,"mid":"AUDIT.$now.${UUID.randomUUID()}"
|,"actor":{"type":"System","id":"Course Batch Updater"},"context":{"pdata":{"ver":"1.0","id":"org.sunbird.platform"}}
|,"object":{"type":"CourseBatchEnrolment","id":"${batchId}_${userId}"},"edata":{"action":"user-enrolment-sync"
|,"iteration":1,"batchId":"$batchId","userId":"$userId","courseId":"$courseId"}}""".stripMargin
|,"iteration":1,"batchId":"$batchId","userId":"$userId","courseId":"$courseId","rootOrgId":"$rootOrgId"}}""".stripMargin
.replaceAll("\n", "")
if(pushTokafkaEnabled){
val topic = ProjectUtil.getConfigValue("kafka_enrolment_sync_topic")
Expand Down
7 changes: 5 additions & 2 deletions service/app/controllers/LearnerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public CompletionStage<Result> updateContentState(Http.Request httpRequest) {
String loggingHeaders = httpRequest.attrs().getOptional(Attrs.X_LOGGING_HEADERS).orElse(null);
String requestedBy = httpRequest.attrs().getOptional(Attrs.USER_ID).orElse(null);
String requestedFor = httpRequest.attrs().getOptional(Attrs.REQUESTED_FOR).orElse(null);
String apiDebugLog = "UpdateContentState Request: " + requestData.toString() + " RequestedBy: " + requestedBy + " RequestedFor: " + requestedFor + " ";
String rootOrgId = httpRequest.attrs().getOptional(Attrs.X_AUTH_USER_ORG_ID).orElse(null);
String apiDebugLog = "UpdateContentState Request: " + requestData.toString() + " RequestedBy: " + requestedBy + " RequestedFor: " + requestedFor + " " + " Root Org Id: " + rootOrgId + " ";
try {
Request reqObj = (Request) mapper.RequestMapper.mapRequest(requestData, Request.class);
RequestValidator.validateUpdateContent(reqObj);
Expand All @@ -107,7 +108,9 @@ public CompletionStage<Result> updateContentState(Http.Request httpRequest) {
innerMap.put(JsonKey.CONTENTS, reqObj.get(JsonKey.CONTENTS));
innerMap.put(JsonKey.ASSESSMENT_EVENTS, reqObj.getRequest().get(JsonKey.ASSESSMENT_EVENTS));
}
innerMap.put(JsonKey.USER_ID, reqObj.getRequest().get(JsonKey.USER_ID));
innerMap.put(JsonKey.USER_ID, reqObj.getRequest().get(JsonKey.USER_ID));
if (StringUtils.isNotBlank(rootOrgId))
innerMap.put(SunbirdKey.ROOT_ORG_ID, rootOrgId);
reqObj.setRequest(innerMap);
CompletionStage<Result> result = actorResponseHandler(contentConsumptionActor, reqObj, timeout, null, httpRequest);
return result.thenApplyAsync(r -> {
Expand Down
1 change: 1 addition & 0 deletions service/app/util/Attrs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class Attrs {
public static final TypedKey<String> ACTOR_TYPE = TypedKey.<String>create(JsonKey.ACTOR_TYPE);
public static final TypedKey<String> X_AUTH_TOKEN = TypedKey.<String>create(JsonKey.X_AUTH_TOKEN);
public static final TypedKey<String> X_LOGGING_HEADERS = TypedKey.<String>create(JsonKey.X_LOGGING_HEADERS);
public static final TypedKey<String> X_AUTH_USER_ORG_ID = TypedKey.<String>create(JsonKey.X_AUTH_USER_ORG_ID);
}