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