Refactoring BP Code with ErrorCatalog 90/103490/7
authorBrinda Santh <bs2796@att.com>
Fri, 6 Mar 2020 18:04:37 +0000 (13:04 -0500)
committerSteve Siani <alphonse.steve.siani.djissitchi@ibm.com>
Mon, 6 Apr 2020 15:59:21 +0000 (11:59 -0400)
Issue-ID: CCSDK-2124
Signed-off-by: Steve Siani <alphonse.steve.siani.djissitchi@ibm.com>
Change-Id: Ief468a56f9e7b3ef86c357965aa7b15f0a4cfa22

57 files changed:
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHost.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
ms/blueprintsprocessor/modules/inbounds/configs-api/pom.xml
ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorHandling.kt [moved from ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotException.kt with 53% similarity]
ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt
ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt
ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/resources/application-test.properties
ms/blueprintsprocessor/modules/inbounds/designer-api/pom.xml
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorCatalogTestConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/application-test.properties
ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResolutionException.kt [deleted file]
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt
ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorCatalogTestConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/resources/application-test.properties
ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumer.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceExceptionHandler.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingIntegrationTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorCatalogTestConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ErrorHandling.kt [new file with mode: 0644]
ms/error-catalog/application/pom.xml
ms/error-catalog/core/pom.xml
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/utils/ErrorCatalogUtils.kt [moved from ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt with 88% similarity]
ms/error-catalog/pom.xml
ms/error-catalog/services/pom.xml
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt

index 93fe2b1..3d2f10e 100644 (file)
@@ -15,7 +15,9 @@
  */
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.scripts
 
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceDomains
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.python.core.PyObject
 import org.python.util.PythonInterpreter
 
@@ -42,6 +44,10 @@ open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython) {
         bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]"
         try {
             return blueprintPythonInterpreterProxy.getPythonInstance(properties)
+        } catch (e: BluePrintProcessorException) {
+            val errorMsg = "Failed to get python instance."
+            throw e.updateErrorMessage(ExecutionServiceDomains.PYTHON_EXECUTOR, errorMsg,
+                    "Error in environment properties")
         } catch (e: Exception) {
             throw BluePrintProcessorException("Failed to execute Jython component $e", e)
         }
index 0bfd7e4..a0fa97b 100644 (file)
@@ -23,10 +23,12 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDBLibGenericService
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceDomains
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
 import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
 import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
@@ -64,6 +66,10 @@ open class DatabaseResourceAssignmentProcessor(
             }
             // Check the value has populated for mandatory case
             ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+        } catch (e: BluePrintProcessorException) {
+            val errorMsg = "Failed to process Database resource resolution in template key ($resourceAssignment) assignments."
+            throw e.updateErrorMessage(ExecutionServiceDomains.RESOURCE_RESOLUTION, errorMsg,
+                    "Wrong resource definition or DB resolution failed.")
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
             throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
index 7705c11..2921cb6 100644 (file)
@@ -19,7 +19,9 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.pro
 
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceDomains
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
@@ -49,6 +51,10 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
             }
             // Check the value has populated for mandatory case
             ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+        } catch (e: BluePrintProcessorException) {
+            val errorMsg = "Failed to process default resource resolution in template key ($resourceAssignment) assignments."
+            throw e.updateErrorMessage(ExecutionServiceDomains.RESOURCE_RESOLUTION, errorMsg,
+                    "Wrong default value was set.")
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
             throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
index f04a787..d078a2d 100644 (file)
@@ -20,8 +20,10 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.pro
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceDomains
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
@@ -48,6 +50,10 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
             }
             // Check the value has populated for mandatory case
             ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+        } catch (e: BluePrintProcessorException) {
+            val errorMsg = "Failed to process input resource resolution in template key ($resourceAssignment) assignments."
+            throw e.updateErrorMessage(ExecutionServiceDomains.RESOURCE_RESOLUTION, errorMsg,
+                    "Wrong input value was set.")
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
             throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with : (${e.message})", e)
index 5d92268..8f933c1 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *  Copyright Â© 2018 IBM.
- *  Modifications Copyright Â© 2017-2019 AT&T, Bell Canada
+ *  Copyright Â© 2018 - 2020 IBM.
+ *  Modifications Copyright Â© 2017-2020 AT&T, Bell Canada
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -22,10 +22,12 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Rest
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceDomains
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
 import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
 import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
@@ -114,6 +116,10 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
             }
             // Check the value has populated for mandatory case
             ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+        } catch (e: BluePrintProcessorException) {
+            val errorMsg = "Failed to process REST resource resolution in template key ($resourceAssignment) assignments."
+            throw e.updateErrorMessage(ExecutionServiceDomains.RESOURCE_RESOLUTION, errorMsg,
+                    "Wrong resource definition or resolution failed.")
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
             throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
index acb158d..310c9b0 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.onap.ccsdk.cds.controllerblueprints.core
 
+import org.apache.commons.lang.exception.ExceptionUtils
 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogExceptionFluent
 import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage
@@ -56,6 +57,14 @@ open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExce
         return this.updateGrpc(type)
     }
 
+    override fun convertToHttp(): BluePrintProcessorException {
+        return this.inverseToHttp()
+    }
+
+    override fun convertToGrpc(): BluePrintProcessorException {
+        return this.inverseToHttp()
+    }
+
     override fun payloadMessage(message: String): BluePrintProcessorException {
         return this.updatePayloadMessage(message)
     }
@@ -82,10 +91,26 @@ fun processorException(message: String): BluePrintProcessorException {
     return BluePrintProcessorException(message)
 }
 
+fun processorException(message: String, cause: Throwable): BluePrintProcessorException {
+    return BluePrintProcessorException(message, cause)
+}
+
+fun processorException(cause: Throwable, message: String, vararg args: Any?): BluePrintProcessorException {
+    return BluePrintProcessorException(cause, message, args)
+}
+
 fun processorException(code: Int, message: String): BluePrintProcessorException {
     return processorException(message).code(code)
 }
 
+fun processorException(code: Int, message: String, cause: Throwable): BluePrintProcessorException {
+    return processorException(message, cause).code(code)
+}
+
+fun processorException(code: Int, cause: Throwable, message: String, vararg args: Any?): BluePrintProcessorException {
+    return processorException(cause, message, args).code(code)
+}
+
 fun httpProcessorException(type: String, message: String): BluePrintProcessorException {
     return processorException(message).http(type)
 }
