summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorJosephKeenan <joseph.keenan@est.tech>2021-08-20 10:33:54 +0100
committerJosephKeenan <joseph.keenan@est.tech>2021-08-30 17:38:03 +0100
commit0af60de4fbb3a3e6c828e179c667b173b1539b62 (patch)
tree0694c43ec6f905e250fd74be87c3b6627bbdbf44 /cps-ncmp-service/src/main
parent7edbeb6d5853206cc1d3b4cadd7ba50e96f4f04d (diff)
CPS-505 Retrieving modules for new CM handle
-Added some production code for getting missing modules for new CM handle -Groovy test template added by Toine for getting msissing modules -Added json example for test -Modified test to check map contents -Differentiated restTemplate calls based on URL -Fixed code review comment`s -Groovy test now passing -Modified behaviour for sending moduleReferences and added null to namespace (jira to follow) -Combined NetworkCmProxyDataServiceImpl tests into one class & addressed code review comments Issue-ID: CPS-505 Change-Id: I91ef65467496caea7834ba2e8af99cfe58d4f880 Signed-off-by: JosephKeenan <joseph.keenan@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java2
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java200
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java5
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java99
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandlesList.java14
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/YangResource.java34
6 files changed, 255 insertions, 99 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 03d70c18f6..0693f61e44 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
@@ -105,7 +105,7 @@ public interface NetworkCmProxyDataService {
*
* @param dmiPluginRegistration Dmi Plugin Registration
*/
- void updateDmiPluginRegistration(DmiPluginRegistration dmiPluginRegistration);
+ void updateDmiRegistrationAndSyncModule(DmiPluginRegistration dmiPluginRegistration);
/**
* Get resource data for data store pass-through operational
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 11477abe0d..dfe5603431 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
@@ -25,16 +25,23 @@ package org.onap.cps.ncmp.api.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import java.time.OffsetDateTime;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsModuleService;
import org.onap.cps.api.CpsQueryService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.api.impl.exception.NcmpException;
@@ -44,10 +51,12 @@ import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.GenericRequestBody;
import org.onap.cps.ncmp.api.models.PersistenceCmHandle;
import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList;
+import org.onap.cps.ncmp.api.models.YangResource;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.spi.model.ModuleReference;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -75,6 +84,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private DmiOperations dmiOperations;
+ private CpsModuleService cpsModuleService;
+
+ private CpsAdminService cpsAdminService;
+
+ public static final String NO_NAMESPACE = null;
+
/**
* Constructor Injection for Dependencies.
* @param dmiOperations DMI operation
@@ -82,58 +97,60 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
* @param cpsQueryService Query Service Interface
* @param objectMapper Object Mapper
*/
- public NetworkCmProxyDataServiceImpl(final DmiOperations dmiOperations, final CpsDataService cpsDataService,
- final CpsQueryService cpsQueryService, final ObjectMapper objectMapper) {
+ public NetworkCmProxyDataServiceImpl(final DmiOperations dmiOperations,
+ final CpsModuleService cpsModuleService,
+ final CpsDataService cpsDataService,
+ final CpsQueryService cpsQueryService,
+ final CpsAdminService cpsAdminService,
+ final ObjectMapper objectMapper) {
this.dmiOperations = dmiOperations;
+ this.cpsModuleService = cpsModuleService;
this.cpsDataService = cpsDataService;
this.cpsQueryService = cpsQueryService;
+ this.cpsAdminService = cpsAdminService;
this.objectMapper = objectMapper;
}
- private String getDataspaceName() {
- return NF_PROXY_DATASPACE_NAME;
- }
-
@Override
public DataNode getDataNode(final String cmHandle, final String xpath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataService.getDataNode(getDataspaceName(), cmHandle, xpath, fetchDescendantsOption);
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return cpsDataService.getDataNode(NF_PROXY_DATASPACE_NAME, cmHandle, xpath, fetchDescendantsOption);
}
@Override
public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsQueryService.queryDataNodes(getDataspaceName(), cmHandle, cpsPath, fetchDescendantsOption);
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return cpsQueryService.queryDataNodes(NF_PROXY_DATASPACE_NAME, cmHandle, cpsPath, fetchDescendantsOption);
}
@Override
public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
if (!StringUtils.hasText(parentNodeXpath) || "/".equals(parentNodeXpath)) {
- cpsDataService.saveData(getDataspaceName(), cmHandle, jsonData, NO_TIMESTAMP);
+ cpsDataService.saveData(NF_PROXY_DATASPACE_NAME, cmHandle, jsonData, NO_TIMESTAMP);
} else {
- cpsDataService.saveData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
+ cpsDataService.saveData(NF_PROXY_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
}
}
@Override
public void addListNodeElements(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.saveListNodeData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
+ cpsDataService.saveListNodeData(NF_PROXY_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
}
@Override
public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.updateNodeLeaves(getDataspaceName(), cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
+ cpsDataService.updateNodeLeaves(NF_PROXY_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
}
@Override
public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.replaceNodeTree(getDataspaceName(), cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
+ cpsDataService.replaceNodeTree(NF_PROXY_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
}
@Override
- public void updateDmiPluginRegistration(final DmiPluginRegistration dmiPluginRegistration) {
+ public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) {
if (dmiPluginRegistration.getCreatedCmHandles() != null) {
- parseAndCreateCmHandlesInDmiRegistration(dmiPluginRegistration);
+ parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(dmiPluginRegistration);
}
if (dmiPluginRegistration.getUpdatedCmHandles() != null) {
parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration);
@@ -218,10 +235,10 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private String prepareOperationBody(final GenericRequestBody requestBodyObject) {
try {
return objectMapper.writeValueAsString(requestBodyObject);
- } catch (final JsonProcessingException je) {
+ } catch (final JsonProcessingException e) {
log.error("Parsing error occurred while converting Object to JSON.");
throw new NcmpException("Parsing error occurred while converting given object to JSON.",
- je.getMessage());
+ e.getMessage());
}
}
@@ -265,67 +282,132 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return prepareOperationBody(requetBodyObject);
}
- private PersistenceCmHandle toPersistenceCmHandle(final String dmiPluginService,
- final CmHandle cmHandle) {
- final PersistenceCmHandle persistenceCmHandle = new PersistenceCmHandle();
- persistenceCmHandle.setDmiServiceName(dmiPluginService);
- persistenceCmHandle.setId(cmHandle.getCmHandleID());
- if (cmHandle.getCmHandleProperties() == null) {
- persistenceCmHandle.setAdditionalProperties(Collections.EMPTY_MAP);
- } else {
- persistenceCmHandle.setAdditionalProperties(cmHandle.getCmHandleProperties());
+ private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
+ try {
+ final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList();
+
+ for (final CmHandle cmHandle : dmiPluginRegistration.getUpdatedCmHandles()) {
+ final PersistenceCmHandle persistenceCmHandle =
+ toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle);
+ persistenceCmHandlesList.add(persistenceCmHandle);
+ }
+ final String cmHandlesJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
+ cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ "/dmi-registry", cmHandlesJsonData, NO_TIMESTAMP);
+ } catch (final JsonProcessingException e) {
+ log.error("Parsing error occurred while converting Object to JSON DMI Registry.");
+ throw new DataValidationException(
+ "Parsing error occurred while processing DMI Plugin Registration" + dmiPluginRegistration, e
+ .getMessage(), e);
}
- return persistenceCmHandle;
}
- private void parseAndCreateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
+ private void parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(
+ final DmiPluginRegistration dmiPluginRegistration) {
try {
- final List<PersistenceCmHandle> createdPersistenceCmHandles =
- new LinkedList<>();
- for (final CmHandle cmHandle: dmiPluginRegistration.getCreatedCmHandles()) {
- createdPersistenceCmHandles.add(toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle));
+ final var persistenceCmHandlesList = new PersistenceCmHandlesList();
+ for (final CmHandle cmHandle : dmiPluginRegistration.getCreatedCmHandles()) {
+ final PersistenceCmHandle persistenceCmHandle =
+ toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle);
+ persistenceCmHandlesList.add(persistenceCmHandle);
+ createAnchorAndSyncModel(persistenceCmHandle);
}
- final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList();
- persistenceCmHandlesList.setCmHandles(createdPersistenceCmHandles);
final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
cpsDataService.saveListNodeData(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry",
- cmHandleJsonData, NO_TIMESTAMP);
+ cmHandleJsonData, NO_TIMESTAMP);
} catch (final JsonProcessingException e) {
log.error("Parsing error occurred while converting Object to JSON for DMI Registry.");
throw new DataValidationException(
- "Parsing error occurred while processing DMI Plugin Registration" + dmiPluginRegistration, e
- .getMessage(), e);
+ "Parsing error occurred while processing DMI Plugin Registration" + dmiPluginRegistration, e
+ .getMessage(), e);
}
}
- private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
- try {
- final List<PersistenceCmHandle> updatedPersistenceCmHandles =
- new LinkedList<>();
- for (final CmHandle cmHandle: dmiPluginRegistration.getUpdatedCmHandles()) {
- updatedPersistenceCmHandles.add(toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle));
- }
- final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList();
- persistenceCmHandlesList.setCmHandles(updatedPersistenceCmHandles);
- final String cmHandlesJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
- cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry", cmHandlesJsonData, NO_TIMESTAMP);
- } catch (final JsonProcessingException e) {
- log.error("Parsing error occurred while converting Object to JSON DMI Registry.");
- throw new DataValidationException(
- "Parsing error occurred while processing DMI Plugin Registration" + dmiPluginRegistration, e
- .getMessage(), e);
+ private PersistenceCmHandle toPersistenceCmHandle(final String dmiPluginService,
+ final CmHandle cmHandle) {
+ final PersistenceCmHandle persistenceCmHandle = new PersistenceCmHandle();
+ persistenceCmHandle.setDmiServiceName(dmiPluginService);
+ persistenceCmHandle.setId(cmHandle.getCmHandleID());
+ if (cmHandle.getCmHandleProperties() == null) {
+ persistenceCmHandle.setAdditionalProperties(Collections.EMPTY_MAP);
+ } else {
+ persistenceCmHandle.setAdditionalProperties(cmHandle.getCmHandleProperties());
}
+ return persistenceCmHandle;
}
private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
- for (final String cmHandle: dmiPluginRegistration.getRemovedCmHandles()) {
+ for (final String cmHandle : dmiPluginRegistration.getRemovedCmHandles()) {
try {
cpsDataService.deleteListNodeData(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
+ "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
} catch (final DataNodeNotFoundException e) {
log.warn("Datanode {} not deleted message {}", cmHandle, e.getMessage());
}
}
}
+
+ protected void createAnchorAndSyncModel(final PersistenceCmHandle cmHandle) {
+ final var modulesForCmHandle =
+ dmiOperations.getResourceFromDmi(cmHandle.getDmiServiceName(), cmHandle.getId(), "modules");
+
+ final List<ModuleReference> moduleReferencesFromDmiForCmHandle = getModuleReferences(modulesForCmHandle);
+
+ final var knownModuleReferencesInCps = cpsModuleService.getAllYangResourcesModuleReferences();
+
+ final List<ModuleReference> existingModuleReferences = new ArrayList<>();
+ for (final ModuleReference moduleReferenceFromDmiForCmHandle : moduleReferencesFromDmiForCmHandle) {
+ if (knownModuleReferencesInCps.contains(moduleReferenceFromDmiForCmHandle)) {
+ existingModuleReferences.add(moduleReferenceFromDmiForCmHandle);
+ }
+ }
+
+ final Map<String, String> newYangResourcesModuleNameToContentMap =
+ getNewYangResources(cmHandle);
+
+ cpsModuleService.createSchemaSetFromModules(NCMP_DATASPACE_NAME, cmHandle.getId(),
+ newYangResourcesModuleNameToContentMap, existingModuleReferences);
+
+ cpsAdminService.createAnchor(NCMP_DATASPACE_NAME, cmHandle.getId(), cmHandle.getId());
+ }
+
+ private Map<String, String> getNewYangResources(final PersistenceCmHandle cmHandle) {
+ final var moduleResourcesAsJsonString = dmiOperations.getResourceFromDmi(
+ cmHandle.getDmiServiceName(), cmHandle.getId(), "moduleResources");
+ final JsonArray moduleResources = new Gson().fromJson(moduleResourcesAsJsonString.getBody(), JsonArray.class);
+ final Map<String, String> newYangResourcesModuleNameToContentMap = new HashMap<>();
+
+ for (final JsonElement moduleResource : moduleResources) {
+ final YangResource yangResource = toYangResource((JsonObject) moduleResource);
+ newYangResourcesModuleNameToContentMap.put(yangResource.getModuleName(), yangResource.getYangSource());
+ }
+ return newYangResourcesModuleNameToContentMap;
+ }
+
+ private YangResource toYangResource(final JsonObject yangResourceAsJson) {
+ final YangResource yangResource = new YangResource();
+ yangResource.setModuleName(yangResourceAsJson.get("moduleName").getAsString());
+ yangResource.setRevision(yangResourceAsJson.get("revision").getAsString());
+ yangResource.setYangSource(yangResourceAsJson.get("yangSource").getAsString());
+ return yangResource;
+ }
+
+ private List<ModuleReference> getModuleReferences(final ResponseEntity<String> response) {
+ final List<ModuleReference> modulesFromDmiForCmHandle = new ArrayList<>();
+ final JsonObject convertedObject = new Gson().fromJson(response.getBody(), JsonObject.class);
+ final JsonArray moduleReferencesAsJson = convertedObject.getAsJsonArray("schemas");
+ for (final JsonElement moduleReferenceAsJson : moduleReferencesAsJson) {
+ final ModuleReference moduleReference = toModuleReference((JsonObject) moduleReferenceAsJson);
+ modulesFromDmiForCmHandle.add(moduleReference);
+ }
+ return modulesFromDmiForCmHandle;
+ }
+
+ private ModuleReference toModuleReference(final JsonObject moduleReferenceAsJson) {
+ final var moduleReference = new ModuleReference();
+ moduleReference.setName(moduleReferenceAsJson.get("moduleName").getAsString());
+ moduleReference.setNamespace(NO_NAMESPACE);
+ moduleReference.setRevision(moduleReferenceAsJson.get("revision").getAsString());
+ return moduleReference;
+ }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
index cc4e2c7881..af691f6341 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
@@ -57,4 +57,9 @@ public class DmiRestClient {
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return httpHeaders;
}
+
+ public ResponseEntity<String> postOperation(final String dmiResourceUrl, final HttpHeaders httpHeaders) {
+ final var httpEntity = new HttpEntity<>(configureHttpHeaders(httpHeaders));
+ return restTemplate.exchange(dmiResourceUrl, HttpMethod.POST, httpEntity, String.class);
+ }
} \ No newline at end of file
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
index 63c4d49a91..8896b9fd59 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
@@ -30,7 +30,6 @@ import org.springframework.stereotype.Component;
@Component
public class DmiOperations {
-
@Getter
public enum DataStoreEnum {
PASSTHROUGH_OPERATIONAL("ncmp-datastore:passthrough-operational"),
@@ -49,9 +48,9 @@ public class DmiOperations {
}
private DmiRestClient dmiRestClient;
- private static final String DMI_BASE_PATH = "/dmi/api";
- private static final String PARENT_CM_HANDLE_URI =
- "/v1/ch/{cmHandle}/data/ds";
+ private static final String DMI_API_PATH = "/dmi/api";
+ private static final String DMI_CM_HANDLE_PATH = "/v1/ch/{cmHandle}";
+ private static final String DMI_CM_HANDLE_DATASTORE_PATH = DMI_CM_HANDLE_PATH + "/data/ds";
private static final String URL_SEPARATOR = "/";
/**
@@ -64,27 +63,44 @@ public class DmiOperations {
}
/**
+ * Get resources from DMI.
+ *
+ * @param dmiServiceName dmi base path
+ * @param cmHandle cmHandle
+ * @param resourceName name of the resource(s)
+ * @return {@code ResponseEntity} response entity
+ */
+ public ResponseEntity<String> getResourceFromDmi(final String dmiServiceName,
+ final String cmHandle,
+ final String resourceName) {
+ final var dmiResourceDataUrl = getDmiResourceUrl(dmiServiceName, cmHandle, resourceName);
+ final var httpHeaders = new HttpHeaders();
+ return dmiRestClient.postOperation(dmiResourceDataUrl, httpHeaders);
+
+ }
+
+ /**
* This method fetches the resource data from operational data store for given cm handle
* identifier on given resource using dmi client.
*
- * @param dmiBasePath dmi base path
- * @param cmHandle network resource identifier
- * @param resourceId resource identifier
+ * @param dmiServiceName dmi service name
+ * @param cmHandle network resource identifier
+ * @param resourceId resource identifier
* @param fieldsQuery fields query
- * @param depthQuery depth query
+ * @param depthQuery depth query
* @param acceptParam accept parameter
- * @param jsonBody json body for put operation
+ * @param jsonBody json body for put operation
* @return {@code ResponseEntity} response entity
*/
- public ResponseEntity<Object> getResourceDataOperationalFromDmi(final String dmiBasePath,
+ public ResponseEntity<Object> getResourceDataOperationalFromDmi(final String dmiServiceName,
final String cmHandle,
final String resourceId,
final String fieldsQuery,
final Integer depthQuery,
final String acceptParam,
final String jsonBody) {
- final var dmiResourceDataUrl = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId,
- fieldsQuery, depthQuery, DataStoreEnum.PASSTHROUGH_OPERATIONAL);
+ final var dmiResourceDataUrl = getDmiDatastoreUrl(dmiServiceName, cmHandle, resourceId,
+ fieldsQuery, depthQuery, DataStoreEnum.PASSTHROUGH_OPERATIONAL);
final var httpHeaders = prepareHeader(acceptParam);
return dmiRestClient.putOperationWithJsonData(dmiResourceDataUrl, jsonBody, httpHeaders);
}
@@ -93,24 +109,24 @@ public class DmiOperations {
* This method fetches the resource data from pass-through running data store for given cm handle
* identifier on given resource using dmi client.
*
- * @param dmiBasePath dmi base path
- * @param cmHandle network resource identifier
- * @param resourceId resource identifier
+ * @param dmiServiceName dmi service name
+ * @param cmHandle network resource identifier
+ * @param resourceId resource identifier
* @param fieldsQuery fields query
- * @param depthQuery depth query
+ * @param depthQuery depth query
* @param acceptParam accept parameter
- * @param jsonBody json body for put operation
+ * @param jsonBody json body for put operation
* @return {@code ResponseEntity} response entity
*/
- public ResponseEntity<Object> getResourceDataPassThroughRunningFromDmi(final String dmiBasePath,
+ public ResponseEntity<Object> getResourceDataPassThroughRunningFromDmi(final String dmiServiceName,
final String cmHandle,
final String resourceId,
final String fieldsQuery,
final Integer depthQuery,
final String acceptParam,
final String jsonBody) {
- final var dmiResourceDataUrl = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId,
- fieldsQuery, depthQuery, DataStoreEnum.PASSTHROUGH_RUNNING);
+ final var dmiResourceDataUrl = getDmiDatastoreUrl(dmiServiceName, cmHandle, resourceId,
+ fieldsQuery, depthQuery, DataStoreEnum.PASSTHROUGH_RUNNING);
final var httpHeaders = prepareHeader(acceptParam);
return dmiRestClient.putOperationWithJsonData(dmiResourceDataUrl, jsonBody, httpHeaders);
}
@@ -120,9 +136,9 @@ public class DmiOperations {
* identifier on given resource using dmi client.
*
* @param dmiBasePath dmi base path
- * @param cmHandle network resource identifier
- * @param resourceId resource identifier
- * @param jsonBody json body for put operation
+ * @param cmHandle network resource identifier
+ * @param resourceId resource identifier
+ * @param jsonBody json body for put operation
* @return {@code ResponseEntity} response entity
*/
public ResponseEntity<Void> createResourceDataPassThroughRunningFromDmi(final String dmiBasePath,
@@ -130,19 +146,30 @@ public class DmiOperations {
final String resourceId,
final String jsonBody) {
final var stringBuilder = getStringBuilderForPassThroughRunningUrl(dmiBasePath,
- cmHandle, resourceId, DataStoreEnum.PASSTHROUGH_RUNNING);
+ cmHandle, resourceId, DataStoreEnum.PASSTHROUGH_RUNNING);
return dmiRestClient.postOperationWithJsonData(stringBuilder.toString(), jsonBody, new HttpHeaders());
}
@NotNull
- private String getDmiResourceDataUrl(final String dmiBasePath,
- final String cmHandle,
- final String resourceId,
- final String fieldsQuery,
- final Integer depthQuery,
- final DataStoreEnum dataStoreEnum) {
- final var stringBuilder = getStringBuilderForPassThroughRunningUrl(dmiBasePath,
- cmHandle, resourceId, dataStoreEnum);
+ private String getDmiResourceUrl(final String dmiServiceName,
+ final String cmHandle,
+ final String resourceName) {
+ final var stringBuilder = new StringBuilder(dmiServiceName);
+ stringBuilder.append(DMI_API_PATH);
+ stringBuilder.append(DMI_CM_HANDLE_PATH.replace("{cmHandle}", cmHandle));
+ stringBuilder.append(URL_SEPARATOR + resourceName);
+ return stringBuilder.toString();
+ }
+
+ @NotNull
+ private String getDmiDatastoreUrl(final String dmiServiceName,
+ final String cmHandle,
+ final String resourceId,
+ final String fieldsQuery,
+ final Integer depthQuery,
+ final DataStoreEnum dataStoreEnum) {
+ final var stringBuilder = getStringBuilderForPassThroughRunningUrl(dmiServiceName,
+ cmHandle, resourceId, dataStoreEnum);
appendFieldsAndDepth(stringBuilder, fieldsQuery, depthQuery);
return stringBuilder.toString();
}
@@ -152,11 +179,11 @@ public class DmiOperations {
final String cmHandle,
final String resourceId,
final DataStoreEnum dataStoreEnum) {
- final var stringBuilder = new StringBuilder(dmiServiceName);
- stringBuilder.append(DMI_BASE_PATH);
- stringBuilder.append(PARENT_CM_HANDLE_URI.replace("{cmHandle}", cmHandle));
+ final var stringBuilder = new StringBuilder(dmiServiceName);
+ stringBuilder.append(DMI_API_PATH);
+ stringBuilder.append(DMI_CM_HANDLE_DATASTORE_PATH.replace("{cmHandle}", cmHandle));
stringBuilder.append(URL_SEPARATOR + dataStoreEnum.getValue());
- stringBuilder.insert(stringBuilder.length(), URL_SEPARATOR + resourceId);
+ stringBuilder.append(URL_SEPARATOR + resourceId);
return stringBuilder;
}
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
index 95e8515d51..beeb00f116 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/models/PersistenceCmHandlesList.java
@@ -27,10 +27,18 @@ import java.util.List;
public class PersistenceCmHandlesList {
@JsonProperty("cm-handles")
- private List<PersistenceCmHandle> cmHandles;
+ private List<PersistenceCmHandle> persistenceCmHandles;
- public void setCmHandles(final List<PersistenceCmHandle> cmHandlesAsList) {
- cmHandles = new ArrayList<>(cmHandlesAsList);
+ /**
+ * Add a persistenceCmHandle.
+ *
+ * @param persistenceCmHandle the persistenceCmHandle to add
+ */
+ public void add(final PersistenceCmHandle persistenceCmHandle) {
+ if (persistenceCmHandles == null) {
+ persistenceCmHandles = new ArrayList<>();
+ }
+ persistenceCmHandles.add(persistenceCmHandle);
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/YangResource.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/YangResource.java
new file mode 100644
index 0000000000..7975777aa5
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/YangResource.java
@@ -0,0 +1,34 @@
+/*
+ * ============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 lombok.Data;
+
+@Data
+public class YangResource {
+
+ private String moduleName;
+
+ private String revision;
+
+ private String yangSource;
+
+}