diff options
Diffstat (limited to 'ms/error-catalog/core')
5 files changed, 91 insertions, 5 deletions
diff --git a/ms/error-catalog/core/pom.xml b/ms/error-catalog/core/pom.xml index a7ecdccbb..81ad38f00 100644 --- a/ms/error-catalog/core/pom.xml +++ b/ms/error-catalog/core/pom.xml @@ -32,4 +32,23 @@ <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> diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt index 032feb62c..348b60ceb 100644 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt @@ -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 } diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt index 86483e3e9..8023d97c8 100644 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt @@ -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]!! } } diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt index 2c0772e31..4158cfaf8 100644 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt @@ -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()) + } } /** diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/utils/ErrorCatalogUtils.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/utils/ErrorCatalogUtils.kt new file mode 100644 index 000000000..f13a3604f --- /dev/null +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/utils/ErrorCatalogUtils.kt @@ -0,0 +1,41 @@ +/* + * 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.error.catalog.core.utils + +import org.apache.commons.lang3.exception.ExceptionUtils + +object ErrorCatalogUtils { + private const val REGEX_PATTERN = "^cause=(.*),action=(.*)" + private val regex = REGEX_PATTERN.toRegex() + + fun readErrorCauseFromMessage(message: String): String { + val matchResults = regex.matchEntire(message) + return matchResults!!.groupValues[1] + } + + fun readErrorActionFromMessage(message: String): String { + val matchResults = regex.matchEntire(message) + return matchResults!!.groupValues[2] + } +} + +fun Exception.errorCauseOrDefault(): Throwable { + return ExceptionUtils.getRootCause(this) +} + +fun Exception.errorMessageOrDefault(): String { + return this.message ?: "" +} |