@@ -106,17 +131,29 @@ fun grpcProcessorException(type: String, domain: String, message: String): BlueP
 
 fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
         BluePrintProcessorException {
-    val bluePrintProcessorException = processorException(message).http(type)
-    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
+    val bluePrintProcessorException = processorException(message, cause).http(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
 }
 
 fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
         BluePrintProcessorException {
-    val bluePrintProcessorException = processorException(message).grpc(type)
-    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
+    val bluePrintProcessorException = processorException(message, cause).grpc(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
+}
+
+fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
+        BluePrintProcessorException {
+    val bluePrintProcessorException = processorException(cause, message, args).http(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
+}
+
+fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
+        BluePrintProcessorException {
+    val bluePrintProcessorException = processorException(cause, message, args).grpc(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
 }
 
-fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: Throwable):
+fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: String):
         BluePrintProcessorException {
     return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
             .addErrorPayloadMessage(message)
@@ -132,8 +169,7 @@ fun BluePrintProcessorException.updateErrorMessage(domain: String, message: Stri
 private fun BluePrintProcessorException.addDomainAndErrorMessage(
     domain: String,
     message: String,
-    cause: Throwable = Throwable()
+    cause: String = ""
 ): BluePrintProcessorException {
-    return this.addSubError(ErrorMessage(domain, message, cause.message
-            ?: "")).domain(domain)
+    return this.addSubError(ErrorMessage(domain, message, cause)).domain(domain)
 }
index 8e907ab..af2eba0 100644 (file)
@@ -43,5 +43,9 @@
            <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
            <artifactId>blueprint-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+            <artifactId>error-catalog-services</artifactId>
+        </dependency>
     </dependencies>
 </project>
@@ -1,11 +1,11 @@
 /*
- * Copyright (C) 2019 Bell Canada.
+ * 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
+ *     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,
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onap.ccsdk.cds.blueprintsprocessor.configs.api
 
-class ResourceConfigSnapshotException(message: String) : RuntimeException(message) {
-    var code: Int = 404
+object ConfigsApiDomains {
+    // ConfigsApi Domains Constants
+    const val CONFIGS_API = "org.onap.ccsdk.cds.blueprintsprocessor.configs.api"
+}
+
+object ConfigsApiHttpErrorCodes {
+    init {
+        // Register HttpErrorCodes
+        // HttpErrorCodes.register("", 200)
+    }
+}
+
+object ConfigsGrpcErrorCodes {
+    init {
+        // Register GrpcErrorCodes
+        // GrpcErrorCodes.register("", 3)
+    }
 }
index 0b18fb0..2a5f4c3 100644 (file)
@@ -24,6 +24,9 @@ import kotlinx.coroutines.runBlocking
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.config.snapshots.db.ResourceConfigSnapshot
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.config.snapshots.db.ResourceConfigSnapshotService
 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault
 import org.springframework.http.MediaType
 import org.springframework.http.ResponseEntity
 import org.springframework.security.access.prepost.PreAuthorize
@@ -101,12 +104,17 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe
                     resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())
                 )
             } catch (ex: NoSuchElementException) {
-                throw ResourceConfigSnapshotException(
-                    "Could not find configuration snapshot entry for type $resourceType and Id $resourceId"
-                )
+                throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API,
+                        "Could not find configuration snapshot entry for type $resourceType and Id $resourceId",
+                        ex.errorCauseOrDefault())
+            } catch (ex: Exception) {
+                throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API,
+                        "Could not find configuration snapshot entry for type $resourceType and Id $resourceId",
+                        ex.errorCauseOrDefault())
             }
         } else {
-            throw IllegalArgumentException("Missing param. You must specify resource-id and resource-type.")
+            throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API,
+                    "Missing param. You must specify resource-id and resource-type.")
         }
 
         var expectedContentType = format
index d4c31e7..2b9bb31 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright Â© 2019 Bell Canada
+ * Copyright Â© 2019 - 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.
 
 package org.onap.ccsdk.cds.blueprintsprocessor.configs.api
 
-import com.fasterxml.jackson.annotation.JsonFormat
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.annotation.JsonTypeInfo
-import com.fasterxml.jackson.annotation.JsonTypeName
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
-import org.slf4j.LoggerFactory
-import org.springframework.dao.EmptyResultDataAccessException
-import org.springframework.dao.IncorrectResultSizeDataAccessException
-import org.springframework.http.HttpStatus
-import org.springframework.http.ResponseEntity
-import org.springframework.orm.jpa.JpaObjectRetrievalFailureException
-import org.springframework.web.bind.annotation.ExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
 import org.springframework.web.bind.annotation.RestControllerAdvice
-import org.springframework.web.server.ServerWebInputException
-import java.io.Serializable
-import java.util.Date
 
 /**
  * Handle exceptions in ResourceConfigSnapshot API and provide relevant HTTP status codes and messages
  *
  * @author Serge Simard
- * @version 1.0
+ * @version 2.0
  */
 @RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.configs.api")
-open class ResourceConfigSnapshotExceptionHandler {
-
-    private val log = LoggerFactory.getLogger(ResourceConfigSnapshotExceptionHandler::class.toString())
-
-    private val debugMsg = "Resource_Config_Snapshot_ExceptionHandler_Error_Message"
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: BluePrintProcessorException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.BLUEPRINT_PATH_MISSING
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: ServerWebInputException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.INVALID_REQUEST_FORMAT
-        return returnError(e, errorCode, false)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: IllegalArgumentException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.INVALID_REQUEST_FORMAT
-        return returnError(e, errorCode, false)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: IncorrectResultSizeDataAccessException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.DUPLICATE_DATA
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: EmptyResultDataAccessException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.RESOURCE_NOT_FOUND
-        return returnError(e, errorCode, false)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: JpaObjectRetrievalFailureException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.RESOURCE_NOT_FOUND
-        return returnError(e, errorCode, false)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: Exception): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.GENERIC_FAILURE
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resourceConfigSnapshotExceptionHandler(e: ResourceConfigSnapshotException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.RESOURCE_NOT_FOUND
-        return returnError(e, errorCode, false)
-    }
-
-    fun returnError(e: Exception, errorCode: ErrorCode, toBeLogged: Boolean = true): ResponseEntity<ErrorMessage> {
-        if (toBeLogged) {
-            log.error(e.message, e)
-        } else {
-            log.error(e.message)
-        }
-        val errorMessage =
-            ErrorMessage(
-                errorCode.message(e.message!!),
-                errorCode.value,
-                debugMsg
-            )
-        return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode.httpCode)!!)
-    }
-}
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonTypeName("errorMessage")
-@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
-class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable {
-
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    var timestamp = Date()
-}
+open class ResourceConfigSnapshotExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+        ErrorCatalogExceptionHandler(errorCatalogService)
diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt
new file mode 100644 (file)
index 0000000..66fc3b2
--- /dev/null
@@ -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.configs.api
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan(
+        basePackages = ["org.onap.ccsdk.cds.error.catalog"]
+)
+@EnableAutoConfiguration
+open class ErrorCatalogTestConfiguration
index d55568d..b54d92b 100644 (file)
@@ -35,7 +35,7 @@ import org.springframework.web.reactive.function.BodyInserters
 @RunWith(SpringRunner::class)
 @WebFluxTest
 @ContextConfiguration(
-    classes = [BluePrintCoreConfiguration::class, BluePrintCatalogService::class]
+    classes = [BluePrintCoreConfiguration::class, BluePrintCatalogService::class, ErrorCatalogTestConfiguration::class]
 )
 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
@@ -112,7 +112,7 @@ class ResourceConfigSnapshotControllerTest {
 
             webTestClient.get().uri("/api/v1/configs?$arguments")
                 .exchange()
-                .expectStatus().isBadRequest
+                .expectStatus().is4xxClientError
         }
     }
 
index ebd394c..69dbe23 100644 (file)
@@ -1,4 +1,4 @@
-#  Copyright Â© 2019 Bell Canada.
+#  Copyright Â© 2019 - 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.
@@ -28,3 +28,8 @@ blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
 blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
+
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./../../../application/src/test/resources/
index edfcdf8..f1f3132 100644 (file)
 
     <name>Blueprints Processor Designer API</name>
     <description>Blueprints Processor Designer API</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+            <artifactId>error-catalog-services</artifactId>
+        </dependency>
+    </dependencies>
 </project>
