summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2022-07-25 09:49:40 +0100
committersourabh_sourabh <sourabh.sourabh@est.tech>2022-07-25 09:49:40 +0100
commit9fdaf6c0f472cad13ade1469458822d468fd2d6d (patch)
tree335596498754c7719b67e5d7e6f272174d39a094 /cps-ncmp-service/src/main
parent71e676dd1cd2ed4ae348cb686dfd6ed96a4fc5b4 (diff)
De-registration: send event(s) using central state
- refactored method "parseAndRemoveCmHandlesInDmiRegistration" - added method to send events for DELETING and DELETED - introduced private method in state handler - updated unit tests for registration spec - added unit test to cover new private method in state handler Issue-ID: CPS-1003 Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech> Change-Id: Ifc1d1e94b7103d85b6352b196edf7075257c211a Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java19
2 files changed, 38 insertions, 15 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 16b9a66f4e..8d32c1ade5 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
@@ -37,6 +37,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler;
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;
@@ -76,6 +77,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private final NetworkCmProxyCmHandlerQueryService networkCmProxyCmHandlerQueryService;
+ private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
+
@Override
public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
final DmiPluginRegistration dmiPluginRegistration) {
@@ -262,32 +265,41 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final List<String> tobeRemovedCmHandles) {
final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
new ArrayList<>(tobeRemovedCmHandles.size());
- for (final String cmHandle : tobeRemovedCmHandles) {
+ for (final String cmHandleId : tobeRemovedCmHandles) {
try {
- CpsValidator.validateNameCharacters(cmHandle);
- inventoryPersistence.deleteSchemaSetWithCascade(cmHandle);
- inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandle + "']");
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandle));
+ CpsValidator.validateNameCharacters(cmHandleId);
+ final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
+ lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle,
+ CmHandleState.DELETING);
+ deleteSchemaSetAndListElementByCmHandleId(cmHandleId);
+ cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
+ lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle,
+ CmHandleState.DELETED);
} catch (final DataNodeNotFoundException dataNodeNotFoundException) {
log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
- cmHandle, dataNodeNotFoundException.getMessage());
+ cmHandleId, dataNodeNotFoundException.getMessage());
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse
- .createFailureResponse(cmHandle, RegistrationError.CM_HANDLE_DOES_NOT_EXIST));
+ .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_DOES_NOT_EXIST));
} catch (final DataValidationException dataValidationException) {
log.error("Unable to de-register cm-handle id: {}, caused by: {}",
- cmHandle, dataValidationException.getMessage());
+ cmHandleId, dataValidationException.getMessage());
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse
- .createFailureResponse(cmHandle, RegistrationError.CM_HANDLE_INVALID_ID));
+ .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_INVALID_ID));
} catch (final Exception exception) {
log.error("Unable to de-register cm-handle id : {} , caused by : {}",
- cmHandle, exception.getMessage());
+ cmHandleId, exception.getMessage());
cmHandleRegistrationResponses.add(
- CmHandleRegistrationResponse.createFailureResponse(cmHandle, exception));
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception));
}
}
return cmHandleRegistrationResponses;
}
+ private void deleteSchemaSetAndListElementByCmHandleId(final String cmHandleId) {
+ inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
+ inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");
+ }
+
private CmHandleRegistrationResponse registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
try {
inventoryPersistence.saveCmHandle(yangModelCmHandle);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java
index 650251f5ae..bd47bea73a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java
@@ -21,6 +21,7 @@
package org.onap.cps.ncmp.api.impl.event.lcm;
import static org.onap.cps.ncmp.api.inventory.CmHandleState.ADVISED;
+import static org.onap.cps.ncmp.api.inventory.CmHandleState.DELETED;
import static org.onap.cps.ncmp.api.inventory.CmHandleState.LOCKED;
import static org.onap.cps.ncmp.api.inventory.CmHandleState.READY;
@@ -75,11 +76,11 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState
} else {
registerNewCmHandle(yangModelCmHandle);
}
+ } else if (DELETED == targetCmHandleState) {
+ setCmHandleState(yangModelCmHandle, targetCmHandleState);
} else {
- CompositeStateUtils.setCompositeState(targetCmHandleState).accept(yangModelCmHandle.getCompositeState());
- inventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState());
+ updateAndSaveCmHandleState(yangModelCmHandle, targetCmHandleState);
}
-
}
private void retryCmHandle(final YangModelCmHandle yangModelCmHandle) {
@@ -88,7 +89,7 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState
}
private void registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
- CompositeStateUtils.setCompositeState(ADVISED).accept(yangModelCmHandle.getCompositeState());
+ setCmHandleState(yangModelCmHandle, ADVISED);
inventoryPersistence.saveCmHandle(yangModelCmHandle);
}
@@ -99,4 +100,14 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState
final LcmEvent lcmEvent = lcmEventsCreator.populateLcmEvent(cmHandleId);
lcmEventsService.publishLcmEvent(cmHandleId, lcmEvent);
}
+
+ private void updateAndSaveCmHandleState(final YangModelCmHandle yangModelCmHandle,
+ final CmHandleState targetCmHandleState) {
+ setCmHandleState(yangModelCmHandle, targetCmHandleState);
+ inventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState());
+ }
+
+ private void setCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState targetCmHandleState) {
+ CompositeStateUtils.setCompositeState(targetCmHandleState).accept(yangModelCmHandle.getCompositeState());
+ }
}