summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java28
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java47
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java88
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy96
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy17
5 files changed, 230 insertions, 46 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 82be7bf55c..3e715e5e75 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
@@ -23,6 +23,7 @@
package org.onap.cps.ncmp.api;
import java.util.Collection;
+import javax.validation.constraints.NotNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.spi.FetchDescendantsOption;
@@ -117,9 +118,26 @@ public interface NetworkCmProxyDataService {
* @param depth depth query
* @return {@code Object} resource data
*/
- Object getResourceDataOperationalFoCmHandle(@NonNull String cmHandle,
- @NonNull String resourceIdentifier,
- String accept,
- String fields,
- Integer depth);
+ Object getResourceDataOperationalForCmHandle(@NotNull String cmHandle,
+ @NotNull String resourceIdentifier,
+ String accept,
+ String fields,
+ Integer depth);
+
+ /**
+ * Get resource data for data store pass-through running
+ * using dmi.
+ *
+ * @param cmHandle cm handle
+ * @param resourceIdentifier resource identifier
+ * @param accept accept param
+ * @param fields fields query
+ * @param depth depth query
+ * @return {@code Object} resource data
+ */
+ Object getResourceDataPassThroughRunningForCmHandle(@NotNull String cmHandle,
+ @NotNull String resourceIdentifier,
+ String accept,
+ String fields,
+ Integer depth);
}
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 84dcc770d9..c2be9e9db5 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
@@ -29,6 +29,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsQueryService;
@@ -149,17 +150,17 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
@Override
- public Object getResourceDataOperationalFoCmHandle(final String cmHandle,
- final String resourceIdentifier,
- final String acceptParam,
- final String fieldsQueryParam,
- final Integer depthQueryParam) {
-
- final DataNode dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
- final String dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name"));
+ public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle,
+ final @NotNull String resourceIdentifier,
+ final String acceptParam,
+ final String fieldsQueryParam,
+ final Integer depthQueryParam) {
+
+ final var dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
+ final var dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name"));
final Collection<DataNode> additionalPropsList = dataNode.getChildDataNodes();
- final String jsonBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList);
- final ResponseEntity<Object> response = dmiOperations.getResouceDataFromDmi(dmiServiceName,
+ final var jsonBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList);
+ final ResponseEntity<Object> response = dmiOperations.getResouceDataOperationalFromDmi(dmiServiceName,
cmHandle,
resourceIdentifier,
fieldsQueryParam,
@@ -169,6 +170,26 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return handleResponse(response);
}
+ @Override
+ public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle,
+ final @NotNull String resourceIdentifier,
+ final String accept,
+ final String fields,
+ final Integer depth) {
+ final var cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
+ final var dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name"));
+ final Collection<DataNode> additionalPropsList = cmHandleDataNode.getChildDataNodes();
+ final var dmiRequesBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList);
+ final ResponseEntity<Object> response = dmiOperations.getResouceDataPassThroughRunningFromDmi(dmiServiceName,
+ cmHandle,
+ resourceIdentifier,
+ fields,
+ depth,
+ accept,
+ dmiRequesBody);
+ return handleResponse(response);
+ }
+
private DataNode fetchDataNodeFromDmiRegistryForCmHandle(final String cmHandle) {
final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']";
final var dataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
@@ -180,12 +201,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private String prepareOperationBody(final GenericRequestBody.OperationEnum operation,
final Collection<DataNode> additionalPropertyList) {
- final GenericRequestBody requestBody = new GenericRequestBody();
+ final var requestBody = new GenericRequestBody();
final Map<String, String> additionalPropertyMap = getAdditionalPropertiesMap(additionalPropertyList);
requestBody.setOperation(GenericRequestBody.OperationEnum.READ);
requestBody.setCmHandleProperties(additionalPropertyMap);
try {
- final String requestJson = objectMapper.writeValueAsString(requestBody);
+ final var requestJson = objectMapper.writeValueAsString(requestBody);
return requestJson;
} catch (final JsonProcessingException je) {
log.error("Parsing error occurred while converting Object to JSON.");
@@ -199,7 +220,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return null;
}
final Map<String, String> additionalPropertyMap = new LinkedHashMap<>();
- for (final DataNode node: additionalPropertyList) {
+ for (final var node: additionalPropertyList) {
additionalPropertyMap.put(String.valueOf(node.getLeaves().get("name")),
String.valueOf(node.getLeaves().get("value")));
}
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 c7554bc482..2b13d165f2 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
@@ -20,6 +20,8 @@
package org.onap.cps.ncmp.api.impl.operation;
+import com.fasterxml.jackson.annotation.JsonValue;
+import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
import org.springframework.http.HttpHeaders;
@@ -29,10 +31,27 @@ import org.springframework.stereotype.Component;
@Component
public class DmiOperations {
+ @Getter
+ public enum PassThroughEnum {
+ OPERATIONAL("/ncmp-datastore:passthrough-operational/"),
+ RUNNING("/ncmp-datastore:passthrough-running/");
+ private String value;
+
+ PassThroughEnum(final String value) {
+ this.value = value;
+ }
+
+ @Override
+ @JsonValue
+ public String toString() {
+ return String.valueOf(value);
+ }
+ }
+
private DmiRestClient dmiRestClient;
- private static final String GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL =
- "/v1/ch/{cmHandle}/data/ds/ncmp-datastore:passthrough-operational/";
- private int indexCmHandleForGetOperational;
+ private static final String PARENT_CM_HANDLE_URI =
+ "/v1/ch/{cmHandle}/data/ds";
+ private final int indexCmHandleInUri;
/**
* Constructor for {@code DmiOperations}. This method also manipulates url properties.
@@ -41,12 +60,38 @@ public class DmiOperations {
*/
public DmiOperations(final DmiRestClient dmiRestClient) {
this.dmiRestClient = dmiRestClient;
- indexCmHandleForGetOperational = GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL.indexOf("{cmHandle}");
+ indexCmHandleInUri = PARENT_CM_HANDLE_URI.indexOf("{cmHandle}");
+ }
+
+ /**
+ * 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 fieldsQuery fields query
+ * @param depthQuery depth query
+ * @param acceptParam accept parameter
+ * @param jsonBody json body for put operation
+ * @return {@code ResponseEntity} response entity
+ */
+ public ResponseEntity<Object> getResouceDataOperationalFromDmi(final String dmiBasePath,
+ final String cmHandle,
+ final String resourceId,
+ final String fieldsQuery,
+ final Integer depthQuery,
+ final String acceptParam,
+ final String jsonBody) {
+ final var builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId,
+ fieldsQuery, depthQuery, PassThroughEnum.OPERATIONAL);
+ final var httpHeaders = prepareHeader(acceptParam);
+ return dmiRestClient.putOperationWithJsonData(builder.toString(), jsonBody, httpHeaders);
}
/**
- * This method fetches the resource data for given cm handle identifier on given resource
- * using dmi client.
+ * 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
@@ -57,15 +102,16 @@ public class DmiOperations {
* @param jsonBody json body for put operation
* @return {@code ResponseEntity} response entity
*/
- public ResponseEntity<Object> getResouceDataFromDmi(final String dmiBasePath,
- final String cmHandle,
- final String resourceId,
- final String fieldsQuery,
- final Integer depthQuery,
- final String acceptParam,
- final String jsonBody) {
- final StringBuilder builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId, fieldsQuery, depthQuery);
- final HttpHeaders httpHeaders = prepareHeader(acceptParam);
+ public ResponseEntity<Object> getResouceDataPassThroughRunningFromDmi(final String dmiBasePath,
+ final String cmHandle,
+ final String resourceId,
+ final String fieldsQuery,
+ final Integer depthQuery,
+ final String acceptParam,
+ final String jsonBody) {
+ final var builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId,
+ fieldsQuery, depthQuery, PassThroughEnum.RUNNING);
+ final var httpHeaders = prepareHeader(acceptParam);
return dmiRestClient.putOperationWithJsonData(builder.toString(), jsonBody, httpHeaders);
}
@@ -74,10 +120,10 @@ public class DmiOperations {
final String cmHandle,
final String resourceId,
final String fieldsQuery,
- final Integer depthQuery) {
- final StringBuilder builder = new StringBuilder(GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL);
- builder.replace(indexCmHandleForGetOperational,
- indexCmHandleForGetOperational + "{cmHandle}".length(), cmHandle);
+ final Integer depthQuery,
+ final PassThroughEnum passThrough) {
+ final var builder = new StringBuilder(PARENT_CM_HANDLE_URI.replace("{cmHandle}", cmHandle));
+ builder.append(passThrough.getValue());
builder.insert(builder.length(), resourceId);
appendFieldsAndDepth(fieldsQuery, depthQuery, builder);
builder.insert(0, dmiBasePath);
@@ -85,7 +131,7 @@ public class DmiOperations {
}
private void appendFieldsAndDepth(final String fieldsQuery, final Integer depthQuery, final StringBuilder builder) {
- final boolean doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty());
+ final var doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty());
if (doesFieldExists) {
builder.append("?").append("fields=").append(fieldsQuery);
}
@@ -100,7 +146,7 @@ public class DmiOperations {
}
private HttpHeaders prepareHeader(final String acceptParam) {
- final HttpHeaders httpHeaders = new HttpHeaders();
+ final var httpHeaders = new HttpHeaders();
if (acceptParam != null && !acceptParam.isEmpty()) {
httpHeaders.set(HttpHeaders.ACCEPT, acceptParam);
}
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 65d96a4296..ac290af411 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
@@ -126,7 +126,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
childDataNode.leaves = ['name':'testName','value':'testValue']
dataNode.childDataNodes = [childDataNode]
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
@@ -134,8 +134,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
then: 'cps data service is being called once to get data node'
1 * mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi operation is being calle to get resource data'
- 1 * mockDmiOperations.getResouceDataFromDmi('testDmiService',
+ and: 'dmi operation is being called to get resource data'
+ 1 * mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -161,7 +161,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
objectUnderTest.objectMapper = mockObjectMapper
mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
@@ -181,7 +181,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
and: 'dmi returns NOK response'
- mockDmiOperations.getResouceDataFromDmi('testDmiService',
+ mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -190,7 +190,91 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
>> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+ def 'Get resource data for pass-through running from dmi.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns valid response and data'
+ mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('{result-json}', HttpStatus.OK)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'get resource data returns expected response'
+ response == '{result-json}'
+ }
+ def 'Get resource data for pass-through running from dmi threw parsing exception.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'objectMapper not able to parse object'
+ def mockObjectMapper = Mock(ObjectMapper)
+ objectUnderTest.objectMapper = mockObjectMapper
+ mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+ def 'Get resource data for pass-through running from dmi return NOK response.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns NOK response'
+ mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
+ >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
index 75b5383d8a..ceb35696a9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
@@ -45,7 +45,22 @@ class DmiOperationsSpec extends Specification {
def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
'/ncmp-datastore:passthrough-operational/testResourceId?fields=testFieldsQuery&depth=10'
when: 'get resource data is called to dmi'
- objectUnderTest.getResouceDataFromDmi('testDmiBasePath',
+ objectUnderTest.getResouceDataOperationalFromDmi('testDmiBasePath',
+ 'testCmhandle',
+ 'testResourceId',
+ 'testFieldsQuery',
+ 10,
+ 'testAcceptJson',
+ 'testJsonbody')
+ then: 'the put operation is executed with the correct URL'
+ 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+ }
+ def 'call get resource data for pass-through:running datastore from dmi.'() {
+ given: 'expected url'
+ def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
+ '/ncmp-datastore:passthrough-running/testResourceId?fields=testFieldsQuery&depth=10'
+ when: 'get resource data is called to dmi'
+ objectUnderTest.getResouceDataPassThroughRunningFromDmi('testDmiBasePath',
'testCmhandle',
'testResourceId',
'testFieldsQuery',