index bca77f2..7600979 100644 (file)
@@ -40,13 +40,20 @@ import org.onap.ccsdk.cds.controllerblueprints.management.api.DownloadAction
 import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk
 import org.onap.ccsdk.cds.controllerblueprints.management.api.RemoveAction
 import org.onap.ccsdk.cds.controllerblueprints.management.api.UploadAction
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
+import org.onap.ccsdk.cds.error.catalog.core.GrpcErrorCodes
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorMessageOrDefault
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
 import org.slf4j.LoggerFactory
 import org.springframework.security.access.prepost.PreAuthorize
 import org.springframework.stereotype.Service
 
 // TODO("Convert to coroutines handler")
 @Service
-open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: BluePrintModelHandler) :
+open class BluePrintManagementGRPCHandler(
+    private val bluePrintModelHandler: BluePrintModelHandler,
+    private val errorCatalogService: ErrorCatalogService
+) :
     BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() {
 
     private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java)
@@ -266,20 +273,42 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
 
     private fun failStatus(header: CommonHeader, message: String, e: Exception): BluePrintManagementOutput {
         log.error(message, e)
+        return if (e is BluePrintProcessorException) onErrorCatalog(header, message, e) else onError(header, message, e)
+    }
+
+    private fun onError(header: CommonHeader, message: String, error: Exception): BluePrintManagementOutput {
+        val code = GrpcErrorCodes.code(ErrorCatalogCodes.GENERIC_FAILURE)
         return BluePrintManagementOutput.newBuilder()
-            .setCommonHeader(header)
-            .setStatus(
-                Status.newBuilder()
-                    .setTimestamp(currentTimestamp())
-                    .setMessage(BluePrintConstants.STATUS_FAILURE)
-                    .setErrorMessage(message)
-                    .setCode(500)
-                    .build()
-            )
-            .build()
-        //        return io.grpc.Status.INTERNAL
-        //                .withDescription(message)
-        //                .withCause(e)
-        //                .asException()
+                .setCommonHeader(header)
+                .setStatus(
+                        Status.newBuilder()
+                                .setTimestamp(currentTimestamp())
+                                .setMessage(BluePrintConstants.STATUS_FAILURE)
+                                .setErrorMessage("Error : $message \n Details: ${error.errorMessageOrDefault()}")
+                                .setCode(code)
+                                .build()
+                )
+                .build()
+    }
+
+    private fun onErrorCatalog(header: CommonHeader, message: String, error: BluePrintProcessorException):
+            BluePrintManagementOutput {
+        val err = if (error.protocol == "") {
+            error.grpc(ErrorCatalogCodes.GENERIC_FAILURE)
+        } else {
+            error.convertToGrpc()
+        }
+        val errorPayload = errorCatalogService.errorPayload(err.addErrorPayloadMessage(message))
+        return BluePrintManagementOutput.newBuilder()
+                .setCommonHeader(header)
+                .setStatus(
+                        Status.newBuilder()
+                                .setTimestamp(currentTimestamp())
+                                .setMessage(BluePrintConstants.STATUS_FAILURE)
+                                .setErrorMessage("Error : ${errorPayload.message}")
+                                .setCode(errorPayload.code)
+                                .build()
+                )
+                .build()
     }
 }
index 3698444..1d61c7f 100644 (file)
 
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
 
-import com.fasterxml.jackson.annotation.JsonFormat
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.annotation.JsonTypeInfo
-import com.fasterxml.jackson.annotation.JsonTypeName
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DATA_TYPE_JSON
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DEFAULT_VERSION_NUMBER
@@ -28,8 +24,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.TOSCA_SPE
 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
-import java.io.Serializable
-import java.util.Date
 
 class BootstrapRequest {
     var loadModelType: Boolean = false
@@ -75,12 +69,3 @@ class AutoMapResponse {
     var resourceAssignments: List<ResourceAssignment>? = null
     var dataDictionaries: List<ResourceDictionary>? = null
 }
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonTypeName("errorMessage")
-@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
-class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable {
-
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    var timestamp = Date()
-}
index c140c9a..a083d7a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright Â© 2018-2019 Bell Canada Intellectual Property.
+ * Copyright Â© 2019 - 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.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
 
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
-import org.slf4j.LoggerFactory
-import org.springframework.http.HttpStatus
-import org.springframework.http.ResponseEntity
-import org.springframework.web.bind.annotation.ExceptionHandler
-import org.springframework.web.bind.annotation.RestControllerAdvice
-
 /**
  * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right
  * HTTP code status
  *
- * @author Vinal Patel
- * @version 1.0
+ * @author Steve Siani
+ * @version 2.0
  */
-@RestControllerAdvice("org.onap.ccsdk.cds.controllerblueprints")
-open class DesignerBlueprintExceptionHandler {
-
-    companion object ControllerBlueprintExceptionHandler {
-        val LOG = LoggerFactory.getLogger(DesignerBlueprintExceptionHandler::class.java)
-    }
-
-    @ExceptionHandler
-    fun ControllerBlueprintExceptionHandler(e: BluePrintException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.valueOf(e.code)
-        val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
-        LOG.error("Error: $errorCode ${e.message}")
-        return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
-    }
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
+import org.springframework.web.bind.annotation.RestControllerAdvice
 
-    @ExceptionHandler
-    fun ControllerBlueprintExceptionHandler(e: Exception): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.GENERIC_FAILURE
-        val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
-        LOG.error("Error: $errorCode ${e.message}")
-        return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
-    }
-}
+@RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.designer.api")
+open class DesignerBlueprintExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+        ErrorCatalogExceptionHandler(errorCatalogService)
index e99f494..1d534bb 100644 (file)
 
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer
 
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiDomains
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
-import org.onap.ccsdk.cds.controllerblueprints.core.logger
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault
 import org.springframework.stereotype.Service
+import java.io.IOException
 import java.util.UUID
 
 @Service
@@ -74,9 +81,17 @@ open class BluePrintEnhancerServiceImpl(
             if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {
                 throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())
             }
+        } catch (e: BluePrintProcessorException) {
+            val errorMsg = "Error while enriching the CBA package."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg,
+                    "Wrong blueprint definitions or resource definitions.")
+        } catch (e: IOException) {
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "IO Error: CBA file failed enrichment - ${e.message}", e.errorCauseOrDefault())
         } catch (e: Exception) {
-            throw e
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "Error in Enriching CBA: ${e.message}", e.errorCauseOrDefault())
+        }
+            return blueprintRuntimeService.bluePrintContext()
         }
-        return blueprintRuntimeService.bluePrintContext()
-    }
 }
index e983932..f55fee0 100644 (file)
@@ -24,27 +24,33 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSe
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelContentRepository
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelSearchRepository
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiDomains
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.BootstrapRequest
-import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowData
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecRequest
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowData
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowsResponse
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BluePrintDatabaseLoadService
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
+import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
-import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
-import org.onap.ccsdk.cds.controllerblueprints.core.logger
-import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
-import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorMessageOrDefault
 import org.springframework.core.io.ByteArrayResource
 import org.springframework.core.io.Resource
 import org.springframework.data.domain.Page
@@ -188,10 +194,8 @@ open class BluePrintModelHandler(
         try {
             return upload(filePart, false)
         } catch (e: IOException) {
-            throw BluePrintException(
-                ErrorCode.IO_FILE_INTERRUPT.value,
-                "Error in Save CBA: ${e.message}", e
-            )
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "Error in Save CBA: ${e.message}", e.errorCauseOrDefault())
         }
     }
 
