From 38dbf3378f54bdab34de342f736e30160d65353d Mon Sep 17 00:00:00 2001 From: JosephKeenan Date: Thu, 20 Jan 2022 16:30:18 +0000 Subject: [TECHDEBT] Align CPS NCMP REST API Specification and Implementation - Updated ncmp.yml to align implementation with specification - Added new Exception classes to differentiate between server NCMP issues and client based NCMP issues - Added 500 error to specification Issue-ID: CPS-823 Signed-off-by: JosephKeenan Change-Id: Ic646db5cc4dfc8d14106c8374b7c62cc9f9ab6e7 --- cps-ncmp-rest/docs/openapi/components.yaml | 12 ++++++- cps-ncmp-rest/docs/openapi/ncmp-inventory.yml | 3 ++ cps-ncmp-rest/docs/openapi/ncmp.yml | 33 +++++++++--------- .../api/impl/NetworkCmProxyDataServiceImpl.java | 4 +-- .../api/impl/exception/DmiRequestException.java | 39 ++++++++++++++++++++++ .../api/impl/exception/ServerNcmpException.java | 39 ++++++++++++++++++++++ .../ncmp/api/impl/operations/DmiOperations.java | 6 ++-- .../cps/ncmp/api/models/DmiPluginRegistration.java | 5 +-- .../impl/NetworkCmProxyDataServiceImplSpec.groovy | 11 +++--- 9 files changed, 124 insertions(+), 28 deletions(-) create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/DmiRequestException.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/ServerNcmpException.java diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index e63f9c0b8..36338d8d4 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (C) 2021 Nordix Foundation +# Copyright (C) 2021-2022 Nordix Foundation # Modifications Copyright (C) 2021 Pantheon.tech # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); @@ -374,6 +374,16 @@ components: application/json: schema: type: object + InternalServerError: + description: Internal Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/ErrorMessage" + example: + status: 500 + message: Internal Server Error + details: Internal Server Error occured Created: description: Created content: {} diff --git a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml index b0a50aa83..f3f84fed9 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml @@ -1,5 +1,6 @@ # ============LICENSE_START======================================================= # Copyright (C) 2021 Bell Canada +# Modifications 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. @@ -38,3 +39,5 @@ updateDmiRegistration: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml index d80ec6508..c9d9b5778 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp.yml @@ -17,6 +17,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= + getResourceDataForPassthroughOperational: get: tags: @@ -45,8 +46,8 @@ getResourceDataForPassthroughOperational: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' - 404: - $ref: 'components.yaml#/components/responses/NotFound' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' resourceDataForPassthroughRunning: get: @@ -76,8 +77,8 @@ resourceDataForPassthroughRunning: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' - 404: - $ref: 'components.yaml#/components/responses/NotFound' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' post: tags: - network-cm-proxy @@ -112,9 +113,8 @@ resourceDataForPassthroughRunning: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' - 404: - $ref: 'components.yaml#/components/responses/NotFound' - + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' put: tags: - network-cm-proxy @@ -149,9 +149,8 @@ resourceDataForPassthroughRunning: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' - 404: - $ref: 'components.yaml#/components/responses/NotFound' - + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' patch: tags: - network-cm-proxy @@ -180,9 +179,8 @@ resourceDataForPassthroughRunning: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' - 404: - $ref: 'components.yaml#/components/responses/NotFound' - + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' delete: tags: - network-cm-proxy @@ -204,7 +202,8 @@ resourceDataForPassthroughRunning: $ref: 'components.yaml#/components/responses/Forbidden' 404: $ref: 'components.yaml#/components/responses/NotFound' - + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' fetchModuleReferencesByCmHandle: get: @@ -230,8 +229,8 @@ fetchModuleReferencesByCmHandle: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' - 404: - $ref: 'components.yaml#/components/responses/NotFound' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' executeCmHandleSearch: post: @@ -259,3 +258,5 @@ executeCmHandleSearch: $ref: 'components.yaml#/components/responses/Unauthorized' 403: $ref: 'components.yaml#/components/responses/Forbidden' + 500: + $ref: 'components.yaml#/components/responses/InternalServerError' 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 240d6b5ca..8fee3f464 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 @@ -39,7 +39,7 @@ 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.NcmpException; +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; @@ -188,7 +188,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity.getBody(); } else { - throw new NcmpException(exceptionMessage, + throw new ServerNcmpException(exceptionMessage, "DMI status code: " + responseEntity.getStatusCodeValue() + ", DMI response body: " + responseEntity.getBody()); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/DmiRequestException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/DmiRequestException.java new file mode 100644 index 000000000..1428ec53c --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/DmiRequestException.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.api.impl.exception; + +/** + * Client Based Network CM Proxy exception. + */ +public class DmiRequestException extends NcmpException { + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + */ + public DmiRequestException(final String message, final String details) { + super(message, details); + } + +} + diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/ServerNcmpException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/ServerNcmpException.java new file mode 100644 index 000000000..d57bfb161 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/ServerNcmpException.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.api.impl.exception; + +/** + * Server Based Network CM Proxy exception. + */ +public class ServerNcmpException extends NcmpException { + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + */ + public ServerNcmpException(final String message, final String details) { + super(message, details); + } + +} + 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 509728061..853a8aacc 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 @@ -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. @@ -27,7 +27,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration; -import org.onap.cps.ncmp.api.impl.exception.NcmpException; +import org.onap.cps.ncmp.api.impl.exception.DmiRequestException; import org.springframework.http.HttpHeaders; @Slf4j @@ -106,7 +106,7 @@ public class DmiOperations { return objectMapper.writeValueAsString(dmiRequestBody); } 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.", + throw new DmiRequestException("Parsing error occurred while converting given object to JSON.", e.getMessage()); } } 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 9faf7331e..f1b3888c6 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 @@ -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. @@ -28,6 +28,7 @@ import com.google.common.base.Strings; import java.util.List; import lombok.Getter; import lombok.Setter; +import org.onap.cps.ncmp.api.impl.exception.DmiRequestException; import org.onap.cps.ncmp.api.impl.exception.NcmpException; /** @@ -80,7 +81,7 @@ public class DmiPluginRegistration { } if (errorMessage != null) { - throw new NcmpException(errorMessage, "Please supply correct plugin information."); + throw new DmiRequestException(errorMessage, "Please supply correct plugin information."); } } 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 5753d7b67..aaab658b4 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -22,6 +22,9 @@ package org.onap.cps.ncmp.api.impl + +import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException + import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE @@ -91,7 +94,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 'testResourceId', CREATE, '{some-json}', 'application/json') then: 'exception is thrown' - def exceptionThrown = thrown(NcmpException.class) + def exceptionThrown = thrown(ServerNcmpException.class) and: 'details contains (not found) error code: 404' exceptionThrown.details.contains('404') } @@ -138,7 +141,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 'testAcceptParam', '(a=1,b=2)') then: 'exception is thrown with the expected details' - def exceptionThrown = thrown(NcmpException.class) + def exceptionThrown = thrown(ServerNcmpException.class) exceptionThrown.details == 'DMI status code: 404, DMI response body: NOK-json' } @@ -161,7 +164,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 'testAcceptParam', '(a=1,b=2)') then: 'exception is thrown' - def exceptionThrown = thrown(NcmpException.class) + def exceptionThrown = thrown(ServerNcmpException.class) and: 'details contains the original response' exceptionThrown.details.contains('NOK-json') } @@ -206,7 +209,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 'testAcceptParam', '(a=1,b=2)') then: 'exception is thrown' - def exceptionThrown = thrown(NcmpException.class) + def exceptionThrown = thrown(ServerNcmpException.class) and: 'details contains the original response' exceptionThrown.details.contains('NOK-json') } -- cgit 1.2.3-korg