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
24 interface BlueprintFunctionNode<T, R> : Function<T, R> {
28 @Throws(BluePrintProcessorException::class)
29 fun prepareRequest(executionRequest: T): T = runBlocking {
30 prepareRequestNB(executionRequest)
33 @Throws(BluePrintProcessorException::class)
34 fun process(executionRequest: T) = runBlocking {
35 processNB(executionRequest)
38 @Throws(BluePrintProcessorException::class)
39 fun recover(runtimeException: RuntimeException, executionRequest: T) = runBlocking {
40 recoverNB(runtimeException, executionRequest)
43 @Throws(BluePrintProcessorException::class)
44 fun prepareResponse(): R = runBlocking {
48 override fun apply(executionServiceInput: T): R {
50 prepareRequest(executionServiceInput)
51 process(executionServiceInput)
52 } catch (runtimeException: RuntimeException) {
53 recover(runtimeException, executionServiceInput)
55 return prepareResponse()
58 @Throws(BluePrintProcessorException::class)
59 suspend fun prepareRequestNB(executionRequest: T): T
61 @Throws(BluePrintProcessorException::class)
62 suspend fun processNB(executionRequest: T)
64 @Throws(BluePrintProcessorException::class)
65 suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: T)
67 @Throws(BluePrintProcessorException::class)
68 suspend fun prepareResponseNB(): R
70 @Throws(BluePrintProcessorException::class)
71 suspend fun applyNB(t: T): R