From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../modules/services/execution-service/pom.xml | 16 +-- .../execution/AbstractComponentFunction.kt | 148 --------------------- .../execution/AbstractScriptComponentFunction.kt | 50 ------- .../execution/ComponentFunctionScriptingService.kt | 87 ------------ .../execution/scripts/BlueprintJythonService.kt | 131 ------------------ .../execution/scripts/BlueprintPythonHost.kt | 46 ------- .../scripts/BlueprintPythonInterpreterProxy.kt | 40 ------ .../scripts/PythonExecutorConfiguration.kt | 68 ---------- .../execution/AbstractComponentFunction.kt | 148 +++++++++++++++++++++ .../execution/AbstractScriptComponentFunction.kt | 50 +++++++ .../execution/ComponentFunctionScriptingService.kt | 87 ++++++++++++ .../execution/scripts/BlueprintJythonService.kt | 131 ++++++++++++++++++ .../execution/scripts/BlueprintPythonHost.kt | 46 +++++++ .../scripts/BlueprintPythonInterpreterProxy.kt | 40 ++++++ .../scripts/PythonExecutorConfiguration.kt | 68 ++++++++++ .../scripts/BlueprintJythonServiceTest.kt | 57 -------- .../scripts/BlueprintJythonServiceTest.kt | 57 ++++++++ ms/blueprintsprocessor/modules/services/pom.xml | 2 +- .../modules/services/workflow-service/pom.xml | 6 +- .../BluePrintWorkflowExecutionServiceImpl.kt | 72 ---------- .../services/workflow/BlueprintSvcLogicContext.kt | 52 -------- .../services/workflow/BlueprintSvcLogicService.kt | 143 -------------------- .../workflow/ComponentWorkflowExecutionService.kt | 49 ------- .../workflow/DGWorkflowExecutionService.kt | 70 ---------- .../workflow/NodeTemplateExecutionService.kt | 72 ---------- .../workflow/WorkflowServiceConfiguration.kt | 31 ----- .../executor/ComponentExecuteNodeExecutor.kt | 69 ---------- .../services/workflow/utils/SvcGraphUtils.kt | 35 ----- .../BluePrintWorkflowExecutionServiceImpl.kt | 72 ++++++++++ .../services/workflow/BlueprintSvcLogicContext.kt | 52 ++++++++ .../services/workflow/BlueprintSvcLogicService.kt | 143 ++++++++++++++++++++ .../workflow/ComponentWorkflowExecutionService.kt | 49 +++++++ .../workflow/DGWorkflowExecutionService.kt | 70 ++++++++++ .../workflow/NodeTemplateExecutionService.kt | 72 ++++++++++ .../workflow/WorkflowServiceConfiguration.kt | 31 +++++ .../executor/ComponentExecuteNodeExecutor.kt | 69 ++++++++++ .../services/workflow/utils/SvcGraphUtils.kt | 35 +++++ .../BluePrintWorkflowExecutionServiceImplTest.kt | 54 -------- .../services/workflow/BlueprintServiceLogicTest.kt | 99 -------------- .../workflow/DGWorkflowExecutionServiceTest.kt | 57 -------- .../workflow/mock/MockComponentFunction.kt | 82 ------------ .../BluePrintWorkflowExecutionServiceImplTest.kt | 54 ++++++++ .../services/workflow/BlueprintServiceLogicTest.kt | 99 ++++++++++++++ .../workflow/DGWorkflowExecutionServiceTest.kt | 57 ++++++++ .../workflow/mock/MockComponentFunction.kt | 82 ++++++++++++ .../src/test/resources/logback.xml | 2 +- 46 files changed, 1525 insertions(+), 1525 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt (limited to 'ms/blueprintsprocessor/modules/services') diff --git a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml index 913ce4671..9ce5292e8 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml +++ b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml @@ -18,7 +18,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor services 0.4.2-SNAPSHOT @@ -34,31 +34,31 @@ jython-standalone - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-core - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-scripts - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor processor-core - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor db-lib - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor rest-lib - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints resource-dict - org.onap.ccsdk.apps.components + org.onap.ccsdk.cds.components proto-definition diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt deleted file mode 100644 index 4c381706a..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.execution - - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.JsonNodeFactory -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status -import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.asObjectNode -import org.onap.ccsdk.apps.controllerblueprints.core.getAsString -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.slf4j.LoggerFactory - -/** - * AbstractComponentFunction - * @author Brinda Santh - */ -abstract class AbstractComponentFunction : BlueprintFunctionNode { - @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 = 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 diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt deleted file mode 100644 index 811ee4a21..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.execution - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException - -abstract class AbstractScriptComponentFunction : AbstractComponentFunction() { - - companion object { - const val DYNAMIC_PROPERTIES = "dynamic-properties" - } - - /** - * Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained. - */ - var functionDependencyInstances: MutableMap = hashMapOf() - - /** - * This will be called from the scripts to serve instance from runtime to scripts. - */ - open fun functionDependencyInstanceAsType(name: String): T { - return functionDependencyInstances[name] as? T - ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") - } - - fun checkDynamicProperties(key: String): Boolean { - return operationInputs[DYNAMIC_PROPERTIES]?.has(key) ?: false - } - - fun getDynamicProperties(key: String): JsonNode { - return operationInputs[DYNAMIC_PROPERTIES]!!.get(key) - } - - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt deleted file mode 100644 index 2cf223256..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright © 2018 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.apps.blueprintsprocessor.services.execution - -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.slf4j.LoggerFactory -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service - -@Service -class ComponentFunctionScriptingService(private val applicationContext: ApplicationContext, - private val bluePrintScriptsService: BluePrintScriptsService, - private val blueprintJythonService: BlueprintJythonService) { - - private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java) - - fun scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String, - scriptClassReference: String, - instanceDependencies: List): T { - - log.info("creating component function of script type($scriptType), reference name($scriptClassReference) and " + - "instanceDependencies($instanceDependencies)") - - val scriptComponent: T = scriptInstance(componentFunction.bluePrintRuntimeService.bluePrintContext(), - scriptType, scriptClassReference) - - checkNotNull(scriptComponent) { "failed to initialize script component" } - - scriptComponent.bluePrintRuntimeService = componentFunction.bluePrintRuntimeService - scriptComponent.processId = componentFunction.processId - scriptComponent.workflowName = componentFunction.workflowName - scriptComponent.stepName = componentFunction.stepName - scriptComponent.interfaceName = componentFunction.interfaceName - scriptComponent.operationName = componentFunction.operationName - scriptComponent.nodeTemplateName = componentFunction.nodeTemplateName - scriptComponent.operationInputs = componentFunction.operationInputs - - // Populate Instance Properties - instanceDependencies.forEach { instanceDependency -> - scriptComponent.functionDependencyInstances[instanceDependency] = applicationContext - .getBean(instanceDependency) - } - return scriptComponent - } - - - fun > scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, - scriptClassReference: String): T { - var scriptComponent: T? = null - - when (scriptType) { - BluePrintConstants.SCRIPT_INTERNAL -> { - scriptComponent = bluePrintScriptsService.scriptInstance(scriptClassReference) - } - BluePrintConstants.SCRIPT_KOTLIN -> { - scriptComponent = bluePrintScriptsService.scriptInstance(bluePrintContext, scriptClassReference, false) - } - BluePrintConstants.SCRIPT_JYTHON -> { - scriptComponent = blueprintJythonService.jythonComponentInstance(bluePrintContext, scriptClassReference) as T - } - else -> { - throw BluePrintProcessorException("script type($scriptType) is not supported") - } - } - return scriptComponent - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt deleted file mode 100644 index 3937f27c3..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright © 2019 IBM, Bell Canada. - * - * 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.apps.blueprintsprocessor.services.execution.scripts - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.ArrayNode -import org.apache.commons.io.FilenameUtils -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service -import java.io.File - -@Service -class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, - private val applicationContext: ApplicationContext) { - - val log: Logger = LoggerFactory.getLogger(BlueprintJythonService::class.java) - - inline fun jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String, - dependencyInstanceNames: MutableMap?): T { - - val blueprintBasePath: String = blueprintContext.rootPath - val pythonPath: MutableList = arrayListOf() - pythonPath.add(blueprintBasePath) - pythonPath.addAll(pythonExecutorProperty.modulePaths) - - val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf()) - - val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations) - val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames) - - log.info("Component Object {}", pyObject) - - return pyObject.__tojava__(T::class.java) as T - } - - fun jythonComponentInstance(bluePrintContext: BluePrintContext, scriptClassReference: String): - BlueprintFunctionNode<*, *> { - val blueprintBasePath: String = bluePrintContext.rootPath - - val pythonFileName = bluePrintContext.rootPath - .plus(File.separator) - .plus(scriptClassReference) - - val pythonClassName = FilenameUtils.getBaseName(pythonFileName) - log.info("Getting Jython Script Class($pythonClassName)") - - val content: String = JacksonUtils.getContent(pythonFileName) - - val pythonPath: MutableList = arrayListOf() - pythonPath.add(blueprintBasePath) - pythonPath.addAll(pythonExecutorProperty.modulePaths) - - val jythonInstances: MutableMap = hashMapOf() - jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) - - return jythonInstance>(bluePrintContext, pythonClassName, - content, jythonInstances) - } - - fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction { - - val bluePrintRuntimeService = abstractComponentFunction.bluePrintRuntimeService - val bluePrintContext = bluePrintRuntimeService.bluePrintContext() - val nodeTemplateName: String = abstractComponentFunction.nodeTemplateName - val operationInputs: MutableMap = abstractComponentFunction.operationInputs - - val operationAssignment: OperationAssignment = bluePrintContext - .nodeTemplateInterfaceOperation(abstractComponentFunction.nodeTemplateName, - abstractComponentFunction.interfaceName, abstractComponentFunction.operationName) - - val blueprintBasePath: String = bluePrintContext.rootPath - - val artifactName: String = operationAssignment.implementation?.primary - ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") - - val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) - - val pythonFileName = artifactDefinition.file - ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)") - - val pythonClassName = FilenameUtils.getBaseName(pythonFileName) - log.info("Getting Jython Script Class($pythonClassName)") - - val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) - - checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty") - - val pythonPath: MutableList = operationAssignment.implementation?.dependencies ?: arrayListOf() - pythonPath.add(blueprintBasePath) - pythonPath.addAll(pythonExecutorProperty.modulePaths) - - val jythonInstances: MutableMap = hashMapOf() - jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName) - - val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode - ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") - - instanceDependenciesNode.forEach { instanceName -> - jythonInstances[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue()) - } - - val scriptComponentFunction = jythonInstance(bluePrintContext, pythonClassName, - content!!, jythonInstances) - - return scriptComponentFunction - - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt deleted file mode 100644 index e5b248b6c..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2019 IBM, Bell Canada. - * - * 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.apps.blueprintsprocessor.services.execution.scripts - -import org.python.core.PyObject -import org.python.util.PythonInterpreter - -open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){ - private val blueprintPythonInterpreterProxy: BlueprintPythonInterpreterProxy - - init { - PythonInterpreter.initialize(System.getProperties(), bluePrintPython.props, bluePrintPython.argv.toTypedArray()) - blueprintPythonInterpreterProxy = BlueprintPythonInterpreterProxy(bluePrintPython) - } - - /** - * getPythonComponent Purpose: execute the python script and return the python interpreter object - * - * @param content String - * @param interfaceName String - * @param properties MutableMap - * @return pyObject PyObject - */ - fun getPythonComponent(content: String?, interfaceName: String, properties: MutableMap?): PyObject { - bluePrintPython.content = content!! - bluePrintPython.pythonClassName = interfaceName - bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]" - - return blueprintPythonInterpreterProxy.getPythonInstance(properties) - } - - //TODO Check potential errors in python scripts -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt deleted file mode 100644 index 735b8d77a..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2019 IBM, Bell Canada. - * - * 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.apps.blueprintsprocessor.services.execution.scripts - -import org.python.core.PyObject -import org.python.util.PythonInterpreter - -open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrintPython): PythonInterpreter(){ - - fun getPythonInstance(properties: MutableMap?): PyObject{ - properties?.forEach { (name, value) -> - this.set(name, value) - } - - this.exec("import sys") - - bluePrintPython.content.let { - this.exec(bluePrintPython.content) - } - - val initCommand = bluePrintPython.pythonClassName.plus(" = ").plus( - bluePrintPython.pythonClassName).plus("()") - this.exec(initCommand) - - return this.get(bluePrintPython.pythonClassName) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt deleted file mode 100644 index fa3e3a134..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Modifications Copyright © 2019 IBM, Bell Canada. - * - * 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.apps.blueprintsprocessor.services.execution.scripts - -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration -import java.io.File -import java.util.* - -@Configuration -@ComponentScan -@EnableConfigurationProperties -open class PythonExecutorConfiguration - -@Configuration -open class PythonExecutorProperty { - @Value("\${blueprints.processor.functions.python.executor.executionPath}") - lateinit var executionPath: String - @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}") - lateinit var modulePaths: List -} - -class PythonExecutorConstants { - companion object { - const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies" - } -} - -open class BluePrintPython(executablePath: String, blueprintPythonPlatform: MutableList, - val argv: MutableList){ - lateinit var moduleName: String - lateinit var pythonClassName: String - lateinit var content: String - var props: Properties = Properties() - - init { - // Build up the python.path - val sb = StringBuilder() - sb.append(System.getProperty("java.class.path")) - - for (p in blueprintPythonPlatform) { - sb.append(File.pathSeparator).append(p) - } - - props["python.import.site"] = "true" - props.setProperty("python.path", sb.toString()) - props.setProperty("python.verbose", "error") - props.setProperty("python.executable", executablePath) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt new file mode 100644 index 000000000..d6c1a7c21 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -0,0 +1,148 @@ +/* + * 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 { + @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 = 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 diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt new file mode 100644 index 000000000..789ba9f5f --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt @@ -0,0 +1,50 @@ +/* + * 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 org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException + +abstract class AbstractScriptComponentFunction : AbstractComponentFunction() { + + companion object { + const val DYNAMIC_PROPERTIES = "dynamic-properties" + } + + /** + * Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained. + */ + var functionDependencyInstances: MutableMap = hashMapOf() + + /** + * This will be called from the scripts to serve instance from runtime to scripts. + */ + open fun functionDependencyInstanceAsType(name: String): T { + return functionDependencyInstances[name] as? T + ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") + } + + fun checkDynamicProperties(key: String): Boolean { + return operationInputs[DYNAMIC_PROPERTIES]?.has(key) ?: false + } + + fun getDynamicProperties(key: String): JsonNode { + return operationInputs[DYNAMIC_PROPERTIES]!!.get(key) + } + + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt new file mode 100644 index 000000000..907aae4cd --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt @@ -0,0 +1,87 @@ +/* + * Copyright © 2018 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 org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintScriptsService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.slf4j.LoggerFactory +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +@Service +class ComponentFunctionScriptingService(private val applicationContext: ApplicationContext, + private val bluePrintScriptsService: BluePrintScriptsService, + private val blueprintJythonService: BlueprintJythonService) { + + private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java) + + fun scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String, + scriptClassReference: String, + instanceDependencies: List): T { + + log.info("creating component function of script type($scriptType), reference name($scriptClassReference) and " + + "instanceDependencies($instanceDependencies)") + + val scriptComponent: T = scriptInstance(componentFunction.bluePrintRuntimeService.bluePrintContext(), + scriptType, scriptClassReference) + + checkNotNull(scriptComponent) { "failed to initialize script component" } + + scriptComponent.bluePrintRuntimeService = componentFunction.bluePrintRuntimeService + scriptComponent.processId = componentFunction.processId + scriptComponent.workflowName = componentFunction.workflowName + scriptComponent.stepName = componentFunction.stepName + scriptComponent.interfaceName = componentFunction.interfaceName + scriptComponent.operationName = componentFunction.operationName + scriptComponent.nodeTemplateName = componentFunction.nodeTemplateName + scriptComponent.operationInputs = componentFunction.operationInputs + + // Populate Instance Properties + instanceDependencies.forEach { instanceDependency -> + scriptComponent.functionDependencyInstances[instanceDependency] = applicationContext + .getBean(instanceDependency) + } + return scriptComponent + } + + + fun > scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, + scriptClassReference: String): T { + var scriptComponent: T? = null + + when (scriptType) { + BluePrintConstants.SCRIPT_INTERNAL -> { + scriptComponent = bluePrintScriptsService.scriptInstance(scriptClassReference) + } + BluePrintConstants.SCRIPT_KOTLIN -> { + scriptComponent = bluePrintScriptsService.scriptInstance(bluePrintContext, scriptClassReference, false) + } + BluePrintConstants.SCRIPT_JYTHON -> { + scriptComponent = blueprintJythonService.jythonComponentInstance(bluePrintContext, scriptClassReference) as T + } + else -> { + throw BluePrintProcessorException("script type($scriptType) is not supported") + } + } + return scriptComponent + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt new file mode 100644 index 000000000..2a4509033 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt @@ -0,0 +1,131 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * 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.scripts + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.ArrayNode +import org.apache.commons.io.FilenameUtils +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow +import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service +import java.io.File + +@Service +class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, + private val applicationContext: ApplicationContext) { + + val log: Logger = LoggerFactory.getLogger(BlueprintJythonService::class.java) + + inline fun jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String, + dependencyInstanceNames: MutableMap?): T { + + val blueprintBasePath: String = blueprintContext.rootPath + val pythonPath: MutableList = arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf()) + + val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations) + val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames) + + log.info("Component Object {}", pyObject) + + return pyObject.__tojava__(T::class.java) as T + } + + fun jythonComponentInstance(bluePrintContext: BluePrintContext, scriptClassReference: String): + BlueprintFunctionNode<*, *> { + val blueprintBasePath: String = bluePrintContext.rootPath + + val pythonFileName = bluePrintContext.rootPath + .plus(File.separator) + .plus(scriptClassReference) + + val pythonClassName = FilenameUtils.getBaseName(pythonFileName) + log.info("Getting Jython Script Class($pythonClassName)") + + val content: String = JacksonUtils.getContent(pythonFileName) + + val pythonPath: MutableList = arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val jythonInstances: MutableMap = hashMapOf() + jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) + + return jythonInstance>(bluePrintContext, pythonClassName, + content, jythonInstances) + } + + fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction { + + val bluePrintRuntimeService = abstractComponentFunction.bluePrintRuntimeService + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + val nodeTemplateName: String = abstractComponentFunction.nodeTemplateName + val operationInputs: MutableMap = abstractComponentFunction.operationInputs + + val operationAssignment: OperationAssignment = bluePrintContext + .nodeTemplateInterfaceOperation(abstractComponentFunction.nodeTemplateName, + abstractComponentFunction.interfaceName, abstractComponentFunction.operationName) + + val blueprintBasePath: String = bluePrintContext.rootPath + + val artifactName: String = operationAssignment.implementation?.primary + ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") + + val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) + + val pythonFileName = artifactDefinition.file + ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)") + + val pythonClassName = FilenameUtils.getBaseName(pythonFileName) + log.info("Getting Jython Script Class($pythonClassName)") + + val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) + + checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty") + + val pythonPath: MutableList = operationAssignment.implementation?.dependencies ?: arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val jythonInstances: MutableMap = hashMapOf() + jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName) + + val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode + ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") + + instanceDependenciesNode.forEach { instanceName -> + jythonInstances[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue()) + } + + val scriptComponentFunction = jythonInstance(bluePrintContext, pythonClassName, + content!!, jythonInstances) + + return scriptComponentFunction + + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt new file mode 100644 index 000000000..600308959 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt @@ -0,0 +1,46 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * 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.scripts + +import org.python.core.PyObject +import org.python.util.PythonInterpreter + +open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){ + private val blueprintPythonInterpreterProxy: BlueprintPythonInterpreterProxy + + init { + PythonInterpreter.initialize(System.getProperties(), bluePrintPython.props, bluePrintPython.argv.toTypedArray()) + blueprintPythonInterpreterProxy = BlueprintPythonInterpreterProxy(bluePrintPython) + } + + /** + * getPythonComponent Purpose: execute the python script and return the python interpreter object + * + * @param content String + * @param interfaceName String + * @param properties MutableMap + * @return pyObject PyObject + */ + fun getPythonComponent(content: String?, interfaceName: String, properties: MutableMap?): PyObject { + bluePrintPython.content = content!! + bluePrintPython.pythonClassName = interfaceName + bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]" + + return blueprintPythonInterpreterProxy.getPythonInstance(properties) + } + + //TODO Check potential errors in python scripts +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt new file mode 100644 index 000000000..8998337c9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt @@ -0,0 +1,40 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * 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.scripts + +import org.python.core.PyObject +import org.python.util.PythonInterpreter + +open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrintPython): PythonInterpreter(){ + + fun getPythonInstance(properties: MutableMap?): PyObject{ + properties?.forEach { (name, value) -> + this.set(name, value) + } + + this.exec("import sys") + + bluePrintPython.content.let { + this.exec(bluePrintPython.content) + } + + val initCommand = bluePrintPython.pythonClassName.plus(" = ").plus( + bluePrintPython.pythonClassName).plus("()") + this.exec(initCommand) + + return this.get(bluePrintPython.pythonClassName) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt new file mode 100644 index 000000000..430692ce0 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt @@ -0,0 +1,68 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Modifications Copyright © 2019 IBM, Bell Canada. + * + * 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.scripts + +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration +import java.io.File +import java.util.* + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class PythonExecutorConfiguration + +@Configuration +open class PythonExecutorProperty { + @Value("\${blueprints.processor.functions.python.executor.executionPath}") + lateinit var executionPath: String + @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}") + lateinit var modulePaths: List +} + +class PythonExecutorConstants { + companion object { + const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies" + } +} + +open class BluePrintPython(executablePath: String, blueprintPythonPlatform: MutableList, + val argv: MutableList){ + lateinit var moduleName: String + lateinit var pythonClassName: String + lateinit var content: String + var props: Properties = Properties() + + init { + // Build up the python.path + val sb = StringBuilder() + sb.append(System.getProperty("java.class.path")) + + for (p in blueprintPythonPlatform) { + sb.append(File.pathSeparator).append(p) + } + + props["python.import.site"] = "true" + props.setProperty("python.path", sb.toString()) + props.setProperty("python.verbose", "error") + props.setProperty("python.executable", executablePath) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt deleted file mode 100644 index b48a10e9c..000000000 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2019 IBM, Bell Canada. - * - * 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.apps.blueprintsprocessor.services.execution.scripts - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class]) -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) -class BlueprintJythonServiceTest { - - @Autowired - private lateinit var blueprintJythonService: BlueprintJythonService - - @Test - fun testGetAbstractPythonPlugin() { - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val dependencies: MutableMap = hashMapOf() - - val content = JacksonUtils.getContent("./../../../../." + - "./components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py") - - val abstractComponentFunction = blueprintJythonService.jythonInstance(bluePrintContext, "SamplePythonComponentNode", content, dependencies) - - assertNotNull(abstractComponentFunction, "failed to get python component") - - abstractComponentFunction.process(ExecutionServiceInput()) - - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt new file mode 100644 index 000000000..d6c0cf58b --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt @@ -0,0 +1,57 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * 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.scripts + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class]) +@TestPropertySource(properties = +["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) +class BlueprintJythonServiceTest { + + @Autowired + private lateinit var blueprintJythonService: BlueprintJythonService + + @Test + fun testGetAbstractPythonPlugin() { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val dependencies: MutableMap = hashMapOf() + + val content = JacksonUtils.getContent("./../../../../." + + "./components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py") + + val abstractComponentFunction = blueprintJythonService.jythonInstance(bluePrintContext, "SamplePythonComponentNode", content, dependencies) + + assertNotNull(abstractComponentFunction, "failed to get python component") + + abstractComponentFunction.process(ExecutionServiceInput()) + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/pom.xml b/ms/blueprintsprocessor/modules/services/pom.xml index ee5b73cc7..751ad94d4 100755 --- a/ms/blueprintsprocessor/modules/services/pom.xml +++ b/ms/blueprintsprocessor/modules/services/pom.xml @@ -20,7 +20,7 @@ 4.0.0 - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor modules 0.4.2-SNAPSHOT diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml b/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml index 4331eec77..c48ff250f 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml +++ b/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml @@ -17,7 +17,7 @@ --> - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor services 0.4.2-SNAPSHOT @@ -29,11 +29,11 @@ - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-core - org.onap.ccsdk.apps.blueprintsprocessor + org.onap.ccsdk.cds.blueprintsprocessor execution-service diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt deleted file mode 100644 index 73f6f497e..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -@Service("bluePrintWorkflowExecutionService") -open class BluePrintWorkflowExecutionServiceImpl( - private val componentWorkflowExecutionService: ComponentWorkflowExecutionService, - private val dgWorkflowExecutionService: DGWorkflowExecutionService -) : BluePrintWorkflowExecutionService { - - private val log = LoggerFactory.getLogger(BluePrintWorkflowExecutionServiceImpl::class.java)!! - - override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, - executionServiceInput: ExecutionServiceInput, - properties: MutableMap): ExecutionServiceOutput { - - val bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val workflowName = executionServiceInput.actionIdentifiers.actionName - - // Get the DG Node Template - val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) - - val derivedFrom = bluePrintContext.nodeTemplateNodeType(nodeTemplateName).derivedFrom - - log.info("Executing workflow($workflowName) NodeTemplate($nodeTemplateName), derived from($derivedFrom)") - - val executionServiceOutput: ExecutionServiceOutput = when { - derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { - componentWorkflowExecutionService - .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, properties) - } - derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { - dgWorkflowExecutionService - .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, properties) - } - else -> { - throw BluePrintProcessorException("couldn't execute workflow($workflowName) step mapped " + - "to node template($nodeTemplateName) derived from($derivedFrom)") - } - } - - executionServiceOutput.commonHeader = executionServiceInput.commonHeader - executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers - // TODO("Populate Response Payload and status") - return executionServiceOutput - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt deleted file mode 100644 index d2648c079..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.blueprintsprocessor.services.workflow - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.sli.core.sli.SvcLogicContext - -class BlueprintSvcLogicContext : SvcLogicContext() { - - private var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null - private var request: Any? = null - private var response: Any? = null - - fun getBluePrintService(): BluePrintRuntimeService<*> { - return this.bluePrintRuntimeService!! - } - - fun setBluePrintRuntimeService(bluePrintRuntimeService: BluePrintRuntimeService<*>) { - this.bluePrintRuntimeService = bluePrintRuntimeService - } - - fun setRequest(request: Any) { - this.request = request - } - - fun getRequest(): Any { - return this.request!! - } - - fun setResponse(response: Any) { - this.response = response - } - - fun getResponse(): Any { - return this.response!! - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt deleted file mode 100644 index fd7ec45b3..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.sli.core.sli.* -import org.onap.ccsdk.sli.core.sli.provider.base.* -import org.slf4j.LoggerFactory -import org.slf4j.MDC -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service -import java.util.* -import javax.annotation.PostConstruct - -interface BlueprintSvcLogicService : SvcLogicServiceBase { - - fun registerDefaultExecutors() - - fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) - - fun unRegisterExecutors(name: String) - - suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any - - @Deprecated("Populate Graph Dynamically from Blueprints, No need to get from Database Store ") - override fun getStore(): SvcLogicStore { - TODO("not implemented") - } - - @Deprecated("Not used in Micro service Implementation") - override fun hasGraph(module: String, rpc: String, version: String?, mode: String): Boolean { - TODO("not implemented") - } - - @Deprecated("Not used in Micro service Implementation") - override fun execute(p0: String?, p1: String?, p2: String?, p3: String?, p4: Properties?): Properties { - TODO("not implemented") - } -} - - -@Service -class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService { - - private val log = LoggerFactory.getLogger(DefaultBlueprintSvcLogicService::class.java) - - private val nodeExecutors: MutableMap = hashMapOf() - - @Autowired - private lateinit var context: ApplicationContext - - @PostConstruct - override fun registerDefaultExecutors() { - - val executeNodeExecutor = context.getBean(ExecuteNodeExecutor::class.java) - registerExecutors("execute", executeNodeExecutor) - registerExecutors("block", BlockNodeExecutor()) - registerExecutors("return", ReturnNodeExecutor()) - registerExecutors("break", BreakNodeExecutor()) - registerExecutors("exit", ExitNodeExecutor()) - } - - override fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) { - log.info("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}") - nodeExecutors[name] = svcLogicNodeExecutor - } - - override fun unRegisterExecutors(name: String) { - if (nodeExecutors.containsKey(name)) { - log.info("UnRegistering executors($name)") - nodeExecutors.remove(name) - } - } - - override suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, - input: Any): Any { - //Initialise BlueprintSvcLogic Context with Blueprint Runtime Service and Input Request - val blueprintSvcLogicContext = BlueprintSvcLogicContext() - blueprintSvcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService) - blueprintSvcLogicContext.setRequest(input) - // Execute the Graph - execute(graph, blueprintSvcLogicContext) - // Get the Response - return blueprintSvcLogicContext.getResponse() - } - - override fun executeNode(node: SvcLogicNode?, ctx: SvcLogicContext): SvcLogicNode? { - if (node == null) { - return null - } else { - if (log.isDebugEnabled) { - log.debug("Executing node {}", node.nodeId) - } - - val executor = this.nodeExecutors[node.nodeType] - - if (executor != null) { - log.debug("Executing node executor for node type {} - {}", node.nodeType, executor.javaClass.name) - return executor.execute(this, node, ctx) - } else { - throw SvcLogicException("Attempted to execute a node of type " + node.nodeType + ", but no executor was registered for this type") - } - } - } - - override fun execute(graph: SvcLogicGraph, svcLogicContext: SvcLogicContext): SvcLogicContext { - MDC.put("currentGraph", graph.toString()) - - var curNode: SvcLogicNode? = graph.rootNode - log.info("About to execute graph {}", graph.toString()) - - try { - while (curNode != null) { - MDC.put("nodeId", curNode.nodeId.toString() + " (" + curNode.nodeType + ")") - log.info("About to execute node # {} ({})", curNode.nodeId, curNode.nodeType) - val nextNode = this.executeNode(curNode, svcLogicContext) - curNode = nextNode - } - } catch (var5: ExitNodeException) { - log.debug("SvcLogicServiceImpl caught ExitNodeException") - } - - MDC.remove("nodeId") - MDC.remove("currentGraph") - return svcLogicContext - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt deleted file mode 100644 index 76d0c46b5..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.stereotype.Service - -@Service("componentWorkflowExecutionService") -open class ComponentWorkflowExecutionService(private val nodeTemplateExecutionService: NodeTemplateExecutionService) - : BluePrintWorkflowExecutionService { - - override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, - executionServiceInput: ExecutionServiceInput, - properties: MutableMap): ExecutionServiceOutput { - - val bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val workflowName = executionServiceInput.actionIdentifiers.actionName - - // Get the DG Node Template - val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) - - // Assign Workflow inputs - val input = executionServiceInput.payload.get("$workflowName-request") - bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) - - return nodeTemplateExecutionService.executeNodeTemplate(bluePrintRuntimeService, - nodeTemplateName, executionServiceInput) - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt deleted file mode 100644 index 262b1be19..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.io.File - - -@Service("dgWorkflowExecutionService") -open class DGWorkflowExecutionService(private val blueprintSvcLogicService: BlueprintSvcLogicService) - : BluePrintWorkflowExecutionService { - - private val log = LoggerFactory.getLogger(DGWorkflowExecutionService::class.java) - - override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, - executionServiceInput: ExecutionServiceInput, - properties: MutableMap): ExecutionServiceOutput { - - val bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val workflowName = executionServiceInput.actionIdentifiers.actionName - - // Get the DG Node Template - val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) - - log.info("Executing workflow($workflowName) directed graph NodeTemplate($nodeTemplateName)") - - // Get the DG file info - val artifactDefinition = bluePrintContext.nodeTemplateArtifactForArtifactType(nodeTemplateName, - WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH) - - // Populate the DG Path - val dgFilePath = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file) - - log.info("Executing directed graph ($dgFilePath)") - - // Create DG instance - val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath) - - // Assign Workflow inputs - val input = executionServiceInput.payload.get("$workflowName-request") - bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) - - // Execute the DG - return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput - - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt deleted file mode 100644 index 6ce4753b8..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import com.fasterxml.jackson.databind.JsonNode -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.slf4j.LoggerFactory -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service - -@Service -open class NodeTemplateExecutionService(private val applicationContext: ApplicationContext) { - - private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!! - - suspend fun executeNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { - // Get the Blueprint Context - val blueprintContext = bluePrintRuntimeService.bluePrintContext() - // Get the Component Name, NodeTemplate type is mapped to Component Name - val componentName = blueprintContext.nodeTemplateByName(nodeTemplateName).type - - val interfaceName = blueprintContext.nodeTemplateFirstInterfaceName(nodeTemplateName) - - val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName) - - log.info("executing node template($nodeTemplateName) component($componentName) " + - "interface($interfaceName) operation($operationName)") - - // Get the Component Instance - val plugin = applicationContext.getBean(componentName, AbstractComponentFunction::class.java) - // Set the Blueprint Service - plugin.bluePrintRuntimeService = bluePrintRuntimeService - plugin.stepName = nodeTemplateName - - // Populate Step Meta Data - val stepInputs: MutableMap = hashMapOf() - stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, nodeTemplateName) - stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, interfaceName) - stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, operationName) - - plugin.bluePrintRuntimeService.put("$nodeTemplateName-step-inputs", stepInputs.asJsonNode()) - - // Get the Request from the Context and Set to the Function Input and Invoke the function - return withContext(Dispatchers.Default) { - plugin.apply(executionServiceInput) - } - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt deleted file mode 100644 index b3186e849..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.blueprintsprocessor.services.workflow - -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -open class WorkflowServiceConfiguration - - -class WorkflowServiceConstants { - companion object { - const val ARTIFACT_TYPE_DIRECTED_GRAPH = "artifact-directed-graph" - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt deleted file mode 100644 index 1e856b689..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow.executor - -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintSvcLogicContext -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.NodeTemplateExecutionService -import org.onap.ccsdk.sli.core.sli.SvcLogicContext -import org.onap.ccsdk.sli.core.sli.SvcLogicException -import org.onap.ccsdk.sli.core.sli.SvcLogicNode -import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor -import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver -import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -@Service -open class ComponentExecuteNodeExecutor(private val nodeTemplateExecutionService: NodeTemplateExecutionService) - : ExecuteNodeExecutor() { - - private val log = LoggerFactory.getLogger(ComponentExecuteNodeExecutor::class.java) - - @Throws(SvcLogicException::class) - override fun execute(svc: SvcLogicServiceBase, node: SvcLogicNode, svcLogicContext: SvcLogicContext) - : SvcLogicNode = runBlocking { - - var outValue: String - - val ctx = svcLogicContext as BlueprintSvcLogicContext - - val nodeTemplateName = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx) - - val executionInput = ctx.getRequest() as ExecutionServiceInput - - try { // Get the Request from the Context and Set to the Function Input and Invoke the function - val executionOutput = nodeTemplateExecutionService.executeNodeTemplate(ctx.getBluePrintService(), - nodeTemplateName, executionInput) - - ctx.setResponse(executionOutput) - - outValue = executionOutput.status.message - ctx.status = executionOutput.status.message - - } catch (e: Exception) { - log.error("Could not execute plugin($nodeTemplateName) : ", e) - outValue = "failure" - ctx.status = "failure" - } - - getNextNode(node, outValue) - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt deleted file mode 100644 index ada36ac0b..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.blueprintsprocessor.services.workflow.utils - -import org.onap.ccsdk.sli.core.sli.SvcLogicGraph -import org.onap.ccsdk.sli.core.sli.SvcLogicParser - -object SvcGraphUtils { - - @JvmStatic - fun getSvcGraphFromClassPathFile(fileName: String): SvcLogicGraph { - val url = SvcGraphUtils::class.java.classLoader.getResource(fileName) - return getSvcGraphFromFile(url.path) - } - - @JvmStatic - fun getSvcGraphFromFile(fileName: String): SvcLogicGraph { - val svcLogicParser = SvcLogicParser() - return svcLogicParser.parse(fileName).first - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt new file mode 100644 index 000000000..fbd9f4c8b --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt @@ -0,0 +1,72 @@ +/* + * 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.workflow + +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.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service + +@Service("bluePrintWorkflowExecutionService") +open class BluePrintWorkflowExecutionServiceImpl( + private val componentWorkflowExecutionService: ComponentWorkflowExecutionService, + private val dgWorkflowExecutionService: DGWorkflowExecutionService +) : BluePrintWorkflowExecutionService { + + private val log = LoggerFactory.getLogger(BluePrintWorkflowExecutionServiceImpl::class.java)!! + + override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + executionServiceInput: ExecutionServiceInput, + properties: MutableMap): ExecutionServiceOutput { + + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val workflowName = executionServiceInput.actionIdentifiers.actionName + + // Get the DG Node Template + val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) + + val derivedFrom = bluePrintContext.nodeTemplateNodeType(nodeTemplateName).derivedFrom + + log.info("Executing workflow($workflowName) NodeTemplate($nodeTemplateName), derived from($derivedFrom)") + + val executionServiceOutput: ExecutionServiceOutput = when { + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { + componentWorkflowExecutionService + .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, properties) + } + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { + dgWorkflowExecutionService + .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, properties) + } + else -> { + throw BluePrintProcessorException("couldn't execute workflow($workflowName) step mapped " + + "to node template($nodeTemplateName) derived from($derivedFrom)") + } + } + + executionServiceOutput.commonHeader = executionServiceInput.commonHeader + executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers + // TODO("Populate Response Payload and status") + return executionServiceOutput + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt new file mode 100644 index 000000000..a2db8aab7 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicContext.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.workflow + +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.sli.core.sli.SvcLogicContext + +class BlueprintSvcLogicContext : SvcLogicContext() { + + private var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null + private var request: Any? = null + private var response: Any? = null + + fun getBluePrintService(): BluePrintRuntimeService<*> { + return this.bluePrintRuntimeService!! + } + + fun setBluePrintRuntimeService(bluePrintRuntimeService: BluePrintRuntimeService<*>) { + this.bluePrintRuntimeService = bluePrintRuntimeService + } + + fun setRequest(request: Any) { + this.request = request + } + + fun getRequest(): Any { + return this.request!! + } + + fun setResponse(response: Any) { + this.response = response + } + + fun getResponse(): Any { + return this.response!! + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt new file mode 100644 index 000000000..6712a7ff4 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt @@ -0,0 +1,143 @@ +/* + * 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.workflow + +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.sli.core.sli.* +import org.onap.ccsdk.sli.core.sli.provider.base.* +import org.slf4j.LoggerFactory +import org.slf4j.MDC +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service +import java.util.* +import javax.annotation.PostConstruct + +interface BlueprintSvcLogicService : SvcLogicServiceBase { + + fun registerDefaultExecutors() + + fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) + + fun unRegisterExecutors(name: String) + + suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any + + @Deprecated("Populate Graph Dynamically from Blueprints, No need to get from Database Store ") + override fun getStore(): SvcLogicStore { + TODO("not implemented") + } + + @Deprecated("Not used in Micro service Implementation") + override fun hasGraph(module: String, rpc: String, version: String?, mode: String): Boolean { + TODO("not implemented") + } + + @Deprecated("Not used in Micro service Implementation") + override fun execute(p0: String?, p1: String?, p2: String?, p3: String?, p4: Properties?): Properties { + TODO("not implemented") + } +} + + +@Service +class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService { + + private val log = LoggerFactory.getLogger(DefaultBlueprintSvcLogicService::class.java) + + private val nodeExecutors: MutableMap = hashMapOf() + + @Autowired + private lateinit var context: ApplicationContext + + @PostConstruct + override fun registerDefaultExecutors() { + + val executeNodeExecutor = context.getBean(ExecuteNodeExecutor::class.java) + registerExecutors("execute", executeNodeExecutor) + registerExecutors("block", BlockNodeExecutor()) + registerExecutors("return", ReturnNodeExecutor()) + registerExecutors("break", BreakNodeExecutor()) + registerExecutors("exit", ExitNodeExecutor()) + } + + override fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) { + log.info("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}") + nodeExecutors[name] = svcLogicNodeExecutor + } + + override fun unRegisterExecutors(name: String) { + if (nodeExecutors.containsKey(name)) { + log.info("UnRegistering executors($name)") + nodeExecutors.remove(name) + } + } + + override suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, + input: Any): Any { + //Initialise BlueprintSvcLogic Context with Blueprint Runtime Service and Input Request + val blueprintSvcLogicContext = BlueprintSvcLogicContext() + blueprintSvcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService) + blueprintSvcLogicContext.setRequest(input) + // Execute the Graph + execute(graph, blueprintSvcLogicContext) + // Get the Response + return blueprintSvcLogicContext.getResponse() + } + + override fun executeNode(node: SvcLogicNode?, ctx: SvcLogicContext): SvcLogicNode? { + if (node == null) { + return null + } else { + if (log.isDebugEnabled) { + log.debug("Executing node {}", node.nodeId) + } + + val executor = this.nodeExecutors[node.nodeType] + + if (executor != null) { + log.debug("Executing node executor for node type {} - {}", node.nodeType, executor.javaClass.name) + return executor.execute(this, node, ctx) + } else { + throw SvcLogicException("Attempted to execute a node of type " + node.nodeType + ", but no executor was registered for this type") + } + } + } + + override fun execute(graph: SvcLogicGraph, svcLogicContext: SvcLogicContext): SvcLogicContext { + MDC.put("currentGraph", graph.toString()) + + var curNode: SvcLogicNode? = graph.rootNode + log.info("About to execute graph {}", graph.toString()) + + try { + while (curNode != null) { + MDC.put("nodeId", curNode.nodeId.toString() + " (" + curNode.nodeType + ")") + log.info("About to execute node # {} ({})", curNode.nodeId, curNode.nodeType) + val nextNode = this.executeNode(curNode, svcLogicContext) + curNode = nextNode + } + } catch (var5: ExitNodeException) { + log.debug("SvcLogicServiceImpl caught ExitNodeException") + } + + MDC.remove("nodeId") + MDC.remove("currentGraph") + return svcLogicContext + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt new file mode 100644 index 000000000..3b2fc3368 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/ComponentWorkflowExecutionService.kt @@ -0,0 +1,49 @@ +/* + * 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.workflow + + +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.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.springframework.stereotype.Service + +@Service("componentWorkflowExecutionService") +open class ComponentWorkflowExecutionService(private val nodeTemplateExecutionService: NodeTemplateExecutionService) + : BluePrintWorkflowExecutionService { + + override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + executionServiceInput: ExecutionServiceInput, + properties: MutableMap): ExecutionServiceOutput { + + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val workflowName = executionServiceInput.actionIdentifiers.actionName + + // Get the DG Node Template + val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) + + // Assign Workflow inputs + val input = executionServiceInput.payload.get("$workflowName-request") + bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) + + return nodeTemplateExecutionService.executeNodeTemplate(bluePrintRuntimeService, + nodeTemplateName, executionServiceInput) + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt new file mode 100644 index 000000000..571b6c7c0 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionService.kt @@ -0,0 +1,70 @@ +/* + * 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.workflow + +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.services.workflow.utils.SvcGraphUtils +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.io.File + + +@Service("dgWorkflowExecutionService") +open class DGWorkflowExecutionService(private val blueprintSvcLogicService: BlueprintSvcLogicService) + : BluePrintWorkflowExecutionService { + + private val log = LoggerFactory.getLogger(DGWorkflowExecutionService::class.java) + + override suspend fun executeBluePrintWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, + executionServiceInput: ExecutionServiceInput, + properties: MutableMap): ExecutionServiceOutput { + + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val workflowName = executionServiceInput.actionIdentifiers.actionName + + // Get the DG Node Template + val nodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(workflowName) + + log.info("Executing workflow($workflowName) directed graph NodeTemplate($nodeTemplateName)") + + // Get the DG file info + val artifactDefinition = bluePrintContext.nodeTemplateArtifactForArtifactType(nodeTemplateName, + WorkflowServiceConstants.ARTIFACT_TYPE_DIRECTED_GRAPH) + + // Populate the DG Path + val dgFilePath = bluePrintContext.rootPath.plus(File.separator).plus(artifactDefinition.file) + + log.info("Executing directed graph ($dgFilePath)") + + // Create DG instance + val graph = SvcGraphUtils.getSvcGraphFromFile(dgFilePath) + + // Assign Workflow inputs + val input = executionServiceInput.payload.get("$workflowName-request") + bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) + + // Execute the DG + return blueprintSvcLogicService.execute(graph, bluePrintRuntimeService, executionServiceInput) as ExecutionServiceOutput + + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt new file mode 100644 index 000000000..67be26e6d --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt @@ -0,0 +1,72 @@ +/* + * 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.workflow + +import com.fasterxml.jackson.databind.JsonNode +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +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.services.execution.AbstractComponentFunction +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.slf4j.LoggerFactory +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +@Service +open class NodeTemplateExecutionService(private val applicationContext: ApplicationContext) { + + private val log = LoggerFactory.getLogger(NodeTemplateExecutionService::class.java)!! + + suspend fun executeNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + // Get the Blueprint Context + val blueprintContext = bluePrintRuntimeService.bluePrintContext() + // Get the Component Name, NodeTemplate type is mapped to Component Name + val componentName = blueprintContext.nodeTemplateByName(nodeTemplateName).type + + val interfaceName = blueprintContext.nodeTemplateFirstInterfaceName(nodeTemplateName) + + val operationName = blueprintContext.nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName) + + log.info("executing node template($nodeTemplateName) component($componentName) " + + "interface($interfaceName) operation($operationName)") + + // Get the Component Instance + val plugin = applicationContext.getBean(componentName, AbstractComponentFunction::class.java) + // Set the Blueprint Service + plugin.bluePrintRuntimeService = bluePrintRuntimeService + plugin.stepName = nodeTemplateName + + // Populate Step Meta Data + val stepInputs: MutableMap = hashMapOf() + stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, nodeTemplateName) + stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, interfaceName) + stepInputs.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, operationName) + + plugin.bluePrintRuntimeService.put("$nodeTemplateName-step-inputs", stepInputs.asJsonNode()) + + // Get the Request from the Context and Set to the Function Input and Invoke the function + return withContext(Dispatchers.Default) { + plugin.apply(executionServiceInput) + } + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt new file mode 100644 index 000000000..67f13f760 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/WorkflowServiceConfiguration.kt @@ -0,0 +1,31 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.workflow + +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +open class WorkflowServiceConfiguration + + +class WorkflowServiceConstants { + companion object { + const val ARTIFACT_TYPE_DIRECTED_GRAPH = "artifact-directed-graph" + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt new file mode 100644 index 000000000..cfba5becd --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt @@ -0,0 +1,69 @@ +/* + * 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.workflow.executor + +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.BlueprintSvcLogicContext +import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.NodeTemplateExecutionService +import org.onap.ccsdk.sli.core.sli.SvcLogicContext +import org.onap.ccsdk.sli.core.sli.SvcLogicException +import org.onap.ccsdk.sli.core.sli.SvcLogicNode +import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service + +@Service +open class ComponentExecuteNodeExecutor(private val nodeTemplateExecutionService: NodeTemplateExecutionService) + : ExecuteNodeExecutor() { + + private val log = LoggerFactory.getLogger(ComponentExecuteNodeExecutor::class.java) + + @Throws(SvcLogicException::class) + override fun execute(svc: SvcLogicServiceBase, node: SvcLogicNode, svcLogicContext: SvcLogicContext) + : SvcLogicNode = runBlocking { + + var outValue: String + + val ctx = svcLogicContext as BlueprintSvcLogicContext + + val nodeTemplateName = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx) + + val executionInput = ctx.getRequest() as ExecutionServiceInput + + try { // Get the Request from the Context and Set to the Function Input and Invoke the function + val executionOutput = nodeTemplateExecutionService.executeNodeTemplate(ctx.getBluePrintService(), + nodeTemplateName, executionInput) + + ctx.setResponse(executionOutput) + + outValue = executionOutput.status.message + ctx.status = executionOutput.status.message + + } catch (e: Exception) { + log.error("Could not execute plugin($nodeTemplateName) : ", e) + outValue = "failure" + ctx.status = "failure" + } + + getNextNode(node, outValue) + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt new file mode 100644 index 000000000..8f9579230 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/utils/SvcGraphUtils.kt @@ -0,0 +1,35 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.workflow.utils + +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph +import org.onap.ccsdk.sli.core.sli.SvcLogicParser + +object SvcGraphUtils { + + @JvmStatic + fun getSvcGraphFromClassPathFile(fileName: String): SvcLogicGraph { + val url = SvcGraphUtils::class.java.classLoader.getResource(fileName) + return getSvcGraphFromFile(url.path) + } + + @JvmStatic + fun getSvcGraphFromFile(fileName: String): SvcLogicGraph { + val svcLogicParser = SvcLogicParser() + return svcLogicParser.parse(fileName).first + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt deleted file mode 100644 index 7ac9bc33d..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner - - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [WorkflowServiceConfiguration::class]) -class BluePrintWorkflowExecutionServiceImplTest { - - @Autowired - lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService - - @Test - fun testBluePrintWorkflowExecutionService() { - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", - ExecutionServiceInput::class.java)!! - - runBlocking { - bluePrintWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, - hashMapOf()) - } - } - -} diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt deleted file mode 100644 index b374e7d44..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.PrototypeComponentFunction -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.SingletonComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.ApplicationContext -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertEquals - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class]) -class BlueprintServiceLogicTest { - - private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java) - - @Autowired - lateinit var applicationContext: ApplicationContext - - @Autowired - lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService - - @Test - fun testExecuteGraphWithSingleComponent() { - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! - - runBlocking { - dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) - } - - - } - - @Test - fun testExecuteGraphWithMultipleComponents() { - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!! - - runBlocking { - dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) - } - - } - - @Test - fun testSingleton() { - val singleton1 = applicationContext.getBean(SingletonComponentFunction::class.java) - singleton1.stepName = "step1" - val singleton2 = applicationContext.getBean(SingletonComponentFunction::class.java) - assertEquals(singleton1.stepName, singleton2.stepName, " failed to get singleton data") - } - - @Test - fun testProtoTypeFunction() { - val stepName1 = "step1" - val stepName2 = "step2" - val proto1 = applicationContext.getBean(PrototypeComponentFunction::class.java) - proto1.stepName = stepName1 - - val proto2 = applicationContext.getBean(PrototypeComponentFunction::class.java) - proto2.stepName = stepName2 - - assertEquals(stepName1, proto1.stepName, " Failed to match the step1 name") - assertEquals(stepName2, proto2.stepName, " Failed to match the step2 name") - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt deleted file mode 100644 index 2e36fb5ff..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.services.workflow - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class]) -class DGWorkflowExecutionServiceTest { - - private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java) - - @Autowired - lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService - - - @Test - fun testExecuteDirectedGraph() { - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! - - runBlocking { - dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) - } - - } - - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt deleted file mode 100644 index 4c1245621..000000000 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.blueprintsprocessor.services.workflow.mock - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Component - -@Configuration -open class MockComponentConfiguration { - - @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"]) - open fun createComponentFunction(): AbstractComponentFunction { - return MockComponentFunction() - } -} - -class MockComponentFunction : AbstractComponentFunction() { - - private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) - - override fun process(executionRequest: ExecutionServiceInput) { - log.info("Processing component : $operationInputs") - - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - "assignment-params", "params".asJsonPrimitive()) - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - log.info("Recovering component..") - } -} - -@Component("singleton-function") -@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) -class SingletonComponentFunction : AbstractComponentFunction() { - - private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) - - override fun process(executionRequest: ExecutionServiceInput) { - log.info("Processing component : $operationInputs") - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - log.info("Recovering component..") - } -} - -@Component("prototype-function") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -class PrototypeComponentFunction : AbstractComponentFunction() { - - private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) - - override fun process(executionRequest: ExecutionServiceInput) { - log.info("Processing component : $operationInputs") - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - log.info("Recovering component..") - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt new file mode 100644 index 000000000..3958f0c15 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt @@ -0,0 +1,54 @@ +/* + * 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.workflow + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +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.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner + + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [WorkflowServiceConfiguration::class]) +class BluePrintWorkflowExecutionServiceImplTest { + + @Autowired + lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService + + @Test + fun testBluePrintWorkflowExecutionService() { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", + ExecutionServiceInput::class.java)!! + + runBlocking { + bluePrintWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, + hashMapOf()) + } + } + +} diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt new file mode 100644 index 000000000..ad2ee57d7 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt @@ -0,0 +1,99 @@ +/* + * 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.workflow + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor +import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.PrototypeComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.SingletonComponentFunction +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertEquals + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class]) +class BlueprintServiceLogicTest { + + private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java) + + @Autowired + lateinit var applicationContext: ApplicationContext + + @Autowired + lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService + + @Test + fun testExecuteGraphWithSingleComponent() { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! + + runBlocking { + dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) + } + + + } + + @Test + fun testExecuteGraphWithMultipleComponents() { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!! + + runBlocking { + dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) + } + + } + + @Test + fun testSingleton() { + val singleton1 = applicationContext.getBean(SingletonComponentFunction::class.java) + singleton1.stepName = "step1" + val singleton2 = applicationContext.getBean(SingletonComponentFunction::class.java) + assertEquals(singleton1.stepName, singleton2.stepName, " failed to get singleton data") + } + + @Test + fun testProtoTypeFunction() { + val stepName1 = "step1" + val stepName2 = "step2" + val proto1 = applicationContext.getBean(PrototypeComponentFunction::class.java) + proto1.stepName = stepName1 + + val proto2 = applicationContext.getBean(PrototypeComponentFunction::class.java) + proto2.stepName = stepName2 + + assertEquals(stepName1, proto1.stepName, " Failed to match the step1 name") + assertEquals(stepName2, proto2.stepName, " Failed to match the step2 name") + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt new file mode 100644 index 000000000..0980f84aa --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/DGWorkflowExecutionServiceTest.kt @@ -0,0 +1,57 @@ +/* + * 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.workflow + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class]) +class DGWorkflowExecutionServiceTest { + + private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java) + + @Autowired + lateinit var dgWorkflowExecutionService: DGWorkflowExecutionService + + + @Test + fun testExecuteDirectedGraph() { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!! + + runBlocking { + dgWorkflowExecutionService.executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, mutableMapOf()) + } + + } + + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt new file mode 100644 index 000000000..1cae01ffa --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.workflow.mock + +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Component + +@Configuration +open class MockComponentConfiguration { + + @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"]) + open fun createComponentFunction(): AbstractComponentFunction { + return MockComponentFunction() + } +} + +class MockComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : $operationInputs") + + bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, + "assignment-params", "params".asJsonPrimitive()) + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +} + +@Component("singleton-function") +@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) +class SingletonComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : $operationInputs") + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +} + +@Component("prototype-function") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class PrototypeComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : $operationInputs") + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/logback.xml b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/logback.xml index 95947ad3e..56e662286 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/logback.xml +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/logback.xml @@ -26,7 +26,7 @@ - + -- cgit 1.2.3-korg