diff options
author | 2022-01-27 17:12:52 +0000 | |
---|---|---|
committer | 2022-03-01 16:17:16 +0000 | |
commit | e557338803286d8aaa0f877aa25d52d18735f309 (patch) | |
tree | 059b68301b3e6c34d8bb68a8cb7dadf6bed45a06 /cps-ncmp-service/src/main/java/org/onap | |
parent | 03459a08895ecc7e481fc5ec34779556268992f1 (diff) |
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 <dylan.byrne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
12 files changed, 218 insertions, 152 deletions
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<ModuleReference> getYangResourcesModuleReferences(String cmHandle); + Collection<ModuleReference> getYangResourcesModuleReferences(String cmHandleId); /** * Query cm handle identifiers for the given collection of module names. @@ -103,4 +104,12 @@ public interface NetworkCmProxyDataService { */ Collection<String> executeCmHandleHasAllModulesSearch(Collection<String> 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<ModuleReference> getYangResourcesModuleReferences(final String cmHandle) { - return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle); + public Collection<ModuleReference> 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<YangModelCmHandle.Property> dmiProperties = yangModelCmHandle.getDmiProperties(); + final List<YangModelCmHandle.Property> publicProperties = yangModelCmHandle.getPublicProperties(); + ncmpServiceCmHandle.setCmHandleID(yangModelCmHandle.getId()); + setDmiProperties(dmiProperties, ncmpServiceCmHandle); + setPublicProperties(publicProperties, ncmpServiceCmHandle); + return ncmpServiceCmHandle; + } + + private void setDmiProperties(final List<YangModelCmHandle.Property> dmiProperties, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final Map<String, String> dmiPropertiesMap = new LinkedHashMap<>(dmiProperties.size()); + asPropertiesMap(dmiProperties, dmiPropertiesMap); + ncmpServiceCmHandle.setDmiProperties(dmiPropertiesMap); + } + + private void setPublicProperties(final List<YangModelCmHandle.Property> publicProperties, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final Map<String, String> publicPropertiesMap = new LinkedHashMap<>(); + asPropertiesMap(publicProperties, publicPropertiesMap); + ncmpServiceCmHandle.setPublicProperties(publicPropertiesMap); + } + + private void asPropertiesMap(final List<YangModelCmHandle.Property> properties, + final Map<String, String> 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<CmHandle> updatedCmHandles) { - return PersistenceCmHandlesList.toPersistenceCmHandlesList( + final List<NcmpServiceCmHandle> 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<ModuleReference> moduleReferencesFromCmHandle = - dmiModelOperations.getModuleReferences(persistenceCmHandle); + dmiModelOperations.getModuleReferences(yangModelCmHandle); final Collection<ModuleReference> 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<CmHandle> cmHandles) throws DataNodeNotFoundException { - for (final CmHandle cmHandle : cmHandles) { + public void updateCmHandleProperties(final Collection<NcmpServiceCmHandle> 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<Object> getResourceDataFromDmi(final String cmHandle, + public ResponseEntity<Object> 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<Object> writeResourceDataPassThroughRunningFromDmi(final String cmHandle, + public ResponseEntity<Object> 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<ModuleReference> getModuleReferences(final PersistenceCmHandle persistenceCmHandle) { + public List<ModuleReference> getModuleReferences(final YangModelCmHandle yangModelCmHandle) { final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .build(); - dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); + dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties()); final ResponseEntity<Object> 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<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle, + public Map<String, String> getNewYangResourcesFromDmi(final YangModelCmHandle yangModelCmHandle, final Collection<ModuleReference> newModuleReferences) { final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources( - newModuleReferences, persistenceCmHandle.getDmiProperties()); + newModuleReferences, yangModelCmHandle.getDmiProperties()); final ResponseEntity<Object> 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<ModuleReference> newModuleReferences, - final List<PersistenceCmHandle.Property> dmiProperties) { + final List<YangModelCmHandle.Property> 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<PersistenceCmHandle.Property> + private static JsonObject toJsonObject(final List<YangModelCmHandle.Property> 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<String, String> 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<PersistenceCmHandle.Property> dmiPropertiesAsList) { + final List<YangModelCmHandle.Property> 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/YangModelCmHandleRetriever.java index c489eef8e..6b6bdf5be 100644 --- 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/YangModelCmHandleRetriever.java @@ -24,39 +24,39 @@ 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.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 PersistenceCmHandles & properties. + * Retrieves YangModelCmHandles & properties. */ @Component @AllArgsConstructor -public class PersistenceCmHandleRetriever { +public class YangModelCmHandleRetriever { private static final String NCMP_DATASPACE_NAME = "NCMP-Admin"; private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; - private final CpsDataService cpsDataService; + 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 persistence cm handle + * @return yang model cm handle */ - public PersistenceCmHandle retrieveCmHandleDmiServiceNameAndDmiProperties(final String cmHandleId) { + public YangModelCmHandle getDmiServiceNamesAndProperties(final String cmHandleId) { final DataNode cmHandleDataNode = getCmHandleDataNode(cmHandleId); - final CmHandle cmHandle = new CmHandle(); - cmHandle.setCmHandleID(cmHandleId); - populateCmHandleDmiProperties(cmHandleDataNode, cmHandle); - return PersistenceCmHandle.toPersistenceCmHandle( + 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")), - cmHandle + ncmpServiceCmHandle ); } @@ -68,14 +68,19 @@ public class PersistenceCmHandleRetriever { FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); } - private static void populateCmHandleDmiProperties(final DataNode cmHandleDataNode, final CmHandle cmHandle) { + private static void populateCmHandleProperties(final DataNode cmHandleDataNode, + final NcmpServiceCmHandle ncmpServiceCmHandle) { final Map<String, String> dmiProperties = new LinkedHashMap<>(); + final Map<String, String> 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); } } - cmHandle.setDmiProperties(dmiProperties); + ncmpServiceCmHandle.setDmiProperties(dmiProperties); + ncmpServiceCmHandle.setPublicProperties(publicProperties); } private static void addProperty(final DataNode propertyDataNode, final Map<String, String> propertiesAsMap) { 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/impl/yangmodels/YangModelCmHandle.java index cc32bb75c..47062b354 100644 --- 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/impl/yangmodels/YangModelCmHandle.java @@ -19,7 +19,7 @@ */ -package org.onap.cps.ncmp.api.models; +package org.onap.cps.ncmp.api.impl.yangmodels; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Strings; @@ -32,14 +32,16 @@ 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; /** - * DmiRegistry. + * 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 PersistenceCmHandle { +public class YangModelCmHandle { private String id; @@ -59,25 +61,26 @@ public class PersistenceCmHandle { private List<Property> publicProperties; /** - * Create a persistenceCmHandle. + * Create a yangModelCmHandle. * @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 + * @param ncmpServiceCmHandle the cm handle + * @return instance of yangModelCmHandle */ - 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; + 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; } /** @@ -95,12 +98,12 @@ public class PersistenceCmHandle { return dmiServiceName; } - private static List<Property> asPersistenceCmHandleProperties(final Map<String, String> propertiesAsMap) { - final List<Property> persistenceCmHandleProperties = new ArrayList<>(propertiesAsMap.size()); + private static List<Property> asYangModelCmHandleProperties(final Map<String, String> propertiesAsMap) { + final List<Property> yangModelCmHandleProperties = new ArrayList<>(propertiesAsMap.size()); for (final Map.Entry<String, String> entry : propertiesAsMap.entrySet()) { - persistenceCmHandleProperties.add(new PersistenceCmHandle.Property(entry.getKey(), entry.getValue())); + yangModelCmHandleProperties.add(new YangModelCmHandle.Property(entry.getKey(), entry.getValue())); } - return persistenceCmHandleProperties; + return yangModelCmHandleProperties; } private static boolean isNullEmptyOrBlank(final String serviceName) { 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/impl/yangmodels/YangModelCmHandlesList.java index 9762ac4e1..261a0181c 100644 --- 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/impl/yangmodels/YangModelCmHandlesList.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * 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. @@ -18,51 +18,53 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.models; +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 PersistenceCmHandlesList { +public class YangModelCmHandlesList { @JsonProperty("cm-handles") - private final List<PersistenceCmHandle> persistenceCmHandles = new ArrayList<>(); + private final List<YangModelCmHandle> yangModelCmHandles = new ArrayList<>(); /** - * Create a PersistenceCmHandleList given all service names and a collection of cmHandles. + * 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 cmHandles cm handles - * @return instance of PersistenceCmHandleList + * @param ncmpServiceCmHandles cm handles rest model + * @return instance of YangModelCmHandleList */ - public static PersistenceCmHandlesList toPersistenceCmHandlesList(final String dmiServiceName, - final String dmiDataServiceName, - final String dmiModelServiceName, - final Collection<CmHandle> cmHandles) { - final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList(); - for (final CmHandle cmHandle : cmHandles) { - final PersistenceCmHandle persistenceCmHandle = - PersistenceCmHandle.toPersistenceCmHandle( + public static YangModelCmHandlesList toYangModelCmHandlesList(final String dmiServiceName, + final String dmiDataServiceName, + final String dmiModelServiceName, + final Collection<NcmpServiceCmHandle> + ncmpServiceCmHandles) { + final YangModelCmHandlesList yangModelCmHandlesList = new YangModelCmHandlesList(); + for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) { + final YangModelCmHandle yangModelCmHandle = + YangModelCmHandle.toYangModelCmHandle( dmiServiceName, dmiDataServiceName, dmiModelServiceName, - cmHandle); - persistenceCmHandlesList.add(persistenceCmHandle); + ncmpServiceCmHandle); + yangModelCmHandlesList.add(yangModelCmHandle); } - return persistenceCmHandlesList; + return yangModelCmHandlesList; } /** - * Add a persistenceCmHandle. + * Add a yangModelCmHandle. * - * @param persistenceCmHandle the persistenceCmHandle to add + * @param yangModelCmHandle the yangModelCmHandle to add */ - public void add(final PersistenceCmHandle persistenceCmHandle) { - persistenceCmHandles.add(persistenceCmHandle); + public void add(final YangModelCmHandle yangModelCmHandle) { + yangModelCmHandles.add(yangModelCmHandle); } } 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<CmHandle> createdCmHandles = Collections.emptyList(); + private List<NcmpServiceCmHandle> createdCmHandles = Collections.emptyList(); - private List<CmHandle> updatedCmHandles = Collections.emptyList(); + private List<NcmpServiceCmHandle> updatedCmHandles = Collections.emptyList(); private List<String> 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/CmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java index 88c6f3376..938127020 100644 --- 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/NcmpServiceCmHandle.java @@ -30,13 +30,14 @@ import lombok.Setter; import org.springframework.validation.annotation.Validated; /** - * CmHandle. + * The NCMP Service model used for the java service API. + * NCMP Service CmHandle. */ @Validated @Getter @Setter @NoArgsConstructor -public class CmHandle { +public class NcmpServiceCmHandle { private String cmHandleID; |