@@ -239,11 +243,11 @@ open class BluePrintModelHandler(
             val archiveByteArray = download(name, version)
             val fileName = "${name}_$version.zip"
             return prepareResourceEntity(fileName, archiveByteArray)
-        } catch (e: BluePrintException) {
-            throw BluePrintException(
-                ErrorCode.RESOURCE_NOT_FOUND.value,
-                String.format("Error while " + "downloading the CBA file: %s", e.message), e
-            )
+        } catch (e: BluePrintProcessorException) {
+            e.http(ErrorCatalogCodes.RESOURCE_NOT_FOUND)
+            val errorMsg = "Error while downloading the CBA file by Blueprint Name ($name) and Version ($version)."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg,
+                    "Wrong resource definition or resolution failed.")
         }
     }
 
@@ -259,15 +263,15 @@ open class BluePrintModelHandler(
         try {
             blueprintModel = getBlueprintModel(id)
         } catch (e: BluePrintException) {
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e)
+            throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                    "Error while downloading the CBA file: couldn't get blueprint modelby ID ($id)",
+                    e.errorCauseOrDefault())
         }
 
         val fileName = "${blueprintModel.artifactName}_${blueprintModel.artifactVersion}.zip"
         val file = blueprintModel.blueprintModelContent?.content
-            ?: throw BluePrintException(
-                ErrorCode.RESOURCE_NOT_FOUND.value,
-                String.format("Error while downloading the CBA file: couldn't get model content")
-            )
+            ?: throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                    "Error while downloading the CBA file: couldn't get model content")
         return prepareResourceEntity(fileName, file)
     }
 
@@ -296,7 +300,7 @@ open class BluePrintModelHandler(
             blueprintModel = dbBlueprintModel.get()
         } else {
             val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+            throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API, msg)
         }
         return blueprintModel
     }
@@ -317,7 +321,7 @@ open class BluePrintModelHandler(
             return blueprintModel
         } else {
             val msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+            throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API, msg)
         }
     }
 
@@ -331,10 +335,8 @@ open class BluePrintModelHandler(
     @Throws(BluePrintException::class)
     open fun getBlueprintModelSearch(id: String): BlueprintModelSearch {
         return blueprintModelSearchRepository.findById(id)
-            ?: throw BluePrintException(
-                ErrorCode.RESOURCE_NOT_FOUND.value,
-                String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
-            )
+            ?: throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                    String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id))
     }
 
     /**
@@ -385,7 +387,7 @@ open class BluePrintModelHandler(
             blueprintModelRepository.delete(dbBlueprintModel.get())
         } else {
             val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+            throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API, msg)
         }
     }
 
@@ -410,11 +412,14 @@ open class BluePrintModelHandler(
         try {
             val enhancedByteArray = enrichBlueprintFileSource(filePart)
             return BluePrintEnhancerUtils.prepareResourceEntity("enhanced-cba.zip", enhancedByteArray)
-        } catch (e: IOException) {
-            throw BluePrintException(
-                ErrorCode.IO_FILE_INTERRUPT.value,
-                "Error in Enriching CBA: ${e.message}", e
-            )
+        } catch (e: BluePrintProcessorException) {
+            e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
+            val errorMsg = "Error while enhancing the CBA package."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg,
+                    "Wrong CBA file provided, please verify and enrich Again.")
+        } catch (e: Exception) {
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "EnrichBlueprint: ${e.message}", e.errorCauseOrDefault())
         }
     }
 
@@ -429,11 +434,14 @@ open class BluePrintModelHandler(
     open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch {
         try {
             return upload(filePart, true)
+        } catch (e: BluePrintProcessorException) {
+            e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
+            val errorMsg = "Error in Publishing CBA."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg,
+                    "Wrong CBA provided, please verify and enrich your CBA.")
         } catch (e: Exception) {
-            throw BluePrintException(
-                ErrorCode.IO_FILE_INTERRUPT.value,
-                "Error in Publishing CBA: ${e.message}", e
-            )
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "Error in Publishing CBA: ${e.message}", e.errorCauseOrDefault())
         }
     }
 
@@ -453,15 +461,16 @@ open class BluePrintModelHandler(
             val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, validate)
 
             return blueprintModelSearchRepository.findById(blueprintId)
-                ?: throw BluePrintException(
-                    ErrorCode.RESOURCE_NOT_FOUND.value,
-                    String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId)
-                )
+                ?: throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                        String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId))
+        } catch (e: BluePrintException) {
+            e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
+            val errorMsg = "Error in Upload CBA."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg,
+                    "Wrong enriched CBA.")
         } catch (e: IOException) {
-            throw BluePrintException(
-                ErrorCode.IO_FILE_INTERRUPT.value,
-                "Error in Upload CBA: ${e.message}", e
-            )
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "Error in Upload CBA: ${e.errorMessageOrDefault()}", e.errorCauseOrDefault())
         } finally {
             // Clean blueprint script cache
             val cacheKey = BluePrintFileUtils
@@ -478,15 +487,13 @@ open class BluePrintModelHandler(
         try {
             val blueprintModel = getBlueprintModelByNameAndVersion(name, version)
             return blueprintModel.blueprintModelContent?.content
-                ?: throw BluePrintException(
-                    ErrorCode.RESOURCE_NOT_FOUND.value,
-                    String.format("Error while downloading the CBA file: couldn't get model content")
-                )
+                ?: throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                        "Error while downloading the CBA file: couldn't get model content")
         } catch (e: BluePrintException) {
-            throw BluePrintException(
-                ErrorCode.RESOURCE_NOT_FOUND.value,
-                String.format("Error while " + "downloading the CBA file: %s", e.message), e
-            )
+            e.http(ErrorCatalogCodes.RESOURCE_NOT_FOUND)
+            val errorMsg = "Fail to get Blueprint Model content."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg,
+                    "Wrong name and version was provide.")
         }
     }
 
@@ -506,11 +513,13 @@ open class BluePrintModelHandler(
             bluePrintEnhancerService.enhance(blueprintWorkingDir)
 
             return BluePrintEnhancerUtils.compressEnhanceDirAndReturnByteArray(blueprintWorkingDir, blueprintArchive)
+        } catch (e: BluePrintException) {
+            e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
+            val errorMsg = "Fail Enriching the CBA."
+            throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg)
         } catch (e: IOException) {
-            throw BluePrintException(
-                ErrorCode.IO_FILE_INTERRUPT.value,
-                "Error in Enriching CBA: ${e.message}", e
-            )
+            throw httpProcessorException(ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
+                    "Error while Enriching the CBA file.", e.errorCauseOrDefault())
         } finally {
             BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintWorkingDir)
         }
index a364f36..d11c128 100644 (file)
 
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
 
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiDomains
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ModelTypeRepository
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.ModelTypeValidator
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
 import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Service
 
@@ -42,7 +45,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository
         return if (modelType != null) {
             modelType
         } else {
-            throw BluePrintException("couldn't get modelType($modelTypeName)")
+            throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                    "couldn't get modelType($modelTypeName)")
         }
     }
 
index 0f0bfef..20895ef 100644 (file)
@@ -20,13 +20,16 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
 import com.google.common.base.Preconditions
 import org.apache.commons.collections.CollectionUtils
 import org.apache.commons.lang3.StringUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiDomains
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
 import org.springframework.stereotype.Service
 
 @Service
@@ -46,7 +49,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
         return if (resourceDictionaryDb != null) {
             resourceDictionaryDb
         } else {
-            throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name))
+            throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
+                    String.format("couldn't get resource dictionary for name (%s)", name))
         }
     }
 
index 0e33884..9489f28 100644 (file)
@@ -63,7 +63,7 @@ import kotlin.test.assertTrue
 @RunWith(SpringRunner::class)
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ContextConfiguration(
-    classes = [DesignerApiTestConfiguration::class]
+    classes = [DesignerApiTestConfiguration::class, ErrorCatalogTestConfiguration::class]
 )
 @TestPropertySource(locations = ["classpath:application-test.properties"])
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorCatalogTestConfiguration.kt
new file mode 100644 (file)
index 0000000..d081dc5
--- /dev/null
@@ -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.designer.api
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan(
+        basePackages = ["org.onap.ccsdk.cds.error.catalog"]
+)
+@EnableAutoConfiguration
+open class ErrorCatalogTestConfiguration
index e22e522..5e3e661 100755 (executable)
@@ -1,5 +1,5 @@
 #
-#  Copyright Â© 2019 IBM.
+#  Copyright Â© 2019 - 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.
@@ -36,6 +36,11 @@ blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
 blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
 blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./../../../application/src/test/resources/
+
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
 blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
index bec0d18..7ef99d4 100644 (file)
@@ -38,5 +38,9 @@
            <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
            <artifactId>blueprint-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+            <artifactId>error-catalog-services</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResolutionException.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResolutionException.kt
deleted file mode 100644 (file)
index 62e89e2..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2019 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.resource.api
-
-class ResolutionException(message: String) : RuntimeException(message) {
-    var code: Int = 404
-}
index 264cd23..1aae8aa 100644 (file)
@@ -23,7 +23,9 @@ import io.swagger.annotations.ApiParam
 import kotlinx.coroutines.runBlocking
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
 import org.springframework.http.MediaType
 import org.springframework.http.ResponseEntity
 import org.springframework.security.access.prepost.PreAuthorize
@@ -83,7 +85,8 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
             ResponseEntity<List<ResourceResolution>> = runBlocking {
 
         if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) {
-            throw ResolutionException("Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
+            throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API,
+                    "Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
         } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) {
             ResponseEntity.ok()
                 .body(resourceResolutionDBService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey))
@@ -98,7 +101,8 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
                     )
                 )
         } else {
-            throw ResolutionException("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
+            throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API,
+                    "Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.")
         }
     }
 
index 5d5623d..9c09bd8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright Â© 2019 Bell Canada
+ * Copyright Â© 2019 - 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.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.onap.ccsdk.cds.blueprintsprocessor.resource.api
 
-import com.fasterxml.jackson.annotation.JsonFormat
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.annotation.JsonTypeInfo
-import com.fasterxml.jackson.annotation.JsonTypeName
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
-import org.slf4j.LoggerFactory
-import org.springframework.dao.EmptyResultDataAccessException
-import org.springframework.dao.IncorrectResultSizeDataAccessException
-import org.springframework.http.HttpStatus
-import org.springframework.http.ResponseEntity
-import org.springframework.orm.jpa.JpaObjectRetrievalFailureException
-import org.springframework.web.bind.annotation.ExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
 import org.springframework.web.bind.annotation.RestControllerAdvice
-import org.springframework.web.server.ServerWebInputException
-import java.io.Serializable
-import java.util.Date
 
 /**
  * Handle exceptions in Resolution API and provide relevant HTTP status codes and messages
  *
  * @author Serge Simard
- * @version 1.0
+ * @version 2.0
  */
 @RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.resource.api")
