From e557338803286d8aaa0f877aa25d52d18735f309 Mon Sep 17 00:00:00 2001 From: DylanB95EST Date: Thu, 27 Jan 2022 17:12:52 +0000 Subject: Create Endpoint For Get Cm Handles By Name Create endpoint and implement logic for get cm handle details by cm handle name Issue-ID: CPS-817 Change-Id: I83bd2da9219d13fac715a08b19108028ca6f6751 Signed-off-by: DylanB95EST --- .../cps/ncmp/api/NetworkCmProxyDataService.java | 25 +++-- .../api/impl/NetworkCmProxyDataServiceImpl.java | 108 ++++++++++++------ .../NetworkCmProxyDataServicePropertyHandler.java | 21 ++-- .../api/impl/operations/DmiDataOperations.java | 38 +++---- .../api/impl/operations/DmiModelOperations.java | 30 ++--- .../ncmp/api/impl/operations/DmiOperations.java | 2 +- .../ncmp/api/impl/operations/DmiRequestBody.java | 10 +- .../operations/PersistenceCmHandleRetriever.java | 86 -------------- .../operations/YangModelCmHandleRetriever.java | 91 +++++++++++++++ .../api/impl/yangmodels/YangModelCmHandle.java | 124 +++++++++++++++++++++ .../impl/yangmodels/YangModelCmHandlesList.java | 70 ++++++++++++ .../org/onap/cps/ncmp/api/models/CmHandle.java | 49 -------- .../cps/ncmp/api/models/DmiPluginRegistration.java | 5 +- .../cps/ncmp/api/models/NcmpServiceCmHandle.java | 50 +++++++++ .../cps/ncmp/api/models/PersistenceCmHandle.java | 121 -------------------- .../ncmp/api/models/PersistenceCmHandlesList.java | 68 ----------- ...tworkCmProxyDataServiceImplModelSyncSpec.groovy | 26 +++-- ...rkCmProxyDataServiceImplRegistrationSpec.groovy | 40 +++---- .../impl/NetworkCmProxyDataServiceImplSpec.groovy | 22 +++- ...orkCmProxyDataServicePropertyHandlerSpec.groovy | 10 +- .../impl/operations/DmiDataOperationsSpec.groovy | 14 +-- .../impl/operations/DmiModelOperationsSpec.groovy | 54 ++++----- .../impl/operations/DmiOperationsBaseSpec.groovy | 20 ++-- .../PersistenceCmHandleRetrieverSpec.groovy | 63 ----------- .../YangModelCmHandleRetrieverSpec.groovy | 72 ++++++++++++ .../ncmp/api/models/PersistenceCmHandleSpec.groovy | 66 ----------- .../ncmp/api/models/YangModelCmHandleSpec.groovy | 67 +++++++++++ 27 files changed, 726 insertions(+), 626 deletions(-) delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandlesList.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandlesList.java delete mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy create mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy delete mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy create mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy (limited to 'cps-ncmp-service') 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 5d2ab5339..471e97e08 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 @@ -26,6 +26,7 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum import java.util.Collection; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.spi.model.ModuleReference; /* @@ -44,13 +45,13 @@ public interface NetworkCmProxyDataService { * Get resource data for data store pass-through operational * using dmi. * - * @param cmHandle cm handle + * @param cmHandleId cm handle identifier * @param resourceIdentifier resource identifier * @param acceptParamInHeader accept param * @param optionsParamInQuery options query * @return {@code Object} resource data */ - Object getResourceDataOperationalForCmHandle(String cmHandle, + Object getResourceDataOperationalForCmHandle(String cmHandleId, String resourceIdentifier, String acceptParamInHeader, String optionsParamInQuery); @@ -59,13 +60,13 @@ public interface NetworkCmProxyDataService { * Get resource data for data store pass-through running * using dmi. * - * @param cmHandle cm handle + * @param cmHandleId cm handle identifier * @param resourceIdentifier resource identifier * @param acceptParamInHeader accept param * @param optionsParamInQuery options query * @return {@code Object} resource data */ - Object getResourceDataPassThroughRunningForCmHandle(String cmHandle, + Object getResourceDataPassThroughRunningForCmHandle(String cmHandleId, String resourceIdentifier, String acceptParamInHeader, String optionsParamInQuery); @@ -73,14 +74,14 @@ public interface NetworkCmProxyDataService { /** * Write resource data for data store pass-through running * using dmi for given cm-handle. - * @param cmHandle cm handle + * @param cmHandleId cm handle identifier * @param resourceIdentifier resource identifier * @param operation required operation * @param requestBody request body to create resource * @param contentType content type in body * @return {@code Object} return data */ - Object writeResourceDataPassThroughRunningForCmHandle(String cmHandle, + Object writeResourceDataPassThroughRunningForCmHandle(String cmHandleId, String resourceIdentifier, OperationEnum operation, String requestBody, @@ -89,10 +90,10 @@ public interface NetworkCmProxyDataService { /** * Retrieve module references for the given cm handle. * - * @param cmHandle cm handle + * @param cmHandleId cm handle identifier * @return a collection of modules names and revisions */ - Collection getYangResourcesModuleReferences(String cmHandle); + Collection getYangResourcesModuleReferences(String cmHandleId); /** * Query cm handle identifiers for the given collection of module names. @@ -103,4 +104,12 @@ public interface NetworkCmProxyDataService { */ Collection executeCmHandleHasAllModulesSearch(Collection moduleNames); + /** + * Query cm handle details by cm handle's name. + * + * @param cmHandleId cm handle identifier + * @return a collection of cm handle details. + */ + NcmpServiceCmHandle getNcmpServiceCmHandle(String cmHandleId); + } 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 446e45b2b..1762e4628 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 @@ -34,6 +34,7 @@ import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED; import com.fasterxml.jackson.core.JsonProcessingException; import java.util.Collection; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -47,10 +48,11 @@ import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException; import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations; import org.onap.cps.ncmp.api.impl.operations.DmiOperations; -import org.onap.cps.ncmp.api.models.CmHandle; +import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandlesList; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; -import org.onap.cps.ncmp.api.models.PersistenceCmHandle; -import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.ModuleReference; @@ -77,6 +79,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler; + private final YangModelCmHandleRetriever yangModelCmHandleRetriever; + @Override public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) { dmiPluginRegistration.validateDmiPluginRegistration(); @@ -97,12 +101,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } @Override - public Object getResourceDataOperationalForCmHandle(final String cmHandle, + public Object getResourceDataOperationalForCmHandle(final String cmHandleId, final String resourceIdentifier, final String acceptParamInHeader, final String optionsParamInQuery) { return handleResponse(dmiDataOperations.getResourceDataFromDmi( - cmHandle, + cmHandleId, resourceIdentifier, optionsParamInQuery, acceptParamInHeader, @@ -110,12 +114,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } @Override - public Object getResourceDataPassThroughRunningForCmHandle(final String cmHandle, + public Object getResourceDataPassThroughRunningForCmHandle(final String cmHandleId, final String resourceIdentifier, final String acceptParamInHeader, final String optionsParamInQuery) { return handleResponse(dmiDataOperations.getResourceDataFromDmi( - cmHandle, + cmHandleId, resourceIdentifier, optionsParamInQuery, acceptParamInHeader, @@ -123,21 +127,21 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } @Override - public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandle, + public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId, final String resourceIdentifier, final OperationEnum operation, final String requestData, final String dataType) { return handleResponse( dmiDataOperations.writeResourceDataPassThroughRunningFromDmi( - cmHandle, resourceIdentifier, operation, requestData, dataType), + cmHandleId, resourceIdentifier, operation, requestData, dataType), "Not able to " + operation + " resource data."); } @Override - public Collection getYangResourcesModuleReferences(final String cmHandle) { - return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle); + public Collection getYangResourcesModuleReferences(final String cmHandleId) { + return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId); } /** @@ -152,16 +156,56 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } /** - * THis method registers a cm handle and intiates modules sync. + * Retrieve cm handle details for a given cm handle. + * @param cmHandleId cm handle identifier + * @return cm handle details + */ + @Override + public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) { + final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle(); + final YangModelCmHandle yangModelCmHandle = + yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId); + final List dmiProperties = yangModelCmHandle.getDmiProperties(); + final List publicProperties = yangModelCmHandle.getPublicProperties(); + ncmpServiceCmHandle.setCmHandleID(yangModelCmHandle.getId()); + setDmiProperties(dmiProperties, ncmpServiceCmHandle); + setPublicProperties(publicProperties, ncmpServiceCmHandle); + return ncmpServiceCmHandle; + } + + private void setDmiProperties(final List dmiProperties, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final Map dmiPropertiesMap = new LinkedHashMap<>(dmiProperties.size()); + asPropertiesMap(dmiProperties, dmiPropertiesMap); + ncmpServiceCmHandle.setDmiProperties(dmiPropertiesMap); + } + + private void setPublicProperties(final List publicProperties, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final Map publicPropertiesMap = new LinkedHashMap<>(); + asPropertiesMap(publicProperties, publicPropertiesMap); + ncmpServiceCmHandle.setPublicProperties(publicPropertiesMap); + } + + private void asPropertiesMap(final List properties, + final Map propertiesMap) { + for (final YangModelCmHandle.Property property: properties) { + propertiesMap.put(property.getName(), property.getValue()); + } + } + + /** + * THis method registers a cm handle and initiates modules sync. * * @param dmiPluginRegistration dmi plugin registration information. * @throws JsonProcessingException thrown if json is malformed or missing. */ public void parseAndCreateCmHandlesInDmiRegistrationAndSyncModules( final DmiPluginRegistration dmiPluginRegistration) throws JsonProcessingException { - final PersistenceCmHandlesList createdPersistenceCmHandlesList = - getUpdatedPersistenceCmHandlesList(dmiPluginRegistration, dmiPluginRegistration.getCreatedCmHandles()); - registerAndSyncNewCmHandles(createdPersistenceCmHandlesList); + final YangModelCmHandlesList createdYangModelCmHandlesList = + getUpdatedYangModelCmHandlesList(dmiPluginRegistration, + dmiPluginRegistration.getCreatedCmHandles()); + registerAndSyncNewCmHandles(createdYangModelCmHandlesList); } private static Object handleResponse(final ResponseEntity responseEntity, @@ -179,29 +223,29 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService networkCmProxyDataServicePropertyHandler.updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()); } - private PersistenceCmHandlesList getUpdatedPersistenceCmHandlesList( + private YangModelCmHandlesList getUpdatedYangModelCmHandlesList( final DmiPluginRegistration dmiPluginRegistration, - final List updatedCmHandles) { - return PersistenceCmHandlesList.toPersistenceCmHandlesList( + final List updatedCmHandles) { + return YangModelCmHandlesList.toYangModelCmHandlesList( dmiPluginRegistration.getDmiPlugin(), dmiPluginRegistration.getDmiDataPlugin(), dmiPluginRegistration.getDmiModelPlugin(), updatedCmHandles); } - private void registerAndSyncNewCmHandles(final PersistenceCmHandlesList persistenceCmHandlesList) { - final String cmHandleJsonData = jsonObjectMapper.asJsonString(persistenceCmHandlesList); + private void registerAndSyncNewCmHandles(final YangModelCmHandlesList yangModelCmHandlesList) { + final String cmHandleJsonData = jsonObjectMapper.asJsonString(yangModelCmHandlesList); cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, cmHandleJsonData, NO_TIMESTAMP); - for (final PersistenceCmHandle persistenceCmHandle : persistenceCmHandlesList.getPersistenceCmHandles()) { - syncModulesAndCreateAnchor(persistenceCmHandle); + for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandlesList.getYangModelCmHandles()) { + syncModulesAndCreateAnchor(yangModelCmHandle); } } - protected void syncModulesAndCreateAnchor(final PersistenceCmHandle persistenceCmHandle) { - syncAndCreateSchemaSet(persistenceCmHandle); - createAnchor(persistenceCmHandle); + protected void syncModulesAndCreateAnchor(final YangModelCmHandle yangModelCmHandle) { + syncAndCreateSchemaSet(yangModelCmHandle); + createAnchor(yangModelCmHandle); } private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) { @@ -225,9 +269,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } } - private void syncAndCreateSchemaSet(final PersistenceCmHandle persistenceCmHandle) { + private void syncAndCreateSchemaSet(final YangModelCmHandle yangModelCmHandle) { final Collection moduleReferencesFromCmHandle = - dmiModelOperations.getModuleReferences(persistenceCmHandle); + dmiModelOperations.getModuleReferences(yangModelCmHandle); final Collection identifiedNewModuleReferencesFromCmHandle = cpsModuleService .identifyNewModuleReferences(moduleReferencesFromCmHandle); @@ -241,16 +285,16 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService if (identifiedNewModuleReferencesFromCmHandle.isEmpty()) { newModuleNameToContentMap = new HashMap<>(); } else { - newModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle, + newModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, identifiedNewModuleReferencesFromCmHandle); } cpsModuleService - .createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, persistenceCmHandle.getId(), + .createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, yangModelCmHandle.getId(), newModuleNameToContentMap, existingModuleReferencesFromCmHandle); } - private void createAnchor(final PersistenceCmHandle persistenceCmHandle) { - cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, persistenceCmHandle.getId(), - persistenceCmHandle.getId()); + private void createAnchor(final YangModelCmHandle yangModelCmHandle) { + cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, yangModelCmHandle.getId(), + yangModelCmHandle.getId()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java index 359921349..ca2f578f4 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java @@ -37,7 +37,7 @@ import java.util.regex.Pattern; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsDataService; -import org.onap.cps.ncmp.api.models.CmHandle; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.model.DataNode; @@ -56,28 +56,31 @@ public class NetworkCmProxyDataServicePropertyHandler { private final CpsDataService cpsDataService; /** - * Iterates over incoming cmHandles and update the dataNodes based on the updated attributes. + * Iterates over incoming ncmpServiceCmHandles and update the dataNodes based on the updated attributes. * The attributes which are not passed will remain as is. * - * @param cmHandles collection of cmHandles + * @param ncmpServiceCmHandles collection of ncmpServiceCmHandles */ - public void updateCmHandleProperties(final Collection cmHandles) throws DataNodeNotFoundException { - for (final CmHandle cmHandle : cmHandles) { + public void updateCmHandleProperties(final Collection ncmpServiceCmHandles) + throws DataNodeNotFoundException { + for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) { try { - final String cmHandleXpath = String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandle.getCmHandleID()); + final String cmHandleXpath = String.format(CM_HANDLE_XPATH_TEMPLATE, + ncmpServiceCmHandle.getCmHandleID()); final DataNode existingCmHandleDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandleXpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); - processUpdates(existingCmHandleDataNode, cmHandle); + processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle); } catch (final DataNodeNotFoundException e) { - log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandle.getCmHandleID(), + log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", + ncmpServiceCmHandle.getCmHandleID(), e.getMessage()); throw e; } } } - private void processUpdates(final DataNode existingCmHandleDataNode, final CmHandle incomingCmHandle) { + private void processUpdates(final DataNode existingCmHandleDataNode, final NcmpServiceCmHandle incomingCmHandle) { if (!incomingCmHandle.getPublicProperties().isEmpty()) { updateProperties(existingCmHandleDataNode, PUBLIC_PROPERTY, incomingCmHandle.getPublicProperties()); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java index bce3ac384..229d4fc91 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java @@ -27,7 +27,7 @@ import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration; -import org.onap.cps.ncmp.api.models.PersistenceCmHandle; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; @@ -44,7 +44,7 @@ public class DmiDataOperations extends DmiOperations { * * @param dmiRestClient {@code DmiRestClient} */ - public DmiDataOperations(final PersistenceCmHandleRetriever cmHandlePropertiesRetriever, + public DmiDataOperations(final YangModelCmHandleRetriever cmHandlePropertiesRetriever, final JsonObjectMapper jsonObjectMapper, final NcmpConfiguration.DmiProperties dmiProperties, final DmiRestClient dmiRestClient) { @@ -55,28 +55,28 @@ public class DmiDataOperations extends DmiOperations { * This method fetches the resource data from operational data store for given cm handle * identifier on given resource using dmi client. * - * @param cmHandle network resource identifier + * @param cmHandleId network resource identifier * @param resourceId resource identifier * @param optionsParamInQuery options query * @param acceptParamInHeader accept parameter * @param dataStore data store enum * @return {@code ResponseEntity} response entity */ - public ResponseEntity getResourceDataFromDmi(final String cmHandle, + public ResponseEntity getResourceDataFromDmi(final String cmHandleId, final String resourceId, final String optionsParamInQuery, final String acceptParamInHeader, final DataStoreEnum dataStore) { - final PersistenceCmHandle persistenceCmHandle = - cmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandle); + final YangModelCmHandle yangModelCmHandle = + yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId); final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .operation(READ) .build(); - dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); + dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties()); final String jsonBody = jsonObjectMapper.asJsonString(dmiRequestBody); final var dmiResourceDataUrl = getDmiDatastoreUrlWithOptions( - persistenceCmHandle.resolveDmiServiceName(DATA), cmHandle, resourceId, + yangModelCmHandle.resolveDmiServiceName(DATA), cmHandleId, resourceId, optionsParamInQuery, dataStore); final var httpHeaders = prepareHeader(acceptParamInHeader); return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonBody, httpHeaders); @@ -86,38 +86,38 @@ public class DmiDataOperations extends DmiOperations { * This method creates the resource data from pass-through running data store for given cm handle * identifier on given resource using dmi client. * - * @param cmHandle network resource identifier + * @param cmHandleId network resource identifier * @param resourceId resource identifier * @param operation operation enum * @param requestData the request data * @param dataType data type * @return {@code ResponseEntity} response entity */ - public ResponseEntity writeResourceDataPassThroughRunningFromDmi(final String cmHandle, + public ResponseEntity writeResourceDataPassThroughRunningFromDmi(final String cmHandleId, final String resourceId, final OperationEnum operation, final String requestData, final String dataType) { - final PersistenceCmHandle persistenceCmHandle = - cmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandle); + final YangModelCmHandle yangModelCmHandle = + yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId); final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .operation(operation) .data(requestData) .dataType(dataType) .build(); - dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); + dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties()); final String jsonBody = jsonObjectMapper.asJsonString(dmiRequestBody); final String dmiUrl = - getResourceInDataStoreUrl(persistenceCmHandle.resolveDmiServiceName(DATA), - cmHandle, resourceId, PASSTHROUGH_RUNNING); + getResourceInDataStoreUrl(yangModelCmHandle.resolveDmiServiceName(DATA), + cmHandleId, resourceId, PASSTHROUGH_RUNNING); return dmiRestClient.postOperationWithJsonData(dmiUrl, jsonBody, new HttpHeaders()); } private String getResourceInDataStoreUrl(final String dmiServiceName, - final String cmHandle, + final String cmHandleId, final String resourceId, final DataStoreEnum dataStoreEnum) { - return getCmHandleUrl(dmiServiceName, cmHandle) + return getCmHandleUrl(dmiServiceName, cmHandleId) + "data" + URL_SEPARATOR + "ds" @@ -128,12 +128,12 @@ public class DmiDataOperations extends DmiOperations { } private String getDmiDatastoreUrlWithOptions(final String dmiServiceName, - final String cmHandle, + final String cmHandleId, final String resourceId, final String optionsParamInQuery, final DataStoreEnum dataStoreEnum) { final String resourceInDataStoreUrl = getResourceInDataStoreUrl(dmiServiceName, - cmHandle, resourceId, dataStoreEnum); + cmHandleId, resourceId, dataStoreEnum); return appendOptionsQuery(resourceInDataStoreUrl, optionsParamInQuery); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java index aec4517c0..bfe934dfd 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration; -import org.onap.cps.ncmp.api.models.PersistenceCmHandle; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.models.YangResource; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.utils.JsonObjectMapper; @@ -50,7 +50,7 @@ public class DmiModelOperations extends DmiOperations { * * @param dmiRestClient {@code DmiRestClient} */ - public DmiModelOperations(final PersistenceCmHandleRetriever dmiPropertiesRetriever, + public DmiModelOperations(final YangModelCmHandleRetriever dmiPropertiesRetriever, final JsonObjectMapper jsonObjectMapper, final NcmpConfiguration.DmiProperties dmiProperties, final DmiRestClient dmiRestClient) { @@ -60,34 +60,34 @@ public class DmiModelOperations extends DmiOperations { /** * Retrieves module references. * - * @param persistenceCmHandle the persistence cm handle + * @param yangModelCmHandle the yang model cm handle * @return module references */ - public List getModuleReferences(final PersistenceCmHandle persistenceCmHandle) { + public List getModuleReferences(final YangModelCmHandle yangModelCmHandle) { final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .build(); - dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); + dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties()); final ResponseEntity dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData( - persistenceCmHandle.resolveDmiServiceName(MODEL), - jsonObjectMapper.asJsonString(dmiRequestBody), persistenceCmHandle.getId(), "modules"); + yangModelCmHandle.resolveDmiServiceName(MODEL), + jsonObjectMapper.asJsonString(dmiRequestBody), yangModelCmHandle.getId(), "modules"); return toModuleReferences((Map) dmiFetchModulesResponseEntity.getBody()); } /** * Retrieve yang resources from dmi for any modules that CPS-NCMP hasn't cached before. * - * @param persistenceCmHandle the persistenceCmHandle + * @param yangModelCmHandle the yangModelCmHandle * @param newModuleReferences the unknown module references * @return yang resources as map of module name to yang(re)source */ - public Map getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle, + public Map getNewYangResourcesFromDmi(final YangModelCmHandle yangModelCmHandle, final Collection newModuleReferences) { final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources( - newModuleReferences, persistenceCmHandle.getDmiProperties()); + newModuleReferences, yangModelCmHandle.getDmiProperties()); final ResponseEntity responseEntity = getResourceFromDmiWithJsonData( - persistenceCmHandle.resolveDmiServiceName(MODEL), + yangModelCmHandle.resolveDmiServiceName(MODEL), jsonWithDataAndDmiProperties, - persistenceCmHandle.getId(), + yangModelCmHandle.getId(), "moduleResources"); return asModuleNameToYangResourceMap(responseEntity); } @@ -110,7 +110,7 @@ public class DmiModelOperations extends DmiOperations { } private static String getRequestBodyToFetchYangResources(final Collection newModuleReferences, - final List dmiProperties) { + final List dmiProperties) { final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(newModuleReferences); final JsonObject data = new JsonObject(); data.add("modules", moduleReferencesAsJson); @@ -132,10 +132,10 @@ public class DmiModelOperations extends DmiOperations { return moduleReferences; } - private static JsonObject toJsonObject(final List + private static JsonObject toJsonObject(final List dmiProperties) { final JsonObject asJsonObject = new JsonObject(); - for (final PersistenceCmHandle.Property additionalProperty : dmiProperties) { + for (final YangModelCmHandle.Property additionalProperty : dmiProperties) { asJsonObject.addProperty(additionalProperty.getName(), additionalProperty.getValue()); } return asJsonObject; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java index 2f7376e87..645d9799f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java @@ -46,7 +46,7 @@ public class DmiOperations { } } - protected final PersistenceCmHandleRetriever cmHandlePropertiesRetriever; + protected final YangModelCmHandleRetriever yangModelCmHandleRetriever; protected final JsonObjectMapper jsonObjectMapper; protected final NcmpConfiguration.DmiProperties dmiProperties; protected final DmiRestClient dmiRestClient; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java index 1066eacf7..d97e90cbb 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Map; import lombok.Builder; import lombok.Getter; -import org.onap.cps.ncmp.api.models.PersistenceCmHandle; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; @JsonInclude(JsonInclude.Include.NON_NULL) @Getter @@ -60,14 +60,14 @@ public class DmiRequestBody { private Map dmiProperties; /** - * Set DMI Properties by converting a list of PersistenceCmHandle.Property objects. + * Set DMI Properties by converting a list of YangModelCmHandle.Property objects. * - * @param dmiPropertiesAsList list of cm handle dmi properties + * @param yangModelCmHandleProperties list of cm handle dmi properties */ public void asDmiProperties( - final List dmiPropertiesAsList) { + final List yangModelCmHandleProperties) { dmiProperties = new LinkedHashMap<>(); - for (final PersistenceCmHandle.Property dmiProperty : dmiPropertiesAsList) { + for (final YangModelCmHandle.Property dmiProperty : yangModelCmHandleProperties) { dmiProperties.put(dmiProperty.getName(), dmiProperty.getValue()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java deleted file mode 100644 index c489eef8e..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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.operations; - -import java.util.LinkedHashMap; -import java.util.Map; -import lombok.AllArgsConstructor; -import org.onap.cps.api.CpsDataService; -import org.onap.cps.ncmp.api.models.CmHandle; -import org.onap.cps.ncmp.api.models.PersistenceCmHandle; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.model.DataNode; -import org.springframework.stereotype.Component; - -/** - * Retrieves PersistenceCmHandles & properties. - */ -@Component -@AllArgsConstructor -public class PersistenceCmHandleRetriever { - - private static final String NCMP_DATASPACE_NAME = "NCMP-Admin"; - private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; - - private final CpsDataService cpsDataService; - - /** - * This method retrieves DMI service name and DMI properties for a given cm handle. - * @param cmHandleId the id of the cm handle - * @return persistence cm handle - */ - public PersistenceCmHandle retrieveCmHandleDmiServiceNameAndDmiProperties(final String cmHandleId) { - final DataNode cmHandleDataNode = getCmHandleDataNode(cmHandleId); - final CmHandle cmHandle = new CmHandle(); - cmHandle.setCmHandleID(cmHandleId); - populateCmHandleDmiProperties(cmHandleDataNode, cmHandle); - return PersistenceCmHandle.toPersistenceCmHandle( - String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name")), - String.valueOf(cmHandleDataNode.getLeaves().get("dmi-data-service-name")), - String.valueOf(cmHandleDataNode.getLeaves().get("dmi-model-service-name")), - cmHandle - ); - } - - private DataNode getCmHandleDataNode(final String cmHandle) { - final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']"; - return cpsDataService.getDataNode(NCMP_DATASPACE_NAME, - NCMP_DMI_REGISTRY_ANCHOR, - xpathForDmiRegistryToFetchCmHandle, - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); - } - - private static void populateCmHandleDmiProperties(final DataNode cmHandleDataNode, final CmHandle cmHandle) { - final Map dmiProperties = new LinkedHashMap<>(); - for (final DataNode childDataNode: cmHandleDataNode.getChildDataNodes()) { - if (childDataNode.getXpath().contains("/additional-properties[@name=")) { - addProperty(childDataNode, dmiProperties); - } - } - cmHandle.setDmiProperties(dmiProperties); - } - - private static void addProperty(final DataNode propertyDataNode, final Map propertiesAsMap) { - propertiesAsMap.put(String.valueOf(propertyDataNode.getLeaves().get("name")), - String.valueOf(propertyDataNode.getLeaves().get("value"))); - } - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java new file mode 100644 index 000000000..6b6bdf5be --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetriever.java @@ -0,0 +1,91 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.operations; + +import java.util.LinkedHashMap; +import java.util.Map; +import lombok.AllArgsConstructor; +import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.spi.FetchDescendantsOption; +import org.onap.cps.spi.model.DataNode; +import org.springframework.stereotype.Component; + +/** + * Retrieves YangModelCmHandles & properties. + */ +@Component +@AllArgsConstructor +public class YangModelCmHandleRetriever { + + private static final String NCMP_DATASPACE_NAME = "NCMP-Admin"; + private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; + + private CpsDataService cpsDataService; + + /** + * This method retrieves DMI service name and DMI properties for a given cm handle. + * @param cmHandleId the id of the cm handle + * @return yang model cm handle + */ + public YangModelCmHandle getDmiServiceNamesAndProperties(final String cmHandleId) { + final DataNode cmHandleDataNode = getCmHandleDataNode(cmHandleId); + final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle(); + ncmpServiceCmHandle.setCmHandleID(cmHandleId); + populateCmHandleProperties(cmHandleDataNode, ncmpServiceCmHandle); + return YangModelCmHandle.toYangModelCmHandle( + String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name")), + String.valueOf(cmHandleDataNode.getLeaves().get("dmi-data-service-name")), + String.valueOf(cmHandleDataNode.getLeaves().get("dmi-model-service-name")), + ncmpServiceCmHandle + ); + } + + private DataNode getCmHandleDataNode(final String cmHandle) { + final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']"; + return cpsDataService.getDataNode(NCMP_DATASPACE_NAME, + NCMP_DMI_REGISTRY_ANCHOR, + xpathForDmiRegistryToFetchCmHandle, + FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); + } + + private static void populateCmHandleProperties(final DataNode cmHandleDataNode, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final Map dmiProperties = new LinkedHashMap<>(); + final Map publicProperties = new LinkedHashMap<>(); + for (final DataNode childDataNode: cmHandleDataNode.getChildDataNodes()) { + if (childDataNode.getXpath().contains("/additional-properties[@name=")) { + addProperty(childDataNode, dmiProperties); + } else if (childDataNode.getXpath().contains("/public-properties[@name=")) { + addProperty(childDataNode, publicProperties); + } + } + ncmpServiceCmHandle.setDmiProperties(dmiProperties); + ncmpServiceCmHandle.setPublicProperties(publicProperties); + } + + private static void addProperty(final DataNode propertyDataNode, final Map propertiesAsMap) { + propertiesAsMap.put(String.valueOf(propertyDataNode.getLeaves().get("name")), + String.valueOf(propertyDataNode.getLeaves().get("value"))); + } + +} 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 new file mode 100644 index 000000000..47062b354 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java @@ -0,0 +1,124 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.yangmodels; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; + +/** + * Cm Handle which follows the Yang resource dmi registry model when persisting data to DMI or the DB. + * Yang model CmHandle + */ +@Getter +@Setter +@NoArgsConstructor +public class YangModelCmHandle { + + private String id; + + @JsonProperty("dmi-service-name") + private String dmiServiceName; + + @JsonProperty("dmi-data-service-name") + private String dmiDataServiceName; + + @JsonProperty("dmi-model-service-name") + private String dmiModelServiceName; + + @JsonProperty("additional-properties") + private List dmiProperties; + + @JsonProperty("public-properties") + private List publicProperties; + + /** + * Create a yangModelCmHandle. + * @param dmiServiceName dmi service name + * @param dmiDataServiceName dmi data service name + * @param dmiModelServiceName dmi model service name + * @param ncmpServiceCmHandle the cm handle + * @return instance of yangModelCmHandle + */ + public static YangModelCmHandle toYangModelCmHandle(final String dmiServiceName, + final String dmiDataServiceName, + final String dmiModelServiceName, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final YangModelCmHandle yangModelCmHandle = new YangModelCmHandle(); + yangModelCmHandle.setId(ncmpServiceCmHandle.getCmHandleID()); + yangModelCmHandle.setDmiServiceName(dmiServiceName); + yangModelCmHandle.setDmiDataServiceName(dmiDataServiceName); + yangModelCmHandle.setDmiModelServiceName(dmiModelServiceName); + yangModelCmHandle.setDmiProperties(asYangModelCmHandleProperties(ncmpServiceCmHandle.getDmiProperties())); + yangModelCmHandle.setPublicProperties(asYangModelCmHandleProperties( + ncmpServiceCmHandle.getPublicProperties())); + return yangModelCmHandle; + } + + /** + * Resolve a dmi service name. + * @param requiredService indicates what typo of service is required + * @return dmi service name + */ + public String resolveDmiServiceName(final RequiredDmiService requiredService) { + if (isNullEmptyOrBlank(dmiServiceName)) { + if (RequiredDmiService.DATA.equals(requiredService)) { + return dmiDataServiceName; + } + return dmiModelServiceName; + } + return dmiServiceName; + } + + private static List asYangModelCmHandleProperties(final Map propertiesAsMap) { + final List yangModelCmHandleProperties = new ArrayList<>(propertiesAsMap.size()); + for (final Map.Entry entry : propertiesAsMap.entrySet()) { + yangModelCmHandleProperties.add(new YangModelCmHandle.Property(entry.getKey(), entry.getValue())); + } + return yangModelCmHandleProperties; + } + + private static boolean isNullEmptyOrBlank(final String serviceName) { + return Strings.isNullOrEmpty(serviceName) || serviceName.isBlank(); + } + + @AllArgsConstructor + @Data + public static class Property { + + @JsonProperty() + private final String name; + + @JsonProperty() + private final String value; + } + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandlesList.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandlesList.java new file mode 100644 index 000000000..261a0181c --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandlesList.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.yangmodels; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import lombok.Getter; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; + +@Getter +public class YangModelCmHandlesList { + + @JsonProperty("cm-handles") + private final List yangModelCmHandles = new ArrayList<>(); + + /** + * Create a YangModelCmHandleList given all service names and a collection of cmHandles. + * @param dmiServiceName the dmi service name + * @param dmiDataServiceName the dmi data service name + * @param dmiModelServiceName the dmi model service name + * @param ncmpServiceCmHandles cm handles rest model + * @return instance of YangModelCmHandleList + */ + public static YangModelCmHandlesList toYangModelCmHandlesList(final String dmiServiceName, + final String dmiDataServiceName, + final String dmiModelServiceName, + final Collection + ncmpServiceCmHandles) { + final YangModelCmHandlesList yangModelCmHandlesList = new YangModelCmHandlesList(); + for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) { + final YangModelCmHandle yangModelCmHandle = + YangModelCmHandle.toYangModelCmHandle( + dmiServiceName, + dmiDataServiceName, + dmiModelServiceName, + ncmpServiceCmHandle); + yangModelCmHandlesList.add(yangModelCmHandle); + } + return yangModelCmHandlesList; + } + + /** + * Add a yangModelCmHandle. + * + * @param yangModelCmHandle the yangModelCmHandle to add + */ + public void add(final YangModelCmHandle yangModelCmHandle) { + yangModelCmHandles.add(yangModelCmHandle); + } +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java deleted file mode 100644 index 88c6f3376..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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.models; - -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import java.util.Collections; -import java.util.Map; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.springframework.validation.annotation.Validated; - -/** - * CmHandle. - */ -@Validated -@Getter -@Setter -@NoArgsConstructor -public class CmHandle { - - private String cmHandleID; - - @JsonSetter(nulls = Nulls.AS_EMPTY) - private Map dmiProperties = Collections.emptyMap(); - - @JsonSetter(nulls = Nulls.AS_EMPTY) - private Map publicProperties = Collections.emptyMap(); - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/DmiPluginRegistration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/DmiPluginRegistration.java index c302f7de5..d1360c325 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/DmiPluginRegistration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/DmiPluginRegistration.java @@ -44,15 +44,14 @@ public class DmiPluginRegistration { private String dmiModelPlugin; - private List createdCmHandles = Collections.emptyList(); + private List createdCmHandles = Collections.emptyList(); - private List updatedCmHandles = Collections.emptyList(); + private List updatedCmHandles = Collections.emptyList(); private List removedCmHandles = Collections.emptyList(); /** * Validates plugin service names. - * * @throws NcmpException if validation fails. */ public void validateDmiPluginRegistration() throws NcmpException { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java new file mode 100644 index 000000000..938127020 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.models; + +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import java.util.Collections; +import java.util.Map; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.springframework.validation.annotation.Validated; + +/** + * The NCMP Service model used for the java service API. + * NCMP Service CmHandle. + */ +@Validated +@Getter +@Setter +@NoArgsConstructor +public class NcmpServiceCmHandle { + + private String cmHandleID; + + @JsonSetter(nulls = Nulls.AS_EMPTY) + private Map dmiProperties = Collections.emptyMap(); + + @JsonSetter(nulls = Nulls.AS_EMPTY) + private Map publicProperties = Collections.emptyMap(); + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java deleted file mode 100644 index cc32bb75c..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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.models; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService; - -/** - * DmiRegistry. - */ -@Getter -@Setter -@NoArgsConstructor -public class PersistenceCmHandle { - - private String id; - - @JsonProperty("dmi-service-name") - private String dmiServiceName; - - @JsonProperty("dmi-data-service-name") - private String dmiDataServiceName; - - @JsonProperty("dmi-model-service-name") - private String dmiModelServiceName; - - @JsonProperty("additional-properties") - private List dmiProperties; - - @JsonProperty("public-properties") - private List publicProperties; - - /** - * Create a persistenceCmHandle. - * @param dmiServiceName dmi service name - * @param dmiDataServiceName dmi data service name - * @param dmiModelServiceName dmi model service name - * @param cmHandle the cm handle - * @return instance of persistenceCmHandle - */ - public static PersistenceCmHandle toPersistenceCmHandle(final String dmiServiceName, - final String dmiDataServiceName, - final String dmiModelServiceName, - final CmHandle cmHandle) { - final PersistenceCmHandle persistenceCmHandle = new PersistenceCmHandle(); - persistenceCmHandle.setId(cmHandle.getCmHandleID()); - persistenceCmHandle.setDmiServiceName(dmiServiceName); - persistenceCmHandle.setDmiDataServiceName(dmiDataServiceName); - persistenceCmHandle.setDmiModelServiceName(dmiModelServiceName); - persistenceCmHandle.setDmiProperties(asPersistenceCmHandleProperties(cmHandle.getDmiProperties())); - persistenceCmHandle.setPublicProperties(asPersistenceCmHandleProperties(cmHandle.getPublicProperties())); - return persistenceCmHandle; - } - - /** - * Resolve a dmi service name. - * @param requiredService indicates what typo of service is required - * @return dmi service name - */ - public String resolveDmiServiceName(final RequiredDmiService requiredService) { - if (isNullEmptyOrBlank(dmiServiceName)) { - if (RequiredDmiService.DATA.equals(requiredService)) { - return dmiDataServiceName; - } - return dmiModelServiceName; - } - return dmiServiceName; - } - - private static List asPersistenceCmHandleProperties(final Map propertiesAsMap) { - final List persistenceCmHandleProperties = new ArrayList<>(propertiesAsMap.size()); - for (final Map.Entry entry : propertiesAsMap.entrySet()) { - persistenceCmHandleProperties.add(new PersistenceCmHandle.Property(entry.getKey(), entry.getValue())); - } - return persistenceCmHandleProperties; - } - - private static boolean isNullEmptyOrBlank(final String serviceName) { - return Strings.isNullOrEmpty(serviceName) || serviceName.isBlank(); - } - - @AllArgsConstructor - @Data - public static class Property { - - @JsonProperty() - private final String name; - - @JsonProperty() - private final String value; - } - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandlesList.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandlesList.java deleted file mode 100644 index 9762ac4e1..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandlesList.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.models; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import lombok.Getter; - -@Getter -public class PersistenceCmHandlesList { - - @JsonProperty("cm-handles") - private final List persistenceCmHandles = new ArrayList<>(); - - /** - * Create a PersistenceCmHandleList given all service names and a collection of cmHandles. - * @param dmiServiceName the dmi service name - * @param dmiDataServiceName the dmi data service name - * @param dmiModelServiceName the dmi model service name - * @param cmHandles cm handles - * @return instance of PersistenceCmHandleList - */ - public static PersistenceCmHandlesList toPersistenceCmHandlesList(final String dmiServiceName, - final String dmiDataServiceName, - final String dmiModelServiceName, - final Collection cmHandles) { - final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList(); - for (final CmHandle cmHandle : cmHandles) { - final PersistenceCmHandle persistenceCmHandle = - PersistenceCmHandle.toPersistenceCmHandle( - dmiServiceName, - dmiDataServiceName, - dmiModelServiceName, - cmHandle); - persistenceCmHandlesList.add(persistenceCmHandle); - } - return persistenceCmHandlesList; - } - - /** - * Add a persistenceCmHandle. - * - * @param persistenceCmHandle the persistenceCmHandle to add - */ - public void add(final PersistenceCmHandle persistenceCmHandle) { - persistenceCmHandles.add(persistenceCmHandle); - } -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy index 3f82f5e0b..553ac7279 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy @@ -24,8 +24,9 @@ import org.onap.cps.api.CpsAdminService import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations -import org.onap.cps.ncmp.api.models.CmHandle -import org.onap.cps.ncmp.api.models.PersistenceCmHandle +import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper import spock.lang.Specification @@ -38,34 +39,35 @@ class NetworkCmProxyDataServiceImplModelSyncSpec extends Specification { def mockCpsAdminService = Mock(CpsAdminService) def mockDmiModelOperations = Mock(DmiModelOperations) def mockDmiDataOperations = Mock(DmiDataOperations) + def mockYangModelCmHandleRetriever = Mock(YangModelCmHandleRetriever) def nullNetworkCmProxyDataServicePropertyHandler = null def objectUnderTest = new NetworkCmProxyDataServiceImpl(nullCpsDataService, mockJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations, - mockCpsModuleService, mockCpsAdminService, nullNetworkCmProxyDataServicePropertyHandler) + mockCpsModuleService, mockCpsAdminService, nullNetworkCmProxyDataServicePropertyHandler,mockYangModelCmHandleRetriever) def expectedDataspaceName = 'NFP-Operational' def 'Sync model for a (new) cm handle with #scenario'() { - given: 'persistence cm handle is given' - def cmHandle = new CmHandle() + given: 'a cm handle' + def ncmpServiceCmHandle = new NcmpServiceCmHandle() def dmiServiceName = 'some service name' - cmHandle.cmHandleID = 'cm handle id 1' - def persistenceCmHandle = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, '' , '', cmHandle) + ncmpServiceCmHandle.cmHandleID = 'cm handle id 1' + def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '' , '', ncmpServiceCmHandle) and: 'DMI operations returns some module references' def moduleReferences = [ new ModuleReference(moduleName:'module1',revision:'1'), new ModuleReference(moduleName:'module2',revision:'2') ] - mockDmiModelOperations.getModuleReferences(persistenceCmHandle) >> moduleReferences + 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(persistenceCmHandle, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap + mockDmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap when: 'module sync is triggered' mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReference(identifiedNewModuleReferences) - objectUnderTest.syncModulesAndCreateAnchor(persistenceCmHandle) + objectUnderTest.syncModulesAndCreateAnchor(yangModelCmHandle) then: 'the CPS module service is called once with the correct parameters' - 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, persistenceCmHandle.getId(), yangResourceToContentMap, toModuleReference(expectedKnownModules)) + 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, yangModelCmHandle.getId(), yangResourceToContentMap, toModuleReference(expectedKnownModules)) and: 'admin service create anchor method has been called with correct parameters' - 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, persistenceCmHandle.getId(), persistenceCmHandle.getId()) + 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, yangModelCmHandle.getId(), yangModelCmHandle.getId()) where: 'the following parameters are used' scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | yangResourceToContentMap || expectedKnownModules 'one new module' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source'] || [['module2' : '2']] 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 a475f9c34..e410463af 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 @@ -28,8 +28,9 @@ import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.impl.exception.DmiRequestException import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations -import org.onap.cps.ncmp.api.models.CmHandle +import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever import org.onap.cps.ncmp.api.models.DmiPluginRegistration +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.spi.exceptions.DataNodeNotFoundException import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.utils.JsonObjectMapper @@ -41,7 +42,7 @@ import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { @Shared - def persistenceCmHandle = new CmHandle() + def ncmpServiceCmHandle = new NcmpServiceCmHandle() @Shared def cmHandlesArray = ['cmHandle001'] @@ -53,16 +54,17 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def mockDmiModelOperations = Mock(DmiModelOperations) def mockDmiDataOperations = Mock(DmiDataOperations) def mockNetworkCmProxyDataServicePropertyHandler = Mock(NetworkCmProxyDataServicePropertyHandler) + def mockYangModelCmHandleRetriever = Mock(YangModelCmHandleRetriever) def noTimestamp = null def 'Register or re-register a DMI Plugin for the given cm-handle(s) with #scenario process.'() { given: 'a registration' def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() - def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server') - persistenceCmHandle.cmHandleID = '123' - persistenceCmHandle.dmiProperties = [dmiProp1: 'dmiValue1', dmiProp2: 'dmiValue2'] - persistenceCmHandle.publicProperties = [publicProp1: 'publicValue1', publicProp2: 'publicValue2'] + def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server') + ncmpServiceCmHandle.cmHandleID = '123' + ncmpServiceCmHandle.dmiProperties = [dmiProp1: 'dmiValue1', dmiProp2: 'dmiValue2'] + ncmpServiceCmHandle.publicProperties = [publicProp1: 'publicValue1', publicProp2: 'publicValue2' ] dmiPluginRegistration.createdCmHandles = createdCmHandles dmiPluginRegistration.updatedCmHandles = updatedCmHandles dmiPluginRegistration.removedCmHandles = removedCmHandles @@ -81,13 +83,13 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { expectedCallsToDeleteSchemaSetAndListElement * mockCpsModuleService.deleteSchemaSet('NFP-Operational', 'cmHandle001', CASCADE_DELETE_ALLOWED) and: 'delete list or list element is invoked with the correct parameters' expectedCallsToDeleteSchemaSetAndListElement * mockCpsDataService.deleteListOrListElement('NCMP-Admin', - 'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='cmHandle001']", noTimestamp) + 'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='cmHandle001']", noTimestamp) where: scenario | createdCmHandles | updatedCmHandles | removedCmHandles || expectedCallsToSaveNode | expectedCallsToDeleteSchemaSetAndListElement | expectedCallsToUpdateCmHandleProperty - 'create' | [persistenceCmHandle] | [] | [] || 1 | 0 | 0 - 'update' | [] | [persistenceCmHandle] | [] || 0 | 0 | 1 + 'create' | [ncmpServiceCmHandle] | [] | [] || 1 | 0 | 0 + 'update' | [] | [ncmpServiceCmHandle] | [] || 0 | 0 | 1 'delete' | [] | [] | cmHandlesArray || 0 | 1 | 0 - 'create, update and delete' | [persistenceCmHandle] | [persistenceCmHandle] | cmHandlesArray || 1 | 1 | 1 + 'create, update and delete' | [ncmpServiceCmHandle] | [ncmpServiceCmHandle] | cmHandlesArray || 1 | 1 | 1 'no valid data' | [] | [] | [] || 0 | 0 | 0 } @@ -95,10 +97,10 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { given: 'a registration without cm-handle properties' NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server') - persistenceCmHandle.cmHandleID = '123' - persistenceCmHandle.dmiProperties = Collections.emptyMap() - persistenceCmHandle.publicProperties = Collections.emptyMap() - dmiPluginRegistration.createdCmHandles = [persistenceCmHandle] + ncmpServiceCmHandle.cmHandleID = '123' + ncmpServiceCmHandle.dmiProperties = Collections.emptyMap() + ncmpServiceCmHandle.publicProperties = Collections.emptyMap() + dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle] def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[],"public-properties":[]}]}' when: 'registration is updated' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) @@ -111,7 +113,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { given: 'a registration without cm-handle properties ' NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'some-plugin') - dmiPluginRegistration.createdCmHandles = [persistenceCmHandle] + dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle] and: 'an json processing exception occurs' spiedJsonObjectMapper.asJsonString(_) >> { throw (new JsonProcessingException('')) } when: 'registration is updated and modules are synced' @@ -151,7 +153,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:dmiPlugin, dmiModelPlugin:dmiModelPlugin, dmiDataPlugin:dmiDataPlugin) - dmiPluginRegistration.createdCmHandles = [persistenceCmHandle] + dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle] when: 'update registration and sync module is called with correct DMI plugin information' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'create cm handles registration and sync modules is called with the correct plugin information' @@ -168,7 +170,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:dmiPlugin, dmiModelPlugin:dmiModelPlugin, dmiDataPlugin:dmiDataPlugin) - dmiPluginRegistration.createdCmHandles = [persistenceCmHandle] + dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle] when: 'registration is called with incorrect DMI plugin information' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'a DMI Request Exception is thrown with correct message details' @@ -194,7 +196,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { and: 'dmi plugin registration input update request' def dmiPluginReg = new DmiPluginRegistration(); dmiPluginReg.dmiPlugin = 'onap.dmap.plugin'; - dmiPluginReg.updatedCmHandles = [new CmHandle(cmHandleID: 'unknownHandle')] + dmiPluginReg.updatedCmHandles = [new NcmpServiceCmHandle(cmHandleID: 'unknownHandle')] and: 'update data node leaves is unable to find data node' mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(*_) >> { throw new DataNodeNotFoundException('NCMP-Admin', 'ncmp-dmi-registry') } when: 'update dmi registration is called' @@ -206,7 +208,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def getObjectUnderTestWithModelSyncDisabled() { def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations, - mockCpsModuleService, mockCpsAdminService, mockNetworkCmProxyDataServicePropertyHandler)) + mockCpsModuleService, mockCpsAdminService, mockNetworkCmProxyDataServicePropertyHandler,mockYangModelCmHandleRetriever)) objectUnderTest.syncModulesAndCreateAnchor(*_) >> null return objectUnderTest } 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 6d7bdefb8..b2a3d77ca 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 @@ -22,6 +22,9 @@ package org.onap.cps.ncmp.api.impl +import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle + import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE @@ -52,9 +55,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def mockDmiModelOperations = Mock(DmiModelOperations) def mockDmiDataOperations = Mock(DmiDataOperations) def nullNetworkCmProxyDataServicePropertyHandler = null + def mockYangModelCmHandleRetriever = Mock(YangModelCmHandleRetriever) def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations, - mockCpsModuleService, mockCpsAdminService, nullNetworkCmProxyDataServicePropertyHandler) + mockCpsModuleService, mockCpsAdminService, nullNetworkCmProxyDataServicePropertyHandler, mockYangModelCmHandleRetriever) def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']" @@ -210,6 +214,22 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 1 * mockCpsAdminService.queryAnchorNames('NFP-Operational', ['some-module-name']) } + def 'Get a cm handle.'() { + given: 'the system returns a yang modelled cm handle' + def dmiServiceName = 'some service name' + def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')] + def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')] + def yangModelCmHandle = new YangModelCmHandle(id:'Some-Cm-Handle', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties, publicProperties: publicProperties) + 1 * mockYangModelCmHandleRetriever.getDmiServiceNamesAndProperties('Some-Cm-Handle') >> yangModelCmHandle + when: 'getting cm handle details for a given cm handle id from ncmp service' + def result = objectUnderTest.getNcmpServiceCmHandle('Some-Cm-Handle') + then: 'the result returns the correct data' + result.cmHandleID == 'Some-Cm-Handle' + result.dmiProperties ==[ Book:'Romance Novel' ] + result.publicProperties == [ "Public Book":'Public Romance Novel' ] + + } + def 'Update resource data for pass-through running from dmi using POST #scenario DMI properties.'() { given: 'cpsDataService returns valid datanode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy index 5bdb744b2..9b8d4ada5 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy @@ -21,7 +21,7 @@ package org.onap.cps.ncmp.api.impl import org.onap.cps.api.CpsDataService -import org.onap.cps.ncmp.api.models.CmHandle +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.spi.FetchDescendantsOption import org.onap.cps.spi.exceptions.DataNodeNotFoundException import org.onap.cps.spi.exceptions.DataValidationException @@ -50,7 +50,7 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { given: 'the CPS service return a CM handle' mockCpsDataService.getDataNode(dataspaceName, anchorName, cmHandleXpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode and: 'an update cm handle request with public properties updates' - def cmHandleUpdateRequest = [new CmHandle(cmHandleID: cmHandleId, publicProperties: updatedPublicProperties)] + def cmHandleUpdateRequest = [new NcmpServiceCmHandle(cmHandleID: cmHandleId, publicProperties: updatedPublicProperties)] when: 'update data node leaves is called with the update request' objectUnderTest.updateCmHandleProperties(cmHandleUpdateRequest) then: 'the replace list method is called with correct params' @@ -72,7 +72,7 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { given: 'the CPS service return a CM handle' mockCpsDataService.getDataNode(dataspaceName, anchorName, cmHandleXpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode and: 'an update cm handle request with DMI properties updates' - def cmHandleUpdateRequest = [new CmHandle(cmHandleID: cmHandleId, dmiProperties: updatedDmiProperties)] + def cmHandleUpdateRequest = [new NcmpServiceCmHandle(cmHandleID: cmHandleId, dmiProperties: updatedDmiProperties)] when: 'update data node leaves is called with the update request' objectUnderTest.updateCmHandleProperties(cmHandleUpdateRequest) then: 'replace list method should is called with correct params' @@ -96,7 +96,7 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { def cmHandleDataNode = new DataNode(xpath: cmHandleXpath, childDataNodes: originalPropertyDataNodes) mockCpsDataService.getDataNode(dataspaceName, anchorName, cmHandleXpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode and: 'an update cm handle request that removes all public properties(existing and non-existing)' - def cmHandleUpdateRequest = [new CmHandle(cmHandleID: cmHandleId, publicProperties: ['publicProp3': null, 'publicProp4': null])] + def cmHandleUpdateRequest = [new NcmpServiceCmHandle(cmHandleID: cmHandleId, publicProperties: ['publicProp3': null, 'publicProp4': null])] when: 'update data node leaves is called with the update request' objectUnderTest.updateCmHandleProperties(cmHandleUpdateRequest) then: 'the replace list method is not called' @@ -115,7 +115,7 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { def 'Exception thrown when we try to update cmHandle'() { given: 'cm handles request' - def cmHandleUpdateRequest = [new CmHandle(cmHandleID: cmHandleId, publicProperties: [:], dmiProperties: [:])] + def cmHandleUpdateRequest = [new NcmpServiceCmHandle(cmHandleID: cmHandleId, publicProperties: [:], dmiProperties: [:])] and: 'data node cannot be found' mockCpsDataService.getDataNode(*_) >> { throw new DataNodeNotFoundException(dataspaceName, anchorName, cmHandleXpath) } when: 'update data node leaves is called using correct parameters' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy index 7873f39bb..e585825ca 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy @@ -46,8 +46,8 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { DmiDataOperations objectUnderTest def 'call get resource data for #expectedDatastoreInUrl from DMI #scenario.'() { - given: 'a persistence cm handle for #cmHandleId' - mockPersistenceCmHandleRetrieval(dmiProperties) + given: 'a cm handle for #cmHandleId' + mockYangModelCmHandleRetrieval(dmiProperties) and: 'a positive response from DMI service when it is called with the expected parameters' def responseFromDmi = new ResponseEntity(HttpStatus.OK) mockDmiRestClient.postOperationWithJsonData( @@ -60,15 +60,15 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { where: 'the following parameters are used' scenario | dmiProperties | dataStore | options || expectedJson | expectedDatastoreInUrl | expectedOptionsInUrl 'without properties' | [] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-operational' | '&options=(a=1,b=2)' - 'with properties' | [dmiSampleProperty] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '&options=(a=1,b=2)' - 'null options' | [dmiSampleProperty] | PASSTHROUGH_OPERATIONAL | null || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '' - 'empty options' | [dmiSampleProperty] | PASSTHROUGH_OPERATIONAL | '' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '' + 'with properties' | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '&options=(a=1,b=2)' + 'null options' | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | null || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '' + 'empty options' | [yangModelCmHandleProperty] | PASSTHROUGH_OPERATIONAL | '' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '' 'datastore running' | [] | PASSTHROUGH_RUNNING | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-running' | '&options=(a=1,b=2)' } def 'Write data for pass-through:running datastore in DMI.'() { - given: 'a persistence cm handle for #cmHandleId' - mockPersistenceCmHandleRetrieval([dmiSampleProperty]) + given: 'a cm handle for #cmHandleId' + mockYangModelCmHandleRetrieval([yangModelCmHandleProperty]) and: 'a positive response from DMI service when it is called with the expected parameters' def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds" + "/ncmp-datastore:passthrough-running?resourceIdentifier=${resourceIdentifier}" diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy index bd5fe6f87..cd2cb7112 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy @@ -47,28 +47,28 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { JsonObjectMapper spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) def 'Retrieving module references.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval([]) + given: 'a cm handle' + mockYangModelCmHandleRetrieval([]) and: 'a positive response from DMI service when it is called with the expected parameters' def moduleReferencesAsLisOfMaps = [[moduleName:'mod1',revision:'A'],[moduleName:'mod2',revision:'X']] def responseFromDmi = new ResponseEntity([schemas:moduleReferencesAsLisOfMaps], HttpStatus.OK) mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules", '{"cmHandleProperties":{}}', [:]) >> responseFromDmi when: 'get module references is called' - def result = objectUnderTest.getModuleReferences(persistenceCmHandle) + def result = objectUnderTest.getModuleReferences(yangModelCmHandle) then: 'the result consists of expected module references' assert result == [new ModuleReference(moduleName:'mod1',revision:'A'), new ModuleReference(moduleName:'mod2',revision:'X')] } def 'Retrieving module references edge case: #scenario.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval([]) + given: 'a cm handle' + mockYangModelCmHandleRetrieval([]) and: 'any response from DMI service when it is called with the expected parameters' // TODO (toine): production code ignores any error code from DMI, this should be improved in future def responseFromDmi = new ResponseEntity(bodyAsMap, HttpStatus.NO_CONTENT) mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi when: 'get module references is called' - def result = objectUnderTest.getModuleReferences(persistenceCmHandle) + def result = objectUnderTest.getModuleReferences(yangModelCmHandle) then: 'the result is empty' assert result == [] where: 'the DMI response body has the following content' @@ -80,25 +80,25 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { } def 'Retrieving module references, DMI property handling: #scenario.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval(dmiProperties) + given: 'a cm handle' + mockYangModelCmHandleRetrieval(dmiProperties) and: 'a positive response from DMI service when it is called with tha expected parameters' def responseFromDmi = new ResponseEntity(HttpStatus.OK) mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules", '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', [:]) >> responseFromDmi when: 'a get module references is called' - def result = objectUnderTest.getModuleReferences(persistenceCmHandle) + def result = objectUnderTest.getModuleReferences(yangModelCmHandle) then: 'the result is the response from DMI service' assert result == [] where: 'the following DMI properties are used' scenario | dmiProperties || expectedAdditionalPropertiesInRequest - 'with properties' | [dmiSampleProperty] || '{"prop1":"val1"}' + 'with properties' | [yangModelCmHandleProperty] || '{"prop1":"val1"}' 'without properties' | [] || '{}' } def 'Retrieving yang resources.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval([]) + given: 'a cm handle' + mockYangModelCmHandleRetrieval([]) and: 'a positive response from DMI service when it is called with the expected parameters' def responseFromDmi = new ResponseEntity([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source'], [moduleName: 'mod2', revision: 'C', yangSource: 'other yang source']], HttpStatus.OK) @@ -106,7 +106,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources", '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', [:]) >> responseFromDmi when: 'get new yang resources from DMI service' - def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, newModuleReferences) + def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences) then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)' assert result.size() == 2 assert result.get('mod1') == 'some yang source' @@ -114,14 +114,14 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { } def 'Retrieving yang resources, edge case: scenario.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval([]) + given: 'a cm handle' + mockYangModelCmHandleRetrieval([]) and: 'a positive response from DMI service when it is called with tha expected parameters' // TODO (toine): production code ignores any error code from DMI, this should be improved in future def responseFromDmi = new ResponseEntity(responseFromDmiBody, HttpStatus.NO_CONTENT) mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi when: 'get new yang resources from DMI service' - def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, newModuleReferences) + def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences) then: 'the result is empty' assert result == [:] where: 'the DMI response body has the following content' @@ -131,40 +131,40 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { } def 'Retrieving yang resources, DMI property handling #scenario.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval(dmiProperties) + given: 'a cm handle' + mockYangModelCmHandleRetrieval(dmiProperties) and: 'a positive response from DMI service when it is called with the expected parameters' def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK) mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources", '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":'+expectedAdditionalPropertiesInRequest+'}', [:]) >> responseFromDmi when: 'get new yang resources from DMI service' - def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, unknownModuleReferences) + def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, unknownModuleReferences) then: 'the result is the response from DMI service' assert result == [mod1:'some yang source'] where: 'the following DMI properties are used' scenario | dmiProperties | unknownModuleReferences || expectedAdditionalPropertiesInRequest | expectedModuleReferencesInRequest - 'with module references and properties' | [dmiSampleProperty] | newModuleReferences || '{"prop1":"val1"}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}' - 'without module references' | [dmiSampleProperty] | [] || '{"prop1":"val1"}' | '' + 'with module references and properties' | [yangModelCmHandleProperty] | newModuleReferences || '{"prop1":"val1"}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}' + 'without module references' | [yangModelCmHandleProperty] | [] || '{"prop1":"val1"}' | '' 'without properties' | [] | newModuleReferences || '{}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}' } def 'Retrieving yang resources from DMI with null DMI properties.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval(null) + given: 'a cm handle' + mockYangModelCmHandleRetrieval(null) when: 'a get new yang resources from DMI is called' - objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, []) + objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, []) then: 'a null pointer is thrown (we might need to address this later)' thrown(NullPointerException) } def 'Retrieving module references with Json processing exception.'() { - given: 'a persistence cm handle' - mockPersistenceCmHandleRetrieval([]) + given: 'a cm handle' + mockYangModelCmHandleRetrieval([]) and: 'a Json processing exception occurs' spiedJsonObjectMapper.asJsonString(_) >> {throw (new JsonProcessingException('parsing error'))} when: 'a DMI operation is executed' - objectUnderTest.getModuleReferences(persistenceCmHandle) + objectUnderTest.getModuleReferences(yangModelCmHandle) then: 'an ncmp exception is thrown' def exceptionThrown = thrown(JsonProcessingException) and: 'the message indicates a parsing error' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy index 7b295f68b..dd0d64dd6 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy @@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl.operations import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.api.impl.client.DmiRestClient -import org.onap.cps.ncmp.api.models.PersistenceCmHandle +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.spockframework.spring.SpringBean import spock.lang.Shared import spock.lang.Specification @@ -30,27 +30,27 @@ import spock.lang.Specification abstract class DmiOperationsBaseSpec extends Specification { @Shared - def dmiSampleProperty = new PersistenceCmHandle.Property('prop1', 'val1') + def yangModelCmHandleProperty = new YangModelCmHandle.Property('prop1', 'val1') @SpringBean DmiRestClient mockDmiRestClient = Mock() @SpringBean - PersistenceCmHandleRetriever mockCmHandlePropertiesRetriever = Mock() + YangModelCmHandleRetriever mockCmHandlePropertiesRetriever = Mock() @SpringBean ObjectMapper spyObjectMapper = Spy() - def persistenceCmHandle = new PersistenceCmHandle() + def yangModelCmHandle = new YangModelCmHandle() def static dmiServiceName = 'some service name' def static cmHandleId = 'some cm handle' def static resourceIdentifier = 'parent/child' - def mockPersistenceCmHandleRetrieval(dmiProperties) { - persistenceCmHandle.dmiDataServiceName = dmiServiceName - persistenceCmHandle.dmiServiceName = dmiServiceName - persistenceCmHandle.dmiProperties = dmiProperties - persistenceCmHandle.id = cmHandleId - mockCmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandleId) >> persistenceCmHandle + def mockYangModelCmHandleRetrieval(dmiProperties) { + yangModelCmHandle.dmiDataServiceName = dmiServiceName + yangModelCmHandle.dmiServiceName = dmiServiceName + yangModelCmHandle.dmiProperties = dmiProperties + yangModelCmHandle.id = cmHandleId + mockCmHandlePropertiesRetriever.getDmiServiceNamesAndProperties(cmHandleId) >> yangModelCmHandle } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy deleted file mode 100644 index c92234f9a..000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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.operations - -import org.onap.cps.api.CpsDataService -import org.onap.cps.ncmp.api.models.PersistenceCmHandle -import spock.lang.Shared - -import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS -import org.onap.cps.spi.model.DataNode -import spock.lang.Specification - -class PersistenceCmHandleRetrieverSpec extends Specification { - - def mockCpsDataService = Mock(CpsDataService) - - def objectUnderTest = new PersistenceCmHandleRetriever(mockCpsDataService) - - def cmHandleId = 'some cm handle' - def leaves = ["dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"] - def xpath = "/dmi-registry/cm-handles[@id='some cm handle']" - - @Shared - def childDataNodesForCmHandleProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1","value":"value1"]), - new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])] - - def "Retrieve CmHandle using datanode #scenario."() { - given: 'the cps data service returns a data node from the DMI registry' - def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves) - mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode - when: 'retrieving the persisted cm handle' - def result = objectUnderTest.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandleId) - then: 'the result has the correct id and service names' - result.id == cmHandleId - result.dmiServiceName == 'common service name' - result.dmiDataServiceName == 'data service name' - result.dmiModelServiceName == 'model service name' - and: 'the expected DMI properties' - result.dmiProperties == expectedCmHandleProperties - where: 'the following parameters are used' - scenario | childDataNodes || expectedCmHandleProperties - 'without DMI properties' | [] || [] - 'with DMI properties' | childDataNodesForCmHandleProperties || [new PersistenceCmHandle.Property("name1", "value1")] - } -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy new file mode 100644 index 000000000..593a6ec93 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.operations + +import org.onap.cps.api.CpsDataService +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import spock.lang.Shared + +import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS +import org.onap.cps.spi.model.DataNode +import spock.lang.Specification + +class YangModelCmHandleRetrieverSpec extends Specification { + + def mockCpsDataService = Mock(CpsDataService) + + def objectUnderTest = new YangModelCmHandleRetriever(mockCpsDataService) + + def cmHandleId = 'some cm handle' + def leaves = ["dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"] + def xpath = "/dmi-registry/cm-handles[@id='some cm handle']" + + @Shared + def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]), + new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])] + + @Shared + def childDataNodesForCmHandleWithDMIProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])] + + @Shared + def childDataNodesForCmHandleWithPublicProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])] + + def "Retrieve CmHandle using datanode with #scenario."() { + given: 'the cps data service returns a data node from the DMI registry' + def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves) + mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode + when: 'retrieving the yang modelled cm handle' + def result = objectUnderTest.getDmiServiceNamesAndProperties(cmHandleId) + then: 'the result has the correct id and service names' + result.id == cmHandleId + result.dmiServiceName == 'common service name' + result.dmiDataServiceName == 'data service name' + result.dmiModelServiceName == 'model service name' + and: 'the expected DMI properties' + result.dmiProperties == expectedDmiProperties + result.publicProperties == expectedPublicProperties + where: 'the following parameters are used' + scenario | childDataNodes || expectedDmiProperties || expectedPublicProperties + 'no properties' | [] || [] || [] + 'DMI and public properties' | childDataNodesForCmHandleWithAllProperties || [new YangModelCmHandle.Property("name1", "value1")] || [new YangModelCmHandle.Property("name2", "value2")] + 'just DMI properties' | childDataNodesForCmHandleWithDMIProperties || [new YangModelCmHandle.Property("name1", "value1")] || [] + 'just public properties' | childDataNodesForCmHandleWithPublicProperties || [] || [new YangModelCmHandle.Property("name2", "value2")] + } +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy deleted file mode 100644 index 49de4422e..000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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.models - -import spock.lang.Specification - -import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA -import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL - -class PersistenceCmHandleSpec extends Specification { - - def 'Creating persistence cm handle from a cm handle.'() { - given: 'a cm handle with properties' - def cmHandle = new CmHandle() - cmHandle.dmiProperties = [myDmiProperty:'value1'] - cmHandle.publicProperties = [myPublicProperty:'value2'] - when: 'it is converted to a persistence cm handle' - def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle('','','', cmHandle) - then: 'the result has the right size' - assert objectUnderTest.dmiProperties.size() == 1 - and: 'the DMI property in the result has the correct name and value' - assert objectUnderTest.dmiProperties[0].name == 'myDmiProperty' - assert objectUnderTest.dmiProperties[0].value == 'value1' - and: 'the public property in the result has the correct name and value' - assert objectUnderTest.publicProperties[0].name == 'myPublicProperty' - assert objectUnderTest.publicProperties[0].value == 'value2' - } - - def 'Resolve DMI service name: #scenario and #requiredService service require.'() { - given: 'a Persistence CM Handle' - def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new CmHandle()) - expect: - assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService - where: - scenario | dmiServiceName | dmiDataServiceName | dmiModelServiceName | requiredService || expectedService - 'common service registered' | 'common service' | 'does not matter' | 'does not matter' | DATA || 'common service' - 'common service registered' | 'common service' | 'does not matter' | 'does not matter' | MODEL || 'common service' - 'common service empty' | '' | 'data service' | 'does not matter' | DATA || 'data service' - 'common service empty' | '' | 'does not matter' | 'model service' | MODEL || 'model service' - 'common service blank' | ' ' | 'data service' | 'does not matter' | DATA || 'data service' - 'common service blank' | ' ' | 'does not matter' | 'model service' | MODEL || 'model service' - 'common service null ' | null | 'data service' | 'does not matter' | DATA || 'data service' - 'common service null' | null | 'does not matter' | 'model service' | MODEL || 'model service' - 'only model service registered' | null | null | 'does not matter' | DATA || null - 'only data service registered' | null | 'does not matter' | null | MODEL || null - } - -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy new file mode 100644 index 000000000..470015ec1 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.models + +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import spock.lang.Specification + +import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA +import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL + +class YangModelCmHandleSpec extends Specification { + + def 'Creating yang model cm handle from a service api cm handle.'() { + given: 'a cm handle with properties' + def ncmpServiceCmHandle = new NcmpServiceCmHandle() + ncmpServiceCmHandle.dmiProperties = [myDmiProperty:'value1'] + ncmpServiceCmHandle.publicProperties = [myPublicProperty:'value2'] + when: 'it is converted to a yang model cm handle' + def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('','','', ncmpServiceCmHandle) + then: 'the result has the right size' + assert objectUnderTest.dmiProperties.size() == 1 + and: 'the DMI property in the result has the correct name and value' + assert objectUnderTest.dmiProperties[0].name == 'myDmiProperty' + assert objectUnderTest.dmiProperties[0].value == 'value1' + and: 'the public property in the result has the correct name and value' + assert objectUnderTest.publicProperties[0].name == 'myPublicProperty' + assert objectUnderTest.publicProperties[0].value == 'value2' + } + + def 'Resolve DMI service name: #scenario and #requiredService service require.'() { + given: 'a yang model cm handle' + def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new NcmpServiceCmHandle()) + expect: + assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService + where: + scenario | dmiServiceName | dmiDataServiceName | dmiModelServiceName | requiredService || expectedService + 'common service registered' | 'common service' | 'does not matter' | 'does not matter' | DATA || 'common service' + 'common service registered' | 'common service' | 'does not matter' | 'does not matter' | MODEL || 'common service' + 'common service empty' | '' | 'data service' | 'does not matter' | DATA || 'data service' + 'common service empty' | '' | 'does not matter' | 'model service' | MODEL || 'model service' + 'common service blank' | ' ' | 'data service' | 'does not matter' | DATA || 'data service' + 'common service blank' | ' ' | 'does not matter' | 'model service' | MODEL || 'model service' + 'common service null ' | null | 'data service' | 'does not matter' | DATA || 'data service' + 'common service null' | null | 'does not matter' | 'model service' | MODEL || 'model service' + 'only model service registered' | null | null | 'does not matter' | DATA || null + 'only data service registered' | null | 'does not matter' | null | MODEL || null + } + +} -- cgit 1.2.3-korg