Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / interfaces / BlueprintFunctionNode.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.cds.controllerblueprints.core.interfaces
19
20 import kotlinx.coroutines.runBlocking
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
22 import java.util.function.Function
23
24 interface BlueprintFunctionNode<T, R> : Function<T, R> {
25
26     fun getName(): String
27
28     @Throws(BluePrintProcessorException::class)
29     fun prepareRequest(executionRequest: T): T = runBlocking {
30         prepareRequestNB(executionRequest)
31     }
32
33     @Throws(BluePrintProcessorException::class)
34     fun process(executionRequest: T) = runBlocking {
35         processNB(executionRequest)
36     }
37
38     @Throws(BluePrintProcessorException::class)
39     fun recover(runtimeException: RuntimeException, executionRequest: T) = runBlocking {
40         recoverNB(runtimeException, executionRequest)
41     }
42
43     @Throws(BluePrintProcessorException::class)
44     fun prepareResponse(): R = runBlocking {
45         prepareResponseNB()
46     }
47
48     override fun apply(executionServiceInput: T): R {
49         try {
50             prepareRequest(executionServiceInput)
51             process(executionServiceInput)
52         } catch (runtimeException: RuntimeException) {
53             recover(runtimeException, executionServiceInput)
54         }
55         return prepareResponse()
56     }
57
58     @Throws(BluePrintProcessorException::class)
59     suspend fun prepareRequestNB(executionRequest: T): T
60
61     @Throws(BluePrintProcessorException::class)
62     suspend fun processNB(executionRequest: T)
63
64     @Throws(BluePrintProcessorException::class)
65     suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: T)
66
67     @Throws(BluePrintProcessorException::class)
68     suspend fun prepareResponseNB(): R
69
70     @Throws(BluePrintProcessorException::class)
71     suspend fun applyNB(t: T): R
72 }