Add property to enable Notification Sevice async processing 19/123819/2
authorRenu Kumari <renu.kumari@bell.ca>
Thu, 2 Sep 2021 14:30:09 +0000 (10:30 -0400)
committerRenu Kumari <renu.kumari@bell.ca>
Thu, 2 Sep 2021 15:44:57 +0000 (11:44 -0400)
- made notification service synchronous by default
- added new property to enable async processing if required

Issue-ID: CPS-630
Signed-off-by: Renu Kumari <renu.kumari@bell.ca>
Change-Id: I28c2c98d7a79219a5932732d2940f5ac37bf1653

cps-application/src/main/resources/application.yml
cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java
cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy
cps-service/src/test/resources/application.yml

index 82c6e0a..42addf1 100644 (file)
@@ -74,12 +74,14 @@ notification:
         topic: ${CPS_CHANGE_EVENT_TOPIC:cps.data-updated-events}\r
         filters:\r
             enabled-dataspaces: ${NOTIFICATION_DATASPACE_FILTER_PATTERNS:""}\r
-    async-executor:\r
-        core-pool-size: 2\r
-        max-pool-size: 10\r
-        queue-capacity: 500\r
-        wait-for-tasks-to-complete-on-shutdown: true\r
-        thread-name-prefix: Async-\r
+    async:\r
+        enabled: false\r
+        executor:\r
+            core-pool-size: 2\r
+            max-pool-size: 10\r
+            queue-capacity: 500\r
+            wait-for-tasks-to-complete-on-shutdown: true\r
+            thread-name-prefix: Async-\r
 \r
 \r
 springdoc:\r
index 4c96159..2667ef4 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.cps.config;
 
 import javax.validation.constraints.Min;
 import lombok.Setter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -32,7 +33,8 @@ import org.springframework.validation.annotation.Validated;
 
 @EnableAsync
 @Configuration
-@ConfigurationProperties("notification.async-executor")
+@ConditionalOnProperty(name = "notification.async.enabled", havingValue = "true", matchIfMissing = false)
+@ConfigurationProperties("notification.async.executor")
 @Validated
 @Setter
 public class AsyncConfig {
index 875113d..ca704ed 100644 (file)
@@ -36,7 +36,6 @@ import spock.lang.Specification
 import java.util.concurrent.TimeUnit
 
 @SpringBootTest
-@EnableAsync
 @EnableConfigurationProperties
 @ContextConfiguration(classes = [NotificationProperties, NotificationService, NotificationErrorHandler, AsyncConfig])
 class NotificationServiceSpec extends Specification {
@@ -105,10 +104,4 @@ class NotificationServiceSpec extends Specification {
             1 * spyNotificationErrorHandler.onException(_, _, _, _)
     }
 
-    NotificationService createNotificationService(boolean notificationEnabled) {
-        spyNotificationProperties = Spy(notificationProperties)
-        spyNotificationProperties.isEnabled() >> notificationEnabled
-        return new NotificationService(spyNotificationProperties, mockNotificationPublisher,
-            mockCpsDataUpdatedEventFactory, spyNotificationErrorHandler)
-    }
 }
index b1546d7..436c3d4 100644 (file)
@@ -22,10 +22,12 @@ notification:
       enabled-dataspaces: ".*-published,.*-important"
     enabled: true
     topic: cps-event
-  async-executor:
-    core-pool-size: 2
-    max-pool-size: 10
-    queue-capacity: 0
+  async:
+    enabled: true
+    executor:
+      core-pool-size: 2
+      max-pool-size: 10
+      queue-capacity: 0
 
 spring:
   kafka: