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.blueprintsprocessor.core.api.data.StepData
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.*
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
import org.slf4j.LoggerFactory
return stepName
}
- override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ override suspend fun prepareRequestNB(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }
+ checkNotNull(executionRequest.stepData) { "failed to get step info" }
- check(stepName.isNotEmpty()) { "failed to assign step name" }
+ // Get the Step Name and Step Inputs
+ this.stepName = executionRequest.stepData!!.name
+ this.operationInputs = executionRequest.stepData!!.properties
+
+ checkNotEmpty(stepName) { "failed to get step name from step data" }
this.executionServiceInput = executionRequest
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)" }
return executionRequest
}
- override fun prepareResponse(): ExecutionServiceOutput {
+ override suspend fun prepareResponseNB(): 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
+ var status = Status()
+ try {
+ // Resolve the Output Expression
+ val stepOutputs = bluePrintRuntimeService
+ .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)
+
+ val stepOutputData = StepData().apply {
+ name = stepName
+ properties = stepOutputs
+ }
+ executionServiceOutput.stepData = stepOutputData
+ // Set the Default Step Status
+ status.eventType = EventType.EVENT_COMPONENT_EXECUTED.name
+ } catch (e: Exception) {
+ status.message = BluePrintConstants.STATUS_FAILURE
+ status.eventType = EventType.EVENT_COMPONENT_FAILURE.name
+ }
executionServiceOutput.status = status
return this.executionServiceOutput
}
- override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ override suspend fun applyNB(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
try {
- prepareRequest(executionServiceInput)
- process(executionServiceInput)
+ prepareRequestNB(executionServiceInput)
+ processNB(executionServiceInput)
} catch (runtimeException: RuntimeException) {
- recover(runtimeException, executionServiceInput)
+ log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
+ recoverNB(runtimeException, executionServiceInput)
}
- return prepareResponse()
+ return prepareResponseNB()
}
fun getOperationInput(key: String): JsonNode {
?: throw BluePrintProcessorException("couldn't get the operation input($key) value.")
}
+ fun getOptionalOperationInput(key: String): JsonNode? {
+ return operationInputs[key]
+ }
+
fun setAttribute(key: String, value: JsonNode) {
bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, key, value)
}