+ private Optional<DataNode> getFirstReadyDataNodeWithModuleSetTag(final String moduleSetTag) {
+ final List<DataNode> dataNodes = StringUtils.isNotBlank(moduleSetTag) ? cmHandleQueries
+ .queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='" + moduleSetTag + "']",
+ FetchDescendantsOption.OMIT_DESCENDANTS) : Collections.emptyList();
+ return dataNodes.stream().filter(dataNode -> {
+ final String cmHandleId = YangDataConverter.extractCmHandleIdFromXpath(dataNode.getXpath());
+ return cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY);
+ }).findFirst();
+ }
+
+ private void setCmHandleModuleSetTag(final YangModelCmHandle upgradedCmHandle, final String moduleSetTag) {
+ final Map<String, Map<String, String>> dmiRegistryProperties = new HashMap<>(1);
+ final Map<String, String> cmHandleProperties = new HashMap<>(2);
+ cmHandleProperties.put("id", upgradedCmHandle.getId());
+ cmHandleProperties.put("module-set-tag", moduleSetTag);
+ dmiRegistryProperties.put("cm-handles", cmHandleProperties);
+ cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
+ jsonObjectMapper.asJsonString(dmiRegistryProperties), OffsetDateTime.now());
+ }
+
+ private void upgradeUsingModuleSetTag(final YangModelCmHandle upgradedCmHandle, final String moduleSetTag) {
+ 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.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,
+ upgradedSchemaSetAndAnchorName, noNewModules, 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;
+ }
+