-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2019 IBM.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.blueprintsprocessor.services.execution\r
-\r
-\r
-import com.fasterxml.jackson.databind.JsonNode\r
-import com.fasterxml.jackson.databind.node.JsonNodeFactory\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status\r
-import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
-import org.onap.ccsdk.apps.controllerblueprints.core.asObjectNode\r
-import org.onap.ccsdk.apps.controllerblueprints.core.getAsString\r
-import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
-import org.slf4j.LoggerFactory\r
-\r
-/**\r
- * AbstractComponentFunction\r
- * @author Brinda Santh\r
- */\r
-abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServiceInput, ExecutionServiceOutput> {\r
- @Transient\r
- private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java)\r
-\r
- lateinit var executionServiceInput: ExecutionServiceInput\r
- var executionServiceOutput = ExecutionServiceOutput()\r
- lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>\r
- lateinit var processId: String\r
- lateinit var workflowName: String\r
- lateinit var stepName: String\r
- lateinit var interfaceName: String\r
- lateinit var operationName: String\r
- lateinit var nodeTemplateName: String\r
- var operationInputs: MutableMap<String, JsonNode> = hashMapOf()\r
-\r
- override fun getName(): String {\r
- return stepName\r
- }\r
-\r
- override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {\r
- checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }\r
-\r
- check(stepName.isNotEmpty()) { "failed to assign step name" }\r
-\r
- this.executionServiceInput = executionRequest\r
-\r
- processId = executionRequest.commonHeader.requestId\r
- check(processId.isNotEmpty()) { "couldn't get process id for step($stepName)" }\r
-\r
- workflowName = executionRequest.actionIdentifiers.actionName\r
- check(workflowName.isNotEmpty()) { "couldn't get action name for step($stepName)" }\r
-\r
- log.info("preparing request id($processId) for workflow($workflowName) step($stepName)")\r
-\r
- val operationInputs = bluePrintRuntimeService.get("$stepName-step-inputs")\r
- ?: JsonNodeFactory.instance.objectNode()\r
-\r
- operationInputs.fields().forEach {\r
- this.operationInputs[it.key] = it.value\r
- }\r
-\r
- nodeTemplateName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE)\r
- check(nodeTemplateName.isNotEmpty()) { "couldn't get NodeTemplate name for step($stepName)" }\r
-\r
- interfaceName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_INTERFACE)\r
- check(interfaceName.isNotEmpty()) { "couldn't get Interface name for step($stepName)" }\r
-\r
- operationName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_OPERATION)\r
- check(operationName.isNotEmpty()) { "couldn't get Operation name for step($stepName)" }\r
-\r
- val operationResolvedProperties = bluePrintRuntimeService\r
- .resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName)\r
-\r
- this.operationInputs.putAll(operationResolvedProperties)\r
-\r
- return executionRequest\r
- }\r
-\r
- override fun prepareResponse(): ExecutionServiceOutput {\r
- log.info("Preparing Response...")\r
- executionServiceOutput.commonHeader = executionServiceInput.commonHeader\r
- executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers\r
-\r
- // Resolve the Output Expression\r
- val stepOutputs = bluePrintRuntimeService\r
- .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)\r
-\r
- // FIXME("Not the right place to populate the response payload")\r
- executionServiceOutput.payload = stepOutputs.asObjectNode()\r
-\r
- bluePrintRuntimeService.put("$stepName-step-outputs", executionServiceOutput.payload)\r
-\r
- // FIXME("Not the right place to populate the status")\r
- // Populate Status\r
- val status = Status()\r
- status.eventType = EventType.EVENT_COMPONENT_EXECUTED.name\r
- status.code = 200\r
- status.message = BluePrintConstants.STATUS_SUCCESS\r
- executionServiceOutput.status = status\r
- return this.executionServiceOutput\r
- }\r
-\r
- override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {\r
- try {\r
- prepareRequest(executionServiceInput)\r
- process(executionServiceInput)\r
- } catch (runtimeException: RuntimeException) {\r
- recover(runtimeException, executionServiceInput)\r
- }\r
- return prepareResponse()\r
- }\r
-\r
- fun getOperationInput(key: String): JsonNode {\r
- return operationInputs[key]\r
- ?: throw BluePrintProcessorException("couldn't get the operation input($key) value.")\r
- }\r
-\r
- fun setAttribute(key: String, value: JsonNode) {\r
- bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, key, value)\r
- }\r
-\r
- fun addError(type: String, name: String, error: String) {\r
- bluePrintRuntimeService.getBluePrintError().addError(type, name, error)\r
- }\r
-\r
- fun addError(error: String) {\r
- bluePrintRuntimeService.getBluePrintError().addError(error)\r
- }\r
-\r
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
+
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status
+import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode
+import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.slf4j.LoggerFactory
+
+/**
+ * AbstractComponentFunction
+ * @author Brinda Santh
+ */
+abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServiceInput, ExecutionServiceOutput> {
+ @Transient
+ private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java)
+
+ lateinit var executionServiceInput: ExecutionServiceInput
+ var executionServiceOutput = ExecutionServiceOutput()
+ lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
+ lateinit var processId: String
+ lateinit var workflowName: String
+ lateinit var stepName: String
+ lateinit var interfaceName: String
+ lateinit var operationName: String
+ lateinit var nodeTemplateName: String
+ var operationInputs: MutableMap<String, JsonNode> = hashMapOf()
+
+ override fun getName(): String {
+ return stepName
+ }
+
+ override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }
+
+ check(stepName.isNotEmpty()) { "failed to assign step name" }
+
+ this.executionServiceInput = executionRequest
+
+ processId = executionRequest.commonHeader.requestId
+ check(processId.isNotEmpty()) { "couldn't get process id for step($stepName)" }
+
+ workflowName = executionRequest.actionIdentifiers.actionName
+ check(workflowName.isNotEmpty()) { "couldn't get action name for step($stepName)" }
+
+ log.info("preparing request id($processId) for workflow($workflowName) step($stepName)")
+
+ val operationInputs = bluePrintRuntimeService.get("$stepName-step-inputs")
+ ?: JsonNodeFactory.instance.objectNode()
+
+ operationInputs.fields().forEach {
+ this.operationInputs[it.key] = it.value
+ }
+
+ nodeTemplateName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE)
+ check(nodeTemplateName.isNotEmpty()) { "couldn't get NodeTemplate name for step($stepName)" }
+
+ interfaceName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_INTERFACE)
+ check(interfaceName.isNotEmpty()) { "couldn't get Interface name for step($stepName)" }
+
+ operationName = this.operationInputs.getAsString(BluePrintConstants.PROPERTY_CURRENT_OPERATION)
+ check(operationName.isNotEmpty()) { "couldn't get Operation name for step($stepName)" }
+
+ val operationResolvedProperties = bluePrintRuntimeService
+ .resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName)
+
+ this.operationInputs.putAll(operationResolvedProperties)
+
+ return executionRequest
+ }
+
+ override fun prepareResponse(): ExecutionServiceOutput {
+ log.info("Preparing Response...")
+ executionServiceOutput.commonHeader = executionServiceInput.commonHeader
+ executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
+
+ // Resolve the Output Expression
+ val stepOutputs = bluePrintRuntimeService
+ .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)
+
+ // FIXME("Not the right place to populate the response payload")
+ executionServiceOutput.payload = stepOutputs.asObjectNode()
+
+ bluePrintRuntimeService.put("$stepName-step-outputs", executionServiceOutput.payload)
+
+ // FIXME("Not the right place to populate the status")
+ // Populate Status
+ val status = Status()
+ status.eventType = EventType.EVENT_COMPONENT_EXECUTED.name
+ status.code = 200
+ status.message = BluePrintConstants.STATUS_SUCCESS
+ executionServiceOutput.status = status
+ return this.executionServiceOutput
+ }
+
+ override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ try {
+ prepareRequest(executionServiceInput)
+ process(executionServiceInput)
+ } catch (runtimeException: RuntimeException) {
+ recover(runtimeException, executionServiceInput)
+ }
+ return prepareResponse()
+ }
+
+ fun getOperationInput(key: String): JsonNode {
+ return operationInputs[key]
+ ?: throw BluePrintProcessorException("couldn't get the operation input($key) value.")
+ }
+
+ fun setAttribute(key: String, value: JsonNode) {
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, key, value)
+ }
+
+ fun addError(type: String, name: String, error: String) {
+ bluePrintRuntimeService.getBluePrintError().addError(type, name, error)
+ }
+
+ fun addError(error: String) {
+ bluePrintRuntimeService.getBluePrintError().addError(error)
+ }
+
}
\ No newline at end of file