aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/designer-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt59
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt15
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt43
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt23
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt121
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt6
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt6
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt2
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt2
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorCatalogTestConfiguration.kt28
-rwxr-xr-xms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/application-test.properties7
11 files changed, 183 insertions, 129 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
index bca77f275..7600979f8 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
@@ -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()
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
index 369844445..1d61c7f0c 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
@@ -17,10 +17,6 @@
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()
-}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt
index c140c9a07..a083d7a8b 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt
@@ -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.
@@ -13,44 +13,19 @@
* 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)
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt
index e99f49489..1d534bb73 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt
@@ -17,15 +17,22 @@
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()
- }
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
index e9839328b..f55fee04b 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
@@ -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)
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt
index a364f3678..d11c128f0 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt
@@ -17,10 +17,13 @@
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)")
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
index 0f0bfef6d..20895efce 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
@@ -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))
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
index 35e440554..d6694de9e 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
@@ -54,7 +54,7 @@ import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
@ContextConfiguration(
- classes = [DesignerApiTestConfiguration::class]
+ classes = [DesignerApiTestConfiguration::class, ErrorCatalogTestConfiguration::class]
)
@TestPropertySource(locations = ["classpath:application-test.properties"])
class BluePrintManagementGRPCHandlerTest {
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt
index 0e33884a0..9489f2882 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt
@@ -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
index 000000000..d081dc5ab
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorCatalogTestConfiguration.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.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
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/application-test.properties
index e22e522ee..5e3e66172 100755
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/application-test.properties
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/application-test.properties
@@ -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