X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Finventory%2FInventoryPersistence.java;h=cbd30a8fef8aff6e59da827d5f5e6aaf339b40b7;hb=7d486385a46b8dfa3a72db27dc4f31bf74d035bb;hp=d47da6c0cf4b19d1a995030f713571afda8cd7d2;hpb=7914c8924723092345e8b4d829f15d2a3a5c72c8;p=cps.git diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java index d47da6c0c..cbd30a8fe 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation - * Modifications Copyright (C) 2022 Bell Canada + * Copyright (C) 2022-2023 Nordix Foundation + * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,147 +21,183 @@ package org.onap.cps.ncmp.api.inventory; -import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME; - -import java.time.OffsetDateTime; import java.util.Collection; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.onap.cps.api.CpsDataService; -import org.onap.cps.api.CpsModuleService; -import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; +import java.util.Map; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; -import org.onap.cps.spi.CpsDataPersistenceService; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.ModuleDefinition; -import org.onap.cps.utils.CpsValidator; -import org.onap.cps.utils.JsonObjectMapper; -import org.springframework.stereotype.Component; +import org.onap.cps.spi.model.ModuleReference; -@RequiredArgsConstructor -@Component -public class InventoryPersistence { +public interface InventoryPersistence { - private static final String NCMP_DATASPACE_NAME = "NCMP-Admin"; + /** + * Get the Cm Handle Composite State from the data node. + * + * @param cmHandleId cm handle id + * @return the cm handle composite state + */ + CompositeState getCmHandleState(String cmHandleId); - private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; + /** + * Save the cm handles state. + * + * @param cmHandleId cm handle id + * @param compositeState composite state + */ + void saveCmHandleState(String cmHandleId, CompositeState compositeState); - private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']"; + /** + * Save all cm handles states in batch. + * + * @param cmHandleStatePerCmHandleId contains cm handle id and updated state + */ + void saveCmHandleStateBatch(Map cmHandleStatePerCmHandleId); - private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles"; + /** + * This method retrieves DMI service name, DMI properties and the state for a given cm handle. + * + * @param cmHandleId the id of the cm handle + * @return yang model cm handle + */ + YangModelCmHandle getYangModelCmHandle(String cmHandleId); - private final JsonObjectMapper jsonObjectMapper; + /** + * This method retrieves DMI service name, DMI properties and the state for a given cm handle. + * + * @param cmHandleIds a list of the ids of the cm handles + * @return collection of yang model cm handles + */ + Collection getYangModelCmHandles(Collection cmHandleIds); - private final CpsDataService cpsDataService; + /** + * Method to return module definitions by cmHandleId. + * + * @param cmHandleId cm handle ID + * @return a collection of module definitions (moduleName, revision and yang resource content) + */ + Collection getModuleDefinitionsByCmHandleId(String cmHandleId); - private final CpsModuleService cpsModuleService; + /** + * Method to return module references by cmHandleId. + * + * @param cmHandleId cm handle ID + * @return a collection of module references (moduleName and revision) + */ + Collection getYangResourcesModuleReferences(String cmHandleId); - private final CpsDataPersistenceService cpsDataPersistenceService; + /** + * Method to save cmHandle. + * + * @param yangModelCmHandle cmHandle represented as Yang Model + */ + void saveCmHandle(YangModelCmHandle yangModelCmHandle); /** - * Get the Cm Handle Composite State from the data node. + * Method to save batch of cm handles. * - * @param cmHandleId cm handle id - * @return the cm handle composite state + * @param yangModelCmHandles cm handle represented as Yang Models */ - public CompositeState getCmHandleState(final String cmHandleId) { - final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(xpathCmHandle, cmHandleId) + "/state", - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); - return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build(); - } + void saveCmHandleBatch(Collection yangModelCmHandles); /** - * Save the cm handles state. + * Method to delete a list or a list element. * - * @param cmHandleId cm handle id - * @param compositeState composite state + * @param listElementXpath list element xPath */ - public void saveCmHandleState(final String cmHandleId, final CompositeState compositeState) { - final String cmHandleJsonData = String.format("{\"state\":%s}", - jsonObjectMapper.asJsonString(compositeState)); - cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(xpathCmHandle, cmHandleId), - cmHandleJsonData, OffsetDateTime.now()); - } + void deleteListOrListElement(String listElementXpath); /** - * Method which returns cm handles by the cm handles state. + * Method to delete a schema set. * - * @param cmHandleState cm handle state - * @return a list of cm handles + * @param schemaSetName schema set name */ - public List getCmHandlesByState(final CmHandleState cmHandleState) { - return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, - NCMP_DMI_REGISTRY_ANCHOR, "//state[@cm-handle-state=\"" - + cmHandleState + ANCESTOR_CM_HANDLES, - FetchDescendantsOption.OMIT_DESCENDANTS); - } + void deleteSchemaSetWithCascade(String schemaSetName); /** - * Method to return data nodes representing the cm handles. + * Method to delete multiple schema sets. * - * @param cpsPath cps path for which the cmHandle is requested - * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes - * @return a list of data nodes representing the cm handles. + * @param schemaSetNames schema set names */ - public List getCmHandleDataNodesByCpsPath(final String cpsPath, - final FetchDescendantsOption fetchDescendantsOption) { - return cpsDataPersistenceService.queryDataNodes( - NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, fetchDescendantsOption); - } + void deleteSchemaSetsWithCascade(Collection schemaSetNames); /** - * Method which returns cm handles by the cm handle id and state. - * @param cmHandleId cm handle id - * @param cmHandleState cm handle state - * @return a list of cm handles + * Get data node via xpath. + * + * @param xpath xpath + * @return data node */ - public List getCmHandlesByIdAndState(final String cmHandleId, final CmHandleState cmHandleState) { - return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, - NCMP_DMI_REGISTRY_ANCHOR, "//cm-handles[@id='" + cmHandleId + "']/state[@cm-handle-state=\"" - + cmHandleState + ANCESTOR_CM_HANDLES, - FetchDescendantsOption.OMIT_DESCENDANTS); - } + Collection getDataNode(String xpath); /** - * Method which returns cm handles by the operational sync state of cm handle. - * @param dataStoreSyncState sync state - * @return a list of cm handles + * Get data node via xpath. + * + * @param xpath xpath + * @param fetchDescendantsOption fetch descendants option + * @return data node */ - public List getCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) { - return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, - NCMP_DMI_REGISTRY_ANCHOR, "//state/datastores" - + "/operational[@sync-state=\"" + dataStoreSyncState + ANCESTOR_CM_HANDLES, - FetchDescendantsOption.OMIT_DESCENDANTS); - } + Collection getDataNode(String xpath, FetchDescendantsOption fetchDescendantsOption); /** - * This method retrieves DMI service name, DMI properties and the state for a given cm handle. - * @param cmHandleId the id of the cm handle - * @return yang model cm handle + * Get collection of data nodes via xpaths. + * + * @param xpaths collection of xpaths + * @return collection of data nodes */ - public YangModelCmHandle getYangModelCmHandle(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); - return YangDataConverter.convertCmHandleToYangModel(getCmHandleDataNode(cmHandleId), cmHandleId); - } + Collection getDataNodes(Collection xpaths); /** - * Method to return module definitions by cmHandleId. + * Get collection of data nodes via xpaths. * - * @param cmHandleId cm handle ID - * @return a collection of module definitions (moduleName, revision and yang resource content) + * @param xpaths collection of xpaths + * @param fetchDescendantsOption fetch descendants option + * @return collection of data nodes */ - public Collection getModuleDefinitionsByCmHandleId(final String cmHandleId) { - return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId); - } + Collection getDataNodes(Collection xpaths, FetchDescendantsOption fetchDescendantsOption); - private DataNode getCmHandleDataNode(final String cmHandle) { - return cpsDataService.getDataNode(NCMP_DATASPACE_NAME, - NCMP_DMI_REGISTRY_ANCHOR, - String.format(xpathCmHandle, cmHandle), - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); - } + /** + * Get data node of given cm handle. + * + * @param cmHandleId cmHandle ID + * @return data node + */ + Collection getCmHandleDataNode(String cmHandleId); -} \ No newline at end of file + /** + * Get collection of data nodes of given cm handles. + * + * @param cmHandleIds collection of cmHandle IDs + * @return collection of data nodes + */ + Collection getCmHandleDataNodes(Collection cmHandleIds); + + /** + * get CM handles that has given module names. + * + * @param moduleNamesForQuery module names + * @return Collection of CM handle Ids + */ + Collection getCmHandleIdsWithGivenModules(Collection moduleNamesForQuery); + + /** + * Replaces list content by removing all existing elements and inserting the given new elements as data nodes. + * + * @param parentNodeXpath parent node xpath + * @param dataNodes datanodes representing the updated data + */ + void replaceListContent(String parentNodeXpath, Collection dataNodes); + + /** + * Deletes data node. + * + * @param dataNodeXpath data node xpath + */ + void deleteDataNode(String dataNodeXpath); + + /** + * Deletes multiple data nodes. + * + * @param dataNodeXpaths data node xpaths + */ + void deleteDataNodes(Collection dataNodeXpaths); +}