package org.onap.cps.ncmp.api.inventory.sync
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
+import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_SYNC_FAILED
+import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE
+import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE_FAILED
+
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.core.read.ListAppender
+import org.onap.cps.ncmp.api.impl.inventory.sync.SyncUtils
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.AnnotationConfigApplicationContext
-
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
-import static org.onap.cps.ncmp.api.inventory.LockReasonCategory.MODULE_SYNC_FAILED
-import static org.onap.cps.ncmp.api.inventory.LockReasonCategory.MODULE_UPGRADE
-import static org.onap.cps.ncmp.api.inventory.LockReasonCategory.MODULE_UPGRADE_FAILED
-
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
-import org.onap.cps.ncmp.api.inventory.CmHandleQueries
-import org.onap.cps.ncmp.api.inventory.CmHandleState
-import org.onap.cps.ncmp.api.inventory.CompositeState
-import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
-import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder
+import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
import org.onap.cps.utils.JsonObjectMapper
def 'Get all locked Cm-Handle where Lock Reason is MODULE_SYNC_FAILED cm handle #scenario'() {
given: 'the cps (persistence service) returns a collection of data nodes'
- mockCmHandleQueries.queryCmHandleDataNodesByCpsPath(
- '//lock-reason[@reason="MODULE_SYNC_FAILED"]',
+ mockCmHandleQueries.queryCmHandleAncestorsByCpsPath(
+ '//lock-reason[@reason="MODULE_SYNC_FAILED" or @reason="MODULE_UPGRADE"]',
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> [dataNode]
when: 'get locked Misbehaving cm handle is called'
- def result = objectUnderTest.getModuleSyncFailedCmHandles()
+ def result = objectUnderTest.getCmHandlesThatFailedModelSyncOrUpgrade()
then: 'the returned cm handle collection is the correct size'
result.size() == 1
and: 'the correct cm handle is returned'
lastUpdatedTime = neverUpdatedBefore
}
when: 'checking to see if cm handle is ready for retry'
- def result = objectUnderTest.needsModuleSyncRetry(new CompositeStateBuilder()
+ def result = objectUnderTest.needsModuleSyncRetryOrUpgrade(new CompositeStateBuilder()
.withLockReason(MODULE_SYNC_FAILED, lockDetails)
.withLastUpdatedTime(lastUpdatedTime).build())
then: 'retry is only attempted when expected'
def 'Retry Locked Cm-Handle with other lock reasons (category) #lockReasonCategory'() {
when: 'checking to see if cm handle is ready for retry'
- def result = objectUnderTest.needsModuleSyncRetry(new CompositeStateBuilder()
+ def result = objectUnderTest.needsModuleSyncRetryOrUpgrade(new CompositeStateBuilder()
.withLockReason(lockReasonCategory, 'some details')
.withLastUpdatedTime(nowAsString).build())
- then: 'retry attempt is never triggered'
- assert result == false
+ then: 'verify retry attempts'
+ assert result == retryAttempt
and: 'logs contain related information'
- def logs = loggingListAppender.list.toString()
- assert logs.contains('Locked for other reason')
+ def logs = loggingListAppender.list.toString()
+ assert logs.contains(logReason)
where: 'the following lock reasons occurred'
- lockReasonCategory << [MODULE_UPGRADE, MODULE_UPGRADE_FAILED]
+ scenario | lockReasonCategory || logReason | retryAttempt
+ 'module upgrade' | MODULE_UPGRADE || 'Locked for module upgrade.' | true
+ 'module sync failed' | MODULE_SYNC_FAILED || 'First Attempt:' | false
}
def 'Get a Cm-Handle where #scenario'() {