Skip to content
Snippets Groups Projects
Commit 63a57b7f authored by Chad Leong's avatar Chad Leong :speech_balloon:
Browse files

Merge branch 'collab-aware' into 'master'

added collaboration context

See merge request !321
parents 62376eda 119b6503
No related branches found
No related tags found
1 merge request!321added collaboration context
Pipeline #159869 failed
Showing
with 69 additions and 17 deletions
...@@ -76,7 +76,7 @@ The following software have components provided under the terms of this license: ...@@ -76,7 +76,7 @@ The following software have components provided under the terms of this license:
- Apache Log4j JUL Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-jul) - Apache Log4j JUL Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-jul)
- Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl) - Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl)
- Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) - Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j)
- AssertJ fluent assertions (from ${project.parent.url}#${project.artifactId}, https://repo1.maven.org/maven2/org/assertj/assertj-core) - AssertJ Core (from ${project.organization.url}#${project.artifactId})
- Asynchronous Http Client (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client) - Asynchronous Http Client (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client)
- Asynchronous Http Client Netty Utils (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client-netty-utils) - Asynchronous Http Client Netty Utils (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client-netty-utils)
- AutoValue Annotations (from https://github.com/google/auto/tree/master/value, https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations) - AutoValue Annotations (from https://github.com/google/auto/tree/master/value, https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations)
...@@ -321,8 +321,8 @@ The following software have components provided under the terms of this license: ...@@ -321,8 +321,8 @@ The following software have components provided under the terms of this license:
- proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-iamcredentials-v1) - proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-iamcredentials-v1)
- proto-google-cloud-logging-v2 (from https://github.com/googleapis/java-logging/proto-google-cloud-logging-v2, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2) - proto-google-cloud-logging-v2 (from https://github.com/googleapis/java-logging/proto-google-cloud-logging-v2, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2)
- proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1) - proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1)
- proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos) - proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/gapic-generator-java, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos)
- proto-google-iam-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1) - proto-google-iam-v1 (from https://github.com/googleapis/gapic-generator-java, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1)
- resilience4j (from https://github.com/resilience4j/resilience4j, https://resilience4j.readme.io, ttps://resilience4j.readme.io) - resilience4j (from https://github.com/resilience4j/resilience4j, https://resilience4j.readme.io, ttps://resilience4j.readme.io)
- spring-boot-starter-undertow (from https://spring.io/projects/spring-boot) - spring-boot-starter-undertow (from https://spring.io/projects/spring-boot)
- spring-security-crypto (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security) - spring-security-crypto (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security)
...@@ -353,7 +353,7 @@ BSD-2-Clause ...@@ -353,7 +353,7 @@ BSD-2-Clause
======================================================================== ========================================================================
The following software have components provided under the terms of this license: The following software have components provided under the terms of this license:
- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) - API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java, https://repo1.maven.org/maven2/com/google/api/api-common)
- GAX (Google Api eXtensions) for Java (Core) (from https://repo1.maven.org/maven2/com/google/api/gax) - GAX (Google Api eXtensions) for Java (Core) (from https://repo1.maven.org/maven2/com/google/api/gax)
- GAX (Google Api eXtensions) for Java (HTTP JSON) (from https://repo1.maven.org/maven2/com/google/api/gax-httpjson) - GAX (Google Api eXtensions) for Java (HTTP JSON) (from https://repo1.maven.org/maven2/com/google/api/gax-httpjson)
- GAX (Google Api eXtensions) for Java (gRPC) (from https://repo1.maven.org/maven2/com/google/api/gax-grpc) - GAX (Google Api eXtensions) for Java (gRPC) (from https://repo1.maven.org/maven2/com/google/api/gax-grpc)
...@@ -371,7 +371,7 @@ BSD-3-Clause ...@@ -371,7 +371,7 @@ BSD-3-Clause
======================================================================== ========================================================================
The following software have components provided under the terms of this license: The following software have components provided under the terms of this license:
- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) - API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java, https://repo1.maven.org/maven2/com/google/api/api-common)
- ASM Core (from http://asm.ow2.io/, http://asm.ow2.org/) - ASM Core (from http://asm.ow2.io/, http://asm.ow2.org/)
- AspectJ Weaver (from http://www.aspectj.org, https://www.eclipse.org/aspectj/) - AspectJ Weaver (from http://www.aspectj.org, https://www.eclipse.org/aspectj/)
- Expression Language 3.0 (from http://el-spec.java.net, http://uel.java.net, https://projects.eclipse.org/projects/ee4j.el) - Expression Language 3.0 (from http://el-spec.java.net, http://uel.java.net, https://projects.eclipse.org/projects/ee4j.el)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
package org.opengroup.osdu.notification.provider.azure.messageBus; package org.opengroup.osdu.notification.provider.azure.messageBus;
import com.google.api.client.util.Strings;
import com.microsoft.applicationinsights.TelemetryClient; import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.telemetry.RequestTelemetry; import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
import com.microsoft.azure.servicebus.IMessage; import com.microsoft.azure.servicebus.IMessage;
...@@ -59,13 +60,16 @@ public class ProcessNotification { ...@@ -59,13 +60,16 @@ public class ProcessNotification {
String dataPartitionId = notificationContent.getExtractAttributes().get(DpsHeaders.DATA_PARTITION_ID); String dataPartitionId = notificationContent.getExtractAttributes().get(DpsHeaders.DATA_PARTITION_ID);
String correlationId = notificationContent.getExtractAttributes().get(DpsHeaders.CORRELATION_ID); String correlationId = notificationContent.getExtractAttributes().get(DpsHeaders.CORRELATION_ID);
String collaborationId = null;
if (notificationContent.getExtractAttributes().containsKey("x-collaboration"))
collaborationId = notificationContent.getExtractAttributes().get("x-collaboration");
ConcurrentMap properties = telemetryClient.getContext().getProperties(); ConcurrentMap properties = telemetryClient.getContext().getProperties();
properties.put("correlation-id",correlationId); properties.put("correlation-id",correlationId);
properties.put("data-partition-id", dataPartitionId); properties.put("data-partition-id", dataPartitionId);
if (!Strings.isNullOrEmpty(collaborationId))
MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId)); properties.put("x-collaboration", collaborationId);
dpsHeaders.setThreadContext(dataPartitionId, correlationId); MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId, collaborationId));
dpsHeaders.setThreadContext(dataPartitionId, correlationId, collaborationId);
LOGGER.info("Notification process started for message with id: {}", message.getMessageId()); LOGGER.info("Notification process started for message with id: {}", message.getMessageId());
......
...@@ -15,12 +15,15 @@ ...@@ -15,12 +15,15 @@
package org.opengroup.osdu.notification.provider.azure.messageBus.extractor; package org.opengroup.osdu.notification.provider.azure.messageBus.extractor;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.microsoft.azure.servicebus.IMessage; import com.microsoft.azure.servicebus.IMessage;
import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.notification.provider.azure.models.NotificationRecordsChangedData; import org.opengroup.osdu.notification.provider.azure.models.NotificationRecordsChangedData;
import org.opengroup.osdu.notification.provider.azure.models.NotificationServiceBusRequest; import org.opengroup.osdu.notification.provider.azure.models.NotificationServiceBusRequest;
import org.opengroup.osdu.notification.provider.azure.messageBus.interfaces.IPullRequestBodyExtractor; import org.opengroup.osdu.notification.provider.azure.messageBus.interfaces.IPullRequestBodyExtractor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.context.annotation.ScopedProxyMode;
...@@ -40,7 +43,6 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor ...@@ -40,7 +43,6 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
private NotificationServiceBusRequest notificationRequest; private NotificationServiceBusRequest notificationRequest;
private NotificationRecordsChangedData notificationRecordsChangedData; private NotificationRecordsChangedData notificationRecordsChangedData;
public void InitializeExtractor(IMessage message) { public void InitializeExtractor(IMessage message) {
this.message = message; this.message = message;
...@@ -53,6 +55,9 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor ...@@ -53,6 +55,9 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor
attributes.put("correlation-id", this.notificationRecordsChangedData.getCorrelationId()); attributes.put("correlation-id", this.notificationRecordsChangedData.getCorrelationId());
attributes.put("data-partition-id", this.notificationRecordsChangedData.getDataPartitionId()); attributes.put("data-partition-id", this.notificationRecordsChangedData.getDataPartitionId());
attributes.put("account-id", this.notificationRecordsChangedData.getAccountId()); attributes.put("account-id", this.notificationRecordsChangedData.getAccountId());
if (!Strings.isNullOrEmpty(this.notificationRecordsChangedData.getCollaborationDirectives())) {
attributes.put("x-collaboration", this.notificationRecordsChangedData.getCollaborationDirectives());
}
return attributes; return attributes;
} }
......
...@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Primary; ...@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.google.api.client.util.Strings;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -34,12 +35,14 @@ public class ThreadDpsHeaders extends DpsHeaders { ...@@ -34,12 +35,14 @@ public class ThreadDpsHeaders extends DpsHeaders {
@Autowired @Autowired
private IServiceAccountJwtClient serviceAccountJwtClient; private IServiceAccountJwtClient serviceAccountJwtClient;
public void setThreadContext(String dataPartitionId, String correlationId) { public void setThreadContext(String dataPartitionId, String correlationId, String collaborationId) {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); headers.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId);
headers.put(DpsHeaders.CORRELATION_ID, correlationId); headers.put(DpsHeaders.CORRELATION_ID, correlationId);
String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId); String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId);
headers.put(DpsHeaders.AUTHORIZATION, authToken); headers.put(DpsHeaders.AUTHORIZATION, authToken);
if (!Strings.isNullOrEmpty(collaborationId))
headers.put("x-collaboration", collaborationId);
this.addFromMap(headers); this.addFromMap(headers);
} }
......
...@@ -39,4 +39,7 @@ public class NotificationRecordsChangedData { ...@@ -39,4 +39,7 @@ public class NotificationRecordsChangedData {
@SerializedName("data-partition-id") @SerializedName("data-partition-id")
private String dataPartitionId; private String dataPartitionId;
@SerializedName("x-collaboration")
private String collaborationDirectives;
} }
\ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
package org.opengroup.osdu.notification.provider.azure.util; package org.opengroup.osdu.notification.provider.azure.util;
import com.google.api.client.util.Strings;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import java.util.HashMap; import java.util.HashMap;
...@@ -21,10 +22,12 @@ import java.util.Map; ...@@ -21,10 +22,12 @@ import java.util.Map;
public class MDCContextMap { public class MDCContextMap {
public Map<String, String> getContextMap(String correlationId, String dataPartitionId) { public Map<String, String> getContextMap(String correlationId, String dataPartitionId, String collaborationId) {
final Map<String, String> contextMap = new HashMap<>(); final Map<String, String> contextMap = new HashMap<>();
contextMap.put(DpsHeaders.CORRELATION_ID, correlationId); contextMap.put(DpsHeaders.CORRELATION_ID, correlationId);
contextMap.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); contextMap.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId);
if (!Strings.isNullOrEmpty(collaborationId))
contextMap.put("x-collaboration", collaborationId);
return contextMap; return contextMap;
} }
} }
...@@ -70,8 +70,8 @@ public class ProcessNotificationTest { ...@@ -70,8 +70,8 @@ public class ProcessNotificationTest {
public void init() { public void init() {
requestAttributes.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); requestAttributes.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId);
requestAttributes.put(DpsHeaders.CORRELATION_ID, correlationId); requestAttributes.put(DpsHeaders.CORRELATION_ID, correlationId);
lenient().doNothing().when(dpsHeaders).setThreadContext(dataPartitionId, correlationId); lenient().doNothing().when(dpsHeaders).setThreadContext(dataPartitionId, correlationId, null);
lenient().when(mdcContextMap.getContextMap(dataPartitionId, correlationId)).thenReturn(new HashMap<>()); lenient().when(mdcContextMap.getContextMap(dataPartitionId, correlationId, null)).thenReturn(new HashMap<>());
lenient().when(dpsHeaders.getHeaders()).thenReturn(requestAttributes); lenient().when(dpsHeaders.getHeaders()).thenReturn(requestAttributes);
when(notificationContent.getExtractAttributes()).thenReturn(requestAttributes); when(notificationContent.getExtractAttributes()).thenReturn(requestAttributes);
when(notificationContent.getNotificationId()).thenReturn(notificationId); when(notificationContent.getNotificationId()).thenReturn(notificationId);
......
...@@ -38,6 +38,7 @@ public class ServiceBusRequestBodyExtractorTest { ...@@ -38,6 +38,7 @@ public class ServiceBusRequestBodyExtractorTest {
private static final String dataPartitionId = "opendes"; private static final String dataPartitionId = "opendes";
private static final String correlationId = "908fcf8d-30c5-4c74-a0ae-ab47b48b7a85"; private static final String correlationId = "908fcf8d-30c5-4c74-a0ae-ab47b48b7a85";
private static final String accountId = "ab47b48b7a85-30c5"; private static final String accountId = "ab47b48b7a85-30c5";
private static final String collaborationDirectives = "id=9e1c4e74-3b9b-4b17-a0d5-67766558ec65,application=Test App";
@Test @Test
public void should_throwWhenAttributesAreMissing_extractDataFromRequestBody() { public void should_throwWhenAttributesAreMissing_extractDataFromRequestBody() {
...@@ -65,6 +66,7 @@ public class ServiceBusRequestBodyExtractorTest { ...@@ -65,6 +66,7 @@ public class ServiceBusRequestBodyExtractorTest {
Assert.assertEquals(attributes.get("account-id"), accountId); Assert.assertEquals(attributes.get("account-id"), accountId);
Assert.assertEquals(attributes.get("correlation-id"), correlationId); Assert.assertEquals(attributes.get("correlation-id"), correlationId);
Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId); Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId);
Assert.assertEquals(attributes.get("x-collaboration"), null);
} catch (Exception exception) { } catch (Exception exception) {
fail("Should not Throw AppException"); fail("Should not Throw AppException");
...@@ -72,6 +74,38 @@ public class ServiceBusRequestBodyExtractorTest { ...@@ -72,6 +74,38 @@ public class ServiceBusRequestBodyExtractorTest {
} }
@Test
public void shouldReturnNotificationDataAndAttributesWhenValidRequestBodyWithCollaborationDirectivesProvided() {
IMessage message = getValidMessageWithCollaborationDirectives();
try {
sut.InitializeExtractor(message);
String notificationData = sut.extractDataFromRequestBody();
Assert.assertEquals(notificationData, validData);
Map<String, String> attributes = sut.extractAttributesFromRequestBody();
Assert.assertEquals(attributes.get("account-id"), accountId);
Assert.assertEquals(attributes.get("correlation-id"), correlationId);
Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId);
Assert.assertEquals(attributes.get("x-collaboration"), collaborationDirectives);
} catch (Exception exception) {
fail("Should not Throw AppException");
}
}
private Message getValidMessageWithCollaborationDirectives() {
String body =
" {\n" +
" \"message\": {\n" +
" \"data\":" + validData + ",\n" +
" \"account-id\": \"" + accountId + "\",\n" +
" \"correlation-id\": \"" + correlationId + "\",\n" +
" \"data-partition-id\": \"" + dataPartitionId + "\",\n" +
" \"x-collaboration\": \"" + collaborationDirectives + "\"\n" +
" }\n" +
" }";
return new Message(body);
}
private Message getValidMessage() { private Message getValidMessage() {
String body = String body =
......
...@@ -28,7 +28,7 @@ public class ThreadDpsHeadersTest { ...@@ -28,7 +28,7 @@ public class ThreadDpsHeadersTest {
@Test @Test
public void setThreadContextTest() { public void setThreadContextTest() {
try { try {
threadDpsHeaders.setThreadContext("opendes", "ut"); threadDpsHeaders.setThreadContext("opendes", "ut", null);
assertEquals(threadDpsHeaders.getHeaders().get("data-partition-id"),"opendes"); assertEquals(threadDpsHeaders.getHeaders().get("data-partition-id"),"opendes");
assertEquals(threadDpsHeaders.getHeaders().get("correlation-id"),"ut"); assertEquals(threadDpsHeaders.getHeaders().get("correlation-id"),"ut");
} catch (Exception e) { } catch (Exception e) {
......
...@@ -17,7 +17,7 @@ public class MDCContextMapTest { ...@@ -17,7 +17,7 @@ public class MDCContextMapTest {
@Test @Test
public void getContextMapTest(){ public void getContextMapTest(){
Map<String, String> contextMap = mdcContextMap.getContextMap("ut","opendes"); Map<String, String> contextMap = mdcContextMap.getContextMap("ut","opendes", null);
assertNotNull(contextMap); assertNotNull(contextMap);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment