2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.blueprintsprocessor.services.execution
\r
20 import com.fasterxml.jackson.databind.JsonNode
\r
21 import com.fasterxml.jackson.databind.node.JsonNodeFactory
\r
22 import com.fasterxml.jackson.databind.node.NullNode
\r
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
\r
24 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
\r
25 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status
\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
\r
28 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
\r
29 import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
\r
30 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
\r
31 import org.slf4j.LoggerFactory
\r
34 * AbstractComponentFunction
\r
35 * @author Brinda Santh
\r
37 abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServiceInput, ExecutionServiceOutput> {
\r
39 private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java)
\r
41 var executionServiceInput: ExecutionServiceInput? = null
\r
42 var executionServiceOutput = ExecutionServiceOutput()
\r
43 var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null
\r
44 var processId: String = ""
\r
45 var workflowName: String = ""
\r
46 var stepName: String = ""
\r
47 var interfaceName: String = ""
\r
48 var operationName: String = ""
\r
49 var nodeTemplateName: String = ""
\r
50 var operationInputs: MutableMap<String, JsonNode> = hashMapOf()
\r
53 override fun prepareRequest(executionServiceInput: ExecutionServiceInput): ExecutionServiceInput {
\r
54 checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }
\r
56 this.executionServiceInput = executionServiceInput
\r
58 processId = executionServiceInput.commonHeader.requestId
\r
59 workflowName = executionServiceInput.actionIdentifiers.actionName
\r
61 val metadata = executionServiceInput.metadata
\r
62 stepName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_STEP)
\r
63 log.info("preparing request id($processId) for workflow($workflowName) step($stepName)")
\r
65 val operationInputs = metadata.get("$stepName-step-inputs") ?: JsonNodeFactory.instance.objectNode()
\r
67 operationInputs.fields().forEach {
\r
68 this.operationInputs[it.key] = it.value
\r
71 nodeTemplateName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE)
\r
72 interfaceName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_INTERFACE)
\r
73 operationName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_OPERATION)
\r
76 val operationResolvedProperties = bluePrintRuntimeService!!.resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName)
\r
78 this.operationInputs.putAll(operationResolvedProperties)
\r
82 return executionServiceInput
\r
85 override fun prepareResponse(): ExecutionServiceOutput {
\r
86 log.info("Preparing Response...")
\r
87 executionServiceOutput.commonHeader = executionServiceInput!!.commonHeader
\r
89 // Resolve the Output Expression
\r
90 val operationResolvedProperties = bluePrintRuntimeService!!
\r
91 .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)
\r
93 val metadata = executionServiceOutput.metadata
\r
94 metadata.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP, stepName)
\r
95 metadata.putJsonElement("$stepName-step-outputs", operationResolvedProperties)
\r
98 val status = Status()
\r
99 status.eventType = "EVENT-COMPONENT-EXECUTED"
\r
101 status.message = BluePrintConstants.STATUS_SUCCESS
\r
102 executionServiceOutput.status = status
\r
103 return this.executionServiceOutput
\r
106 override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
\r
107 prepareRequest(executionServiceInput)
\r
108 process(executionServiceInput)
\r
109 return prepareResponse()
\r
112 fun getOperationInput(key: String): JsonNode {
\r
113 return operationInputs.get(key) ?: NullNode.instance
\r