summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java18
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/HttpClientRequestException.java45
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy33
3 files changed, 71 insertions, 25 deletions
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 39641442a0..1a69e45d30 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
@@ -46,8 +46,8 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException;
import org.onap.cps.ncmp.api.impl.exception.InvalidTopicException;
-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;
@@ -145,9 +145,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final String dataType) {
CpsValidator.validateNameCharacters(cmHandleId);
return handleResponse(
- dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(
- cmHandleId, resourceIdentifier, operation, requestData, dataType),
- "Not able to " + operation + " resource data.");
+ dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier, operation,
+ requestData, dataType), operation);
}
@@ -228,14 +227,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
.collect(Collectors.toList());
}
- private static Object handleResponse(final ResponseEntity<?> responseEntity,
- final String exceptionMessage) {
+ private static Object handleResponse(final ResponseEntity<?> responseEntity, final OperationEnum operation) {
if (responseEntity.getStatusCode().is2xxSuccessful()) {
return responseEntity.getBody();
} else {
- throw new ServerNcmpException(exceptionMessage,
- "DMI status code: " + responseEntity.getStatusCodeValue()
- + ", DMI response body: " + responseEntity.getBody());
+ final String exceptionMessage = "Unable to " + operation.toString() + " resource data.";
+ throw new HttpClientRequestException(exceptionMessage, (String) responseEntity.getBody(),
+ responseEntity.getStatusCodeValue());
}
}
@@ -364,6 +362,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(
cmHandleId, resourceIdentifier, optionsParamInQuery, acceptParamInHeader,
dataStore, NO_REQUEST_ID, NO_TOPIC);
- return handleResponse(responseEntity, "Not able to get resource data.");
+ return handleResponse(responseEntity, OperationEnum.READ);
}
} \ No newline at end of file
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/HttpClientRequestException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/HttpClientRequestException.java
new file mode 100644
index 0000000000..9d307e5d2e
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/HttpClientRequestException.java
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.exception;
+
+import lombok.Getter;
+
+/**
+ * Http Client Request exception for passthrough scenarios.
+ */
+@Getter
+public class HttpClientRequestException extends NcmpException {
+
+ private static final long serialVersionUID = 6659897770659834797L;
+ final Integer httpStatus;
+
+ /**
+ * Constructor to form exception for passthrough scenarios.
+ *
+ * @param message message details from NCMP
+ * @param details response body from the client available as details
+ * @param httpStatus http status code from the client
+ */
+ public HttpClientRequestException(final String message, final String details, final Integer httpStatus) {
+ super(message, details);
+ this.httpStatus = httpStatus;
+ }
+}
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 ded4943702..bf5bb73a94 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.api.impl
+import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException
import org.onap.cps.ncmp.api.impl.exception.InvalidTopicException
import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
@@ -40,7 +41,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
-import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
@@ -98,9 +98,9 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'testResourceId', CREATE,
'{some-json}', 'application/json')
then: 'exception is thrown'
- def exceptionThrown = thrown(ServerNcmpException.class)
- and: 'details contains (not found) error code: 404'
- exceptionThrown.details.contains('404')
+ def exceptionThrown = thrown(HttpClientRequestException.class)
+ and: 'http status (not found) error code: 404'
+ exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value()
}
def 'Get resource data for pass-through operational from DMI.'() {
@@ -141,9 +141,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'testAcceptParam',
OPTIONS_PARAM,
NO_TOPIC)
- then: 'exception is thrown with the expected details'
- def exceptionThrown = thrown(ServerNcmpException.class)
- exceptionThrown.details == 'DMI status code: 404, DMI response body: NOK-json'
+ then: 'exception is thrown with the expected response code and details'
+ def exceptionThrown = thrown(HttpClientRequestException.class)
+ exceptionThrown.details.contains('NOK-json')
+ exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value()
}
def 'Get resource data for pass-through operational from DMI return NOK response.'() {
@@ -166,8 +167,9 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
OPTIONS_PARAM,
NO_TOPIC)
then: 'exception is thrown'
- def exceptionThrown = thrown(ServerNcmpException.class)
- and: 'details contains the original response'
+ def exceptionThrown = thrown(HttpClientRequestException.class)
+ and: 'details contain the original response'
+ exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value()
exceptionThrown.details.contains('NOK-json')
}
@@ -213,9 +215,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
OPTIONS_PARAM,
NO_TOPIC)
then: 'exception is thrown'
- def exceptionThrown = thrown(ServerNcmpException.class)
- and: 'details contains the original response'
+ def exceptionThrown = thrown(HttpClientRequestException.class)
+ and: 'details contain the original response'
exceptionThrown.details.contains('NOK-json')
+ exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value()
}
def 'DMI Operational data request with #scenario'() {
@@ -340,12 +343,12 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'{some-json}',
'application/json')
then: 'an exception is thrown with the expected error message details with correct operation'
- def exceptionThrown = thrown(ServerNcmpException.class)
+ def exceptionThrown = thrown(HttpClientRequestException.class)
exceptionThrown.getMessage().contains(expectedResponseMessage)
where:
scenario | givenOperation || expectedResponseMessage
- 'CREATE' | CREATE || 'Not able to create resource data.'
- 'READ' | READ || 'Not able to read resource data.'
- 'UPDATE' | UPDATE || 'Not able to update resource data.'
+ 'CREATE' | CREATE || 'Unable to create resource data.'
+ 'READ' | READ || 'Unable to read resource data.'
+ 'UPDATE' | UPDATE || 'Unable to update resource data.'
}
}