summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java2
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java27
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfig.java46
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java14
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java82
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdog.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java3
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy76
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy32
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateBuilderSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/DataSyncWatchdogSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy)88
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy)6
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/SyncUtilsSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/executor/AsyncTaskExecutorSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/executor/AsyncTaskExecutorSpec.groovy)2
20 files changed, 263 insertions, 133 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 e7ffaa624f..0c12875538 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
@@ -171,7 +171,7 @@ public interface NetworkCmProxyDataService {
* @param cmHandleId cm handle id
* @param dataSyncEnabled data sync enabled flag
*/
- void setDataSyncEnabled(String cmHandleId, boolean dataSyncEnabled);
+ void setDataSyncEnabled(String cmHandleId, Boolean dataSyncEnabled);
/**
* Get all cm handle IDs by DMI plugin identifier.
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 b2c71941c5..febd1cf9c5 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
@@ -218,26 +218,29 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
* based on the data sync enabled boolean for the cm handle id provided.
*
* @param cmHandleId cm handle id
- * @param dataSyncEnabled data sync enabled flag
+ * @param dataSyncEnabledTargetValue data sync enabled flag
*/
@Override
- public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabled) {
+ public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) {
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 {
+ if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) {
+ log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabledTargetValue);
+ return;
+ }
+ if (CmHandleState.READY.equals(compositeState.getCmHandleState())) {
final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores()
.getOperationalDataStore().getDataStoreSyncState();
- if (!dataSyncEnabled && dataStoreSyncState == DataStoreSyncState.SYNCHRONIZED) {
+ if (Boolean.FALSE.equals(dataSyncEnabledTargetValue)
+ && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) {
+ // TODO : This is hard-coded for onap dmi that need to be addressed
cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
"/netconf-state", OffsetDateTime.now());
}
- CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabled, compositeState);
- inventoryPersistence.saveCmHandleState(cmHandleId,
- compositeState);
+ CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabledTargetValue, compositeState);
+ inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
+ } else {
+ throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: "
+ + compositeState.getCmHandleState());
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfig.java
new file mode 100644
index 0000000000..a791a3bbd1
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfig.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.config.embeddedcache;
+
+import com.hazelcast.config.MapConfig;
+import java.util.Collection;
+import java.util.Map;
+import org.onap.cps.cache.HazelcastCacheConfig;
+import org.onap.cps.spi.model.ModuleReference;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ModuleSetTagCacheConfig extends HazelcastCacheConfig {
+
+ private static final MapConfig moduleSetTagCacheMapConfig = createMapConfig("moduleSetTagCacheMapConfig");
+
+ /**
+ * Map instance for cached ModulesSetTags.
+ *
+ * @return configured map of ModuleSetTags
+ */
+ @Bean
+ public Map<String, Collection<ModuleReference>> moduleSetTagCache() {
+ return createHazelcastInstance("moduleSetTags", moduleSetTagCacheMapConfig)
+ .getMap("moduleSetTagCache");
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java
index 8b28717db4..62a380ca5c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfig.java
@@ -23,7 +23,6 @@ package org.onap.cps.ncmp.api.impl.config.embeddedcache;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.QueueConfig;
import com.hazelcast.map.IMap;
-import java.util.Set;
import java.util.concurrent.BlockingQueue;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.cache.HazelcastCacheConfig;
@@ -45,8 +44,6 @@ public class SynchronizationCacheConfig extends HazelcastCacheConfig {
private static final MapConfig moduleSyncStartedConfig = createMapConfig("moduleSyncStartedConfig");
private static final MapConfig dataSyncSemaphoresConfig = createMapConfig("dataSyncSemaphoresConfig");
- private static final MapConfig moduleSetTagCacheMapConfig = createMapConfig("moduleSetTagCacheMapConfig");
-
/**
* Module Sync Distributed Queue Instance.
*
@@ -77,15 +74,4 @@ public class SynchronizationCacheConfig extends HazelcastCacheConfig {
public IMap<String, Boolean> dataSyncSemaphores() {
return createHazelcastInstance("dataSyncSemaphores", dataSyncSemaphoresConfig).getMap("dataSyncSemaphores");
}
-
- /**
- * IMap instance for cached ModulesSetTags.
- *
- * @return configured map of ModuleSetTags
- */
- @Bean
- public IMap<String, Set<String>> moduleSetTagCache() {
- return createHazelcastInstance("moduleSetTags", moduleSetTagCacheMapConfig)
- .getMap("moduleSetTagCache");
- }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java
index 8e17ab9166..2ea39e8dc0 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java
@@ -26,7 +26,6 @@ import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DM
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
import java.time.OffsetDateTime;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -65,51 +64,65 @@ public class ModuleSyncService {
private final CmHandleQueries cmHandleQueries;
private final CpsDataService cpsDataService;
private final JsonObjectMapper jsonObjectMapper;
+ private final Map<String, Collection<ModuleReference>> moduleSetTagCache;
+ private static final Map<String, String> NO_NEW_MODULES = Collections.emptyMap();
/**
* This method registers a cm handle and initiates modules sync.
*
- * @param upgradedCmHandle the yang model of cm handle.
+ * @param yangModelCmHandle the yang model of cm handle.
*/
- public void syncAndCreateOrUpgradeSchemaSetAndAnchor(final YangModelCmHandle upgradedCmHandle) {
+ public void syncAndCreateOrUpgradeSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle) {
- final String moduleSetTag = extractModuleSetTag(upgradedCmHandle.getCompositeState());
- final Optional<DataNode> existingCmHandleWithSameModuleSetTag
- = getFirstReadyDataNodeWithModuleSetTag(moduleSetTag);
+ final String moduleSetTag;
+ final String cmHandleId = yangModelCmHandle.getId();
+ final CompositeState compositeState = yangModelCmHandle.getCompositeState();
+ final boolean inUpgrade = isInUpgrade(compositeState);
- if (existingCmHandleWithSameModuleSetTag.isPresent()) {
- upgradeUsingModuleSetTag(upgradedCmHandle, moduleSetTag);
+ if (inUpgrade) {
+ moduleSetTag = extractModuleSetTag(compositeState);
} else {
- syncAndCreateSchemaSetAndAnchor(upgradedCmHandle);
+ moduleSetTag = yangModelCmHandle.getModuleSetTag();
}
- setCmHandleModuleSetTag(upgradedCmHandle, moduleSetTag);
+
+ final Collection<ModuleReference> moduleReferencesFromCache = moduleSetTagCache.get(moduleSetTag);
+
+ if (moduleReferencesFromCache == null) {
+ final Optional<DataNode> optionalExistingCmHandleWithSameModuleSetTag
+ = getFirstReadyDataNodeWithModuleSetTag(moduleSetTag);
+
+ if (optionalExistingCmHandleWithSameModuleSetTag.isPresent()) {
+ final String existingCmHandleAnchorName
+ = optionalExistingCmHandleWithSameModuleSetTag.get().getAnchorName();
+ createOrUpgradeSchemaSetUsingModuleSetTag(cmHandleId, moduleSetTag, existingCmHandleAnchorName);
+ } else {
+ syncAndCreateSchemaSet(yangModelCmHandle, moduleSetTag);
+ }
+ } else {
+ cpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
+ cmHandleId, NO_NEW_MODULES, moduleReferencesFromCache);
+ }
+ if (!inUpgrade) {
+ cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, cmHandleId);
+ }
+ setCmHandleModuleSetTag(yangModelCmHandle, moduleSetTag);
}
- private void syncAndCreateSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle) {
+ private void syncAndCreateSchemaSet(final YangModelCmHandle yangModelCmHandle, final String moduleSetTag) {
final Collection<ModuleReference> allModuleReferencesFromCmHandle =
dmiModelOperations.getModuleReferences(yangModelCmHandle);
-
final Collection<ModuleReference> identifiedNewModuleReferencesFromCmHandle = cpsModuleService
.identifyNewModuleReferences(allModuleReferencesFromCmHandle);
-
final Map<String, String> newModuleNameToContentMap;
if (identifiedNewModuleReferencesFromCmHandle.isEmpty()) {
- newModuleNameToContentMap = Collections.emptyMap();
+ newModuleNameToContentMap = NO_NEW_MODULES;
} else {
newModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle,
identifiedNewModuleReferencesFromCmHandle);
}
- createSchemaSetAndAnchor(yangModelCmHandle, newModuleNameToContentMap, allModuleReferencesFromCmHandle);
- }
-
- private void createSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle,
- final Map<String, String> newModuleNameToContentMap,
- final Collection<ModuleReference> allModuleReferencesFromCmHandle) {
- final String schemaSetAndAnchorName = yangModelCmHandle.getId();
cpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- schemaSetAndAnchorName, newModuleNameToContentMap, allModuleReferencesFromCmHandle);
- cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetAndAnchorName,
- schemaSetAndAnchorName);
+ yangModelCmHandle.getId(), newModuleNameToContentMap, allModuleReferencesFromCmHandle);
+ moduleSetTagCache.put(moduleSetTag, allModuleReferencesFromCmHandle);
}
/**
@@ -147,21 +160,24 @@ public class ModuleSyncService {
jsonObjectMapper.asJsonString(dmiRegistryProperties), OffsetDateTime.now());
}
- private void upgradeUsingModuleSetTag(final YangModelCmHandle upgradedCmHandle, final String moduleSetTag) {
+ private void createOrUpgradeSchemaSetUsingModuleSetTag(final String schemaSetName,
+ final String moduleSetTag,
+ final String existingCmHandleAnchorName) {
log.info("Found cm handle having module set tag: {}", moduleSetTag);
final Collection<ModuleReference> moduleReferencesFromExistingCmHandle =
- cpsModuleService.getYangResourcesModuleReferences(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR);
- final String upgradedSchemaSetAndAnchorName = upgradedCmHandle.getId();
- final Map<String, String> noNewModules = Collections.emptyMap();
+ cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
+ existingCmHandleAnchorName);
cpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- upgradedSchemaSetAndAnchorName, noNewModules, moduleReferencesFromExistingCmHandle);
+ schemaSetName, NO_NEW_MODULES, moduleReferencesFromExistingCmHandle);
+ moduleSetTagCache.put(moduleSetTag, moduleReferencesFromExistingCmHandle);
}
private static String extractModuleSetTag(final CompositeState compositeState) {
- return compositeState.getLockReason() != null && compositeState.getLockReason().getLockReasonCategory()
- == LockReasonCategory.MODULE_UPGRADE
- ? Arrays.stream(compositeState.getLockReason().getDetails().split(":")).toList().get(1).trim()
- : StringUtils.EMPTY;
+ return compositeState.getLockReason().getDetails().split(":")[1].trim();
}
+ private static boolean isInUpgrade(final CompositeState compositeState) {
+ return compositeState.getLockReason() != null && LockReasonCategory.MODULE_UPGRADE.equals(
+ compositeState.getLockReason().getLockReasonCategory());
+ }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdog.java
index 75781eb1b3..bf005051f9 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdog.java
@@ -25,7 +25,6 @@ import com.hazelcast.map.IMap;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -49,7 +48,6 @@ public class ModuleSyncWatchdog {
private final IMap<String, Object> moduleSyncStartedOnCmHandles;
private final ModuleSyncTasks moduleSyncTasks;
private final AsyncTaskExecutor asyncTaskExecutor;
- private final IMap<String, Set<String>> moduleSetTagCache;
private static final int MODULE_SYNC_BATCH_SIZE = 100;
private static final long PREVENT_CPU_BURN_WAIT_TIME_MILLIS = 10;
private static final String VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP = "Started";
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
index d148f371b5..f930d5b71d 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
@@ -34,6 +34,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
+import org.apache.commons.lang3.StringUtils;
import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
@@ -112,7 +113,7 @@ public class YangModelCmHandle {
yangModelCmHandle.setDmiServiceName(dmiServiceName);
yangModelCmHandle.setDmiDataServiceName(dmiDataServiceName);
yangModelCmHandle.setDmiModelServiceName(dmiModelServiceName);
- yangModelCmHandle.setModuleSetTag(moduleSetTag);
+ yangModelCmHandle.setModuleSetTag(moduleSetTag == null ? StringUtils.EMPTY : moduleSetTag);
yangModelCmHandle.setDmiProperties(asYangModelCmHandleProperties(ncmpServiceCmHandle.getDmiProperties()));
yangModelCmHandle.setPublicProperties(asYangModelCmHandleProperties(
ncmpServiceCmHandle.getPublicProperties()));
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy
new file mode 100644
index 0000000000..8a6a32bd8d
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy
@@ -0,0 +1,76 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.config.embeddedcache
+
+import com.hazelcast.config.Config
+import com.hazelcast.core.Hazelcast
+import org.onap.cps.spi.model.ModuleReference
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import spock.lang.Specification
+
+@SpringBootTest(classes = [ModuleSetTagCacheConfig])
+class ModuleSetTagCacheConfigSpec extends Specification {
+
+ @Autowired
+ private Map<String, Collection<ModuleReference>> moduleSetTagCache
+
+ def 'Embedded (hazelcast) caches for module set tag.'() {
+ expect: 'system is able to create an instance of a map to hold module set tags'
+ assert null != moduleSetTagCache
+ and: 'there is at least 1 instance'
+ assert Hazelcast.allHazelcastInstances.size() > 0
+ and: 'hazelcast instance name of module set tag is correct'
+ assert Hazelcast.allHazelcastInstances.name.contains('moduleSetTags')
+ }
+
+ def 'Verify configs of module set tag distributed object.'(){
+ when: 'retrieving the map config of module set tag'
+ def cacheConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config
+ def moduleSetTagMapConfig = cacheConfig.mapConfigs.get('moduleSetTagCacheMapConfig')
+ then: 'the module set tag map config has correct backup counts'
+ assert moduleSetTagMapConfig.backupCount == 3
+ assert moduleSetTagMapConfig.asyncBackupCount == 3
+ }
+
+ def 'Verify deployment network configs of distributed cache of module set tag object.'() {
+ given: 'network config of module set tag cache'
+ def moduleSetTagNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config.networkConfig
+ expect: 'module set tag cache has the correct settings'
+ assert moduleSetTagNetworkConfig.join.autoDetectionConfig.enabled
+ assert !moduleSetTagNetworkConfig.join.kubernetesConfig.enabled
+ }
+
+ def 'Verify network of module set tag cache'() {
+ given: 'Synchronization config object and test configuration'
+ def objectUnderTest = new ModuleSetTagCacheConfig()
+ def testConfig = new Config()
+ when: 'kubernetes properties are enabled'
+ objectUnderTest.cacheKubernetesEnabled = true
+ objectUnderTest.cacheKubernetesServiceName = 'test-service-name'
+ and: 'method called to update the discovery mode'
+ objectUnderTest.updateDiscoveryMode(testConfig)
+ then: 'applied properties are reflected'
+ assert testConfig.networkConfig.join.kubernetesConfig.enabled
+ assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name'
+
+ }
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
index 2fa9606923..501714a2be 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
@@ -44,9 +44,6 @@ class SynchronizationCacheConfigSpec extends Specification {
@Autowired
private IMap<String, Boolean> dataSyncSemaphores
- @Autowired
- private IMap<String, Set<String>> moduleSetTagCache
-
def 'Embedded (hazelcast) Caches for Module and Data Sync.'() {
expect: 'system is able to create an instance of the Module Sync Work Queue'
assert null != moduleSyncWorkQueue
@@ -54,12 +51,10 @@ class SynchronizationCacheConfigSpec extends Specification {
assert null != moduleSyncStartedOnCmHandles
and: 'system is able to create an instance of a map to hold data sync semaphores'
assert null != dataSyncSemaphores
- and: 'system is able to create an instance of a map to hold module set tags'
- assert null != moduleSetTagCache
- and: 'there are at least 4 instances'
- assert Hazelcast.allHazelcastInstances.size() > 3
+ and: 'there are at least 3 instances'
+ assert Hazelcast.allHazelcastInstances.size() > 2
and: 'they have the correct names (in any order)'
- assert Hazelcast.allHazelcastInstances.name.containsAll('moduleSyncWorkQueue', 'moduleSyncStartedOnCmHandles', 'dataSyncSemaphores', 'moduleSetTags')
+ assert Hazelcast.allHazelcastInstances.name.containsAll('moduleSyncWorkQueue', 'moduleSyncStartedOnCmHandles', 'dataSyncSemaphores')
}
def 'Verify configs for Distributed objects'(){
@@ -72,9 +67,6 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'the Data Sync Semaphores Map config'
def dataSyncSemaphoresConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config
def dataSyncSemaphoresMapConfig = dataSyncSemaphoresConfig.mapConfigs.get('dataSyncSemaphoresConfig')
- and: 'the Module Set Tag Map config'
- def moduleSetTagCacheConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config
- def moduleSetTagMapConfig = moduleSetTagCacheConfig.mapConfigs.get('moduleSetTagCacheMapConfig')
expect: 'system created instance with correct config of Module Sync Work Queue'
assert moduleSyncDefaultWorkQueueConfig.backupCount == 3
assert moduleSyncDefaultWorkQueueConfig.asyncBackupCount == 3
@@ -84,15 +76,11 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'Data Sync Semaphore Map has the correct settings'
assert dataSyncSemaphoresMapConfig.backupCount == 3
assert dataSyncSemaphoresMapConfig.asyncBackupCount == 3
- and: 'Module Set Tag Map has the correct settings'
- assert moduleSetTagMapConfig.backupCount == 3
- assert moduleSetTagMapConfig.asyncBackupCount == 3
and: 'all instances are part of same cluster'
def testClusterName = 'cps-and-ncmp-test-caches'
assert moduleSyncWorkQueueConfig.clusterName == testClusterName
assert moduleSyncStartedOnCmHandlesConfig.clusterName == testClusterName
assert dataSyncSemaphoresConfig.clusterName == testClusterName
- assert moduleSetTagCacheConfig.clusterName == testClusterName
}
def 'Verify deployment network configs for Distributed objects'() {
@@ -102,8 +90,6 @@ class SynchronizationCacheConfigSpec extends Specification {
def moduleSyncStartedOnCmHandlesNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncStartedOnCmHandles').config.networkConfig
and: 'the Data Sync Semaphores Map config'
def dataSyncSemaphoresNetworkConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config.networkConfig
- and: 'the Module Set Tag Map config'
- def moduleSetTagNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config.networkConfig
expect: 'system created instance with correct config of Module Sync Work Queue'
assert queueNetworkConfig.join.autoDetectionConfig.enabled
assert !queueNetworkConfig.join.kubernetesConfig.enabled
@@ -113,9 +99,6 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'Data Sync Semaphore Map has the correct settings'
assert dataSyncSemaphoresNetworkConfig.join.autoDetectionConfig.enabled
assert !dataSyncSemaphoresNetworkConfig.join.kubernetesConfig.enabled
- and: 'Module Set Tag Map has the correct settings'
- assert moduleSetTagNetworkConfig.join.autoDetectionConfig.enabled
- assert !moduleSetTagNetworkConfig.join.kubernetesConfig.enabled
}
def 'Verify network config'() {
@@ -151,15 +134,6 @@ class SynchronizationCacheConfigSpec extends Specification {
waitMax2SecondsForKeyExpiration(dataSyncSemaphores, 'testKeyDataSync')
}
- def 'Time to Live Verify for Module Set Tag'() {
- when: 'the key is inserted with a TTL of 1 second'
- moduleSetTagCache.put('testKeyModuleSetTag', ['module-set-tag'] as Set, 1, TimeUnit.SECONDS)
- then: 'the entry is present in the map'
- assert moduleSetTagCache.get('testKeyModuleSetTag') != null
- and: 'the entry expires in less then 2 seconds'
- waitMax2SecondsForKeyExpiration(moduleSetTagCache, 'testKeyModuleSetTag')
- }
-
def waitMax2SecondsForKeyExpiration(map, key) {
def count = 0
while ( map.get(key)!=null && ++count <= 20 ) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy
index a3a5efc748..78b09e6a15 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateBuilderSpec.groovy
index c2cdd9bc2e..777b505b46 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateBuilderSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
import org.onap.cps.ncmp.api.impl.inventory.CompositeState
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateSpec.groovy
index 985bdc5cd4..d8beba8de0 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
index 724f05b1b8..bb4eebd40e 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/DataSyncWatchdogSpec.groovy
index ed313a0ad8..65dfc05791 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/DataSyncWatchdogSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
index a13f595200..18b87af9a1 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -18,11 +18,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE
@@ -32,6 +30,7 @@ import org.onap.cps.spi.model.DataNode
import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
+import org.onap.cps.spi.model.DataNodeBuilder
import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleSyncService
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
@@ -52,38 +51,76 @@ class ModuleSyncServiceSpec extends Specification {
def mockCmHandleQueries = Mock(CmHandleQueries)
def mockCpsDataService = Mock(CpsDataService)
def mockJsonObjectMapper = Mock(JsonObjectMapper)
+ def mockModuleSetTagCache = [:]
def objectUnderTest = new ModuleSyncService(mockDmiModelOperations, mockCpsModuleService, mockCpsAdminService,
- mockCmHandleQueries, mockCpsDataService, mockJsonObjectMapper)
+ mockCmHandleQueries, mockCpsDataService, mockJsonObjectMapper, mockModuleSetTagCache)
def expectedDataspaceName = NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
+ def static cmHandleWithModuleSetTag = new DataNodeBuilder().withXpath("//cm-handles[@module-set-tag='tag-1'][@id='otherId']").withAnchor('otherId').build()
- def 'Sync model for a (new) cm handle with #scenario'() {
- given: 'a cm handle'
+ def 'Sync model for a NEW cm handle without cache with #scenario'() {
+ given: 'a cm handle having some state'
def ncmpServiceCmHandle = new NcmpServiceCmHandle()
- ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().build())
- def dmiServiceName = 'some service name'
- ncmpServiceCmHandle.cmHandleId = 'cmHandleId-1'
- def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle,'')
+ ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.ADVISED).build())
+ ncmpServiceCmHandle.cmHandleId = 'ch-1'
+ def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('some service name', '', '', ncmpServiceCmHandle, moduleSetTag)
and: 'DMI operations returns some module references'
def moduleReferences = [ new ModuleReference('module1','1'), new ModuleReference('module2','2') ]
mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
- and: 'CPS-Core returns list of existing module resources'
- mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> toModuleReference(existingModuleResourcesInCps)
and: 'DMI-Plugin returns resource(s) for "new" module(s)'
mockDmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, [new ModuleReference('module1', '1')]) >> newModuleNameContentToMap
+ and: 'the module service identifies #identifiedNewModuleReferences.size() new modules'
+ mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReferences(identifiedNewModuleReferences)
+ and: 'system contains #existingCmHandlesWithSameTag.size() cm handles with same tag'
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='new-tag-1']",
+ FetchDescendantsOption.OMIT_DESCENDANTS) >> []
when: 'module sync is triggered'
- mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReference(identifiedNewModuleReferences)
objectUnderTest.syncAndCreateOrUpgradeSchemaSetAndAnchor(yangModelCmHandle)
then: 'create schema set from module is invoked with correct parameters'
- 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cmHandleId-1', newModuleNameContentToMap, moduleReferences)
+ 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', newModuleNameContentToMap, moduleReferences)
and: 'anchor is created with the correct parameters'
- 1 * mockCpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cmHandleId-1', 'cmHandleId-1')
+ 1 * mockCpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', 'ch-1')
where: 'the following parameters are used'
- scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap
- 'one new module' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source']
- 'no add. properties' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source']
- 'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:]
+ scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap | moduleSetTag
+ 'one new module' | [['module2': '2'], ['module3': '3']] | [['module1': '1']] | [module1: 'some yang source'] | ''
+ 'no new module' | [['module1': '1'], ['module2': '2']] | [] | [:] | 'new-tag-1'
+ }
+
+ def 'Upgrade model for an existing cm handle with Module Set Tag where the modules are #scenario'() {
+ given: 'a cm handle being upgraded to module set tag: tag-1'
+ def ncmpServiceCmHandle = new NcmpServiceCmHandle()
+ ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withLockReason(MODULE_UPGRADE, 'new moduleSetTag: tag-1').build())
+ def dmiServiceName = 'some service name'
+ ncmpServiceCmHandle.cmHandleId = 'upgraded-ch'
+ def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle,'tag-1')
+ and: 'some module references'
+ def moduleReferences = [ new ModuleReference('module1','1') ]
+ and: 'cache or DMI operations returns some module references for upgraded cm handle'
+ if (populateCache) {
+ mockModuleSetTagCache.put('tag-1',moduleReferences)
+ } else {
+ mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
+ }
+ and: 'none of these module references are new (unknown to the system)'
+ mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> []
+ and: 'CPS-Core returns list of existing module resources for TBD'
+ mockCpsModuleService.getYangResourcesModuleReferences(*_) >> [ new ModuleReference('module1','1') ]
+ and: 'system contains #existingCmHandlesWithSameTag.size() cm handles with same tag'
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='tag-1']", FetchDescendantsOption.OMIT_DESCENDANTS) >> existingCmHandlesWithSameTag
+ and: 'the other cm handle is a state ready'
+ mockCmHandleQueries.cmHandleHasState('otherId', CmHandleState.READY) >> true
+ when: 'module sync is triggered'
+ objectUnderTest.syncAndCreateOrUpgradeSchemaSetAndAnchor(yangModelCmHandle)
+ then: 'create schema set from module is invoked for the upgraded cm handle'
+ 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'upgraded-ch', [:], moduleReferences)
+ and: 'No anchor is created for the upgraded cm handle'
+ 0 * mockCpsAdminService.createAnchor(*_)
+ where: 'the following parameters are used'
+ scenario | populateCache | existingCmHandlesWithSameTag
+ 'new' | false | []
+ 'in cache' | true | []
+ 'in database' | false | [cmHandleWithModuleSetTag]
}
def 'upgrade model for a existing cm handle'() {
@@ -96,7 +133,7 @@ class ModuleSyncServiceSpec extends Specification {
mockCmHandleQueries.cmHandleHasState('cmHandleId-1', CmHandleState.READY) >> true
and: 'the module service returns some module references'
def moduleReferences = [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')]
- mockCpsModuleService.getYangResourcesModuleReferences(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR) >> moduleReferences
+ mockCpsModuleService.getYangResourcesModuleReferences(*_)>> moduleReferences
and: 'a cm handle with the same moduleSetTag can be found in the registry'
mockCmHandleQueries.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='targetModuleSetTag']",
FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'cmHandleId-1\']', leaves: ['id': 'cmHandleId-1', 'cm-handle-state': 'READY'])]
@@ -133,17 +170,12 @@ class ModuleSyncServiceSpec extends Specification {
result == unsupportedOperationException
}
- def 'Extract module set tag with #scenario'() {
+ def 'Extract module set tag'() {
expect: 'the module set tag is extracted correctly'
- assert expectedModuleSetTag == objectUnderTest.extractModuleSetTag(new CompositeStateBuilder().withLockReason(lockReason, 'new moduleSetTag: targetModuleSetTag').build())
- where: 'the following parameters are used'
- scenario | lockReason || expectedModuleSetTag
- 'locked reason is null' | null || ''
- 'locked for other reason' | LOCKED_MISBEHAVING || ''
- 'locked for module upgrade' | MODULE_UPGRADE || 'targetModuleSetTag'
+ assert 'targetModuleSetTag' == objectUnderTest.extractModuleSetTag(new CompositeStateBuilder().withLockReason(MODULE_UPGRADE, 'new moduleSetTag: targetModuleSetTag').build())
}
- def toModuleReference(moduleReferenceAsMap) {
+ def toModuleReferences(moduleReferenceAsMap) {
def moduleReferences = [].withDefault { [:] }
moduleReferenceAsMap.forEach(property ->
property.forEach((moduleName, revision) -> {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy
index 8698136d65..0d927551d0 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
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/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
index 390e88b3d4..7425a52ff1 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/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import com.hazelcast.map.IMap
import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleSyncTasks
@@ -45,9 +45,7 @@ class ModuleSyncWatchdogSpec extends Specification {
def spiedAsyncTaskExecutor = Spy(AsyncTaskExecutor)
- def moduleSetTagCache = Mock(IMap<String, Set<String>>)
-
- def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, moduleSyncWorkQueue , mockModuleSyncStartedOnCmHandles, mockModuleSyncTasks, spiedAsyncTaskExecutor, moduleSetTagCache)
+ def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, moduleSyncWorkQueue , mockModuleSyncStartedOnCmHandles, mockModuleSyncTasks, spiedAsyncTaskExecutor)
void setup() {
spiedAsyncTaskExecutor.setupThreadPool()
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/SyncUtilsSpec.groovy
index df2ad711ed..025d9482d6 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/SyncUtilsSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING
import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy
index 7361948bc6..7760b39cb3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync.config
+package org.onap.cps.ncmp.api.impl.inventory.sync.config
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/executor/AsyncTaskExecutorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/executor/AsyncTaskExecutorSpec.groovy
index b3ed94520a..64ecafefc7 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/executor/AsyncTaskExecutorSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/executor/AsyncTaskExecutorSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync.executor
+package org.onap.cps.ncmp.api.impl.inventory.sync.executor
import org.onap.cps.ncmp.api.impl.inventory.sync.executor.AsyncTaskExecutor
import org.springframework.beans.factory.annotation.Autowired