aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-02-21 12:38:05 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-02-21 12:38:05 +0000
commita1ab76467ce2d096e3d51eaf144cfe043ef1c241 (patch)
tree6e6d1d5392cbdd2f246d3f9c0d75a1f0a8148fca /cps-ncmp-service
parent18316c037509c4fddf382d8512c6af620019c7b8 (diff)
Upgrade yang modules using module set tag
- New algorithm is implemented as per the pseudo code -> https://wiki.onap.org/display/DW/CPS-1733%3A+Upgrade+YANG+Schema-Set+for+CM+Handle+Using+a+Module+Set+Tag Issue-ID: CPS-2027 Change-Id: I78fc1c8f927de1a1b814c3c1c62351dda58f2139 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Diffstat (limited to 'cps-ncmp-service')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java88
-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/inventory/sync/ModuleOperationsUtils.java8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java128
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasks.java2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy22
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy4
-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/inventory/sync/ModuleSyncServiceSpec.groovy16
9 files changed, 110 insertions, 280 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 7622e7cb49..1f2748b4af 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
@@ -35,11 +35,9 @@ import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.vali
import com.google.common.collect.Lists;
import com.hazelcast.map.IMap;
-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,8 +46,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
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;
@@ -106,7 +104,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
private final TrustLevelManager trustLevelManager;
private final AlternateIdChecker alternateIdChecker;
- private final Map<String, Collection<ModuleReference>> moduleSetTagCache;
@Override
public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
@@ -344,16 +341,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
new ArrayList<>(tobeRemovedCmHandles.size());
final Collection<YangModelCmHandle> yangModelCmHandles =
inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles);
- final Set<String> moduleSetTags = yangModelCmHandles.stream().map(YangModelCmHandle::getModuleSetTag)
- .collect(Collectors.toSet());
updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING);
final Set<String> notDeletedCmHandles = new HashSet<>();
for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) {
try {
batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch);
- moduleSetTags.forEach(moduleSetTagCache::remove);
- log.debug("Removed module set tags: {}", moduleSetTags);
tobeRemovedCmHandleBatch.forEach(cmHandleId ->
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)));
@@ -417,53 +410,55 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final DmiPluginRegistration dmiPluginRegistration) {
final List<String> upgradedCmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles();
-
+ final String upgradedModuleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle
= new HashMap<>(upgradedCmHandleIds.size());
+ final List<CmHandleRegistrationResponse> cmHandleUpgradeResponses = new ArrayList<>(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 -> {
+ for (final String cmHandleId : upgradedCmHandleIds) {
try {
- if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
- final YangModelCmHandle yangModelCmHandleWithUpgradeDetails
- = createYangModelCmHandle(dmiPluginRegistration, cmHandleId);
- acceptedCmHandleStatePerCmHandle.put(yangModelCmHandleWithUpgradeDetails, CmHandleState.LOCKED);
+ final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
+ if (yangModelCmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY) {
+ if (moduleUpgradeCanBeSkipped(yangModelCmHandle, upgradedModuleSetTag)) {
+ cmHandleUpgradeResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
+ } else {
+ updateYangModelCmHandleForUpgrade(yangModelCmHandle, upgradedModuleSetTag);
+ acceptedCmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
+ }
} else {
- nonReadyCmHandleIds.add(cmHandleId);
+ cmHandleUpgradeResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_READY));
}
} catch (final DataNodeNotFoundException dataNodeNotFoundException) {
log.error("Unable to find data node for cm handle id : {} , caused by : {}",
cmHandleId, dataNodeNotFoundException.getMessage());
- nonExistingCmHandleIds.add(cmHandleId);
+ cmHandleUpgradeResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND));
} catch (final DataValidationException dataValidationException) {
log.error("Unable to upgrade cm handle id: {}, caused by : {}",
cmHandleId, dataValidationException.getMessage());
- invalidCmHandleIds.add(cmHandleId);
+ cmHandleUpgradeResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID));
}
- });
- 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);
- }
-
- 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(
- ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT, moduleSetTag);
- ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY)
+ }
+ cmHandleUpgradeResponses.addAll(upgradeCmHandles(acceptedCmHandleStatePerCmHandle));
+ return cmHandleUpgradeResponses;
+ }
+
+ private static boolean moduleUpgradeCanBeSkipped(final YangModelCmHandle yangModelCmHandle,
+ final String upgradedModuleSetTag) {
+ if (StringUtils.isBlank(upgradedModuleSetTag)) {
+ return false;
+ }
+ return yangModelCmHandle.getModuleSetTag().equals(upgradedModuleSetTag);
+ }
+
+ private static void updateYangModelCmHandleForUpgrade(final YangModelCmHandle yangModelCmHandle,
+ final String upgradedModuleSetTag) {
+ final String lockReasonWithModuleSetTag = String.format(ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT,
+ upgradedModuleSetTag);
+ yangModelCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY)
.withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build());
- return YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration.getDmiPlugin(),
- dmiPluginRegistration.getDmiDataPlugin(), dmiPluginRegistration.getDmiModelPlugin(),
- ncmpServiceCmHandle, moduleSetTag, ncmpServiceCmHandle.getAlternateId());
}
private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
@@ -533,17 +528,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
}
- 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>
cmHandleStatePerCmHandle) {
final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
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
deleted file mode 100644
index a791a3bbd1..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfig.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ============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/inventory/sync/ModuleOperationsUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java
index 7b2e3d589f..9f95131cf1 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java
@@ -62,9 +62,9 @@ public class ModuleOperationsUtils {
private final JsonObjectMapper jsonObjectMapper;
private static final String RETRY_ATTEMPT_KEY = "attempt";
private static final String MODULE_SET_TAG_KEY = "moduleSetTag";
- public static final String MODULE_SET_TAG_MESSAGE_FORMAT = "Upgrade to ModuleSetTag: {0}";
- private static final String UPGRADE_FORMAT = "Upgrade to ModuleSetTag: %s";
- private static final String LOCK_REASON_DETAILS_MSG_FORMAT = UPGRADE_FORMAT + " Attempt #%d failed: %s";
+ public static final String MODULE_SET_TAG_MESSAGE_FORMAT = "Upgrade to ModuleSetTag: %s";
+ private static final String LOCK_REASON_DETAILS_MSG_FORMAT =
+ MODULE_SET_TAG_MESSAGE_FORMAT + " Attempt #%d failed: %s";
private static final Pattern retryAttemptPattern = Pattern.compile("Attempt #(\\d+) failed:.+");
private static final Pattern moduleSetTagPattern = Pattern.compile("Upgrade to ModuleSetTag: (\\S+)");
private static final String CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE = """
@@ -220,7 +220,7 @@ public class ModuleOperationsUtils {
* @param compositeState current lock reason of cm handle
* @return true or false based on lock reason category
*/
- public static boolean isInUpgradeOrUpgradeFailed(final CompositeState compositeState) {
+ public static boolean inUpgradeOrUpgradeFailed(final CompositeState compositeState) {
return compositeState.getLockReason() != null
&& (LockReasonCategory.MODULE_UPGRADE.equals(compositeState.getLockReason().getLockReasonCategory())
|| LockReasonCategory.MODULE_UPGRADE_FAILED.equals(compositeState.getLockReason()
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 d4ef5c612a..8b70798eb1 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
@@ -35,12 +35,12 @@ import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
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.operations.DmiModelOperations;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
@@ -63,7 +63,6 @@ public class ModuleSyncService {
private final CpsDataService cpsDataService;
private final CpsAnchorService cpsAnchorService;
private final JsonObjectMapper jsonObjectMapper;
- private final Map<String, Collection<ModuleReference>> moduleSetTagCache;
private static final Map<String, String> NO_NEW_MODULES = Collections.emptyMap();
/**
@@ -73,44 +72,27 @@ public class ModuleSyncService {
*/
public void syncAndCreateOrUpgradeSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle) {
+ final boolean inUpgrade = ModuleOperationsUtils.inUpgradeOrUpgradeFailed(yangModelCmHandle.getCompositeState());
+
+ final ImmutableTriple<String, Map<String, String>, Collection<ModuleReference>>
+ allModuleReferencesAndNewModuleNameByModuleSetTag
+ = getAllModuleReferencesAndNewYangResourcesByModuleSetTag(yangModelCmHandle, inUpgrade);
+
+ final String moduleSetTag = allModuleReferencesAndNewModuleNameByModuleSetTag.getLeft();
+ final Map<String, String> newYangResources = allModuleReferencesAndNewModuleNameByModuleSetTag.getMiddle();
+ final Collection<ModuleReference> allModuleReferences
+ = allModuleReferencesAndNewModuleNameByModuleSetTag.getRight();
final String cmHandleId = yangModelCmHandle.getId();
- final CompositeState compositeState = yangModelCmHandle.getCompositeState();
- final boolean inUpgrade = ModuleOperationsUtils.isInUpgradeOrUpgradeFailed(compositeState);
- final String moduleSetTag = getModuleSetTag(yangModelCmHandle, compositeState, inUpgrade);
-
- final Collection<ModuleReference> moduleReferencesFromCache = moduleSetTagCache.get(moduleSetTag);
-
- if (moduleReferencesFromCache == null) {
- final Optional<DataNode> existingCmHandleWithSameModuleSetTag
- = getFirstReadyDataNodeWithModuleSetTag(moduleSetTag);
-
- if (existingCmHandleWithSameModuleSetTag.isPresent()) {
- final String existingAnchorName = existingCmHandleWithSameModuleSetTag.get().getAnchorName();
- final Collection<ModuleReference> moduleReferencesFromExistingCmHandle =
- upgradeOrCreateSchemaSetUsingModuleSetTag(yangModelCmHandle.getId(), moduleSetTag,
- existingAnchorName, inUpgrade);
- updateModuleSetTagCache(moduleSetTag, moduleReferencesFromExistingCmHandle);
- } else {
- if (inUpgrade) {
- deleteSchemaSetIfExists(cmHandleId);
- }
- final Collection<ModuleReference> allModuleReferencesFromCmHandle
- = syncAndCreateSchemaSet(yangModelCmHandle);
- updateModuleSetTagCache(moduleSetTag, allModuleReferencesFromCmHandle);
- }
+
+ if (inUpgrade) {
+ cpsModuleService.upgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
+ newYangResources, allModuleReferences);
+ setCmHandleModuleSetTag(yangModelCmHandle, moduleSetTag);
} else {
- if (inUpgrade) {
- cpsModuleService.upgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
- NO_NEW_MODULES, moduleReferencesFromCache);
- } else {
- cpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- cmHandleId, NO_NEW_MODULES, moduleReferencesFromCache);
- }
- }
- if (!inUpgrade) {
+ cpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
+ newYangResources, allModuleReferences);
cpsAnchorService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, cmHandleId);
}
- setCmHandleModuleSetTag(yangModelCmHandle, moduleSetTag);
}
/**
@@ -128,7 +110,30 @@ public class ModuleSyncService {
}
}
- private Optional<DataNode> getFirstReadyDataNodeWithModuleSetTag(final String moduleSetTag) {
+ private ImmutableTriple<String, Map<String, String>, Collection<ModuleReference>>
+ getAllModuleReferencesAndNewYangResourcesByModuleSetTag(final YangModelCmHandle yangModelCmHandle,
+ final boolean inUpgrade) {
+
+ final String moduleSetTag = getModuleSetTag(yangModelCmHandle, inUpgrade);
+ final Collection<ModuleReference> allModuleReferences;
+ Map<String, String> newYangResources = Collections.emptyMap();
+
+ final Optional<DataNode> optionalDataNode = getFirstReadyDataNodeByModuleSetTagProvidedInDb(moduleSetTag);
+
+ if (optionalDataNode.isPresent()) {
+ log.info("Found other cm handle having same module set tag: {}", moduleSetTag);
+ final String otherAnchorWithSameModuleSetTag
+ = YangDataConverter.extractCmHandleIdFromXpath(optionalDataNode.get().getXpath());
+ allModuleReferences = cpsModuleService.getYangResourcesModuleReferences(
+ NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, otherAnchorWithSameModuleSetTag);
+ } else {
+ allModuleReferences = dmiModelOperations.getModuleReferences(yangModelCmHandle);
+ newYangResources = getNewModuleNameToContentMap(yangModelCmHandle, allModuleReferences);
+ }
+ return ImmutableTriple.of(moduleSetTag, newYangResources, allModuleReferences);
+ }
+
+ private Optional<DataNode> getFirstReadyDataNodeByModuleSetTagProvidedInDb(final String moduleSetTag) {
final List<DataNode> dataNodes = StringUtils.isNotBlank(moduleSetTag) ? cmHandleQueries
.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='" + moduleSetTag + "']",
FetchDescendantsOption.OMIT_DESCENDANTS) : Collections.emptyList();
@@ -148,55 +153,26 @@ public class ModuleSyncService {
jsonObjectMapper.asJsonString(dmiRegistryProperties), OffsetDateTime.now());
}
- private Collection<ModuleReference> syncAndCreateSchemaSet(final YangModelCmHandle yangModelCmHandle) {
- final Collection<ModuleReference> allModuleReferencesFromCmHandle =
- dmiModelOperations.getModuleReferences(yangModelCmHandle);
- final Collection<ModuleReference> identifiedNewModuleReferencesFromCmHandle = cpsModuleService
- .identifyNewModuleReferences(allModuleReferencesFromCmHandle);
+ private Map<String, String> getNewModuleNameToContentMap(final YangModelCmHandle yangModelCmHandle,
+ final Collection<ModuleReference> moduleReferences) {
+ final Collection<ModuleReference> identifiedNewModuleReferences = cpsModuleService
+ .identifyNewModuleReferences(moduleReferences);
final Map<String, String> newModuleNameToContentMap;
- if (identifiedNewModuleReferencesFromCmHandle.isEmpty()) {
+ if (identifiedNewModuleReferences.isEmpty()) {
newModuleNameToContentMap = NO_NEW_MODULES;
} else {
newModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle,
- identifiedNewModuleReferencesFromCmHandle);
- }
- cpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- yangModelCmHandle.getId(), newModuleNameToContentMap, allModuleReferencesFromCmHandle);
- return allModuleReferencesFromCmHandle;
- }
-
- private Collection<ModuleReference> upgradeOrCreateSchemaSetUsingModuleSetTag(final String schemaSetName,
- final String moduleSetTag,
- final String existingAnchorName,
- final boolean inUpgrade) {
- log.info("Found cm handle having module set tag: {}", moduleSetTag);
- final Collection<ModuleReference> moduleReferencesFromExistingCmHandle =
- cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- existingAnchorName);
- if (inUpgrade) {
- cpsModuleService.upgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
- NO_NEW_MODULES, moduleReferencesFromExistingCmHandle);
- } else {
- cpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- schemaSetName, NO_NEW_MODULES, moduleReferencesFromExistingCmHandle);
+ identifiedNewModuleReferences);
}
- return moduleReferencesFromExistingCmHandle;
+ return newModuleNameToContentMap;
}
- private String getModuleSetTag(final YangModelCmHandle yangModelCmHandle,
- final CompositeState compositeState,
- final boolean inUpgrade) {
+ private String getModuleSetTag(final YangModelCmHandle yangModelCmHandle, final boolean inUpgrade) {
if (inUpgrade) {
- return ModuleOperationsUtils.getUpgradedModuleSetTagFromLockReason(compositeState.getLockReason());
+ return ModuleOperationsUtils.getUpgradedModuleSetTagFromLockReason(
+ yangModelCmHandle.getCompositeState().getLockReason());
}
return yangModelCmHandle.getModuleSetTag();
}
- private void updateModuleSetTagCache(final String moduleSetTag,
- final Collection<ModuleReference> allModuleReferencesFromCmHandle) {
- if (StringUtils.isNotBlank(moduleSetTag)) {
- moduleSetTagCache.putIfAbsent(moduleSetTag, allModuleReferencesFromCmHandle);
- }
- }
-
}
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 e214044189..804653a168 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
@@ -67,7 +67,7 @@ public class ModuleSyncTasks {
final YangModelCmHandle yangModelCmHandle =
YangDataConverter.convertCmHandleToYangModel(cmHandleAsDataNode, cmHandleId);
final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
- final boolean inUpgrade = ModuleOperationsUtils.isInUpgradeOrUpgradeFailed(compositeState);
+ final boolean inUpgrade = ModuleOperationsUtils.inUpgradeOrUpgradeFailed(compositeState);
try {
if (!inUpgrade) {
moduleSyncService.deleteSchemaSetIfExists(cmHandleId);
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
index 572adb8f0f..313d1b4afd 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
@@ -21,14 +21,14 @@
package org.onap.cps.ncmp.api.impl
-import java.util.stream.Collectors
-
import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID
import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR
+import java.util.stream.Collectors
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker
import org.onap.cps.ncmp.api.models.UpgradedCmHandles
@@ -72,7 +72,6 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def mockTrustLevelManager = Mock(TrustLevelManager)
def mockAlternateIdChecker = Mock(AlternateIdChecker)
def objectUnderTest = getObjectUnderTest()
- def mockModuleSetTagCache = [:]
def setup() {
// always accept all cm handles
@@ -89,6 +88,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag'))
and: 'cm handles are persisted'
mockInventoryPersistence.getYangModelCmHandles(['cmhandle-2']) >> [new YangModelCmHandle()]
+ mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> new YangModelCmHandle(id: 'cmhandle-3', moduleSetTag: '', compositeState: new CompositeState(cmHandleState: CmHandleState.READY))
and: 'cm handle is in READY state'
mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> true
when: 'registration is processed'
@@ -96,7 +96,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
then: 'cm-handles are removed first'
1 * objectUnderTest.parseAndProcessDeletedCmHandlesInRegistration(*_)
and: 'de-registered cm handle entry is removed from in progress map'
- 2 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2')
+ 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2')
then: 'cm-handles are created'
1 * objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(*_)
then: 'cm-handles are updated'
@@ -110,15 +110,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag'))
and: 'exception while checking cm handle state'
- mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> isReady
+ mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> new YangModelCmHandle(id: 'cmhandle-3', moduleSetTag: '', compositeState: new CompositeState(cmHandleState: cmHandleState))
when: 'registration is processed'
def result = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration)
then: 'upgrade operation contains expected error code'
- assert result.upgradedCmHandles.status[0] == expectedResponseStatus
+ assert result.upgradedCmHandles[0].status == expectedResponseStatus
where: 'the following parameters are used'
- scenario | isReady || expectedResponseStatus
- 'READY' | true || Status.SUCCESS
- 'Not READY' | false || Status.FAILURE
+ scenario | cmHandleState || expectedResponseStatus
+ 'READY' | CmHandleState.READY || Status.SUCCESS
+ 'Not READY' | CmHandleState.LOCKED || Status.FAILURE
}
def 'DMI Registration upgrade with exception #scenario'() {
@@ -126,7 +126,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag'))
and: 'exception while checking cm handle state'
- mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> { throw exception }
+ mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> { throw exception }
when: 'registration is processed'
def result = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration)
then: 'upgrade operation contains expected error code'
@@ -453,7 +453,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCmHandleQueries,
stubbedNetworkCmProxyCmHandlerQueryService, mockLcmEventsCmHandleStateHandler, mockCpsDataService,
- mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin, mockTrustLevelManager, mockAlternateIdChecker, mockModuleSetTagCache))
+ mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin, mockTrustLevelManager, mockAlternateIdChecker))
}
def addPersistedYangModelCmHandles(ids) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 9221f31866..fc548ebe9b 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -81,7 +81,6 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def stubTrustLevelPerDmiPlugin = Stub(Map<String, TrustLevel>)
def mockTrustLevelManager = Mock(TrustLevelManager)
def mockAlternateIdChecker = Mock(AlternateIdChecker)
- def mockModuleSetTagCache = [:]
def NO_TOPIC = null
def NO_REQUEST_ID = null
@@ -100,8 +99,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
stubModuleSyncStartedOnCmHandles,
stubTrustLevelPerDmiPlugin,
mockTrustLevelManager,
- mockAlternateIdChecker,
- mockModuleSetTagCache)
+ mockAlternateIdChecker)
def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
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
deleted file mode 100644
index 8a6a32bd8d..0000000000
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * ============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/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
index de783ed2ca..b0ff6d886a 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -50,10 +50,9 @@ class ModuleSyncServiceSpec extends Specification {
def mockCmHandleQueries = Mock(CmHandleQueries)
def mockCpsDataService = Mock(CpsDataService)
def mockJsonObjectMapper = Mock(JsonObjectMapper)
- def mockModuleSetTagCache = [:]
def objectUnderTest = new ModuleSyncService(mockDmiModelOperations, mockCpsModuleService,
- mockCmHandleQueries, mockCpsDataService, mockCpsAnchorService, mockJsonObjectMapper, mockModuleSetTagCache)
+ mockCmHandleQueries, mockCpsDataService, mockCpsAnchorService, mockJsonObjectMapper)
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()
@@ -96,11 +95,7 @@ class ModuleSyncServiceSpec extends Specification {
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
- }
+ 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'
@@ -118,10 +113,9 @@ class ModuleSyncServiceSpec extends Specification {
and: 'No anchor is created for the upgraded cm handle'
0 * mockCpsAnchorService.createAnchor(*_)
where: 'the following parameters are used'
- scenario | populateCache | existingCmHandlesWithSameTag || expectedCallsToUpgradeSchemaSet | expectedCallsToCeateSchemaSet
- 'new' | false | [] || 0 | 1
- 'in cache' | true | [] || 1 | 0
- 'in database' | false | [cmHandleWithModuleSetTag] || 1 | 0
+ scenario | existingCmHandlesWithSameTag || expectedCallsToUpgradeSchemaSet | expectedCallsToCeateSchemaSet
+ 'new' | [] || 1 | 0
+ 'in database' | [cmHandleWithModuleSetTag] || 1 | 0
}
def 'upgrade model for a existing cm handle'() {