diff --git a/provider/storage-azure/pom.xml b/provider/storage-azure/pom.xml
index 5c4230f54cad2a8192fc35d5a585b9f6670aeb4d..f8b7ca10c86fb57307948548821272b18e45b0d7 100644
--- a/provider/storage-azure/pom.xml
+++ b/provider/storage-azure/pom.xml
@@ -33,7 +33,7 @@
- 0.0.63
+ 0.6.1
0.6.9
0.8.0-SNAPSHOT
4.12
@@ -95,7 +95,6 @@
org.opengroup.osdu
os-core-common
- ${osdu.oscorecommon.version}
elasticsearch
diff --git a/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/MessageBusImpl.java b/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/MessageBusImpl.java
index 4ef3124fe81cd28fd7d9b235bf4a52f24b9d753d..2b275b97b47c0bd795fba4882f348ef57c69ad8a 100644
--- a/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/MessageBusImpl.java
+++ b/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/MessageBusImpl.java
@@ -20,7 +20,6 @@ import com.microsoft.azure.eventgrid.models.EventGridEvent;
import com.microsoft.azure.servicebus.Message;
import org.joda.time.DateTime;
import org.opengroup.osdu.azure.eventgrid.EventGridTopicStore;
-import org.opengroup.osdu.azure.eventgrid.TopicName;
import org.opengroup.osdu.azure.servicebus.ITopicClientFactory;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
@@ -36,26 +35,21 @@ import java.util.*;
@Component
public class MessageBusImpl implements IMessageBus {
+ private final static String RECORDS_CHANGED_EVENT_SUBJECT = "RecordsChanged";
+ private final static String RECORDS_CHANGED_EVENT_TYPE = "RecordsChanged";
+ private final static String RECORDS_CHANGED_EVENT_DATA_VERSION = "1.0";
+ @Autowired
+ EventGridConfig eventGridConfig;
@Autowired
private ITopicClientFactory topicClientFactory;
-
@Autowired
private EventGridTopicStore eventGridTopicStore;
-
@Autowired
private JaxRsDpsLog logger;
-
@Autowired
@Named("SERVICE_BUS_TOPIC")
private String serviceBusTopic;
- @Autowired
- EventGridConfig eventGridConfig;
-
- private final static String EVENT_SUBJECT = "RecordsChanged";
- private final static String EVENT_TYPE = "RecordsChanged";
- private final static String EVENT_DATA_VERSION = "1.0";
-
@Override
public void publishMessage(DpsHeaders headers, PubSubInfo... messages) {
publishToServiceBus(headers, messages);
@@ -79,11 +73,11 @@ public class MessageBusImpl implements IMessageBus {
String messageId = UUID.randomUUID().toString();
eventsList.add(new EventGridEvent(
messageId,
- EVENT_SUBJECT,
+ RECORDS_CHANGED_EVENT_SUBJECT,
data,
- EVENT_TYPE,
+ RECORDS_CHANGED_EVENT_TYPE,
DateTime.now(),
- EVENT_DATA_VERSION
+ RECORDS_CHANGED_EVENT_DATA_VERSION
));
logger.info("Event generated: " + messageId);
@@ -93,7 +87,7 @@ public class MessageBusImpl implements IMessageBus {
// Event Grid has a capability to publish multiple events in an array. This will have perf implications,
// hence publishing one event at a time. If we are confident about the perf capabilities of consumer services,
// we can publish more more than one event in an array.
- eventGridTopicStore.publishToEventGridTopic(headers.getPartitionId(), TopicName.RECORDS_CHANGED, eventsList);
+ eventGridTopicStore.publishToEventGridTopic(headers.getPartitionId(), eventGridConfig.getTopicName(), eventsList);
}
}
diff --git a/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfig.java b/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfig.java
index 64a2fe795ee206c983c9f24181a407398e6d9ed4..ac34762c500aad329ad8fbaf09ddff58f39cadfc 100644
--- a/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfig.java
+++ b/provider/storage-azure/src/main/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfig.java
@@ -20,19 +20,36 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class EventGridConfig {
+ private boolean publishToEventGridEnabled;
+
+ // The Event Grid Event can be a maximum of 1MB. The batch size manipulation will impact the costing.
+ // https://docs.microsoft.com/en-us/azure/event-grid/event-schema#:~:text=Event%20sources%20send%20events%20to,is%20limited%20to%201%20MB.
+ private Integer eventGridBatchSize;
+
+ private String topicName;
+
+ public EventGridConfig(@Value("#{new Boolean('${azure.publishToEventGrid}')}") boolean publish,
+ @Value("#{new Integer('${azure.eventGridBatchSize}')}") int batchSize,
+ @Value("${azure.eventGrid.topicName}") String topicName) {
+ if (publish) {
+ if ((topicName.isEmpty() || batchSize <= 0)) {
+ throw new RuntimeException("Missing EventGrid Configuration");
+ }
+ }
+ this.publishToEventGridEnabled = publish;
+ this.eventGridBatchSize = batchSize;
+ this.topicName = topicName;
+ }
+
public boolean isPublishingToEventGridEnabled() {
return publishToEventGridEnabled;
}
+ public String getTopicName() {
+ return topicName;
+ }
+
public int getEventGridBatchSize() {
return eventGridBatchSize;
}
-
- @Value("#{new Boolean('${azure.publishToEventGrid:true}')}")
- private boolean publishToEventGridEnabled;
-
- // The Event Grid Event can be a maximum of 1MB. The batch size manipulation will impact the costing.
- // https://docs.microsoft.com/en-us/azure/event-grid/event-schema#:~:text=Event%20sources%20send%20events%20to,is%20limited%20to%201%20MB.
- @Value("#{new Integer('${azure.eventGridBatchSize:10}')}")
- private Integer eventGridBatchSize;
}
diff --git a/provider/storage-azure/src/main/resources/application.properties b/provider/storage-azure/src/main/resources/application.properties
index 49204aafd6a2fc220d7def97f5625bf74bc1b7d9..50f778463fe1d390f97ea61a10b288c9fd5988b2 100644
--- a/provider/storage-azure/src/main/resources/application.properties
+++ b/provider/storage-azure/src/main/resources/application.properties
@@ -72,6 +72,7 @@ redis.database=${REDIS_DATABASE}
# Azure Event Grid Configuration
azure.publishToEventGrid=true
azure.eventGridBatchSize=10
+azure.eventGrid.topicName=recordstopic
#Health checks
management.health.azure-key-vault.enabled=false
diff --git a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/MessageBusImplTest.java b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/MessageBusImplTest.java
index 67fb934da0071a8e25f25338ece0d8f5c172c7e0..dcc267dd2468d2764d8f3d9e34f2cc865441aa35 100644
--- a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/MessageBusImplTest.java
+++ b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/MessageBusImplTest.java
@@ -26,7 +26,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.eventgrid.EventGridTopicStore;
-import org.opengroup.osdu.azure.eventgrid.TopicName;
import org.opengroup.osdu.azure.servicebus.ITopicClientFactory;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
@@ -95,13 +94,14 @@ public class MessageBusImplTest {
}
ArgumentCaptor partitionNameCaptor = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor topicNameArgumentCaptor = ArgumentCaptor.forClass(TopicName.class);
+ ArgumentCaptor topicNameArgumentCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor> listEventGridEventArgumentCaptor = ArgumentCaptor.forClass(List.class);
doNothing().when(this.eventGridTopicStore).publishToEventGridTopic(
partitionNameCaptor.capture(), topicNameArgumentCaptor.capture(), listEventGridEventArgumentCaptor.capture()
);
when(this.eventGridConfig.isPublishingToEventGridEnabled()).thenReturn(true);
when(this.eventGridConfig.getEventGridBatchSize()).thenReturn(5);
+ when(this.eventGridConfig.getTopicName()).thenReturn("recordstopic");
// Act
sut.publishMessage(this.dpsHeaders, pubSubInfo);
@@ -111,7 +111,7 @@ public class MessageBusImplTest {
// The number of events that are being published is verified here.
assertEquals(1, listEventGridEventArgumentCaptor.getValue().size());
- assertEquals(topicNameArgumentCaptor.getValue(), TopicName.RECORDS_CHANGED);
+ assertEquals(topicNameArgumentCaptor.getValue(), "recordstopic");
assertEquals(partitionNameCaptor.getValue(), PARTITION_ID);
// Validate all records are preserved.
diff --git a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfigTest.java b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfigTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f25455cd6fb67261dd698e326df483836df70989
--- /dev/null
+++ b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/di/EventGridConfigTest.java
@@ -0,0 +1,49 @@
+// Copyright © Microsoft Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.opengroup.osdu.storage.provider.azure.di;
+
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@ExtendWith(MockitoExtension.class)
+public class EventGridConfigTest {
+
+ private static String VALID_TOPIC_NAME = "topicname";
+ private static String INVALID_TOPIC_NAME = "";
+ private static int VALID_BATCH_SIZE = 10;
+ private static int INVALID_BATCH_SIZE = 0;
+
+ @Test
+ public void configurationValidationTests() {
+
+ // Positive Case
+ EventGridConfig eventGridConfig = new EventGridConfig(true, VALID_BATCH_SIZE, VALID_TOPIC_NAME);
+ assertEquals(VALID_TOPIC_NAME, eventGridConfig.getTopicName());
+
+ // Negative Cases
+ RuntimeException runtimeException = Assertions.assertThrows(RuntimeException.class,
+ () -> new EventGridConfig(true, VALID_BATCH_SIZE, INVALID_TOPIC_NAME));
+ assertEquals("Missing EventGrid Configuration", runtimeException.getMessage());
+
+ runtimeException = Assertions.assertThrows(RuntimeException.class,
+ () -> new EventGridConfig(true, INVALID_BATCH_SIZE, "topicName"));
+ assertEquals("Missing EventGrid Configuration", runtimeException.getMessage());
+ }
+}