diff options
author | Brinda Santh <bs2796@att.com> | 2020-03-06 13:04:37 -0500 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2020-03-11 17:55:28 +0000 |
commit | 91b3a6477c4d5136bea02d3c1284a51b2f2ec1b1 (patch) | |
tree | fc8fe811f14dced88bc7e7296b60d1ce2990452d /ms/blueprintsprocessor | |
parent | 55ec3c71441abda7c6058f4c2cc569c129f635ba (diff) |
Error Catalog Management Core Library.
Issue-ID: CCSDK-2076
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: I9e8e67bdee77fb359a791f4ef4c2963aa78ab93a
Signed-off-by: Steve Siani <alphonse.steve.siani.djissitchi@ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor')
20 files changed, 521 insertions, 55 deletions
diff --git a/ms/blueprintsprocessor/application/pom.xml b/ms/blueprintsprocessor/application/pom.xml index b75e16134..d17425c40 100755 --- a/ms/blueprintsprocessor/application/pom.xml +++ b/ms/blueprintsprocessor/application/pom.xml @@ -46,9 +46,9 @@ <dependencies> <dependency> - <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> - <artifactId>blueprint-core</artifactId> - <exclusions> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>blueprint-core</artifactId> + <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> @@ -66,6 +66,12 @@ </exclusions> </dependency> + <!-- Error Catalog Services --> + <dependency> + <groupId>org.onap.ccsdk.error.catalog</groupId> + <artifactId>error-catalog-services</artifactId> + </dependency> + <!-- North Bound --> <dependency> <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt index 58464cb10..2e268c356 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt @@ -31,7 +31,8 @@ import javax.sql.DataSource @Configuration @Import(BluePrintDBLibConfiguration::class) @EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor"], + basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor", + "org.onap.ccsdk.error.catalog"], entityManagerFactoryRef = "primaryEntityManager", transactionManagerRef = "primaryTransactionManager" ) @@ -43,7 +44,8 @@ open class BlueprintDatabaseConfiguration(primaryDataSourceProperties: PrimaryDa open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { return primaryEntityManager( "org.onap.ccsdk.cds.controllerblueprints", - "org.onap.ccsdk.cds.blueprintsprocessor" + "org.onap.ccsdk.cds.blueprintsprocessor", + "org.onap.ccsdk.error.catalog" ) } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt index 1d1baeeef..7a888f95c 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt @@ -30,7 +30,10 @@ import org.springframework.context.annotation.ComponentScan */ @SpringBootApplication @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, HazelcastAutoConfiguration::class]) -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@ComponentScan( + basePackages = ["org.onap.ccsdk.error.catalog", + "org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"] +) open class BlueprintProcessorApplication fun main(args: Array<String>) { diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt new file mode 100644 index 000000000..6fcbdfdb7 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt @@ -0,0 +1,25 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor + +import org.onap.ccsdk.error.catalog.services.ErrorCatalogExceptionHandler +import org.onap.ccsdk.error.catalog.services.ErrorCatalogService +import org.springframework.web.bind.annotation.RestControllerAdvice + +@RestControllerAdvice("org.onap.ccsdk.cds") +open class BlueprintProcessorExceptionHandler(private val errorCatalogService: ErrorCatalogService) : + ErrorCatalogExceptionHandler(errorCatalogService) diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties index fffc2f4c6..671000992 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties @@ -27,6 +27,11 @@ server.port=8081 security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu security.user.name: ccsdkapps +# Error Managements +error.catalog.applicationId=cds +error.catalog.type=properties +error.catalog.defaultDirectory=/opt/app/onap/config + ### START -Controller Blueprints Properties # Load Resource Source Mappings resourceSourceMappings=processor-db=source-db,input=source-input,default=source-default,sdnc=source-rest,aai-data=source-rest,capability=source-capability,vault-data=source-rest,rest=source-rest,script=source-capability @@ -137,4 +142,4 @@ blueprintsprocessor.messageproducer.self-service-api.topic=producer.t #blueprintsprocessor.messageconsumer.prioritize-input.type=kafka-streams-basic-auth #blueprintsprocessor.messageconsumer.prioritize-input.bootstrapServers=127.0.0.1:9092 #blueprintsprocessor.messageconsumer.prioritize-input.applicationId=cds-controller -#blueprintsprocessor.messageconsumer.prioritize-input.topic=prioritize-input-topic
\ No newline at end of file +#blueprintsprocessor.messageconsumer.prioritize-input.topic=prioritize-input-topic diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties index d6082bfa9..2a16b3ef9 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties @@ -60,6 +60,11 @@ blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu security.user.name: ccsdkapps +# Error Managements +error.catalog.applicationId=cds +error.catalog.type=properties +error.catalog.defaultDirectory=/opt/app/onap/config + # Used in Health Check #endpoints.user.name=ccsdkapps #endpoints.user.password=ccsdkapps @@ -130,5 +135,3 @@ cdslistener.healthcheck.mapping-service-name-with-service-link=[SDC Listener ser #Actuator properties management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always - - diff --git a/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties b/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties new file mode 100644 index 000000000..246a1d511 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties @@ -0,0 +1,32 @@ +# +# Copyright © 2018-2019 AT&T Intellectual Property. +# +# 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. +# +org.onap.ccsdk.cds.blueprintsprocessor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team. +org.onap.ccsdk.cds.sdclistener.generic_failure=cause=Internal error in SDC Listener.,action=Contact CDS administrator team. +org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team. +org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_process_failure=cause=Internal error while processing REST call to the Self Service API.,action=Verify the request and try again. +org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.resolution_failure=cause=Fail to process Resource Resolution.,action=Verify the resource definitions. +org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.internal_error=cause=Internal error while processing Resource Resolution.,action=Verify the payload. +org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format. +org.onap.ccsdk.cds.blueprintsprocessor.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time. +org.onap.ccsdk.cds.blueprintsprocessor.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format. +org.onap.ccsdk.cds.blueprintsprocessor.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format. +org.onap.ccsdk.cds.blueprintsprocessor.invalid_request_format=cause=bad request provided.,action=Verify the request payload. +org.onap.ccsdk.cds.blueprintsprocessor.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials. +org.onap.ccsdk.cds.blueprintsprocessor.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request. +org.onap.ccsdk.cds.blueprintsprocessor.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist. +org.onap.ccsdk.cds.blueprintsprocessor.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time. +org.onap.ccsdk.cds.blueprintsprocessor.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource. +org.onap.ccsdk.cds.blueprintsprocessor.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format. diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt new file mode 100644 index 000000000..74a17fa1d --- /dev/null +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt @@ -0,0 +1,28 @@ +/* + * Copyright © 2020 IBM, Bell Canada. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.uat + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan( + basePackages = ["org.onap.ccsdk.error.catalog"] +) +@EnableAutoConfiguration +open class ErrorCatalogTestConfiguration diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt new file mode 100644 index 000000000..8e399fd1a --- /dev/null +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt @@ -0,0 +1,97 @@ +/* + * Copyright © 2020 IBM, Bell Canada. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.uat.error + +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.uat.ErrorCatalogTestConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.grpcProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException +import org.onap.ccsdk.error.catalog.core.ErrorCatalog +import org.onap.ccsdk.error.catalog.core.ErrorCatalogCodes +import org.onap.ccsdk.error.catalog.core.ErrorMessage +import org.onap.ccsdk.error.catalog.core.ErrorPayload +import org.onap.ccsdk.error.catalog.services.ErrorCatalogService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [ErrorCatalogTestConfiguration::class] +) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class ErrorCatalogServiceTest { + @Autowired + lateinit var errorCatalogService: ErrorCatalogService + + private val domain = "org.onap.ccsdk.cds.blueprintsprocessor" + private lateinit var errorType: String + private lateinit var errorCatalogHttp: ErrorCatalog + private lateinit var errorCatalogGrpc: ErrorCatalog + private lateinit var errorPayloadHttp: ErrorPayload + private lateinit var errorPayloadGrpc: ErrorPayload + + @BeforeTest + fun setup() { + errorType = ErrorCatalogCodes.GENERIC_FAILURE + errorCatalogHttp = ErrorCatalog(errorType, domain, 500, + "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.") + errorCatalogGrpc = ErrorCatalog(errorType, domain, 2, + "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.") + + errorPayloadHttp = ErrorPayload(500, ErrorCatalogCodes.GENERIC_FAILURE, + "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.", + errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor", + "Internal error in Blueprint Processor run time.", "")) + errorPayloadGrpc = ErrorPayload(2, ErrorCatalogCodes.GENERIC_FAILURE, + "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.", + errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor", + "Internal error in Blueprint Processor run time.", "")) + } + + @Test + fun errorPayloadHttp() { + val errorPayload = errorCatalogService.errorPayload(httpProcessorException(errorType, domain, + "Internal error in Blueprint Processor run time.")) + assertTrue { errorPayload.isEqualTo(errorPayloadHttp) } + } + + @Test + fun errorPayloadGrpc() { + val errorPayload = errorCatalogService.errorPayload(grpcProcessorException(errorType, domain, + "Internal error in Blueprint Processor run time.")) + assertTrue { errorPayload.isEqualTo(errorPayloadGrpc) } + } + + @Test + fun getErrorCatalogHttp() { + val errorCatalog = errorCatalogService.getErrorCatalog(httpProcessorException(errorType, domain, + "Internal error in Blueprint Processor run time.")) + assertTrue { errorCatalog == errorCatalogHttp } + } + + @Test + fun getErrorCatalogGrpc() { + val errorCatalog = errorCatalogService.getErrorCatalog(grpcProcessorException(errorType, domain, + "Internal error in Blueprint Processor run time.")) + assertTrue { errorCatalog == errorCatalogGrpc } + } +} diff --git a/ms/blueprintsprocessor/application/src/test/resources/application-test.properties b/ms/blueprintsprocessor/application/src/test/resources/application-test.properties index 1d2565be3..83589403d 100644 --- a/ms/blueprintsprocessor/application/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/application/src/test/resources/application-test.properties @@ -16,6 +16,11 @@ spring.http.log-request-details=true +# Error Managements +error.catalog.applicationId=cds +error.catalog.type=properties +error.catalog.defaultDirectory=./src/test/resources/ + blueprintsprocessor.httpPort=0 blueprintsprocessor.grpcEnable=true blueprintsprocessor.grpcPort=0 @@ -61,4 +66,3 @@ blueprintprocessor.healthcheck.mapping-service-name-with-service-link=[Execution #BaseUrls for health check Cds Listener services cdslistener.healthcheck.baseUrl=http://cds-sdc-listener:8080/ cdslistener.healthcheck.mapping-service-name-with-service-link=[SDC Listener service,/api/v1/sdclistener/healthcheck] - diff --git a/ms/blueprintsprocessor/application/src/test/resources/application.properties b/ms/blueprintsprocessor/application/src/test/resources/application.properties index ea14c493a..eabc141f9 100644 --- a/ms/blueprintsprocessor/application/src/test/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/test/resources/application.properties @@ -61,6 +61,11 @@ blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts security.user.password:{bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu security.user.name:ccsdkapps +# Error Managements +error.catalog.applicationId=cds +error.catalog.type=properties +error.catalog.defaultDirectory=/opt/app/onap/config + # Executor Options blueprintsprocessor.resourceResolution.enabled=true blueprintsprocessor.netconfExecutor.enabled=true diff --git a/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties b/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties new file mode 100644 index 000000000..246a1d511 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties @@ -0,0 +1,32 @@ +# +# Copyright © 2018-2019 AT&T Intellectual Property. +# +# 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. +# +org.onap.ccsdk.cds.blueprintsprocessor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team. +org.onap.ccsdk.cds.sdclistener.generic_failure=cause=Internal error in SDC Listener.,action=Contact CDS administrator team. +org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team. +org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_process_failure=cause=Internal error while processing REST call to the Self Service API.,action=Verify the request and try again. +org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.resolution_failure=cause=Fail to process Resource Resolution.,action=Verify the resource definitions. +org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.internal_error=cause=Internal error while processing Resource Resolution.,action=Verify the payload. +org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format. +org.onap.ccsdk.cds.blueprintsprocessor.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time. +org.onap.ccsdk.cds.blueprintsprocessor.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format. +org.onap.ccsdk.cds.blueprintsprocessor.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format. +org.onap.ccsdk.cds.blueprintsprocessor.invalid_request_format=cause=bad request provided.,action=Verify the request payload. +org.onap.ccsdk.cds.blueprintsprocessor.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials. +org.onap.ccsdk.cds.blueprintsprocessor.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request. +org.onap.ccsdk.cds.blueprintsprocessor.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist. +org.onap.ccsdk.cds.blueprintsprocessor.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time. +org.onap.ccsdk.cds.blueprintsprocessor.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource. +org.onap.ccsdk.cds.blueprintsprocessor.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format. diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt index a2435da13..74e6bb6bd 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 - 2020 IBM, Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,29 +22,13 @@ package org.onap.ccsdk.cds.controllerblueprints.core * * @author Brinda Santh */ -class BluePrintException : Exception { - - var code: Int = 100 +class BluePrintException : BluePrintProcessorException { constructor(cause: Throwable) : super(cause) constructor(message: String) : super(message) constructor(message: String, cause: Throwable) : super(message, cause) - constructor(cause: Throwable, message: String, vararg args: Any?) : super(String.format(message, *args), cause) - - constructor(code: Int, cause: Throwable) : super(cause) { - this.code = code - } - - constructor(code: Int, message: String) : super(message) { - this.code = code - } - - constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { - this.code = code - } - - constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) : - super(String.format(message, *args), cause) { - this.code = code - } + constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args) + constructor(code: Int, cause: Throwable) : super(code, cause) + constructor(code: Int, message: String) : super(code, message) + constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause) } diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt index b0b217051..50b6614ad 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018 - 2020 IBM, Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,35 +17,55 @@ package org.onap.ccsdk.cds.controllerblueprints.core +import org.onap.ccsdk.error.catalog.core.ErrorCatalogException +import org.onap.ccsdk.error.catalog.core.ErrorCatalogExceptionFluent +import org.onap.ccsdk.error.catalog.core.ErrorMessage + /** * * * @author Brinda Santh */ -class BluePrintProcessorException : RuntimeException { - - var code: Int = 100 +open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BluePrintProcessorException> { constructor(message: String, cause: Throwable) : super(message, cause) constructor(message: String) : super(message) constructor(cause: Throwable) : super(cause) - constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args) + constructor(code: Int, cause: Throwable) : super(code, cause) + constructor(code: Int, message: String) : super(code, message) + constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause) + + override fun code(code: Int): BluePrintProcessorException { + return this.updateCode(code) + } + + override fun domain(domain: String): BluePrintProcessorException { + return this.updateDomain(domain) + } + + override fun action(action: String): BluePrintProcessorException { + return this.updateAction(action) + } - constructor(code: Int, cause: Throwable) : super(cause) { - this.code = code + override fun http(type: String): BluePrintProcessorException { + return this.updateHttp(type) } - constructor(code: Int, message: String) : super(message) { - this.code = code + override fun grpc(type: String): BluePrintProcessorException { + return this.updateGrpc(type) } - constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { - this.code = code + override fun payloadMessage(message: String): BluePrintProcessorException { + return this.updatePayloadMessage(message) } - constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) : - super(String.format(message, *args), cause) { - this.code = code + override fun addErrorPayloadMessage(message: String): BluePrintProcessorException { + return this.updateErrorPayloadMessage(message) + } + + override fun addSubError(errorMessage: ErrorMessage): BluePrintProcessorException { + return this.updateSubError(errorMessage) } } @@ -55,3 +75,64 @@ class BluePrintRetryException : RuntimeException { constructor(cause: Throwable) : super(cause) constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) } + +/** Extension Functions */ + +fun processorException(message: String): BluePrintProcessorException { + return BluePrintProcessorException(message) +} + +fun processorException(code: Int, message: String): BluePrintProcessorException { + return processorException(message).code(code) +} + +fun httpProcessorException(type: String, message: String): BluePrintProcessorException { + return processorException(message).http(type) +} + +fun grpcProcessorException(type: String, message: String): BluePrintProcessorException { + return processorException(message).grpc(type) +} + +fun httpProcessorException(type: String, domain: String, message: String): BluePrintProcessorException { + val bluePrintProcessorException = processorException(message).http(type) + return bluePrintProcessorException.addDomainAndErrorMessage(domain, message) +} + +fun grpcProcessorException(type: String, domain: String, message: String): BluePrintProcessorException { + val bluePrintProcessorException = processorException(message).grpc(type) + return bluePrintProcessorException.addDomainAndErrorMessage(domain, message) +} + +fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable): + BluePrintProcessorException { + val bluePrintProcessorException = processorException(message).http(type) + return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause) +} + +fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable): + BluePrintProcessorException { + val bluePrintProcessorException = processorException(message).grpc(type) + return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause) +} + +fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: Throwable): + BluePrintProcessorException { + return this.addDomainAndErrorMessage(domain, message, cause).domain(domain) + .addErrorPayloadMessage(message) + .payloadMessage(message) +} + +fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String): BluePrintProcessorException { + return this.addDomainAndErrorMessage(domain, message).domain(domain) + .addErrorPayloadMessage(message) + .payloadMessage(message) +} + +private fun BluePrintProcessorException.addDomainAndErrorMessage( + domain: String, + message: String, + cause: Throwable = Throwable() +): BluePrintProcessorException { + return this.addSubError(ErrorMessage(domain, message, cause.message ?: "")).domain(domain) +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt index ff9aed664..1f01d1ce3 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt @@ -211,24 +211,28 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } @PostMapping( - path = arrayOf("/workflow-spec"), produces = arrayOf(MediaType - .APPLICATION_JSON_VALUE), - consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE) + path = arrayOf("/workflow-spec"), produces = arrayOf( + MediaType + .APPLICATION_JSON_VALUE + ), + consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE) ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") suspend fun workflowSpec(@RequestBody workFlowSpecReq: WorkFlowSpecRequest): - ResponseEntity<String> = mdcWebCoroutineScope { + ResponseEntity<String> = mdcWebCoroutineScope { var json = bluePrintModelHandler.prepareWorkFlowSpec(workFlowSpecReq) - .asJsonString() + .asJsonString() ResponseEntity(json, HttpStatus.OK) } @GetMapping( - path = arrayOf("/workflows/blueprint-name/{name}/version/{version" + - "}"), - produces = arrayOf(MediaType.APPLICATION_JSON_VALUE) + path = arrayOf( + "/workflows/blueprint-name/{name}/version/{version" + + "}" + ), + produces = arrayOf(MediaType.APPLICATION_JSON_VALUE) ) @ResponseBody @Throws(BluePrintException::class) @@ -240,7 +244,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @PathVariable(value = "version") version: String ): ResponseEntity<String> = mdcWebCoroutineScope { var json = bluePrintModelHandler.getWorkflowNames(name, version) - .asJsonString() + .asJsonString() ResponseEntity(json, HttpStatus.OK) } } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt new file mode 100644 index 000000000..ae91246fe --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt @@ -0,0 +1,40 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api + +object DesignerApiDomains { + // Designer Api Domains Constants + const val DESIGNER_API = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api" + const val DESIGNER_API_ENHANCER = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer" + const val DESIGNER_API_HANDLER = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler" + const val DESIGNER_API_LOAD = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load" + const val DESIGNER_API_SERVICE = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service" +} + +object DesignerApiHttpErrorCodes { + init { + // Register HttpErrorCodes + // HttpErrorCodes.register("", 200) + } +} + +object DesignerGrpcErrorCodes { + init { + // Register GrpcErrorCodes + // GrpcErrorCodes.register("", 3) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt new file mode 100644 index 000000000..b37cd0eda --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt @@ -0,0 +1,36 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.resource.api + +object ResourceApiDomains { + // Resource Api Domains Constants + const val RESOURCE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api" +} + +object ResourceApiHttpErrorCodes { + init { + // Register HttpErrorCodes + // HttpErrorCodes.register("", 200) + } +} + +object ResourceGrpcErrorCodes { + init { + // Register GrpcErrorCodes + // GrpcErrorCodes.register("", 3) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt new file mode 100644 index 000000000..b76bc263a --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api + +object SelfServiceApiDomains { + // SelfServiceApi Domains Constants + const val BLUEPRINT_PROCESSOR = "org.onap.ccsdk.cds.blueprintsprocessor" + const val SELF_SERVICE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api" + const val SELF_SERVICE_API_VALIDATOR = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api.validator" + const val NETCONF_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor" + const val RESOURCE_RESOLUTION = "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution" + const val RESTCONF_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor" + const val CLI_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor" + const val PYTHON_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor" + const val SDC_LISTENER = "org.onap.ccsdk.cds.sdclistener" +} + +object SelfServiceApiHttpErrorCodes { + init { + // Register HttpErrorCodes + // HttpErrorCodes.register("", 200) + } +} + +object SelfServiceGrpcErrorCodes { + init { + // Register GrpcErrorCodes + // GrpcErrorCodes.register("", 3) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index 8b268d6f8..908c04607 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -27,7 +27,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutp import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.error.catalog.core.ErrorCatalogCodes import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -81,7 +83,9 @@ open class ExecutionServiceController { ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope { if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) { - throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.") + throw httpProcessorException(ErrorCatalogCodes.GENERIC_FAILURE, + SelfServiceApiDomains.BLUEPRINT_PROCESSOR, + "Can't process async request through the REST endpoint. Use gRPC for async processing.") } ph.register() val processResult = executionServiceHandler.doProcess(executionServiceInput) diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index d1de10845..8349fa79a 100755 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -35,6 +35,7 @@ <sli.version>${ccsdk.sli.core.version}</sli.version> <!-- Override CDS version from parent to be project.version --> <ccsdk.cds.version>${project.version}</ccsdk.cds.version> + <error.catalog.version>${project.version}</error.catalog.version> <dmaap.client.version>1.1.5</dmaap.client.version> <!-- Should be using released artifact as soon as available: --> <!-- https://github.com/springfox/springfox/milestone/44 --> @@ -291,6 +292,30 @@ <version>${kafka.version}</version> </dependency> + <!-- Error Catalog --> + <dependency> + <groupId>org.onap.ccsdk.error.catalog</groupId> + <artifactId>error-catalog-core</artifactId> + <version>${error.catalog.version}</version> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.error.catalog</groupId> + <artifactId>error-catalog-services</artifactId> + <version>${error.catalog.version}</version> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- SLI Version --> <dependency> <groupId>org.onap.ccsdk.sli.core</groupId> @@ -689,6 +714,11 @@ <groupId>io.netty</groupId> <artifactId>netty-tcnative-boringssl-static</artifactId> </dependency> + + <dependency> + <groupId>org.onap.ccsdk.error.catalog</groupId> + <artifactId>error-catalog-core</artifactId> + </dependency> </dependencies> <repositories> |