Skip to content
Snippets Groups Projects
Commit 8cbf7fd7 authored by Jiman Kim's avatar Jiman Kim
Browse files

Merge branch 'code-quality' into 'master'

fix code quality AWS

See merge request !680
parents 978a56b4 50b8a416
No related branches found
No related tags found
1 merge request!680fix code quality AWS
Pipeline #270919 failed
......@@ -21,7 +21,6 @@ The following software have components provided under the terms of this license:
- Google Guice - Core Library (from https://repo1.maven.org/maven2/com/google/inject/guice)
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Proton-J (from https://repo1.maven.org/maven2/org/apache/qpid/proton-j)
- QpidJMS Client (from https://repo1.maven.org/maven2/org/apache/qpid/qpid-jms-client)
......@@ -83,8 +82,8 @@ The following software have components provided under the terms of this license:
- Byte Buddy (without dependencies) (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy)
- Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent)
- ClassMate (from http://github.com/cowtowncoder/java-classmate)
- Cloud Key Management Service (KMS) API v1-rev20240502-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms)
- Cloud Storage JSON API v1-rev20240319-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage)
- Cloud Key Management Service (KMS) API v1-rev20240613-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms)
- Cloud Storage JSON API v1-rev20240621-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage)
- Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections)
- Commons Digester (from http://commons.apache.org/digester/)
- Converter: Jackson (from https://github.com/square/retrofit, https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson)
......@@ -170,7 +169,6 @@ The following software have components provided under the terms of this license:
- Metrics Core (from https://repo1.maven.org/maven2/io/dropwizard/metrics/metrics-core)
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Azure Java Core Library (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure Netty HTTP Client Library (from https://github.com/Azure/azure-sdk-for-java)
......@@ -388,7 +386,6 @@ The following software have components provided under the terms of this license:
- Jakarta XML Binding API (from https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api, https://repo1.maven.org/maven2/org/jboss/spec/javax/xml/bind/jboss-jaxb-api_2.3_spec)
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Mockito (from http://mockito.org, http://www.mockito.org, https://github.com/mockito/mockito)
- NanoHttpd-Core (from https://repo1.maven.org/maven2/org/nanohttpd/nanohttpd)
......@@ -416,7 +413,6 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
========================================================================
......@@ -441,7 +437,6 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
========================================================================
......@@ -509,7 +504,6 @@ The following software have components provided under the terms of this license:
- Logback Core Module (from http://logback.qos.ch, https://repo1.maven.org/maven2/ch/qos/logback/logback-core)
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
========================================================================
......@@ -538,7 +532,6 @@ The following software have components provided under the terms of this license:
- Expression Language 3.0 (from http://el-spec.java.net, http://uel.java.net, https://projects.eclipse.org/projects/ee4j.el)
- JSR 374 (JSON Processing) API (from https://javaee.github.io/jsonp)
- javax.annotation API (from http://jcp.org/en/jsr/detail?id=250)
- tomcat-embed-core (from http://tomcat.apache.org/)
========================================================================
......@@ -601,7 +594,6 @@ The following software have components provided under the terms of this license:
- Logback Core Module (from http://logback.qos.ch, https://repo1.maven.org/maven2/ch/qos/logback/logback-core)
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
========================================================================
......@@ -641,6 +633,7 @@ The following software have components provided under the terms of this license:
- Cucumber-JVM: Java (from https://repo1.maven.org/maven2/io/cucumber/cucumber-java)
- Cucumber-JVM: Plugin (from https://repo1.maven.org/maven2/io/cucumber/cucumber-plugin)
- Cucumber-JVN: DataTable (from https://repo1.maven.org/maven2/io/cucumber/datatable)
- Extensions on Apache Proton-J library (from https://github.com/Azure/qpid-proton-j-extensions)
- Google Guice - Core Library (from https://repo1.maven.org/maven2/com/google/inject/guice)
- JUL to SLF4J bridge (from http://www.slf4j.org)
- Jackson-core (from http://wiki.fasterxml.com/JacksonHome, https://github.com/FasterXML/jackson-core)
......@@ -648,7 +641,6 @@ The following software have components provided under the terms of this license:
- Java JWT (from http://www.jwt.io, https://github.com/auth0/java-jwt)
- Microsoft Application Insights Java Agent (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Azure Java Core Library (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure Netty HTTP Client Library (from https://github.com/Azure/azure-sdk-for-java)
......@@ -692,7 +684,6 @@ The following software have components provided under the terms of this license:
- msal (from https://github.com/AzureAD/microsoft-authentication-library-for-python)
- msal4j (from https://github.com/AzureAD/microsoft-authentication-library-for-java)
- msal4j-persistence-extension (from https://github.com/AzureAD/microsoft-authentication-extensions-for-java, https://github.com/AzureAD/microsoft-authentication-library-for-java)
- qpid-proton-j-extensions (from https://github.com/Azure/qpid-proton-j-extensions)
- webjars-locator-core (from <http://webjars.org>, http://webjars.org)
========================================================================
......
......@@ -16,13 +16,14 @@ package org.opengroup.osdu.schema.provider.aws.impl.messagebus;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig;
import org.opengroup.osdu.core.aws.sns.PublishRequestBuilder;
import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider;
import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
......@@ -32,6 +33,7 @@ import org.opengroup.osdu.schema.provider.interfaces.messagebus.IMessageBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.model.PublishRequest;
......@@ -82,12 +84,8 @@ public class MessageBusImpl implements IMessageBus {
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getName).collect(Collectors.toList());
for (String tenant : privateTenantList) {
HashMap<String, String> headersMap = new HashMap<>();
headersMap.put(DpsHeaders.ACCOUNT_ID, tenant);
headersMap.put(DpsHeaders.DATA_PARTITION_ID, tenant);
headersMap.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
DpsHeaders headers = DpsHeaders.createFromMap(headersMap);
publishSchemaEvent(schemaId, eventType, headers);
DpsHeaders newHeaders = createTenantHeaders(tenant);
publishSchemaEvent(schemaId, eventType, newHeaders);
}
} catch (Exception ex) {
......@@ -95,6 +93,14 @@ public class MessageBusImpl implements IMessageBus {
}
}
private DpsHeaders createTenantHeaders(String tenant) {
HashMap<String, String> headersMap = new HashMap<>();
headersMap.put(DpsHeaders.ACCOUNT_ID, tenant);
headersMap.put(DpsHeaders.DATA_PARTITION_ID, tenant);
headersMap.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
return DpsHeaders.createFromMap(headersMap);
}
private void publishSchemaEvent(String schemaId, String eventType, DpsHeaders headers) {
PublishRequestBuilder<SchemaPubSubMessage> publishRequestBuilder = new PublishRequestBuilder<>();
......
......@@ -14,24 +14,32 @@
package org.opengroup.osdu.schema.provider.aws.impl.messagebus;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedConstruction;
import org.mockito.Mockito;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.aws.sns.PublishRequestBuilder;
import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.model.PublishRequest;
@RunWith(MockitoJUnitRunner.class)
public class MessageBusImplTest {
......@@ -47,6 +55,12 @@ public class MessageBusImplTest {
@Mock
private AmazonSNS snsClient;
@Mock
private ITenantFactory tenantFactory;
@Mock
private DpsHeaders headers;
@Test
public void publishMessagePublishesMessages() {
......@@ -64,13 +78,21 @@ public class MessageBusImplTest {
@Test
public void publishMessageForSystemSchemaPublishesMessages() {
TenantInfo tenantInfo = new TenantInfo();
tenantInfo.setName("testTenant");
tenantInfo.setDataPartitionId("testPartition");
List<TenantInfo> tenantInfoList = Arrays.asList(tenantInfo);
when(tenantFactory.listTenantInfo()).thenReturn(tenantInfoList);
when(headers.getCorrelationId()).thenReturn("correlationId");
try (MockedConstruction<PublishRequestBuilder> k8sParameterProvider =
Mockito.mockConstruction(PublishRequestBuilder.class, (mock, context) -> {
when(mock.generatePublishRequest(anyString(), anyString(), any())).thenReturn(new PublishRequest());
})) {
messageBusImpl.publishMessage("schemaId", "eventType_create");
messageBusImpl.publishMessageForSystemSchema("schemaId", "eventType_create");
verify(snsClient, times(1)).publish(any());
}
}
......
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