diff options
author | seanbeirne <sean.beirne@est.tech> | 2024-03-26 10:28:17 +0000 |
---|---|---|
committer | seanbeirne <sean.beirne@est.tech> | 2024-04-12 12:06:59 +0100 |
commit | 6ae429e9975ee752c8d5649b191efd4c94f010b5 (patch) | |
tree | e0af3dab8b491068af08203f9a14290d9a754baf /cps-ncmp-service/src/main | |
parent | 3c8fd515de889c3daaeffb44cac1eb2d8902729c (diff) |
Handle Subscription Response from DMI
Issue-ID: CPS-1972
Change-Id: Idb8ad14f06e365707404d099a4581282d4a0add9
Signed-off-by: seanbeirne <sean.beirne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
2 files changed, 64 insertions, 0 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmNotificationSubscriptionDmiOutEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmNotificationSubscriptionDmiOutEventConsumer.java index ea72fd217b..82ae5467e2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmNotificationSubscriptionDmiOutEventConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmNotificationSubscriptionDmiOutEventConsumer.java @@ -23,16 +23,21 @@ package org.onap.cps.ncmp.api.impl.events.cmsubscription; import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent; import io.cloudevents.CloudEvent; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmNotificationSubscriptionStatus; import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.dmi_to_ncmp.CmNotificationSubscriptionDmiOutEvent; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Component; @Component @Slf4j +@RequiredArgsConstructor public class CmNotificationSubscriptionDmiOutEventConsumer { + private final DmiCmNotificationSubscriptionCacheHandler dmiCmNotificationSubscriptionCacheHandler; + /** * Consume the Cm Notification Subscription event from the dmi-plugin. * @@ -56,7 +61,23 @@ public class CmNotificationSubscriptionDmiOutEventConsumer { final CmNotificationSubscriptionDmiOutEvent cmNotificationSubscriptionDmiOutEvent) { final String subscriptionId = correlationId.split("#")[0]; final String dmiPluginName = correlationId.split("#")[1]; + + if ("ACCEPTED".equals(cmNotificationSubscriptionDmiOutEvent.getData().getStatusMessage())) { + handleCacheStatusPerDmi(subscriptionId, dmiPluginName, CmNotificationSubscriptionStatus.ACCEPTED); + dmiCmNotificationSubscriptionCacheHandler.persistIntoDatabasePerDmi(subscriptionId, dmiPluginName); + } + + if ("REJECTED".equals(cmNotificationSubscriptionDmiOutEvent.getData().getStatusMessage())) { + handleCacheStatusPerDmi(subscriptionId, dmiPluginName, CmNotificationSubscriptionStatus.REJECTED); + } + log.info("Cm Subscription with id : {} handled by the dmi-plugin : {} has the status : {}", subscriptionId, dmiPluginName, cmNotificationSubscriptionDmiOutEvent.getData().getStatusMessage()); } + + private void handleCacheStatusPerDmi(final String subscriptionId, final String dmiPluginName, + final CmNotificationSubscriptionStatus cmNotificationSubscriptionStatus) { + dmiCmNotificationSubscriptionCacheHandler.updateDmiCmNotificationSubscriptionStatusPerDmi(subscriptionId, + dmiPluginName, cmNotificationSubscriptionStatus); + } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/DmiCmNotificationSubscriptionCacheHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/DmiCmNotificationSubscriptionCacheHandler.java index 2f10b1ce1e..8c1cac39dc 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/DmiCmNotificationSubscriptionCacheHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/DmiCmNotificationSubscriptionCacheHandler.java @@ -30,8 +30,10 @@ import java.util.List; import java.util.Map; import java.util.Set; import lombok.RequiredArgsConstructor; +import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmNotificationSubscriptionStatus; import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionDetails; import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionPredicate; +import org.onap.cps.ncmp.api.impl.events.cmsubscription.service.CmNotificationSubscriptionPersistenceService; import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.impl.operations.DatastoreType; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; @@ -42,6 +44,7 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class DmiCmNotificationSubscriptionCacheHandler { + private final CmNotificationSubscriptionPersistenceService cmNotificationSubscriptionPersistenceService; private final Map<String, Map<String, DmiCmNotificationSubscriptionDetails>> cmNotificationSubscriptionCache; private final InventoryPersistence inventoryPersistence; @@ -83,6 +86,46 @@ public class DmiCmNotificationSubscriptionCacheHandler { return dmiCmNotificationSubscriptionDetailsPerDmi; } + /** + * Update status in map of subscription details per DMI. + * + * @param subscriptionId String of subscription Id + * @param dmiServiceName String of dmiServiceName + * @param status String of status + * + */ + public void updateDmiCmNotificationSubscriptionStatusPerDmi( + final String subscriptionId, final String dmiServiceName, final CmNotificationSubscriptionStatus status) { + cmNotificationSubscriptionCache.get(subscriptionId).get(dmiServiceName) + .setCmNotificationSubscriptionStatus(status); + } + + /** + * Persist map of subscription details per DMI. + * + * @param subscriptionId String of subscription Id + * @param dmiServiceName String of dmiServiceName + * + */ + public void persistIntoDatabasePerDmi(final String subscriptionId, final String dmiServiceName) { + final List<DmiCmNotificationSubscriptionPredicate> dmiCmNotificationSubscriptionPredicateList = + cmNotificationSubscriptionCache.get(subscriptionId).get(dmiServiceName) + .getDmiCmNotificationSubscriptionPredicates(); + for (final DmiCmNotificationSubscriptionPredicate dmiCmNotificationSubscriptionPredicate: + dmiCmNotificationSubscriptionPredicateList) { + final DatastoreType datastoreType = dmiCmNotificationSubscriptionPredicate.getDatastoreType(); + final Set<String> cmHandles = dmiCmNotificationSubscriptionPredicate.getTargetCmHandleIds(); + final Set<String> xpaths = dmiCmNotificationSubscriptionPredicate.getXpaths(); + + for (final String cmHandle: cmHandles) { + for (final String xpath: xpaths) { + cmNotificationSubscriptionPersistenceService.addOrUpdateCmNotificationSubscription(datastoreType, + cmHandle, xpath, subscriptionId); + } + } + } + } + private void updateDmiCmNotificationSubscriptionDetailsPerDmi( final String dmiServiceName, final DmiCmNotificationSubscriptionPredicate dmiCmNotificationSubscriptionPredicate, |