2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow
19 import com.fasterxml.jackson.databind.JsonNode
20 import kotlinx.coroutines.Dispatchers
21 import kotlinx.coroutines.withContext
22 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
24 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
25 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
26 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
27 import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
28 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
29 import org.slf4j.LoggerFactory
30 import org.springframework.context.ApplicationContext
31 import org.springframework.stereotype.Service
34 open class NodeTemplateExecutionService(private val applicationContext: ApplicationContext) {
36 private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!!
38 suspend fun executeNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
39 executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
40 // Get the Blueprint Context
41 val blueprintContext = bluePrintRuntimeService.bluePrintContext()
42 // Get the Component Name, NodeTemplate type is mapped to Component Name
43 val componentName = blueprintContext.nodeTemplateByName(nodeTemplateName).type
45 val interfaceName = blueprintContext.nodeTemplateFirstInterfaceName(nodeTemplateName)
47 val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName)
49 log.info("executing node template($nodeTemplateName) component($componentName) " +
50 "interface($interfaceName) operation($operationName)")
52 // Get the Component Instance
53 val plugin = applicationContext.getBean(componentName, AbstractComponentFunction::class.java)
54 // Set the Blueprint Service
55 plugin.bluePrintRuntimeService = bluePrintRuntimeService
56 plugin.stepName = nodeTemplateName
58 // Populate Step Meta Data
59 val stepInputs: MutableMap<String, JsonNode> = hashMapOf()
60 stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, nodeTemplateName)
61 stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, interfaceName)
62 stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, operationName)
64 plugin.bluePrintRuntimeService.put("$nodeTemplateName-step-inputs", stepInputs.asJsonNode())
66 // Get the Request from the Context and Set to the Function Input and Invoke the function
67 return withContext(Dispatchers.Default) {
68 plugin.apply(executionServiceInput)