From 593e3233ffff0b82a8bdf687ca051666688296a7 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Fri, 15 Mar 2019 12:04:07 -0400 Subject: Improve scripting component. Change-Id: I1e0c319e4117553695fa9161e7ffcd91f605be05 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh --- .../execution/AbstractComponentFunction.kt | 21 +++------ .../execution/AbstractScriptComponentFunction.kt | 50 ++++++++++++++++++++++ .../execution/ComponentFunctionScriptingService.kt | 22 +++++++--- 3 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt (limited to 'ms/blueprintsprocessor/modules/services') 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 index f2b6e3ff..8778b1fc 100644 --- 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 @@ -51,13 +51,6 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode = hashMapOf() - //FIXME("Move to Script abstract class") - /** - * Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained. - * Later it will be moved to ScriptComponentFunction class, sub class for abstract class - */ - var functionDependencyInstances: MutableMap = hashMapOf() - override fun getName(): String { return stepName } @@ -144,12 +137,12 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode functionDependencyInstanceAsType(name: String): T { - return functionDependencyInstances[name] as? T - ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") + fun addError(type: String, name: String, error: String) { + bluePrintRuntimeService.getBluePrintError().addError(type, name, type) + } + + 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 new file mode 100644 index 00000000..811ee4a2 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/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.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 index 9bae4eb3..2cf22325 100644 --- 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 @@ -33,18 +33,30 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java) - fun scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String, - scriptClassReference: String, - instanceDependencies: List): T { + 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) - // Populate Instance Properties + + 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 -> - componentFunction.functionDependencyInstances[instanceDependency] = applicationContext + scriptComponent.functionDependencyInstances[instanceDependency] = applicationContext .getBean(instanceDependency) } return scriptComponent -- cgit 1.2.3-korg