Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / workflow-service / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / workflow / executor / ComponentExecuteNodeExecutor.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.blueprintsprocessor.services.workflow.executor
19
20 import kotlinx.coroutines.runBlocking
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
22 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.BlueprintSvcLogicContext
23 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.NodeTemplateExecutionService
24 import org.onap.ccsdk.sli.core.sli.SvcLogicContext
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException
26 import org.onap.ccsdk.sli.core.sli.SvcLogicNode
27 import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor
28 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver
29 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase
30 import org.slf4j.LoggerFactory
31 import org.springframework.stereotype.Service
32
33 @Service
34 open class ComponentExecuteNodeExecutor(private val nodeTemplateExecutionService: NodeTemplateExecutionService) :
35     ExecuteNodeExecutor() {
36
37     private val log = LoggerFactory.getLogger(ComponentExecuteNodeExecutor::class.java)
38
39     @Throws(SvcLogicException::class)
40     override fun execute(svc: SvcLogicServiceBase, node: SvcLogicNode, svcLogicContext: SvcLogicContext):
41         SvcLogicNode = runBlocking {
42
43             var outValue: String
44
45             val ctx = svcLogicContext as BlueprintSvcLogicContext
46
47             val nodeTemplateName = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx)
48
49             val executionInput = ctx.getRequest() as ExecutionServiceInput
50
51             val stepName = executionInput.stepData?.name ?: nodeTemplateName
52
53             try { // Get the Request from the Context and Set to the Function Input and Invoke the function
54                 val executionOutput = nodeTemplateExecutionService.executeNodeTemplate(
55                     ctx.getBluePrintService(), stepName, nodeTemplateName, executionInput
56                 )
57
58                 ctx.setResponse(executionOutput)
59
60                 outValue = executionOutput.status.message
61                 ctx.status = executionOutput.status.message
62             } catch (e: Exception) {
63                 log.error("Could not execute plugin($nodeTemplateName) : ", e)
64                 outValue = "failure"
65                 ctx.status = "failure"
66             }
67
68             getNextNode(node, outValue)
69         }
70 }