-open class ResourceExceptionHandler {
-
-    private val log = LoggerFactory.getLogger(ExceptionHandler::class.toString())
-
-    private val debugMsg = "Resolution_Service_Error_Message"
-
-    @ExceptionHandler
-    fun resolutionResultsServiceExceptionHandler(e: BluePrintProcessorException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.BLUEPRINT_PATH_MISSING
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resolutionResultsServiceExceptionHandler(e: ServerWebInputException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.INVALID_REQUEST_FORMAT
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resolutionResultsServiceExceptionHandler(e: IncorrectResultSizeDataAccessException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.DUPLICATE_DATA
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resolutionResultsServiceExceptionHandler(e: EmptyResultDataAccessException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.RESOURCE_NOT_FOUND
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resolutionResultsServiceExceptionHandler(e: JpaObjectRetrievalFailureException): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.RESOURCE_NOT_FOUND
-        return returnError(e, errorCode)
-    }
-
-    @ExceptionHandler
-    fun resolutionResultsServiceExceptionHandler(e: Exception): ResponseEntity<ErrorMessage> {
-        val errorCode = ErrorCode.GENERIC_FAILURE
-        return returnError(e, errorCode)
-    }
-
-    fun returnError(e: Exception, errorCode: ErrorCode): ResponseEntity<ErrorMessage> {
-        log.error(e.message, e)
-        val errorMessage =
-            ErrorMessage(
-                errorCode.message(e.message!!),
-                errorCode.value,
-                debugMsg
-            )
-        return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode.httpCode)!!)
-    }
-
-    @ExceptionHandler
-    fun ResolutionResultsServiceExceptionHandler(e: ResolutionException): ResponseEntity<ErrorMessage> {
-        log.error(e.message, e)
-        return ResponseEntity(ErrorMessage(e.message, e.code, debugMsg), HttpStatus.resolve(e.code))
-    }
-}
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonTypeName("errorMessage")
-@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
-class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable {
-
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    var timestamp = Date()
-}
+open class ResourceExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+        ErrorCatalogExceptionHandler(errorCatalogService)
index 5913bde..80000d5 100644 (file)
@@ -23,7 +23,9 @@ import io.swagger.annotations.ApiParam
 import kotlinx.coroutines.runBlocking
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolution
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
 import org.springframework.http.MediaType
 import org.springframework.http.ResponseEntity
 import org.springframework.security.access.prepost.PreAuthorize
@@ -99,7 +101,8 @@ open class TemplateController(private val templateResolutionService: TemplateRes
         var result = ""
 
         if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) {
-            throw ResolutionException("Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.")
+            throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API,
+                    "Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.")
         } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) {
             result = templateResolutionService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
                 bpName,
@@ -117,7 +120,8 @@ open class TemplateController(private val templateResolutionService: TemplateRes
                     resourceType
                 )
         } else {
-            throw ResolutionException("Missing param. Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.")
+            throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API,
+                    "Missing param. Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.")
         }
 
         var expectedContentType = format
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorCatalogTestConfiguration.kt
new file mode 100644 (file)
index 0000000..5b0d198
--- /dev/null
@@ -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.resource.api
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan(
+        basePackages = ["org.onap.ccsdk.cds.error.catalog"]
+)
+@EnableAutoConfiguration
+open class ErrorCatalogTestConfiguration
index dab9652..c5e002f 100644 (file)
@@ -27,6 +27,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
@@ -39,7 +40,7 @@ import org.springframework.test.web.reactive.server.WebTestClient
 @RunWith(SpringRunner::class)
 @WebFluxTest
 @ContextConfiguration(
-    classes = [TestDatabaseConfiguration::class,
+    classes = [TestDatabaseConfiguration::class, ErrorCatalogTestConfiguration::class,
         ResourceController::class, ResourceResolutionDBService::class]
 )
 @ComponentScan(
@@ -147,9 +148,11 @@ class ResourceControllerTest {
                 .expectStatus().is4xxClientError
                 .expectBody()
                 .consumeWith {
-                    val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorMessage::class.java)
+                    val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorPayload::class.java)
                     Assert.assertEquals(
-                        "Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.",
+                            "Cause: Missing param. Either retrieve resolved value using artifact name and " +
+                                    "resolution-key OR using resource-id and resource-type. \n" +
+                                    " Action : Please verify your request.",
                         r.message
                     )
                 }
@@ -166,9 +169,10 @@ class ResourceControllerTest {
                 .expectStatus().is4xxClientError
                 .expectBody()
                 .consumeWith {
-                    val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorMessage::class.java)
+                    val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorPayload::class.java)
                     Assert.assertEquals(
-                        "Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.",
+                        "Cause: Either retrieve resolved value using artifact name and resolution-key OR using " +
+                                "resource-id and resource-type. \n Action : Please verify your request.",
                         r.message
                     )
                 }
