aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/restconf-executor
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-02-18 15:10:25 -0500
committerAlexis de Talhouƫt <adetalhouet89@gmail.com>2019-02-20 21:02:05 +0000
commit0613ae8f927834f7621011fda3f0cb1b7f8e07ad (patch)
tree79010a222bfb62ad2cb61d88cccfea8f76dfc186 /ms/blueprintsprocessor/functions/restconf-executor
parent183e2b48ceb4ae58b85f76f9bf182a5958fc92e6 (diff)
Add component function scripting service
Change-Id: I7c5b49617823dd623566fb4be4d431012420e17c Issue-ID: CCSDK-959 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/restconf-executor')
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt56
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt17
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt12
3 files changed, 39 insertions, 46 deletions
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
index bd0559535..742fef4b1 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
@@ -16,28 +16,21 @@
package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
+import com.fasterxml.jackson.databind.node.ArrayNode
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
-import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
-import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
-import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
@Component("component-restconf-executor")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext,
- private val blueprintJythonService: BlueprintJythonService,
- private val bluePrintScriptsService: BluePrintScriptsService,
- private var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService,
- private var resourceResolutionService: ResourceResolutionService) :
+open class ComponentRestconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
AbstractComponentFunction() {
private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
@@ -47,16 +40,28 @@ open class ComponentRestconfExecutor(private var applicationContext: Application
companion object {
const val SCRIPT_TYPE = "script-type"
const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+ const val INSTANCE_DEPENDENCIES = "instance-dependencies"
}
override fun process(executionRequest: ExecutionServiceInput) {
val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+ val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+ val scriptDependencies: MutableList<String> = arrayListOf()
+ scriptDependencies.add(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+ scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+ instanceDependenciesNode?.forEach { instanceName ->
+ scriptDependencies.add(instanceName.textValue())
+ }
/**
* Populate the Script Instance based on the Type
*/
- restconfComponentFunction(scriptType, scriptClassReference)
+ scriptComponent = componentFunctionScriptingService.scriptInstance<RestconfComponentFunction>(this, scriptType,
+ scriptClassReference, scriptDependencies)
+
checkNotNull(scriptComponent) { "failed to get restconf script component" }
scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
@@ -68,35 +73,10 @@ open class ComponentRestconfExecutor(private var applicationContext: Application
scriptComponent.nodeTemplateName = nodeTemplateName
scriptComponent.operationInputs = operationInputs
- // FIXME("Populate the reference in Abstract Script Instance Injection map")
- // Set the Rest Lib Property Service
- scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService
- scriptComponent.resourceResolutionService = resourceResolutionService
-
scriptComponent.process(executionServiceInput)
}
override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
scriptComponent.recover(runtimeException, executionRequest)
}
-
- fun restconfComponentFunction(scriptType: String, scriptClassReference: String): RestconfComponentFunction {
- log.info("processing restconf script type($scriptType), reference name($scriptClassReference)")
- when (scriptType) {
- BluePrintConstants.SCRIPT_INTERNAL -> {
- scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(scriptClassReference)
- }
- BluePrintConstants.SCRIPT_KOTLIN -> {
- scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(bluePrintRuntimeService
- .bluePrintContext(), scriptClassReference, false)
- }
- BluePrintConstants.SCRIPT_JYTHON -> {
- scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction
- }
- else -> {
- throw BluePrintProcessorException("script type($scriptType) is not supported")
- }
- }
- return scriptComponent
- }
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
index d9362af83..c6afc3b87 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
@@ -14,9 +14,12 @@
* limitations under the License.
*/
@file:Suppress("unused")
+
package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
@@ -24,11 +27,15 @@ import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractCompon
abstract class RestconfComponentFunction : AbstractComponentFunction() {
- lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
- lateinit var resourceResolutionService: ResourceResolutionService
+ open fun bluePrintRestLibPropertyService(): BluePrintRestLibPropertyService =
+ functionDependencyInstanceAsType(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+ open fun resourceResolutionService(): ResourceResolutionService =
+ functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
fun restClientService(selector: String): BlueprintWebClientService {
- return bluePrintRestLibPropertyService.blueprintWebClientService(selector)
+ return bluePrintRestLibPropertyService().blueprintWebClientService(selector)
}
fun generateMessage(artifactName: String): String {
@@ -36,12 +43,12 @@ abstract class RestconfComponentFunction : AbstractComponentFunction() {
}
fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
- return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+ return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
artifactMapping, artifactTemplate)
}
fun resolveAndGenerateMessage(artifactPrefix: String): String {
- return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+ return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
artifactPrefix)
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
index 31bd4eb70..c8a2090b1 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
@@ -17,6 +17,7 @@
package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.ObjectNode
import io.mockk.every
import io.mockk.mockk
@@ -27,13 +28,15 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfigurati
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionServiceImpl
import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
@@ -48,7 +51,7 @@ import kotlin.test.assertNotNull
@ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class,
- ResourceResolutionServiceImpl::class])
+ ResourceResolutionServiceImpl::class, ComponentFunctionScriptingService::class])
@TestPropertySource(properties =
["server.port=9111",
"blueprintsprocessor.restconfEnabled=true",
@@ -83,7 +86,10 @@ class ComponentRestconfExecutorTest {
operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
operationInputs[ComponentRestconfExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
operationInputs[ComponentRestconfExecutor.SCRIPT_CLASS_REFERENCE] = "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
+ operationInputs[ComponentRestconfExecutor.INSTANCE_DEPENDENCIES] = JacksonUtils.jsonNode("[]") as ArrayNode
+ val blueprintContext = mockk<BluePrintContext>()
+ every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
every { bluePrintRuntime.get("sample-step-step-inputs") } returns operationInputs.asJsonNode()
every {
bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",