summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main/java')
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java24
-rw-r--r--cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java65
-rw-r--r--cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java26
-rw-r--r--cps-service/src/main/java/org/onap/cps/notification/NotificationPublisher.java7
-rw-r--r--cps-service/src/main/java/org/onap/cps/notification/NotificationService.java15
5 files changed, 115 insertions, 22 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index b45645bc42..8989dc80ef 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -23,6 +23,7 @@
package org.onap.cps.api.impl;
import java.util.Collection;
+import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
@@ -39,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
+@Slf4j
public class CpsDataServiceImpl implements CpsDataService {
private static final String ROOT_NODE_XPATH = "/";
@@ -62,7 +64,7 @@ public class CpsDataServiceImpl implements CpsDataService {
public void saveData(final String dataspaceName, final String anchorName, final String jsonData) {
final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
cpsDataPersistenceService.storeDataNode(dataspaceName, anchorName, dataNode);
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@Override
@@ -70,7 +72,7 @@ public class CpsDataServiceImpl implements CpsDataService {
final String jsonData) {
final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, parentNodeXpath, dataNode);
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@Override
@@ -79,7 +81,7 @@ public class CpsDataServiceImpl implements CpsDataService {
final Collection<DataNode> dataNodesCollection =
buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.addListDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodesCollection);
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@Override
@@ -94,7 +96,7 @@ public class CpsDataServiceImpl implements CpsDataService {
final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService
.updateDataLeaves(dataspaceName, anchorName, dataNode.getXpath(), dataNode.getLeaves());
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@Override
@@ -114,7 +116,7 @@ public class CpsDataServiceImpl implements CpsDataService {
final String jsonData) {
final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode);
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@Override
@@ -123,13 +125,13 @@ public class CpsDataServiceImpl implements CpsDataService {
final Collection<DataNode> dataNodes =
buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.replaceListDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodes);
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@Override
public void deleteListNodeData(final String dataspaceName, final String anchorName, final String listNodeXpath) {
cpsDataPersistenceService.deleteListDataNodes(dataspaceName, anchorName, listNodeXpath);
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(dataspaceName, anchorName);
}
@@ -169,6 +171,14 @@ public class CpsDataServiceImpl implements CpsDataService {
}
+ private void processDataUpdatedEventAsync(final String dataspaceName, final String anchorName) {
+ try {
+ notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+ } catch (final Exception exception) {
+ log.error("Failed to send message to notification service", exception);
+ }
+ }
+
private SchemaContext getSchemaContext(final String dataspaceName, final String schemaSetName) {
return yangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName).getSchemaContext();
}
diff --git a/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java b/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java
new file mode 100644
index 0000000000..4c961598e4
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java
@@ -0,0 +1,65 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2021 Bell Canada.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.config;
+
+import javax.validation.constraints.Min;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.task.TaskExecutor;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.validation.annotation.Validated;
+
+@EnableAsync
+@Configuration
+@ConfigurationProperties("notification.async-executor")
+@Validated
+@Setter
+public class AsyncConfig {
+
+ @Min(0)
+ private int corePoolSize = 2;
+ @Min(2)
+ private int maxPoolSize = 10;
+ @Min(0)
+ private int queueCapacity = Integer.MAX_VALUE;
+ private boolean waitForTasksToCompleteOnShutdown = true;
+ private String threadNamePrefix = "Async-";
+
+ /**
+ * Creates TaskExecutor for processing data-updated events.
+ *
+ * @return TaskExecutor
+ */
+ @Bean("notificationExecutor")
+ public TaskExecutor getThreadAsyncExecutorForNotification() {
+ final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ executor.setCorePoolSize(corePoolSize);
+ executor.setMaxPoolSize(maxPoolSize);
+ executor.setQueueCapacity(queueCapacity);
+ executor.setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown);
+ executor.setThreadNamePrefix(threadNamePrefix);
+ return executor;
+ }
+
+}
diff --git a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
index e1473d3ff9..e0c8fe7055 100644
--- a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
+++ b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
@@ -6,13 +6,15 @@
* 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
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -27,7 +29,6 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.event.model.Content;
import org.onap.cps.event.model.CpsDataUpdatedEvent;
-import org.onap.cps.event.model.CpsDataUpdatedEvent.Schema;
import org.onap.cps.event.model.Data;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.Anchor;
@@ -36,15 +37,17 @@ import org.onap.cps.utils.DataMapUtils;
import org.springframework.stereotype.Component;
@Component
-class CpsDataUpdatedEventFactory {
+public class CpsDataUpdatedEventFactory {
+ private static final URI EVENT_SCHEMA;
private static final URI EVENT_SOURCE;
private static final String EVENT_TYPE = "org.onap.cps.data-updated-event";
private static final DateTimeFormatter dateTimeFormatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
- static {
+ static {
try {
+ EVENT_SCHEMA = new URI("urn:cps:org.onap.cps:data-updated-event-schema:v1");
EVENT_SOURCE = new URI("urn:cps:org.onap.cps");
} catch (final URISyntaxException e) {
// As it is fixed string, I don't expect to see this error
@@ -52,15 +55,22 @@ class CpsDataUpdatedEventFactory {
}
}
- private CpsDataService cpsDataService;
- private CpsAdminService cpsAdminService;
+ private final CpsDataService cpsDataService;
+ private final CpsAdminService cpsAdminService;
public CpsDataUpdatedEventFactory(final CpsDataService cpsDataService, final CpsAdminService cpsAdminService) {
this.cpsDataService = cpsDataService;
this.cpsAdminService = cpsAdminService;
}
- CpsDataUpdatedEvent createCpsDataUpdatedEvent(final String dataspaceName, final String anchorName) {
+ /**
+ * Generates CPS Data Updated event.
+ *
+ * @param dataspaceName dataspaceName
+ * @param anchorName anchorName
+ * @return CpsDataUpdatedEvent
+ */
+ public CpsDataUpdatedEvent createCpsDataUpdatedEvent(final String dataspaceName, final String anchorName) {
final var dataNode = cpsDataService
.getDataNode(dataspaceName, anchorName, "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
@@ -71,7 +81,7 @@ class CpsDataUpdatedEventFactory {
final var cpsDataUpdatedEvent = new CpsDataUpdatedEvent();
cpsDataUpdatedEvent.withContent(createContent(anchor, dataNode));
cpsDataUpdatedEvent.withId(UUID.randomUUID().toString());
- cpsDataUpdatedEvent.withSchema(Schema.URN_CPS_ORG_ONAP_CPS_DATA_UPDATED_EVENT_SCHEMA_1_1_0_SNAPSHOT);
+ cpsDataUpdatedEvent.withSchema(EVENT_SCHEMA);
cpsDataUpdatedEvent.withSource(EVENT_SOURCE);
cpsDataUpdatedEvent.withType(EVENT_TYPE);
return cpsDataUpdatedEvent;
diff --git a/cps-service/src/main/java/org/onap/cps/notification/NotificationPublisher.java b/cps-service/src/main/java/org/onap/cps/notification/NotificationPublisher.java
index 1ab032b57c..2d87488245 100644
--- a/cps-service/src/main/java/org/onap/cps/notification/NotificationPublisher.java
+++ b/cps-service/src/main/java/org/onap/cps/notification/NotificationPublisher.java
@@ -1,12 +1,13 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Copyright (c) 2021 Bell Canada.
* ================================================================================
* 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
+ * 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.
@@ -54,7 +55,7 @@ public class NotificationPublisher {
*
* @param cpsDataUpdatedEvent event to be sent to kafka
*/
- void sendNotification(@NonNull final CpsDataUpdatedEvent cpsDataUpdatedEvent) {
+ public void sendNotification(@NonNull final CpsDataUpdatedEvent cpsDataUpdatedEvent) {
final var messageKey = cpsDataUpdatedEvent.getContent().getDataspaceName() + ","
+ cpsDataUpdatedEvent.getContent().getAnchorName();
log.debug("Data Updated event is being sent with messageKey: '{}' & body : {} ",
diff --git a/cps-service/src/main/java/org/onap/cps/notification/NotificationService.java b/cps-service/src/main/java/org/onap/cps/notification/NotificationService.java
index 9cb2c52e01..4745739a4f 100644
--- a/cps-service/src/main/java/org/onap/cps/notification/NotificationService.java
+++ b/cps-service/src/main/java/org/onap/cps/notification/NotificationService.java
@@ -6,13 +6,15 @@
* 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
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,10 +23,12 @@ package org.onap.cps.notification;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Future;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@Service
@@ -45,12 +49,12 @@ public class NotificationService {
* @param cpsDataUpdatedEventFactory to create CPSDataUpdatedEvent
* @param notificationErrorHandler error handler
*/
- @Autowired
public NotificationService(
final NotificationProperties notificationProperties,
final NotificationPublisher notificationPublisher,
final CpsDataUpdatedEventFactory cpsDataUpdatedEventFactory,
final NotificationErrorHandler notificationErrorHandler) {
+ log.info("Notification Properties {}", notificationProperties);
this.notificationProperties = notificationProperties;
this.notificationPublisher = notificationPublisher;
this.cpsDataUpdatedEventFactory = cpsDataUpdatedEventFactory;
@@ -75,8 +79,10 @@ public class NotificationService {
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
+ * @return future
*/
- public void processDataUpdatedEvent(final String dataspaceName, final String anchorName) {
+ @Async("notificationExecutor")
+ public Future<Void> processDataUpdatedEvent(final String dataspaceName, final String anchorName) {
log.debug("process data updated event for dataspace '{}' & anchor '{}'", dataspaceName, anchorName);
try {
if (shouldSendNotification(dataspaceName)) {
@@ -92,6 +98,7 @@ public class NotificationService {
notificationErrorHandler.onException("Failed to process cps-data-updated-event.",
exception, dataspaceName, anchorName);
}
+ return CompletableFuture.completedFuture(null);
}
/*