diff options
author | mpriyank <priyank.maheshwari@est.tech> | 2022-06-15 14:40:50 +0100 |
---|---|---|
committer | mpriyank <priyank.maheshwari@est.tech> | 2022-06-20 12:52:16 +0100 |
commit | 8a85791b8e38967b637445991caf16160721f4c8 (patch) | |
tree | 8561279e490cc9acba8af6c9b03e92b5c5eead89 /cps-ncmp-service/src/main/java/org/onap | |
parent | 44d933db05217eac411eec4972a0d7c880cf5c4e (diff) |
Publish LCM Events
- Publish LCM Create Event when watchdog process moves the cmHandle state from
ADVISED to READY
- Publish LCM Update Event when public properties are updated, no event
when DMI propertis are updated
- Publish LCM Delete Event when a cmHandle is been removed
- Related test scenarios update
- See User Story CPS-1034 for related sub-tasks
Issue-ID: CPS-1090
Change-Id: I70d81fde7c80794ea13a10cd1f235a7012b20b3c
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
5 files changed, 33 insertions, 4 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index f8cab4f1ca..2c7d92ef40 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -31,6 +31,7 @@ import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMES import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum; import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED; import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters; +import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.DELETE; import java.util.ArrayList; import java.util.Collection; @@ -46,6 +47,7 @@ import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsModuleService; import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService; import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; import org.onap.cps.ncmp.api.impl.operations.DmiOperations; import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; @@ -93,6 +95,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private final NetworkCmProxyCmHandlerQueryService networkCmProxyCmHandlerQueryService; + private final NcmpEventsService ncmpEventsService; + @Override public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( final DmiPluginRegistration dmiPluginRegistration) { @@ -261,6 +265,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandle)); + log.debug("Publishing LCM Delete Event for cmHandleId : {}", cmHandle); + ncmpEventsService.publishNcmpEvent(cmHandle, DELETE); } catch (final DataNodeNotFoundException dataNodeNotFoundException) { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandle, dataNodeNotFoundException.getMessage()); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java index aae2f209ae..1eef4c25f3 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java @@ -27,6 +27,7 @@ import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DAT import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_ANCHOR; import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_PARENT; import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP; +import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.UPDATE; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; @@ -40,6 +41,7 @@ import java.util.regex.Pattern; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; @@ -62,6 +64,8 @@ public class NetworkCmProxyDataServicePropertyHandler { private final CpsDataService cpsDataService; + private final NcmpEventsService ncmpEventsService; + /** * Iterates over incoming ncmpServiceCmHandles and update the dataNodes based on the updated attributes. * The attributes which are not passed will remain as is. @@ -105,6 +109,7 @@ public class NetworkCmProxyDataServicePropertyHandler { private void processUpdates(final DataNode existingCmHandleDataNode, final NcmpServiceCmHandle incomingCmHandle) { if (!incomingCmHandle.getPublicProperties().isEmpty()) { updateProperties(existingCmHandleDataNode, PUBLIC_PROPERTY, incomingCmHandle.getPublicProperties()); + publishLcmEventOnPublicPropertiesUpdate(incomingCmHandle.getCmHandleId()); } if (!incomingCmHandle.getDmiProperties().isEmpty()) { updateProperties(existingCmHandleDataNode, DMI_PROPERTY, incomingCmHandle.getDmiProperties()); @@ -180,6 +185,11 @@ public class NetworkCmProxyDataServicePropertyHandler { return new DataNodeBuilder().withXpath(xpath).withLeaves(ImmutableMap.copyOf(updatedLeaves)).build(); } + private void publishLcmEventOnPublicPropertiesUpdate(final String cmHandleId) { + log.debug("Publishing LCM Update event for cmHandleId : {}", cmHandleId); + ncmpEventsService.publishNcmpEvent(cmHandleId, UPDATE); + } + enum PropertyType { DMI_PROPERTY("additional-properties"), PUBLIC_PROPERTY("public-properties"); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java index 609306f08e..3fca1bae84 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java @@ -20,7 +20,6 @@ package org.onap.cps.ncmp.api.impl.event; -import static org.onap.ncmp.cmhandle.lcm.event.Event.CmhandleState.READY; import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.DELETE; import java.time.ZonedDateTime; @@ -70,7 +69,8 @@ public class NcmpEventsCreator { event.setCmHandleId(eventCorrelationId); if (!DELETE.equals(operation)) { - event.setCmhandleState(READY); + event.setCmhandleState(Event.CmhandleState.fromValue( + ncmpServiceCmHandle.getCompositeState().getCmHandleState().toString())); event.setCmhandleProperties(List.of(ncmpServiceCmHandle.getPublicProperties())); } return event; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java index 045a67a104..3cd4068a9e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java @@ -56,8 +56,11 @@ public class NcmpEventsService { */ public void publishNcmpEvent(final String cmHandleId, final Operation operation) { - final NcmpServiceCmHandle ncmpServiceCmHandle = YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( - inventoryPersistence.getYangModelCmHandle(cmHandleId)); + NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle(); + if (Operation.DELETE != operation) { + ncmpServiceCmHandle = YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( + inventoryPersistence.getYangModelCmHandle(cmHandleId)); + } final NcmpEvent ncmpEvent = ncmpEventsCreator.populateNcmpEvent(cmHandleId, operation, ncmpServiceCmHandle); ncmpEventsPublisher.publishEvent(topicName, cmHandleId, ncmpEvent); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java index dbc7dd4f2c..d6aaa32bef 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java @@ -21,9 +21,12 @@ package org.onap.cps.ncmp.api.inventory.sync; +import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.CREATE; + import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.inventory.CmHandleState; import org.onap.cps.ncmp.api.inventory.CompositeState; @@ -44,8 +47,11 @@ public class ModuleSyncWatchdog { private final ModuleSyncService moduleSyncService; + private final NcmpEventsService ncmpEventsService; + /** * Execute Cm Handle poll which changes the cm handle state from 'ADVISED' to 'READY'. + * Also publish the LCM Create Event when cm handle state is moved to 'READY'. */ @Scheduled(fixedDelayString = "${timers.advised-modules-sync.sleep-time-ms:30000}") public void executeAdvisedCmHandlePoll() { @@ -66,6 +72,10 @@ public class ModuleSyncWatchdog { inventoryPersistence.saveCmHandleState(cmHandleId, compositeState); log.info("{} is now in {} state", cmHandleId, advisedCmHandle.getCompositeState().getCmHandleState()); + if (compositeState.getCmHandleState() == CmHandleState.READY) { + log.debug("Publishing LCM Create Event for cmHandleId : {}", cmHandleId); + ncmpEventsService.publishNcmpEvent(cmHandleId, CREATE); + } advisedCmHandle = syncUtils.getAnAdvisedCmHandle(); } log.debug("No Cm-Handles currently found in an ADVISED state"); |