index 09b2c5b..0984235 100644 (file)
@@ -38,7 +38,7 @@ import kotlin.test.AfterTest
 @WebFluxTest
 @ContextConfiguration(
     classes = [TestDatabaseConfiguration::class, BluePrintCoreConfiguration::class,
-        BluePrintCatalogService::class]
+        BluePrintCatalogService::class, ErrorCatalogTestConfiguration::class]
 )
 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
@@ -120,7 +120,7 @@ class TemplateControllerTest {
 
             webTestClient.get().uri("/api/v1/template?$arguments")
                 .exchange()
-                .expectStatus().isBadRequest
+                .expectStatus().isNotFound
         }
     }
 
index cb7837b..ee7d6e6 100644 (file)
@@ -1,7 +1,7 @@
 #
-# Copyright ï¿½ 2017-2018 AT&T Intellectual Property.
+# Copyright (c) 2017-2018 AT&T Intellectual Property.
 #
-# Modifications Copyright ï¿½ 2019 IBM, Bell Canada.
+# Modifications Copyright (c) 2019 - 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.
@@ -28,6 +28,11 @@ blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
 blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work
 blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./../../../application/src/test/resources/
+
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
 blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
index 5e3ce2c..32dd659 100755 (executable)
            <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
            <artifactId>blueprint-validation</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+            <artifactId>error-catalog-services</artifactId>
+        </dependency>
 
         <!-- For Message libraries -->
         <dependency>
index 3054379..46d91e5 100644 (file)
 
 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
 
+import io.grpc.Status
 import io.grpc.stub.StreamObserver
 import kotlinx.coroutines.runBlocking
 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
 import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.toJava
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorMessageOrDefault
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
 import org.slf4j.LoggerFactory
 import org.springframework.security.access.prepost.PreAuthorize
 import org.springframework.stereotype.Service
