diff options
author | Joseph Keenan <joseph.keenan@est.tech> | 2022-08-02 12:59:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-08-02 12:59:07 +0000 |
commit | 7dfc3a01f327654d64451865ac05b819c5583b27 (patch) | |
tree | 6cf32bf6e0d61055ba26ecad5e3a1a74621d937d /cps-ncmp-service/src/main/java | |
parent | e79e48d75c0a84e7f1b3cef53d29ac89321184ea (diff) | |
parent | 6ddbe4af2b73a306dec89e55b8350c09b8c5766b (diff) |
Merge "Enable/Disable Data Sync for Cm Handle"
Diffstat (limited to 'cps-ncmp-service/src/main/java')
7 files changed, 81 insertions, 18 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java index ea27d4a1e9..3295a6e2b4 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java @@ -154,4 +154,12 @@ public interface NetworkCmProxyDataService { * @return collection of cm handle ids */ Set<String> executeCmHandleIdSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters); + + /** + * Set the data sync enabled flag, along with the data sync state to true or false based on the cm handle id. + * + * @param cmHandleId cm handle id + * @param dataSyncEnabled data sync enabled flag + */ + void setDataSyncEnabled(String cmHandleId, boolean dataSyncEnabled); } 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 28cbf2cc24..8462d687b2 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 @@ -26,6 +26,7 @@ package org.onap.cps.ncmp.api.impl; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum; import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -35,6 +36,7 @@ import java.util.Set; 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.NetworkCmProxyCmHandlerQueryService; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler; @@ -44,6 +46,8 @@ import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; 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; +import org.onap.cps.ncmp.api.inventory.CompositeStateUtils; +import org.onap.cps.ncmp.api.inventory.DataStoreSyncState; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; @@ -52,6 +56,7 @@ 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.spi.exceptions.AlreadyDefinedException; +import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.CmHandleQueryServiceParameters; @@ -79,6 +84,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler; + private final CpsDataService cpsDataService; + @Override public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( final DmiPluginRegistration dmiPluginRegistration) { @@ -182,6 +189,36 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } /** + * Set the data sync enabled flag, along with the data sync state + * based on the data sync enabled boolean for the cm handle id provided. + * + * @param cmHandleId cm handle id + * @param dataSyncEnabled data sync enabled flag + */ + @Override + public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabled) { + CpsValidator.validateNameCharacters(cmHandleId); + final CompositeState compositeState = inventoryPersistence + .getCmHandleState(cmHandleId); + if (compositeState.getDataSyncEnabled().equals(dataSyncEnabled)) { + log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabled); + } else if (compositeState.getCmHandleState() != CmHandleState.READY) { + throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: " + + compositeState.getCmHandleState()); + } else { + final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores() + .getOperationalDataStore().getDataStoreSyncState(); + if (!dataSyncEnabled && dataStoreSyncState == DataStoreSyncState.SYNCHRONIZED) { + cpsDataService.deleteDataNode("NFP-Operational", cmHandleId, + "/netconf-state", OffsetDateTime.now()); + } + CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabled, compositeState); + inventoryPersistence.saveCmHandleState(cmHandleId, + compositeState); + } + } + + /** * Retrieve cm handle details for a given cm handle. * * @param cmHandleId cm handle identifier 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 bd47bea73a..9027a6eb0d 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 @@ -34,7 +34,6 @@ import org.onap.cps.ncmp.api.inventory.CompositeStateUtils; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.ncmp.cmhandle.event.lcm.LcmEvent; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Slf4j @@ -46,14 +45,10 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState private final LcmEventsCreator lcmEventsCreator; private final LcmEventsService lcmEventsService; - @Value("${data-sync.cache.enabled:false}") - private boolean isGlobalDataSyncCacheEnabled; - @Override public void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState targetCmHandleState) { - if (yangModelCmHandle.getCompositeState().getCmHandleState() == targetCmHandleState) { log.debug("CmHandle with id : {} already in state : {}", yangModelCmHandle.getId(), targetCmHandleState); } else { @@ -67,7 +62,7 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState final CmHandleState targetCmHandleState) { if (READY == targetCmHandleState) { - CompositeStateUtils.setCompositeStateToReadyWithInitialDataStoreSyncState(isGlobalDataSyncCacheEnabled) + CompositeStateUtils.setCompositeStateToReadyWithInitialDataStoreSyncState() .accept(yangModelCmHandle.getCompositeState()); inventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState()); } else if (ADVISED == targetCmHandleState) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java index a0fc0c3a91..d6a33302d9 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateBuilder.java @@ -32,6 +32,7 @@ public class CompositeStateBuilder { private LockReason lockReason; private DataStores datastores; private String lastUpdatedTime; + private Boolean dataSyncEnabled; /** * To create the {@link CompositeState}. @@ -44,6 +45,7 @@ public class CompositeStateBuilder { compositeState.setLockReason(lockReason); compositeState.setDataStores(datastores); compositeState.setLastUpdateTime(lastUpdatedTime); + compositeState.setDataSyncEnabled(dataSyncEnabled); return compositeState; } @@ -115,6 +117,9 @@ public class CompositeStateBuilder { this.cmHandleState = CmHandleState.valueOf((String) dataNode.getLeaves() .get("cm-handle-state")); this.lastUpdatedTime = (String) dataNode.getLeaves().get("last-update-time"); + if (this.cmHandleState == CmHandleState.READY) { + this.dataSyncEnabled = (Boolean) dataNode.getLeaves().get("data-sync-enabled"); + } for (final DataNode stateChildNode : dataNode.getChildDataNodes()) { if (stateChildNode.getXpath().endsWith("/lock-reason")) { this.lockReason = getLockReason(stateChildNode); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateUtils.java index 506bd11627..54ca68a0e2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateUtils.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeStateUtils.java @@ -49,10 +49,9 @@ public class CompositeStateUtils { * * @return Updated CompositeState */ - public static Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState( - final boolean isGlobalDataSyncCacheEnabled) { + public static Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState() { return compositeState -> { - compositeState.setDataSyncEnabled(isGlobalDataSyncCacheEnabled); + compositeState.setDataSyncEnabled(false); compositeState.setCmHandleState(CmHandleState.READY); final CompositeState.Operational operational = getInitialDataStoreSyncState(compositeState.getDataSyncEnabled()); @@ -62,6 +61,27 @@ public class CompositeStateUtils { }; } + /** + * Set the data sync enabled flag, along with the data store sync state based on this flag. + * + * @param dataSyncEnabled data sync enabled flag + * @param compositeState cm handle composite state + */ + public static void setDataSyncEnabledFlagWithDataSyncState(final boolean dataSyncEnabled, + final CompositeState compositeState) { + compositeState.setDataSyncEnabled(dataSyncEnabled); + final CompositeState.Operational operational = getInitialDataStoreSyncState(dataSyncEnabled); + final CompositeState.DataStores dataStores = + CompositeState.DataStores.builder().operationalDataStore(operational).build(); + compositeState.setDataStores(dataStores); + } + + /** + * Get initial data sync state based on data sync enabled boolean flag. + * + * @param dataSyncEnabled data sync enabled boolean flag + * @return the data store sync state + */ private static CompositeState.Operational getInitialDataStoreSyncState(final boolean dataSyncEnabled) { final DataStoreSyncState dataStoreSyncState = dataSyncEnabled ? DataStoreSyncState.UNSYNCHRONIZED : DataStoreSyncState.NONE_REQUESTED; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java index adfa33ad81..395fb01f45 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdog.java @@ -58,6 +58,9 @@ public class DataSyncWatchdog { final String resourceData = syncUtils.getResourceData(cmHandleId); if (resourceData == null) { log.debug("Error accessing the node for Cm-Handle: {}", cmHandleId); + } else if (unSynchronizedReadyCmHandle.getCompositeState().getDataSyncEnabled().equals(false)) { + log.debug("Error: data sync enabled for {} must be true." + + "Data sync enabled is currently set to false", cmHandleId); } else { cpsDataService.saveData("NFP-Operational", cmHandleId, resourceData, OffsetDateTime.now()); 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 c71f68f772..37bd1ed0fa 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 @@ -32,7 +32,6 @@ import org.onap.cps.ncmp.api.inventory.CompositeState; import org.onap.cps.ncmp.api.inventory.DataStoreSyncState; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.inventory.LockReasonCategory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -47,9 +46,6 @@ public class ModuleSyncWatchdog { private final ModuleSyncService moduleSyncService; - @Value("${data-sync.cache.enabled:false}") - private boolean isGlobalDataSyncCacheEnabled; - private final ConcurrentMap<String, Boolean> moduleSyncSemaphoreMap; /** @@ -107,9 +103,9 @@ public class ModuleSyncWatchdog { private Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState() { return compositeState -> { - compositeState.setDataSyncEnabled(isGlobalDataSyncCacheEnabled); + compositeState.setDataSyncEnabled(false); compositeState.setCmHandleState(CmHandleState.READY); - final CompositeState.Operational operational = getDataStoreSyncState(compositeState.getDataSyncEnabled()); + final CompositeState.Operational operational = getDataStoreSyncState(); final CompositeState.DataStores dataStores = CompositeState.DataStores.builder() .operationalDataStore(operational) .build(); @@ -126,9 +122,8 @@ public class ModuleSyncWatchdog { compositeState.setLockReason(lockReason); } - private CompositeState.Operational getDataStoreSyncState(final boolean dataSyncEnabled) { - final DataStoreSyncState dataStoreSyncState = dataSyncEnabled - ? DataStoreSyncState.UNSYNCHRONIZED : DataStoreSyncState.NONE_REQUESTED; + private CompositeState.Operational getDataStoreSyncState() { + final DataStoreSyncState dataStoreSyncState = DataStoreSyncState.NONE_REQUESTED; return CompositeState.Operational.builder().dataStoreSyncState(dataStoreSyncState).build(); } |