aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorDaniel Hanrahan <daniel.hanrahan@est.tech>2025-01-28 15:00:33 +0000
committerGerrit Code Review <gerrit@onap.org>2025-01-28 15:00:33 +0000
commitff8da28caba2d287376966eff92653e749c2f25c (patch)
treec94dae8343bc3e94e21d5a64f4998f260d4baad3 /cps-ncmp-service/src/main/java/org/onap
parent8ea43417708c3858b0d590d68fdb1f9a3e192410 (diff)
parentd91020d983c686977158d0900eddda9f2bb1058c (diff)
Merge "Send new module set tag to DMI during model upgrade"
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleOperationsUtils.java9
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java35
3 files changed, 36 insertions, 27 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java
index 1e24671f8d..2cc4375447 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation
+ * Copyright (C) 2021-2025 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,13 +61,14 @@ public class DmiModelOperations {
* Retrieves module references.
*
* @param yangModelCmHandle the yang model cm handle
+ * @param targetModuleSetTag module set tag to send to dmi
* @return module references
*/
@Timed(value = "cps.ncmp.inventory.module.references.from.dmi",
description = "Time taken to get all module references for a cm handle from dmi")
- public List<ModuleReference> getModuleReferences(final YangModelCmHandle yangModelCmHandle) {
- final DmiRequestBody dmiRequestBody = DmiRequestBody.builder()
- .moduleSetTag(yangModelCmHandle.getModuleSetTag()).build();
+ public List<ModuleReference> getModuleReferences(final YangModelCmHandle yangModelCmHandle,
+ final String targetModuleSetTag) {
+ final DmiRequestBody dmiRequestBody = DmiRequestBody.builder().moduleSetTag(targetModuleSetTag).build();
dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties());
final ResponseEntity<Object> dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData(
yangModelCmHandle.resolveDmiServiceName(MODEL),
@@ -79,18 +80,20 @@ public class DmiModelOperations {
* Retrieve yang resources from dmi for any modules that CPS-NCMP hasn't cached before.
*
* @param yangModelCmHandle the yangModelCmHandle
+ * @param targetModuleSetTag module set tag to send to dmi
* @param newModuleReferences the unknown module references
* @return yang resources as map of module name to yang(re)source
*/
@Timed(value = "cps.ncmp.inventory.yang.resources.from.dmi",
description = "Time taken to get list of yang resources from dmi")
public Map<String, String> getNewYangResourcesFromDmi(final YangModelCmHandle yangModelCmHandle,
+ final String targetModuleSetTag,
final Collection<ModuleReference> newModuleReferences) {
if (newModuleReferences.isEmpty()) {
return Collections.emptyMap();
}
final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources(newModuleReferences,
- yangModelCmHandle.getDmiProperties(), yangModelCmHandle.getModuleSetTag());
+ yangModelCmHandle.getDmiProperties(), targetModuleSetTag);
final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData(
yangModelCmHandle.resolveDmiServiceName(MODEL),
jsonWithDataAndDmiProperties,
@@ -123,13 +126,13 @@ public class DmiModelOperations {
private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,
final List<YangModelCmHandle.Property> dmiProperties,
- final String moduleSetTag) {
+ final String targetModuleSetTag) {
final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(newModuleReferences);
final JsonObject data = new JsonObject();
data.add("modules", moduleReferencesAsJson);
final JsonObject jsonRequestObject = new JsonObject();
- if (!moduleSetTag.isEmpty()) {
- jsonRequestObject.addProperty("moduleSetTag", moduleSetTag);
+ if (!targetModuleSetTag.isEmpty()) {
+ jsonRequestObject.addProperty("moduleSetTag", targetModuleSetTag);
}
jsonRequestObject.add("data", data);
jsonRequestObject.add("cmHandleProperties", toJsonObject(dmiProperties));
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleOperationsUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleOperationsUtils.java
index e9f3d9b475..80e41652ee 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleOperationsUtils.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleOperationsUtils.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 Nordix Foundation
+ * Copyright (C) 2022-2025 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -189,7 +189,12 @@ public class ModuleOperationsUtils {
.getLockReasonCategory()));
}
- public static String getTargetModuleSetTagFromLockReason(final CompositeState.LockReason lockReason) {
+ public static String getTargetModuleSetTagForUpgrade(final YangModelCmHandle yangModelCmHandle) {
+ final CompositeState.LockReason lockReason = yangModelCmHandle.getCompositeState().getLockReason();
+ return getTargetModuleSetTagFromLockReason(lockReason);
+ }
+
+ private static String getTargetModuleSetTagFromLockReason(final CompositeState.LockReason lockReason) {
return getLockedCompositeStateDetails(lockReason).getOrDefault(MODULE_SET_TAG_KEY, "");
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java
index 017995e778..f929d6708c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java
@@ -66,9 +66,9 @@ public class ModuleSyncService {
*/
public void syncAndCreateSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle) {
final String cmHandleId = yangModelCmHandle.getId();
- final String moduleSetTag = yangModelCmHandle.getModuleSetTag();
- final String schemaSetName = getSchemaSetName(cmHandleId, moduleSetTag);
- syncAndCreateSchemaSet(yangModelCmHandle, schemaSetName);
+ final String targetModuleSetTag = yangModelCmHandle.getModuleSetTag();
+ final String schemaSetName = getSchemaSetNameForModuleSetTag(cmHandleId, targetModuleSetTag);
+ syncAndCreateSchemaSet(yangModelCmHandle, schemaSetName, targetModuleSetTag);
try {
cpsAnchorService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName, cmHandleId);
} catch (final AlreadyDefinedException alreadyDefinedException) {
@@ -85,27 +85,27 @@ public class ModuleSyncService {
public void syncAndUpgradeSchemaSet(final YangModelCmHandle yangModelCmHandle) {
final String cmHandleId = yangModelCmHandle.getId();
final String sourceModuleSetTag = yangModelCmHandle.getModuleSetTag();
- final String targetModuleSetTag = ModuleOperationsUtils.getTargetModuleSetTagFromLockReason(
- yangModelCmHandle.getCompositeState().getLockReason());
+ final String targetModuleSetTag = ModuleOperationsUtils.getTargetModuleSetTagForUpgrade(yangModelCmHandle);
+ final String schemaSetName = getSchemaSetNameForModuleSetTag(cmHandleId, targetModuleSetTag);
if (sourceModuleSetTag.isEmpty() && targetModuleSetTag.isEmpty()) {
- final ModuleDelta moduleDelta = getModuleDelta(yangModelCmHandle);
+ final ModuleDelta moduleDelta = getModuleDelta(yangModelCmHandle, targetModuleSetTag);
cpsModuleService.upgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
- cmHandleId, moduleDelta.newModuleNameToContentMap, moduleDelta.allModuleReferences);
+ schemaSetName, moduleDelta.newModuleNameToContentMap, moduleDelta.allModuleReferences);
} else {
- final String targetSchemaSetName = getSchemaSetName(cmHandleId, targetModuleSetTag);
- syncAndCreateSchemaSet(yangModelCmHandle, targetSchemaSetName);
- cpsAnchorService.updateAnchorSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
- targetSchemaSetName);
+ syncAndCreateSchemaSet(yangModelCmHandle, schemaSetName, targetModuleSetTag);
+ cpsAnchorService.updateAnchorSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, schemaSetName);
setCmHandleModuleSetTag(yangModelCmHandle, targetModuleSetTag);
log.info("Upgrading schema set for CM handle ID: {}, Source Tag: {}, Target Tag: {}",
cmHandleId, sourceModuleSetTag, targetModuleSetTag);
}
}
- private void syncAndCreateSchemaSet(final YangModelCmHandle yangModelCmHandle, final String schemaSetName) {
+ private void syncAndCreateSchemaSet(final YangModelCmHandle yangModelCmHandle,
+ final String schemaSetName,
+ final String targetModuleSetTag) {
if (isNewSchemaSet(schemaSetName)) {
final String cmHandleId = yangModelCmHandle.getId();
- final ModuleDelta moduleDelta = getModuleDelta(yangModelCmHandle);
+ final ModuleDelta moduleDelta = getModuleDelta(yangModelCmHandle, targetModuleSetTag);
try {
log.info("Creating Schema Set {} for CM Handle {}", schemaSetName, cmHandleId);
cpsModuleService.createSchemaSetFromModules(
@@ -127,13 +127,14 @@ public class ModuleSyncService {
return !cpsModuleService.schemaSetExists(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName);
}
- private ModuleDelta getModuleDelta(final YangModelCmHandle yangModelCmHandle) {
+ private ModuleDelta getModuleDelta(final YangModelCmHandle yangModelCmHandle,
+ final String targetModuleSetTag) {
final Collection<ModuleReference> allModuleReferences =
- dmiModelOperations.getModuleReferences(yangModelCmHandle);
+ dmiModelOperations.getModuleReferences(yangModelCmHandle, targetModuleSetTag);
final Collection<ModuleReference> newModuleReferences =
cpsModuleService.identifyNewModuleReferences(allModuleReferences);
final Map<String, String> newYangResources = dmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle,
- newModuleReferences);
+ targetModuleSetTag, newModuleReferences);
log.debug("Module delta calculated for CM handle ID: {}. All references: {}. New modules: {}",
yangModelCmHandle.getId(), allModuleReferences, newYangResources.keySet());
return new ModuleDelta(allModuleReferences, newYangResources);
@@ -146,7 +147,7 @@ public class ModuleSyncService {
jsonForUpdate, OffsetDateTime.now(), ContentType.JSON);
}
- private static String getSchemaSetName(final String cmHandleId, final String moduleSetTag) {
+ private static String getSchemaSetNameForModuleSetTag(final String cmHandleId, final String moduleSetTag) {
return moduleSetTag.isEmpty() ? cmHandleId : moduleSetTag;
}