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.blueprintsprocessor.services.workflow.executor
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
34 open class ComponentExecuteNodeExecutor(private val nodeTemplateExecutionService: NodeTemplateExecutionService) :
35 ExecuteNodeExecutor() {
37 private val log = LoggerFactory.getLogger(ComponentExecuteNodeExecutor::class.java)
39 @Throws(SvcLogicException::class)
40 override fun execute(svc: SvcLogicServiceBase, node: SvcLogicNode, svcLogicContext: SvcLogicContext):
41 SvcLogicNode = runBlocking {
45 val ctx = svcLogicContext as BlueprintSvcLogicContext
47 val nodeTemplateName = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx)
49 val executionInput = ctx.getRequest() as ExecutionServiceInput
51 val stepName = executionInput.stepData?.name ?: nodeTemplateName
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
58 ctx.setResponse(executionOutput)
60 outValue = executionOutput.status.message
61 ctx.status = executionOutput.status.message
62 } catch (e: Exception) {
63 log.error("Could not execute plugin($nodeTemplateName) : ", e)
65 ctx.status = "failure"
68 getNextNode(node, outValue)