2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
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.interfaces
20 import kotlinx.coroutines.runBlocking
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
22 import java.util.function.Function
25 interface BlueprintFunctionNode<T, R> : Function<T, R> {
29 @Throws(BluePrintProcessorException::class)
30 fun prepareRequest(executionRequest: T): T = runBlocking {
31 prepareRequestNB(executionRequest)
34 @Throws(BluePrintProcessorException::class)
35 fun process(executionRequest: T) = runBlocking {
36 processNB(executionRequest)
39 @Throws(BluePrintProcessorException::class)
40 fun recover(runtimeException: RuntimeException, executionRequest: T) = runBlocking {
41 recoverNB(runtimeException, executionRequest)
44 @Throws(BluePrintProcessorException::class)
45 fun prepareResponse(): R = runBlocking {
49 override fun apply(executionServiceInput: T): R {
51 prepareRequest(executionServiceInput)
52 process(executionServiceInput)
53 } catch (runtimeException: RuntimeException) {
54 recover(runtimeException, executionServiceInput)
56 return prepareResponse()
59 @Throws(BluePrintProcessorException::class)
60 suspend fun prepareRequestNB(executionRequest: T): T
62 @Throws(BluePrintProcessorException::class)
63 suspend fun processNB(executionRequest: T)
65 @Throws(BluePrintProcessorException::class)
66 suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: T)
68 @Throws(BluePrintProcessorException::class)
69 suspend fun prepareResponseNB(): R
71 @Throws(BluePrintProcessorException::class)
72 suspend fun applyNB(t: T): R