aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps-application/src/main/resources/application.yml4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy14
3 files changed, 28 insertions, 7 deletions
diff --git a/cps-application/src/main/resources/application.yml b/cps-application/src/main/resources/application.yml
index d16e977704..e0fb7ef153 100644
--- a/cps-application/src/main/resources/application.yml
+++ b/cps-application/src/main/resources/application.yml
@@ -164,3 +164,7 @@ timers:
sleep-time-ms: 300000
cm-handle-data-sync:
sleep-time-ms: 30000
+
+data-sync:
+ cache:
+ enabled: false \ No newline at end of file
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 0330991fd6..f18d843f81 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
@@ -31,6 +31,7 @@ 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;
@@ -45,6 +46,9 @@ public class ModuleSyncWatchdog {
private final ModuleSyncService moduleSyncService;
+ @Value("${data-sync.cache.enabled:false}")
+ private boolean isGlobalDataSyncCacheEnabled;
+
/**
* Execute Cm Handle poll which changes the cm handle state from 'ADVISED' to 'READY'.
*/
@@ -96,11 +100,9 @@ public class ModuleSyncWatchdog {
private Consumer<CompositeState> setCompositeStateToReadyWithInitialDataStoreSyncState() {
return compositeState -> {
+ compositeState.setDataSyncEnabled(isGlobalDataSyncCacheEnabled);
compositeState.setCmHandleState(CmHandleState.READY);
- final CompositeState.Operational operational = CompositeState.Operational.builder()
- .dataStoreSyncState(DataStoreSyncState.UNSYNCHRONIZED)
- .lastSyncTime(CompositeState.nowInSyncTimeFormat())
- .build();
+ final CompositeState.Operational operational = getDataStoreSyncState(compositeState.getDataSyncEnabled());
final CompositeState.DataStores dataStores = CompositeState.DataStores.builder()
.operationalDataStore(operational)
.build();
@@ -116,4 +118,11 @@ public class ModuleSyncWatchdog {
.details(oldLockReasonDetails).build();
compositeState.setLockReason(lockReason);
}
+
+ private CompositeState.Operational getDataStoreSyncState(final boolean dataSyncEnabled) {
+ final DataStoreSyncState dataStoreSyncState = dataSyncEnabled
+ ? DataStoreSyncState.UNSYNCHRONIZED : DataStoreSyncState.NONE_REQUESTED;
+ return CompositeState.Operational.builder().dataStoreSyncState(dataStoreSyncState).build();
+ }
+
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
index 740a826075..4b92be37ab 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -24,6 +24,7 @@ package org.onap.cps.ncmp.api.inventory.sync
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.DataStoreSyncState
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
@@ -41,12 +42,13 @@ class ModuleSyncWatchdogSpec extends Specification {
def objectUnderTest = new ModuleSyncWatchdog(mockInventoryPersistence, mockSyncUtils, mockModuleSyncService)
- def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() {
- given: 'cm handles in an advised state'
+ def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles where #scenario'() {
+ given: 'cm handles in an advised state and a data sync state'
def compositeState1 = new CompositeState(cmHandleState: cmHandleState)
def compositeState2 = new CompositeState(cmHandleState: cmHandleState)
def yangModelCmHandle1 = new YangModelCmHandle(id: 'some-cm-handle', compositeState: compositeState1)
def yangModelCmHandle2 = new YangModelCmHandle(id: 'some-cm-handle-2', compositeState: compositeState2)
+ objectUnderTest.isGlobalDataSyncCacheEnabled = dataSyncCacheEnabled
and: 'sync utilities return a cm handle twice'
mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null]
when: 'module sync poll is executed'
@@ -57,8 +59,10 @@ class ModuleSyncWatchdogSpec extends Specification {
1 * mockModuleSyncService.deleteSchemaSetIfExists(yangModelCmHandle1)
and: 'module sync service syncs the first cm handle and creates a schema set'
1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle1)
- and: 'the composite state cm handle state is now READY'
+ then: 'the composite state cm handle state is now READY'
assert compositeState1.getCmHandleState() == CmHandleState.READY
+ and: 'the data store sync state returns the expected state'
+ compositeState1.getDataStores().operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState
and: 'the first cm handle state is updated'
1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle', compositeState1)
then: 'the inventory persistence cm handle returns a composite state for the second cm handle'
@@ -69,6 +73,10 @@ class ModuleSyncWatchdogSpec extends Specification {
assert compositeState2.getCmHandleState() == CmHandleState.READY
and: 'the second cm handle state is updated'
1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-2', compositeState2)
+ where:
+ scenario | dataSyncCacheEnabled || expectedDataStoreSyncState
+ 'data sync cache enabled' | true || DataStoreSyncState.UNSYNCHRONIZED
+ 'data sync cache is not enabled' | false || DataStoreSyncState.NONE_REQUESTED
}
def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handle with failure'() {