Commit 9460ba0a authored by harshit aggarwal's avatar harshit aggarwal
Browse files

Minor changes

parent e1a18626
......@@ -56,7 +56,7 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>0.0.17</version>
<version>0.0.19</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
......@@ -134,6 +134,41 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<!-- select non-aggregate reports -->
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
package org.opengroup.osdu.wks.provider.azure.credentials;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.azure.util.AzureServicePrincipal;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
......@@ -24,11 +24,11 @@ public class JwtTokenGenerator implements UserCredential {
private AzureServicePrincipal azureServicePrincipal;
@Autowired
private ILogger logger;
private Slf4JLogger logger;
@Override
public String getIdToken(TenantInfo tenant) throws ApplicationException {
// TODO Tenant based generation of JWT Token, this will be part of the data partitioning work
// Azure service principal will have access to all data partitions
String token = null;
......
......@@ -9,6 +9,7 @@ import com.microsoft.azure.servicebus.primitives.ServiceBusException;
import lombok.Getter;
import org.opengroup.osdu.azure.util.AzureServicePrincipal;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.wks.provider.azure.utils.MDCContextMap;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -97,6 +98,12 @@ public class AzureBootstrapConfig {
return getKeyVaultSecret(kv, "cosmos-primary-key");
}
@Bean
@Named("MDC_CONTEXT_MAP")
public MDCContextMap mdcContextMap() {
return new MDCContextMap();
}
@Bean
@Named("SUBSCRIPTION_CLIENT")
public SubscriptionClient subscriptionClient() {
......
......@@ -4,7 +4,7 @@ import com.microsoft.azure.servicebus.ExceptionPhase;
import com.microsoft.azure.servicebus.IMessage;
import com.microsoft.azure.servicebus.IMessageHandler;
import com.microsoft.azure.servicebus.SubscriptionClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import java.util.Collections;
......@@ -14,10 +14,10 @@ public class MessageHandler implements IMessageHandler {
private final SubscriptionClient receiveClient;
private final ProcessWKSTransform processWKSTransform;
private final ILogger logger;
private final Slf4JLogger logger;
private final AzureBootstrapConfig azureBootstrapConfig;
public MessageHandler(SubscriptionClient client, ProcessWKSTransform processWKSTransform, ILogger logger, AzureBootstrapConfig azureBootstrapConfig) {
public MessageHandler(SubscriptionClient client, ProcessWKSTransform processWKSTransform, Slf4JLogger logger, AzureBootstrapConfig azureBootstrapConfig) {
this.receiveClient = client;
this.processWKSTransform = processWKSTransform;
this.logger = logger;
......
......@@ -4,13 +4,15 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.microsoft.azure.servicebus.IMessage;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
import org.opengroup.osdu.wks.model.RawRecordDetails;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.wks.provider.azure.utils.MDCContextMap;
import org.opengroup.osdu.wks.service.WKSService;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
......@@ -28,14 +30,18 @@ public class ProcessWKSTransform {
private WKSService wKSService;
@Autowired
private ILogger logger;
private Slf4JLogger logger;
@Autowired
private AzureBootstrapConfig azureBootstrapConfig;
@Autowired
private MDCContextMap mdcContextMap;
public boolean initiateWksTransformation(IMessage message) {
String dataPartitionId = message.getProperties().get(DpsHeaders.DATA_PARTITION_ID).toString();
String correlationId = message.getProperties().get(DpsHeaders.CORRELATION_ID).toString();
// MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId));
try {
RawRecordDetails[] rawRecordDetails = retrieveDataFromMessage(message);
......@@ -46,8 +52,10 @@ public class ProcessWKSTransform {
} catch (ApplicationException e) {
logger.error(azureBootstrapConfig.getLogPrefix(), String.format("Application Error Reason: %s, pubsub message id: %s", e.getErrorMsg(),
message.getMessageId()), Collections.emptyMap());
// MDC.clear();
return false;
}
// MDC.clear();
return true;
}
......
......@@ -3,8 +3,9 @@ package org.opengroup.osdu.wks.provider.azure.pubsub;
import com.microsoft.azure.servicebus.MessageHandlerOptions;
import com.microsoft.azure.servicebus.SubscriptionClient;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.wks.provider.azure.utils.MDCAwareThreadPoolExecutor;
import org.opengroup.osdu.wks.provider.interfaces.SubscriptionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -12,12 +13,14 @@ import java.time.Duration;
import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
@Component
public class SubscriptionManagerImpl implements SubscriptionManager {
@Autowired
private ILogger logger;
private Slf4JLogger logger;
@Autowired
private SubscriptionClientFactory subscriptionClientFactory;
......@@ -36,6 +39,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
SubscriptionClient subscriptionClient = this.subscriptionClientFactory.getSubscriptionClient();
ExecutorService executorService = Executors.newFixedThreadPool(Integer.parseUnsignedInt(azureBootstrapConfig.getNThreads()));
//
// int nThreads = Integer.parseUnsignedInt(azureBootstrapConfig.getNThreads());
// ExecutorService executorService = new MDCAwareThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
//
registerMessageHandler(subscriptionClient, executorService);
}
......
......@@ -2,7 +2,7 @@ package org.opengroup.osdu.wks.provider.azure.storage;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.model.MappingsModel;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
......@@ -21,7 +21,7 @@ public class MappingStoreImpl implements MappingStore {
private BlobStore blobStore;
@Autowired
private ILogger logger;
private Slf4JLogger logger;
@Autowired
private AzureBootstrapConfig azureBootstrapConfig;
......
package org.opengroup.osdu.wks.provider.azure.utils;
import org.slf4j.MDC;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class MDCAwareThreadPoolExecutor extends ThreadPoolExecutor {
public MDCAwareThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
@Override
public void execute(Runnable command) {
super.execute(wrapWithMdcContext(command));
}
private Runnable wrapWithMdcContext(Runnable task) {
Map<String, String> contextMap = MDC.getCopyOfContextMap();
return () -> {
setMDCContext(contextMap);
try {
task.run();
} finally {
MDC.clear();
}
};
}
private void setMDCContext(Map<String, String> contextMap) {
MDC.clear();
if (contextMap != null) {
MDC.setContextMap(contextMap);
}
}
}
package org.opengroup.osdu.wks.provider.azure.utils;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import java.util.HashMap;
import java.util.Map;
public class MDCContextMap {
public Map<String, String> getContextMap(String correlationId, String dataPartitionId) {
final Map<String, String> contextMap = new HashMap<>();
contextMap.put(DpsHeaders.CORRELATION_ID, correlationId);
contextMap.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId);
return contextMap;
}
}
......@@ -54,3 +54,8 @@ executor-n-threads=${executor_n_threads}
# Specified the maximum number of concurrent calls to the callback the message pump should initiate
max-concurrent-calls=${max_concurrent_calls}
#logging configuration
logging.transaction.enabled=true
logging.slf4jlogger.enabled=true
#logging.mdccontext.enabled=true
\ No newline at end of file
......@@ -6,8 +6,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.azure.util.AzureServicePrincipal;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
......@@ -43,7 +43,7 @@ public class JwtTokenGeneratorTest {
private AzureBootstrapConfig azureBootstrapConfig;
@Mock
private ILogger logger;
private Slf4JLogger logger;
@BeforeEach
public void init() {
......
......@@ -22,7 +22,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
......@@ -68,7 +68,7 @@ public class ProcessWKSTransformTest {
private AzureBootstrapConfig azureBootstrapConfig;
@Mock
private ILogger logger;
private Slf4JLogger logger;
@BeforeEach
public void init() {
......
......@@ -8,7 +8,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import java.util.Collections;
......@@ -33,7 +33,7 @@ public class SubscriptionManagerImplTest {
private SubscriptionManagerImpl subscriptionManager;
@Mock
private ILogger logger;
private Slf4JLogger logger;
@Mock
private SubscriptionClientFactory subscriptionClientFactory;
......
......@@ -8,7 +8,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.azure.logging.Slf4JLogger;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.model.AttributeMappingModel;
import org.opengroup.osdu.wks.model.MappingsModel;
......@@ -37,7 +37,7 @@ public class MappingStoreImplTest {
private BlobStore blobStore;
@Mock
private ILogger logger;
private Slf4JLogger logger;
@Mock
private AzureBootstrapConfig azureBootstrapConfig;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment