summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
authorRenu Kumari <renu.kumari@bell.ca>2022-01-31 14:01:42 -0500
committerRenu Kumari <renu.kumari@bell.ca>2022-02-07 13:48:25 +0000
commit4125b3266d9cda4a6e37b7efc9caa6bde231405b (patch)
treea46bec1a7a7c02b7acc534113052fed4f5fb2b2b /cps-service/src/main
parente1537e7c389950dd8ad845e46a9e7b647f427eba (diff)
Add support for delete data-node event
- Changed process event input to address delete - Send null data in the event if the operation is DELETE Issue-ID: CPS-791 Signed-off-by: Renu Kumari <renu.kumari@bell.ca> Change-Id: If851f7132e94bcbcaf4324d07a2a00c90d1882b7
Diffstat (limited to 'cps-service/src/main')
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java12
-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/NotificationService.java15
3 files changed, 29 insertions, 24 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 e292bbe77..af06e5fc1 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
@@ -33,6 +33,7 @@ import org.onap.cps.notification.Operation;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.exceptions.DataValidationException;
+import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.utils.YangUtils;
@@ -134,7 +135,9 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void deleteDataNodes(final String dataspaceName, final String anchorName,
final OffsetDateTime observedTimestamp) {
+ final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(anchor, ROOT_NODE_XPATH, Operation.DELETE, observedTimestamp);
}
@Override
@@ -185,9 +188,16 @@ public class CpsDataServiceImpl implements CpsDataService {
private void processDataUpdatedEventAsync(final String dataspaceName, final String anchorName,
final OffsetDateTime observedTimestamp, final String xpath,
final Operation operation) {
+ final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ this.processDataUpdatedEventAsync(anchor, xpath, operation, observedTimestamp);
+ }
+
+ private void processDataUpdatedEventAsync(final Anchor anchor, final String xpath, final Operation operation,
+ final OffsetDateTime observedTimestamp) {
try {
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName, observedTimestamp, xpath, operation);
+ notificationService.processDataUpdatedEvent(anchor, observedTimestamp, xpath, operation);
} catch (final Exception exception) {
+ //If async message can't be queued for notification service, the initial request should not failed.
log.error("Failed to send message to notification service", exception);
}
}
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 6054ce5d7..e7b639d48 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
@@ -25,7 +25,7 @@ import java.net.URISyntaxException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
-import org.onap.cps.api.CpsAdminService;
+import lombok.AllArgsConstructor;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.event.model.Content;
import org.onap.cps.event.model.CpsDataUpdatedEvent;
@@ -38,6 +38,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component
+@AllArgsConstructor(onConstructor = @__(@Lazy))
public class CpsDataUpdatedEventFactory {
private static final URI EVENT_SCHEMA;
@@ -56,29 +57,22 @@ public class CpsDataUpdatedEventFactory {
}
}
+ @Lazy
private final CpsDataService cpsDataService;
- private final CpsAdminService cpsAdminService;
-
- public CpsDataUpdatedEventFactory(@Lazy final CpsDataService cpsDataService,
- final CpsAdminService cpsAdminService) {
- this.cpsDataService = cpsDataService;
- this.cpsAdminService = cpsAdminService;
- }
/**
* Generates CPS Data Updated event. If observedTimestamp is not provided, then current timestamp is used.
*
- * @param dataspaceName dataspaceName
- * @param anchorName anchorName
+ * @param anchor anchor
* @param observedTimestamp observedTimestamp
* @param operation operation
* @return CpsDataUpdatedEvent
*/
- public CpsDataUpdatedEvent createCpsDataUpdatedEvent(final String dataspaceName, final String anchorName,
+ public CpsDataUpdatedEvent createCpsDataUpdatedEvent(final Anchor anchor,
final OffsetDateTime observedTimestamp, final Operation operation) {
- final var dataNode = cpsDataService
- .getDataNode(dataspaceName, anchorName, "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final var dataNode = (operation == Operation.DELETE) ? null :
+ cpsDataService.getDataNode(anchor.getDataspaceName(), anchor.getName(),
+ "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
return toCpsDataUpdatedEvent(anchor, dataNode, observedTimestamp, operation);
}
@@ -105,10 +99,12 @@ public class CpsDataUpdatedEventFactory {
content.withAnchorName(anchor.getName());
content.withDataspaceName(anchor.getDataspaceName());
content.withSchemaSetName(anchor.getSchemaSetName());
- content.withData(createData(dataNode));
content.withOperation(Content.Operation.fromValue(operation.name()));
content.withObservedTimestamp(
DATE_TIME_FORMATTER.format(observedTimestamp == null ? OffsetDateTime.now() : observedTimestamp));
+ if (dataNode != null) {
+ content.withData(createData(dataNode));
+ }
return content;
}
}
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 97a14797b..5ad59df2a 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
@@ -29,6 +29,7 @@ import java.util.concurrent.Future;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.spi.model.Anchor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -80,22 +81,20 @@ public class NotificationService {
/**
* Process Data Updated Event and publishes the notification.
*
- * @param dataspaceName dataspace name
- * @param anchorName anchor name
+ * @param anchor anchor
* @param observedTimestamp observedTimestamp
* @param xpath xpath of changed data node
* @param operation operation
* @return future
*/
@Async("notificationExecutor")
- public Future<Void> processDataUpdatedEvent(final String dataspaceName, final String anchorName,
- final OffsetDateTime observedTimestamp,
+ public Future<Void> processDataUpdatedEvent(final Anchor anchor, final OffsetDateTime observedTimestamp,
final String xpath, final Operation operation) {
- log.debug("process data updated event for dataspace '{}' & anchor '{}'", dataspaceName, anchorName);
+ log.debug("process data updated event for anchor '{}'", anchor);
try {
- if (shouldSendNotification(dataspaceName)) {
+ if (shouldSendNotification(anchor.getDataspaceName())) {
final var cpsDataUpdatedEvent =
- cpsDataUpdatedEventFactory.createCpsDataUpdatedEvent(dataspaceName, anchorName,
+ cpsDataUpdatedEventFactory.createCpsDataUpdatedEvent(anchor,
observedTimestamp, getRootNodeOperation(xpath, operation));
log.debug("data updated event to be published {}", cpsDataUpdatedEvent);
notificationPublisher.sendNotification(cpsDataUpdatedEvent);
@@ -105,7 +104,7 @@ public class NotificationService {
CPS operation should not fail if sending event fails for any reason.
*/
notificationErrorHandler.onException("Failed to process cps-data-updated-event.",
- exception, dataspaceName, anchorName);
+ exception, anchor, xpath, operation);
}
return CompletableFuture.completedFuture(null);
}