2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 - 2020 IBM, Bell Canada.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.controllerblueprints.core
20 import org.apache.commons.lang.exception.ExceptionUtils
21 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
22 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogExceptionFluent
23 import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage
28 * @author Brinda Santh
30 open class BlueprintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BlueprintProcessorException> {
32 constructor(message: String, cause: Throwable) : super(message, cause)
33 constructor(message: String) : super(message)
34 constructor(cause: Throwable) : super(cause)
35 constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
36 constructor(code: Int, cause: Throwable) : super(code, cause)
37 constructor(code: Int, message: String) : super(code, message)
38 constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
40 override fun code(code: Int): BlueprintProcessorException {
41 return this.updateCode(code)
44 override fun domain(domain: String): BlueprintProcessorException {
45 return this.updateDomain(domain)
48 override fun action(action: String): BlueprintProcessorException {
49 return this.updateAction(action)
52 override fun http(type: String): BlueprintProcessorException {
53 return this.updateHttp(type)
56 override fun grpc(type: String): BlueprintProcessorException {
57 return this.updateGrpc(type)
60 override fun convertToHttp(): BlueprintProcessorException {
61 return this.inverseToHttp()
64 override fun convertToGrpc(): BlueprintProcessorException {
65 return this.inverseToHttp()
68 override fun payloadMessage(message: String): BlueprintProcessorException {
69 return this.updatePayloadMessage(message)
72 override fun addErrorPayloadMessage(message: String): BlueprintProcessorException {
73 return this.updateErrorPayloadMessage(message)
76 override fun addSubError(errorMessage: ErrorMessage): BlueprintProcessorException {
77 return this.updateSubError(errorMessage)
81 class BlueprintRetryException : RuntimeException {
82 constructor(message: String, cause: Throwable) : super(message, cause)
83 constructor(message: String) : super(message)
84 constructor(cause: Throwable) : super(cause)
85 constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
88 /** Extension Functions */
90 fun processorException(message: String): BlueprintProcessorException {
91 return BlueprintProcessorException(message)
94 fun processorException(message: String, cause: Throwable): BlueprintProcessorException {
95 return BlueprintProcessorException(message, cause)
98 fun processorException(cause: Throwable, message: String, vararg args: Any?): BlueprintProcessorException {
99 return BlueprintProcessorException(cause, message, args)
102 fun processorException(code: Int, message: String): BlueprintProcessorException {
103 return processorException(message).code(code)
106 fun processorException(code: Int, message: String, cause: Throwable): BlueprintProcessorException {
107 return processorException(message, cause).code(code)
110 fun processorException(code: Int, cause: Throwable, message: String, vararg args: Any?): BlueprintProcessorException {
111 return processorException(cause, message, args).code(code)
114 fun httpProcessorException(type: String, message: String): BlueprintProcessorException {
115 return processorException(message).http(type)
118 fun grpcProcessorException(type: String, message: String): BlueprintProcessorException {
119 return processorException(message).grpc(type)
122 fun httpProcessorException(type: String, domain: String, message: String): BlueprintProcessorException {
123 val bluePrintProcessorException = processorException(message).http(type)
124 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
127 fun grpcProcessorException(type: String, domain: String, message: String): BlueprintProcessorException {
128 val bluePrintProcessorException = processorException(message).grpc(type)
129 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
132 fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
133 BlueprintProcessorException {
134 val bluePrintProcessorException = processorException(message, cause).http(type)
135 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
138 fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
139 BlueprintProcessorException {
140 val bluePrintProcessorException = processorException(message, cause).grpc(type)
141 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
144 fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
145 BlueprintProcessorException {
146 val bluePrintProcessorException = processorException(cause, message, args).http(type)
147 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
150 fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
151 BlueprintProcessorException {
152 val bluePrintProcessorException = processorException(cause, message, args).grpc(type)
153 return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
156 fun BlueprintProcessorException.updateErrorMessage(domain: String, message: String, cause: String):
157 BlueprintProcessorException {
158 return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
159 .addErrorPayloadMessage(message)
160 .payloadMessage(message)
163 fun BlueprintProcessorException.updateErrorMessage(domain: String, message: String): BlueprintProcessorException {
164 return this.addDomainAndErrorMessage(domain, message).domain(domain)
165 .addErrorPayloadMessage(message)
166 .payloadMessage(message)
169 private fun BlueprintProcessorException.addDomainAndErrorMessage(
173 ): BlueprintProcessorException {
174 return this.addSubError(ErrorMessage(domain, message, cause)).domain(domain)