diff options
author | 2023-10-31 13:16:01 +0000 | |
---|---|---|
committer | 2023-11-02 17:09:19 +0000 | |
commit | f3186cccd519b54fdfe167ee587eea3a91ff5111 (patch) | |
tree | 769c356ee703c18eecbe1efdd75c4cb4d7867bf2 /cps-ncmp-service/src/main | |
parent | f41dd3b24da2cc956c3d6e27fc14e409f11c65c0 (diff) |
Handling Yang module upgrade error scenarios
- cm handle not ready, not found , invalid id
Issue-ID: CPS-1802
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Change-Id: I2039faa44abbda17237e7c2dc085b4ac775c2039
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
5 files changed, 72 insertions, 49 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 4ec00daea..d1ef7faa8 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 @@ -39,6 +39,7 @@ import java.text.MessageFormat; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -48,6 +49,7 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.NcmpResponseStatus; import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler; @@ -72,7 +74,6 @@ import org.onap.cps.ncmp.api.models.DataOperationRequest; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.api.models.UpgradedCmHandles; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.spi.exceptions.CpsException; @@ -127,7 +128,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService dmiPluginRegistrationResponse.setUpgradedCmHandles( parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration)); } - return dmiPluginRegistrationResponse; } @@ -365,33 +365,53 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService protected List<CmHandleRegistrationResponse> parseAndProcessUpgradedCmHandlesInRegistration( final DmiPluginRegistration dmiPluginRegistration) { - final UpgradedCmHandles upgradedCmHandles = dmiPluginRegistration.getUpgradedCmHandles(); - final String moduleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag(); - final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = - new HashMap<>(upgradedCmHandles.getCmHandles().size()); - final Collection<String> notReadyCmHandles = new ArrayList<>(upgradedCmHandles.getCmHandles().size()); - final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle(); - final String formattedModuleSetTag = MessageFormat.format("new moduleSetTag: {0}", moduleSetTag); - - upgradedCmHandles.getCmHandles().forEach(cmHandleId -> { - if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) { - ncmpServiceCmHandle.setCmHandleId(cmHandleId); - ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder() - .withCmHandleState(CmHandleState.READY) - .withLockReason(MODULE_UPGRADE, formattedModuleSetTag).build()); - final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle( - dmiPluginRegistration.getDmiPlugin(), - dmiPluginRegistration.getDmiDataPlugin(), - dmiPluginRegistration.getDmiModelPlugin(), - ncmpServiceCmHandle, - moduleSetTag); - cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED); - } else { - notReadyCmHandles.add(cmHandleId); + final List<String> upgradedCmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles(); + + final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle + = new HashMap<>(upgradedCmHandleIds.size()); + + final Map<NcmpResponseStatus, List<String>> failedCmHandlesPerResponseStatus + = new EnumMap<>(NcmpResponseStatus.class); + final List<String> nonExistingCmHandleIds = new ArrayList<>(); + final List<String> nonReadyCmHandleIds = new ArrayList<>(); + final List<String> invalidCmHandleIds = new ArrayList<>(); + + upgradedCmHandleIds.forEach(cmHandleId -> { + try { + if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) { + final YangModelCmHandle yangModelCmHandleWithUpgradeDetails + = createYangModelCmHandle(dmiPluginRegistration, cmHandleId); + acceptedCmHandleStatePerCmHandle.put(yangModelCmHandleWithUpgradeDetails, CmHandleState.LOCKED); + } else { + nonReadyCmHandleIds.add(cmHandleId); + } + } catch (final DataNodeNotFoundException dataNodeNotFoundException) { + log.error("Unable to find data node for cm handle id : {} , caused by : {}", + cmHandleId, dataNodeNotFoundException.getMessage()); + nonExistingCmHandleIds.add(cmHandleId); + } catch (final DataValidationException dataValidationException) { + log.error("Unable to upgrade cm handle id: {}, caused by : {}", + cmHandleId, dataValidationException.getMessage()); + invalidCmHandleIds.add(cmHandleId); } }); + failedCmHandlesPerResponseStatus.put(CM_HANDLES_NOT_READY, nonReadyCmHandleIds); + failedCmHandlesPerResponseStatus.put(CM_HANDLES_NOT_FOUND, nonExistingCmHandleIds); + failedCmHandlesPerResponseStatus.put(CM_HANDLE_INVALID_ID, invalidCmHandleIds); + return mergeAllCmHandleResponses(acceptedCmHandleStatePerCmHandle, failedCmHandlesPerResponseStatus); + } - return prepareAndGetCmHandleUpgradeResponses(cmHandleStatePerCmHandle, notReadyCmHandles); + private static YangModelCmHandle createYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration, + final String cmHandleId) { + final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle(); + ncmpServiceCmHandle.setCmHandleId(cmHandleId); + final String moduleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag(); + final String lockReasonWithModuleSetTag = MessageFormat.format("ModuleSetTag: {0}", moduleSetTag); + ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY) + .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build()); + return YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration.getDmiPlugin(), + dmiPluginRegistration.getDmiDataPlugin(), dmiPluginRegistration.getDmiModelPlugin(), + ncmpServiceCmHandle, moduleSetTag); } private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) { @@ -453,21 +473,22 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds); } catch (final AlreadyDefinedException alreadyDefinedException) { return CmHandleRegistrationResponse.createFailureResponses( - alreadyDefinedException.getAlreadyDefinedObjectNames(), - CM_HANDLE_ALREADY_EXIST); + alreadyDefinedException.getAlreadyDefinedObjectNames(), CM_HANDLE_ALREADY_EXIST); } catch (final Exception exception) { return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception); } } - private List<CmHandleRegistrationResponse> prepareAndGetCmHandleUpgradeResponses(final Map<YangModelCmHandle, - CmHandleState> cmHandleStatePerCmHandle, final Collection<String> notReadyCmHandles) { - final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses - = upgradeCmHandles(cmHandleStatePerCmHandle); - final List<CmHandleRegistrationResponse> failedCmHandleRegistrationResponses - = CmHandleRegistrationResponse.createFailureResponses(notReadyCmHandles, CM_HANDLES_NOT_READY); - failedCmHandleRegistrationResponses.forEach(cmHandleRegistrationResponses::add); - return cmHandleRegistrationResponses; + private List<CmHandleRegistrationResponse> mergeAllCmHandleResponses( + final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle, + final Map<NcmpResponseStatus, List<String>> failedCmHandlesPerResponseStatus) { + final List<CmHandleRegistrationResponse> cmHandleUpgradeResponses + = upgradeCmHandles(acceptedCmHandleStatePerCmHandle); + failedCmHandlesPerResponseStatus.forEach((ncmpResponseStatus, cmHandleIds) -> { + cmHandleIds.forEach(cmHandleId -> cmHandleUpgradeResponses.add(CmHandleRegistrationResponse + .createFailureResponse(cmHandleId, ncmpResponseStatus))); + }); + return cmHandleUpgradeResponses; } private List<CmHandleRegistrationResponse> upgradeCmHandles(final Map<YangModelCmHandle, CmHandleState> @@ -477,8 +498,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService try { lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds); - } catch (final Exception exception) { - return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception); + } catch (final Exception e) { + log.error("Unable to update cmHandleIds : {} , caused by : {}", cmHandleIds, e.getMessage()); + return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, e); } } 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 401b19036..25ded162b 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 @@ -73,18 +73,15 @@ public class NetworkCmProxyDataServicePropertyHandler { processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); } catch (final DataNodeNotFoundException e) { - log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", - cmHandleId, e.getMessage()); + log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse .createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); } catch (final DataValidationException e) { - log.error("Unable to update cm handle : {}, caused by : {}", - cmHandleId, e.getMessage()); + log.error("Unable to update cm handle : {}, caused by : {}", cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add( CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID)); } catch (final Exception exception) { - log.error("Unable to update cmHandle : {} , caused by : {}", - cmHandleId, exception.getMessage()); + log.error("Unable to update cmHandle : {} , caused by : {}", cmHandleId, exception.getMessage()); cmHandleRegistrationResponses.add( CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception)); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java index e5cf8edd6..419d0a345 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java @@ -40,6 +40,7 @@ import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelFilter; import org.onap.cps.spi.CpsDataPersistenceService; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; +import org.onap.cps.spi.utils.CpsValidator; import org.springframework.stereotype.Component; @RequiredArgsConstructor @@ -50,6 +51,7 @@ public class CmHandleQueriesImpl implements CmHandleQueries { private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles"; private final CpsDataPersistenceService cpsDataPersistenceService; private final Map<String, TrustLevel> trustLevelPerCmHandle; + private final CpsValidator cpsValidator; @Override public Collection<String> queryCmHandleAdditionalProperties(final Map<String, String> privatePropertyQueryPairs) { @@ -154,6 +156,7 @@ public class CmHandleQueriesImpl implements CmHandleQueries { } private DataNode getCmHandleState(final String cmHandleId) { + cpsValidator.validateNameCharacters(cmHandleId); final String xpath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']/state"; return cpsDataPersistenceService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, OMIT_DESCENDANTS).iterator().next(); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasks.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasks.java index c19dbeb90..facaf155f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasks.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasks.java @@ -73,10 +73,9 @@ public class ModuleSyncTasks { yangModelCmHandle.getCompositeState().setLockReason(null); cmHandelStatePerCmHandle.put(yangModelCmHandle, CmHandleState.READY); } catch (final Exception e) { - log.warn("Processing of {} module sync failed due to reason {}.", - cmHandleId, e.getMessage()); - syncUtils.updateLockReasonDetailsAndAttempts(compositeState, - LockReasonCategory.MODULE_SYNC_FAILED, e.getMessage()); + log.warn("Processing of {} module sync failed due to reason {}.", cmHandleId, e.getMessage()); + syncUtils.updateLockReasonDetailsAndAttempts(compositeState, LockReasonCategory.MODULE_SYNC_FAILED, + e.getMessage()); setCmHandleStateLocked(yangModelCmHandle, compositeState.getLockReason()); cmHandelStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java index e007491ce..b0aed5763 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java @@ -26,6 +26,7 @@ import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import lombok.Builder; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -116,7 +117,8 @@ public class CmHandleRegistrationResponse { } public static List<CmHandleRegistrationResponse> createSuccessResponses(final List<String> cmHandleIds) { - return cmHandleIds.stream().map(CmHandleRegistrationResponse::createSuccessResponse).toList(); + return cmHandleIds.stream().map(CmHandleRegistrationResponse::createSuccessResponse) + .collect(Collectors.toList()); } public enum Status { |