@@ -33,7 +39,8 @@ import javax.annotation.PreDestroy
 @Service
 open class BluePrintProcessingGRPCHandler(
     private val bluePrintCoreConfiguration: BluePrintCoreConfiguration,
-    private val executionServiceHandler: ExecutionServiceHandler
+    private val executionServiceHandler: ExecutionServiceHandler,
+    private val errorCatalogService: ErrorCatalogService
 ) :
     BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() {
 
@@ -62,10 +69,29 @@ open class BluePrintProcessingGRPCHandler(
 
             override fun onError(error: Throwable) {
                 log.debug("Fail to process message", error)
+                if (error is BluePrintProcessorException) onErrorCatalog(error) else onError(error)
+            }
+
+            fun onError(error: Exception) {
+                responseObserver.onError(
+                        Status.INTERNAL
+                                .withDescription(error.errorMessageOrDefault())
+                                .withCause(error.errorCauseOrDefault())
+                                .asException()
+                )
+            }
+
+            fun onErrorCatalog(error: BluePrintProcessorException) {
+                if (error.protocol == "") {
+                    error.grpc(ErrorCatalogCodes.GENERIC_FAILURE)
+                }
+                val errorPayload = errorCatalogService.errorPayload(error)
+                val grpcCode = Status.fromCodeValue(errorPayload.code)
                 responseObserver.onError(
-                    io.grpc.Status.INTERNAL
-                        .withDescription(error.message)
-                        .asException()
+                        grpcCode
+                                .withDescription(errorPayload.message)
+                                .withCause(error.errorCauseOrDefault())
+                                .asException()
                 )
             }
 
index 6293f48..d0b4df8 100644 (file)
@@ -25,6 +25,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BlueprintMessageCo
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsType
 import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.boot.context.event.ApplicationReadyEvent
 import org.springframework.context.event.EventListener
@@ -65,6 +66,10 @@ open class BluePrintProcessingKafkaConsumer(
             blueprintMessageConsumerService = try {
                 bluePrintMessageLibPropertyService
                     .blueprintMessageConsumerService(CONSUMER_SELECTOR)
+            } catch (e: BluePrintProcessorException) {
+                val errorMsg = "Failed creating Kafka consumer message service."
+                throw e.updateErrorMessage(SelfServiceApiDomains.SELF_SERVICE_API, errorMsg,
+                        "Wrong Kafka selector provided or internal error in Kafka service.")
             } catch (e: Exception) {
                 throw BluePrintProcessorException("failed to create consumer service ${e.message}")
             }
@@ -73,6 +78,10 @@ open class BluePrintProcessingKafkaConsumer(
             val blueprintMessageProducerService = try {
                 bluePrintMessageLibPropertyService
                     .blueprintMessageProducerService(PRODUCER_SELECTOR)
+            } catch (e: BluePrintProcessorException) {
+                val errorMsg = "Failed creating Kafka producer message service."
+                throw e.updateErrorMessage(SelfServiceApiDomains.SELF_SERVICE_API, errorMsg,
+                        "Wrong Kafka selector provided or internal error in Kafka service.")
             } catch (e: Exception) {
                 throw BluePrintProcessorException("failed to create producer service ${e.message}")
             }
index b76bc26..c4baa85 100644 (file)
@@ -21,12 +21,6 @@ object SelfServiceApiDomains {
     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 {
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceExceptionHandler.kt
new file mode 100644 (file)
index 0000000..57c02fe
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *  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.selfservice.api
+
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
+import org.springframework.web.bind.annotation.RestControllerAdvice
+
+/**
+ * ExecutionServiceExceptionHandler.kt Purpose: Handle exceptions in selfservice API and provide the right
+ * HTTP code status
+ *
+ * @author Steve Siani
+ * @version 1.0
+ */
+@RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api")
+class ExecutionServiceExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+        ErrorCatalogExceptionHandler(errorCatalogService)
index af23e79..f33f114 100644 (file)
@@ -42,7 +42,8 @@ import kotlin.test.BeforeTest
 @RunWith(SpringRunner::class)
 @DirtiesContext
 @ContextConfiguration(
-    classes = [SelfServiceApiTestConfiguration::class, TestDatabaseConfiguration::class]
+    classes = [SelfServiceApiTestConfiguration::class, TestDatabaseConfiguration::class,
+        ErrorCatalogTestConfiguration::class]
 )
 @TestPropertySource(locations = ["classpath:application-test.properties"])
 class BluePrintProcessingGRPCHandlerTest {
index b26781a..825b0c8 100644 (file)
@@ -30,7 +30,11 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput
+import org.springframework.test.context.ContextConfiguration
 
+@ContextConfiguration(
+        classes = [SelfServiceApiTestConfiguration::class, ErrorCatalogTestConfiguration::class]
+)
 class BluePrintProcessingIntegrationTest {
 
     private val log = logger(BluePrintProcessingIntegrationTest::class)
index f71d1b4..ed573d7 100644 (file)
@@ -35,8 +35,8 @@ import kotlin.test.assertNotNull
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(
-    classes = [BluePrintMessageLibConfiguration::class,
-        BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class]
+    classes = [BluePrintMessageLibConfiguration::class, SelfServiceApiTestConfiguration::class,
+        BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, ErrorCatalogTestConfiguration::class]
 )
 @TestPropertySource(locations = ["classpath:application-test.properties"])
 class BluePrintProcessingKafkaConsumerTest {
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorCatalogTestConfiguration.kt
new file mode 100644 (file)
index 0000000..a773b4c
--- /dev/null
@@ -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.selfservice.api
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan(
+        basePackages = ["org.onap.ccsdk.cds.error.catalog"]
+)
+@EnableAutoConfiguration
+open class ErrorCatalogTestConfiguration
index 255220f..f2c77d6 100644 (file)
@@ -29,7 +29,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
-import org.springframework.context.annotation.ComponentScan
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.TestPropertySource
 import org.springframework.test.context.junit4.SpringRunner
@@ -45,11 +44,7 @@ import kotlin.test.assertTrue
 @WebFluxTest
 @ContextConfiguration(
     classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class,
-        BluePrintCatalogService::class]
-)
-@ComponentScan(
-    basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor",
-        "org.onap.ccsdk.cds.controllerblueprints"]
+        BluePrintCatalogService::class, SelfServiceApiTestConfiguration::class, ErrorCatalogTestConfiguration::class]
 )
 @TestPropertySource(locations = ["classpath:application-test.properties"])
 class ExecutionServiceControllerTest {
index 5a44403..b21f968 100644 (file)
@@ -30,13 +30,16 @@ import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.context.ApplicationContext
 import org.springframework.stereotype.Service
 import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
 import org.springframework.test.context.junit4.SpringRunner
 import kotlin.test.Test
 import kotlin.test.assertNotNull
 import kotlin.test.assertTrue
 
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [MockServiceAction::class])
+@ContextConfiguration(classes = [MockServiceAction::class, SelfServiceApiTestConfiguration::class,
+    ErrorCatalogTestConfiguration::class])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
 class ExecutionServiceHandlerTest {
 
     @Autowired
index d18b700..6003df1 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Copyright Â© 2017-2018 AT&T Intellectual Property.
 #
-# Modifications Copyright Â© 2019 IBM, Bell Canada.
+# Modifications Copyright Â© 2019 - 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.
@@ -28,6 +28,11 @@ blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
 blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work
 blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./../../../application/src/test/resources/
+
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
 blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ErrorHandling.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ErrorHandling.kt
new file mode 100644 (file)
index 0000000..fd7cde4
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.services.execution
+
+object ExecutionServiceDomains {
+    // ExecutionService Domains Constants
+    const val BLUEPRINT_PROCESSOR = "org.onap.ccsdk.cds.blueprintsprocessor"
+    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 ExecutionServiceHttpErrorCodes {
+    init {
+        // Register HttpErrorCodes
+        // HttpErrorCodes.register("", 200)
+    }
+}
+
+object ExecutionServiceGrpcErrorCodes {
+    init {
+        // Register GrpcErrorCodes
+        // GrpcErrorCodes.register("", 3)
+    }
+}
index c2a09db..51d50b4 100644 (file)
     <properties>
         <sonar.skip>true</sonar.skip>
     </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+            <artifactId>error-catalog-services</artifactId>
+        </dependency>
+    </dependencies>
 </project>
index 0592112..beebd5d 100644 (file)
     <properties>
         <sonar.skip>true</sonar.skip>
     </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-webflux</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.module</groupId>
+            <artifactId>jackson-module-kotlin</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.persistence</groupId>
+            <artifactId>javax.persistence-api</artifactId>
+        </dependency>
+    </dependencies>
 </project>
index 032feb6..348b60c 100644 (file)
@@ -23,6 +23,8 @@ interface ErrorCatalogExceptionFluent<T> {
     fun action(action: String): T
     fun http(type: String): T
     fun grpc(type: String): T
+    fun convertToHttp(): T
+    fun convertToGrpc(): T
     fun payloadMessage(message: String): T
     fun addErrorPayloadMessage(message: String): T
     fun addSubError(errorMessage: ErrorMessage): T
@@ -78,12 +80,30 @@ open class ErrorCatalogException : RuntimeException {
 
     fun <T : ErrorCatalogException> updateHttp(type: String): T {
         this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP
+        this.name = type
         this.code = HttpErrorCodes.code(type)
         return this as T
     }
 
+    fun <T : ErrorCatalogException> inverseToHttp(): T {
+        if (this.protocol != "" && this.protocol == ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC) {
+            this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP
+            this.code = HttpErrorCodes.code(this.name)
+        }
+        return this as T
+    }
+
+    fun <T : ErrorCatalogException> inverseToGrpc(): T {
+        if (this.protocol != "" && this.protocol == ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP) {
+            this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC
+            this.code = GrpcErrorCodes.code(this.name)
+        }
+        return this as T
+    }
+
     fun <T : ErrorCatalogException> updateGrpc(type: String): T {
         this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC
+        this.name = type
         this.code = GrpcErrorCodes.code(type)
         return this as T
     }
index 86483e3..8023d97 100644 (file)
@@ -54,8 +54,7 @@ object HttpErrorCodes {
     }
 
     fun code(type: String): Int {
-        // FIXME("Return Default Error Code , If missing")
-        return store[type]!!
+        return store[type] ?: store[ErrorCatalogCodes.GENERIC_FAILURE]!!
     }
 }
 
@@ -82,7 +81,6 @@ object GrpcErrorCodes {
     }
 
     fun code(type: String): Int {
-        // FIXME("Return Default Error Code , If missing")
-        return store[type]!!
+        return store[type] ?: store[ErrorCatalogCodes.GENERIC_FAILURE]!!
     }
 }
index 2c0772e..4158cfa 100644 (file)
@@ -20,12 +20,15 @@ import com.fasterxml.jackson.annotation.JsonFormat
 import org.slf4j.event.Level
 import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants.ERROR_CATALOG_DEFAULT_ERROR_CODE
 import java.time.LocalDateTime
+import java.time.ZoneId
+import java.util.Date
+import kotlin.collections.ArrayList
 
 open class ErrorPayload {
     var code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE
     var status: String = ""
     @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    var timestamp: LocalDateTime = LocalDateTime.now()
+    var timestamp: Date = controllerDate()
     var message: String = ""
     var debugMessage: String = ""
     var logLevel: String = Level.ERROR.name
@@ -68,6 +71,11 @@ open class ErrorPayload {
             this.logLevel == errorPayload.logLevel && this.debugMessage == errorPayload.debugMessage &&
             this.subErrors == errorPayload.subErrors)
     }
+
+    private fun controllerDate(): Date {
+        val localDateTime = LocalDateTime.now(ZoneId.systemDefault())
+        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant())
+    }
 }
 
 /**
@@ -13,7 +13,9 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.onap.ccsdk.cds.error.catalog.services.utils
+package org.onap.ccsdk.cds.error.catalog.core.utils
+
+import org.apache.commons.lang3.exception.ExceptionUtils
 
 object ErrorCatalogUtils {
     private const val REGEX_PATTERN = "^cause=(.*),action=(.*)"
@@ -31,7 +33,7 @@ object ErrorCatalogUtils {
 }
 
 fun Exception.errorCauseOrDefault(): Throwable {
-    return this.cause ?: Throwable()
+    return ExceptionUtils.getRootCause(this)
 }
 
 fun Exception.errorMessageOrDefault(): String {
index 8b82d7d..31e7658 100644 (file)
         <module>services</module>
     </modules>
 
+    <properties>
+        <error-catalog.version>${project.version}</error-catalog.version>
+    </properties>
+
     <dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
                 <artifactId>error-catalog-core</artifactId>
-                <version>${project.version}</version>
+                <version>${error-catalog.version}</version>
             </dependency>
             <dependency>
                 <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
                 <artifactId>error-catalog-services</artifactId>
-                <version>${project.version}</version>
+                <version>${error-catalog.version}</version>
             </dependency>
         </dependencies>
     </dependencyManagement>
         <!-- Kotlin Dependencies -->
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-stdlib</artifactId>
+            <artifactId>kotlin-stdlib-jdk8</artifactId>
         </dependency>
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-stdlib-common</artifactId>
+            <artifactId>kotlin-reflect</artifactId>
         </dependency>
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-script-util</artifactId>
+            <artifactId>kotlin-stdlib</artifactId>
         </dependency>
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-stdlib-jdk8</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.jetbrains.kotlinx</groupId>
-            <artifactId>kotlinx-coroutines-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.jetbrains.kotlinx</groupId>
-            <artifactId>kotlinx-coroutines-reactor</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.module</groupId>
-            <artifactId>jackson-module-kotlin</artifactId>
+            <artifactId>kotlin-stdlib-common</artifactId>
         </dependency>
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
             <artifactId>kotlin-compiler-embeddable</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-scripting-jvm-host</artifactId>
-            <!--Use kotlin-compiler-embeddable as koltin-compiler wrap-->
-            <!--guava dependency creating classpath issues at runtime-->
-            <exclusions>
-                <exclusion>
-                    <groupId>org.jetbrains.kotlin</groupId>
-                    <artifactId>kotlin-compiler</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-webflux</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.persistence</groupId>
-            <artifactId>javax.persistence-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-jpa</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>io.projectreactor</groupId>
-            <artifactId>reactor-test</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <build>
index a0a1ba9..591b34d 100644 (file)
             <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
             <artifactId>error-catalog-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-scripting-jvm-host</artifactId>
+            <!--Use kotlin-compiler-embeddable as koltin-compiler wrap-->
+            <!--guava dependency creating classpath issues at runtime-->
+            <exclusions>
+                <exclusion>
+                    <groupId>org.jetbrains.kotlin</groupId>
+                    <artifactId>kotlin-compiler</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-reactor</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-script-util</artifactId>
+        </dependency>
+        <!-- Kotlin Dependencies -->
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-test</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
index 88e2f45..258209f 100644 (file)
 
 package org.onap.ccsdk.cds.error.catalog.services
 
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
 import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
+import org.onap.ccsdk.cds.error.catalog.core.HttpErrorCodes
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault
+import org.onap.ccsdk.cds.error.catalog.core.utils.errorMessageOrDefault
+import org.springframework.dao.EmptyResultDataAccessException
+import org.springframework.dao.IncorrectResultSizeDataAccessException
 import org.springframework.http.ResponseEntity
+import org.springframework.orm.jpa.JpaObjectRetrievalFailureException
 import org.springframework.web.bind.annotation.ExceptionHandler
+import org.springframework.web.server.ServerWebInputException
 
 abstract class ErrorCatalogExceptionHandler(private val errorCatalogService: ErrorCatalogService) {
 
@@ -28,4 +36,44 @@ abstract class ErrorCatalogExceptionHandler(private val errorCatalogService: Err
         val errorPayload = errorCatalogService.errorPayload(e)
         return errorPayload.toResponseEntity()
     }
+
+    @ExceptionHandler
+    fun errorCatalogException(e: ServerWebInputException): ResponseEntity<ErrorPayload> {
+        val error = ErrorCatalogException(HttpErrorCodes.code(ErrorCatalogCodes.REQUEST_NOT_FOUND),
+                e.errorMessageOrDefault(), e.errorCauseOrDefault())
+        val errorPayload = ErrorPayload(error.code, error.name, error.errorMessageOrDefault())
+        return errorPayload.toResponseEntity()
+    }
+
+    @ExceptionHandler
+    fun errorCatalogException(e: IncorrectResultSizeDataAccessException): ResponseEntity<ErrorPayload> {
+        val error = ErrorCatalogException(HttpErrorCodes.code(ErrorCatalogCodes.DUPLICATE_DATA),
+                e.errorMessageOrDefault(), e.errorCauseOrDefault())
+        val errorPayload = ErrorPayload(error.code, error.name, error.errorMessageOrDefault())
+        return errorPayload.toResponseEntity()
+    }
+
+    @ExceptionHandler
+    fun errorCatalogException(e: EmptyResultDataAccessException): ResponseEntity<ErrorPayload> {
+        val error = ErrorCatalogException(HttpErrorCodes.code(ErrorCatalogCodes.RESOURCE_NOT_FOUND),
+                e.errorMessageOrDefault(), e.errorCauseOrDefault())
+        val errorPayload = ErrorPayload(error.code, error.name, error.errorMessageOrDefault())
+        return errorPayload.toResponseEntity()
+    }
+
+    @ExceptionHandler
+    fun errorCatalogException(e: JpaObjectRetrievalFailureException): ResponseEntity<ErrorPayload> {
+        val error = ErrorCatalogException(HttpErrorCodes.code(ErrorCatalogCodes.RESOURCE_NOT_FOUND),
+                e.errorMessageOrDefault(), e.errorCauseOrDefault())
+        val errorPayload = ErrorPayload(error.code, error.name, error.errorMessageOrDefault())
+        return errorPayload.toResponseEntity()
+    }
+
+    @ExceptionHandler
+    fun errorCatalogException(e: Exception): ResponseEntity<ErrorPayload> {
+        val error = ErrorCatalogException(HttpErrorCodes.code(ErrorCatalogCodes.GENERIC_FAILURE),
+                e.errorMessageOrDefault(), e.errorCauseOrDefault())
+        val errorPayload = ErrorPayload(error.code, error.name, error.errorMessageOrDefault())
+        return errorPayload.toResponseEntity()
+    }
 }
index 91f8171..21fd51b 100644 (file)
@@ -24,7 +24,8 @@ import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants
 import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
 import org.onap.ccsdk.cds.error.catalog.core.GrpcErrorCodes
 import org.onap.ccsdk.cds.error.catalog.core.HttpErrorCodes
-import org.onap.ccsdk.cds.error.catalog.services.utils.ErrorCatalogUtils
+import org.onap.ccsdk.cds.error.catalog.core.utils.ErrorCatalogUtils
+import org.apache.commons.lang3.exception.ExceptionUtils
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
 import org.springframework.stereotype.Service
 import javax.annotation.PostConstruct
@@ -40,10 +41,17 @@ open class ErrorCatalogService(private var errorCatalogLoadService: ErrorCatalog
 
     fun errorPayload(errorCatalogException: ErrorCatalogException): ErrorPayload {
         val errorCatalog = getErrorCatalog(errorCatalogException)
-        val errorPayload = ErrorPayload(errorCatalog.code, errorCatalog.errorId, errorCatalog.getMessage())
-        errorPayload.subErrors.addAll(errorCatalogException.errorPayload!!.subErrors)
+        val errorPayload: ErrorPayload
+        if (errorCatalogException.errorPayload == null) {
+            errorPayload = ErrorPayload(errorCatalog.code, errorCatalog.errorId, errorCatalog.getMessage())
+        } else {
+            errorPayload = errorCatalogException.errorPayload!!
+            errorPayload.code = errorCatalog.code
+            errorPayload.message = errorCatalog.getMessage()
+            errorPayload.status = errorCatalog.errorId
+        }
         if (errorCatalogException.cause != null) {
-            errorPayload.debugMessage = errorCatalogException.cause!!.printStackTrace().toString()
+            errorPayload.debugMessage = ExceptionUtils.getStackTrace(errorCatalogException.cause)
         }
         return errorPayload
     }