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.cds.blueprintsprocessor.services.workflow
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
23 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
25 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
27 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
28 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
29 import org.slf4j.LoggerFactory
30 import org.springframework.stereotype.Service
33 open class NodeTemplateExecutionService {
35 private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!!
37 suspend fun executeNodeTemplate(
38 bluePrintRuntimeService: BluePrintRuntimeService<*>,
39 nodeTemplateName: String,
40 executionServiceInput: ExecutionServiceInput
41 ): ExecutionServiceOutput {
42 // Get the Blueprint Context
43 val blueprintContext = bluePrintRuntimeService.bluePrintContext()
45 val nodeTemplate = blueprintContext.nodeTemplateByName(nodeTemplateName)
46 // Get the Component Name, NodeTemplate type is mapped to Component Name
47 val componentName = nodeTemplate.type
49 val interfaceName = blueprintContext.nodeTemplateFirstInterfaceName(nodeTemplateName)
51 val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName)
53 val nodeTemplateImplementation = blueprintContext
54 .nodeTemplateOperationImplementation(nodeTemplateName, interfaceName, operationName)
58 "executing node template($nodeTemplateName) component($componentName) " +
59 "interface($interfaceName) operation($operationName) on host (${nodeTemplateImplementation.operationHost}) " +
60 "with timeout(${nodeTemplateImplementation.timeout}) sec."
63 // Get the Component Instance
64 val plugin = BluePrintDependencyService.instance<AbstractComponentFunction>(componentName)
65 // Set the Blueprint Service
66 plugin.bluePrintRuntimeService = bluePrintRuntimeService
67 plugin.stepName = nodeTemplateName
69 // Parent request shouldn't tamper, so need to clone the request and send to the actual component.
70 val clonedExecutionServiceInput = ExecutionServiceInput().apply {
71 commonHeader = executionServiceInput.commonHeader
72 actionIdentifiers = executionServiceInput.actionIdentifiers
73 payload = executionServiceInput.payload
76 // Populate Step Meta Data
77 val stepInputs: MutableMap<String, JsonNode> = hashMapOf()
78 stepInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = nodeTemplateName.asJsonPrimitive()
79 stepInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = interfaceName.asJsonPrimitive()
80 stepInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = operationName.asJsonPrimitive()
81 val stepInputData = StepData().apply {
82 name = nodeTemplateName
83 properties = stepInputs
85 clonedExecutionServiceInput.stepData = stepInputData
87 // Get the Request from the Context and Set to the Function Input and Invoke the function
88 return plugin.applyNB(clonedExecutionServiceInput)