summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-02-12 16:06:01 +0000
committerGerrit Code Review <gerrit@onap.org>2019-02-12 16:06:01 +0000
commit702a59b0ac36cfdd9eed43e539f953f5277877eb (patch)
tree6772fe2b3f009020109c247aae53c419f8fa7d70 /ms
parentd67af8c778829f3116bef2d13f761286e1a34f16 (diff)
parentdba22de28e496ae2d6d2fde9384fd1187e4b8fc1 (diff)
Merge "Jython execution component and service"
Diffstat (limited to 'ms')
-rwxr-xr-xms/blueprintsprocessor/application/opt/app/onap/config/application.properties6
-rwxr-xr-xms/blueprintsprocessor/application/src/main/resources/application-dev.properties7
-rwxr-xr-xms/blueprintsprocessor/application/src/main/resources/application.properties7
-rw-r--r--ms/blueprintsprocessor/application/src/test/resources/application.properties8
-rwxr-xr-xms/blueprintsprocessor/distribution/src/main/docker/Dockerfile1
-rwxr-xr-xms/blueprintsprocessor/distribution/src/main/docker/distribution.xml5
-rw-r--r--[-rwxr-xr-x]ms/blueprintsprocessor/distribution/src/main/docker/startService.sh2
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt11
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt104
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt52
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt42
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt78
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt6
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt47
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt33
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt52
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt28
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonHost.kt47
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonInterpreterProxy.kt41
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt78
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonServiceTest.kt56
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt15
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt52
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/pom.xml4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt20
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt62
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt43
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties8
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json18
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py13
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties8
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt1
33 files changed, 443 insertions, 514 deletions
diff --git a/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties b/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties
index c4880b67..37a57082 100755
--- a/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties
+++ b/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties
@@ -33,4 +33,8 @@ blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=validate
blueprintsprocessor.db.primary.hibernateDDLAuto=none
blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
-blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect \ No newline at end of file
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
+blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython \ No newline at end of file
diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
index 6bfa2407..b1f16898 100755
--- a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
+++ b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
@@ -1,5 +1,6 @@
#
# Copyright � 2017-2018 AT&T Intellectual Property.
+#
# Modifications Copyright © 2019 IBM, Bell Canada.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,4 +34,8 @@ blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=update
blueprintsprocessor.db.primary.hibernateDDLAuto=none
blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
-blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect \ No newline at end of file
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../components/scripts/python/ccsdk_blueprints \ No newline at end of file
diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties
index 62695207..a7ffc42b 100755
--- a/ms/blueprintsprocessor/application/src/main/resources/application.properties
+++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties
@@ -1,5 +1,6 @@
#
# Copyright � 2017-2018 AT&T Intellectual Property.
+#
# Modifications Copyright © 2019 IBM, Bell Canada.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,4 +34,8 @@ blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=validate
blueprintsprocessor.db.primary.hibernateDDLAuto=none
blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
-blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect \ No newline at end of file
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
+blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython \ No newline at end of file
diff --git a/ms/blueprintsprocessor/application/src/test/resources/application.properties b/ms/blueprintsprocessor/application/src/test/resources/application.properties
index d21264c0..bfbf4582 100644
--- a/ms/blueprintsprocessor/application/src/test/resources/application.properties
+++ b/ms/blueprintsprocessor/application/src/test/resources/application.properties
@@ -1,6 +1,8 @@
#
# 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
@@ -26,4 +28,8 @@ blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
blueprintsprocessor.db.primary.hibernateDDLAuto=update
blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
-blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect \ No newline at end of file
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
+blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython \ No newline at end of file
diff --git a/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile b/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile
index 21362329..bd6bcb3f 100755
--- a/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile
+++ b/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile
@@ -15,6 +15,7 @@ RUN (mkdir -p /source /opt/app/onap) && (tar -xzf /source.tar.gz -C /source) \
&& (cp -rf /source/app/opt/app/onap/lib /opt/app/onap/) \
&& (cp -rf /source/app/etc /) \
&& (cp -rf /source/app/config /) \
+&& (cp -rf /source/app/scripts /opt/app/onap/) \
&& (rm -rf /source)
ENTRYPOINT /startService.sh \ No newline at end of file
diff --git a/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml b/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml
index b538b73b..f84ed2dc 100755
--- a/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml
+++ b/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml
@@ -61,6 +61,11 @@
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
+ <directory>${project.basedir}/../../../components/scripts/python/ccsdk_blueprints</directory>
+ <outputDirectory>./scripts/jython</outputDirectory>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ </fileSet>
+ <fileSet>
<directory>${project.basedir}/../application/etc</directory>
<outputDirectory>./etc</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
diff --git a/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh b/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh
index 79bcbc06..5f75de8a 100755..100644
--- a/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh
+++ b/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh
@@ -5,5 +5,5 @@ nodeName=BlueprintsProcessor_1.0.0_$(cat /proc/self/cgroup | grep docker | sed s
echo "APP Config HOME : ${APP_CONFIG_HOME}"
export APP_HOME=/opt/app/onap
-cp -rf /config /opt/app/onap/
+mv -rf /config /opt/app/onap/
source /etc/run.source
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
index 4612ddaf..c007914a 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
@@ -1,6 +1,8 @@
/*
* 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
@@ -17,19 +19,20 @@
package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo
import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.ComponentJythonExecutor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
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-netconf-executor")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentNetconfExecutor(private val netconfExecutorConfiguration: NetconfExecutorConfiguration,
- private val pythonExecutorProperty: PythonExecutorProperty)
- : ComponentJythonExecutor(pythonExecutorProperty) {
+open class ComponentNetconfExecutor(private var applicationContext: ApplicationContext, private val netconfExecutorConfiguration: NetconfExecutorConfiguration,
+ private val blueprintPythonService: BlueprintPythonService)
+ : ComponentJythonExecutor(applicationContext, blueprintPythonService) {
private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java)
lateinit var deviceInfo: DeviceInfo
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
deleted file mode 100644
index 06c1c752..00000000
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
+++ /dev/null
@@ -1,104 +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.functions.python.executor
-
-import com.fasterxml.jackson.databind.node.ArrayNode
-import org.apache.commons.io.FilenameUtils
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils
-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.slf4j.LoggerFactory
-import org.springframework.beans.factory.annotation.Autowired
-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-jython-executor")
-@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExecutorProperty) : AbstractComponentFunction() {
-
- private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
-
- private var componentFunction: AbstractComponentFunction? = null
-
- @Autowired
- lateinit var applicationContext: ApplicationContext
-
- fun populateJythonComponentInstance(executionServiceInput: ExecutionServiceInput) {
- val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
-
- val operationAssignment: OperationAssignment = bluePrintContext
- .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, 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)
-
- val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
-
- checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty")
-
- val pythonPath: MutableList<String> = operationAssignment.implementation?.dependencies ?: arrayListOf()
- pythonPath.add(blueprintBasePath)
- pythonPath.addAll(pythonExecutorProperty.modulePaths)
-
- val jythonInstances: MutableMap<String, Any> = hashMapOf()
- jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName)
- jythonInstances["bluePrintRuntimeService"] = bluePrintRuntimeService
-
- 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())
- }
-
- componentFunction = PythonExecutorUtils.getPythonComponent(pythonExecutorProperty.executionPath,
- pythonPath, content, pythonClassName, jythonInstances)
- }
-
-
- override fun process(executionServiceInput: ExecutionServiceInput) {
-
- log.info("Processing : $operationInputs")
- checkNotNull(bluePrintRuntimeService) { "failed to get bluePrintRuntimeService" }
-
- // Populate Component Instance
- populateJythonComponentInstance(executionServiceInput)
-
- // Invoke Jython Component Script
- componentFunction!!.process(executionServiceInput)
-
- }
-
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
- componentFunction!!.recover(runtimeException, executionRequest)
- }
-
-} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt
deleted file mode 100644
index 6618d13c..00000000
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.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.functions.python.executor
-
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils
-import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.slf4j.LoggerFactory
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.context.ApplicationContext
-import org.springframework.stereotype.Service
-
-@Service
-class JythonExecutionService(private val pythonExecutorProperty: PythonExecutorProperty) {
-
-
- private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
-
- @Autowired
- lateinit var applicationContext: ApplicationContext
-
-
- fun getJythonComponentFunction(pythonClassName: String, content: String, pythonPath: MutableList<String>,
- jythonContextInstance: MutableMap<String, Any>,
- dependencyInstanceNames: List<String>): AbstractComponentFunction {
-
- pythonPath.addAll(pythonExecutorProperty.modulePaths)
-
- dependencyInstanceNames.forEach { instanceName ->
- jythonContextInstance[instanceName] = applicationContext.getBean(instanceName)
-
- }
-
- return PythonExecutorUtils.getPythonComponent(pythonExecutorProperty.executionPath,
- pythonPath, content, pythonClassName, jythonContextInstance)
-
- }
-
-} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt
deleted file mode 100644
index be7374c5..00000000
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt
+++ /dev/null
@@ -1,42 +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.functions.python.executor
-
-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
-
-@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<String>
-
-}
-
-class PythonExecutorConstants {
- companion object {
- const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies"
- }
-} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt
deleted file mode 100644
index 341ede58..00000000
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt
+++ /dev/null
@@ -1,78 +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.functions.python.executor.utils
-
-import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.python.core.PyObject
-import org.python.util.PythonInterpreter
-import org.slf4j.LoggerFactory
-import java.io.File
-import java.util.*
-
-class PythonExecutorUtils {
- companion object {
-
- private val log = LoggerFactory.getLogger(PythonExecutorUtils::class.java)
-
- fun getPythonComponent(executePath: String, pythonPath: MutableList<String>, content: String?, interfaceName: String,
- properties: MutableMap<String, Any>): AbstractComponentFunction {
-
- initPython(executePath, pythonPath, arrayListOf())
- val pythonInterpreter = PythonInterpreter()
-
- properties.forEach { (name, value) ->
- pythonInterpreter.set(name, value)
- }
-
- pythonInterpreter.exec("import sys")
-
- content?.let {
- pythonInterpreter.exec(content)
- }
-
- val initCommand = interfaceName.plus(" = ").plus(interfaceName).plus("()")
- pythonInterpreter.exec(initCommand)
- val pyObject: PyObject = pythonInterpreter.get(interfaceName)
-
- log.info("Component Object {}", pyObject)
-
- return pyObject.__tojava__(AbstractComponentFunction::class.java) as AbstractComponentFunction
- }
-
- private fun initPython(executablePath: String,
- pythonPath: MutableList<String>, argv: MutableList<String>) {
-
- val props = Properties()
- // Build up the python.path
- val sb = StringBuilder()
- sb.append(System.getProperty("java.class.path"))
-
- for (p in pythonPath) {
- sb.append(File.pathSeparator).append(p)
- }
- log.debug("Python Paths : $sb")
-
- props["python.import.site"] = "true"
- props.setProperty("python.path", sb.toString())
- props.setProperty("python.verbose", "error")
- props.setProperty("python.executable", executablePath)
-
- PythonInterpreter.initialize(System.getProperties(), props, argv.toTypedArray())
- }
-
- }
-} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
index 5f58dd38..c33bfcfa 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
@@ -1,6 +1,8 @@
/*
* 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
@@ -20,6 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode
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.functions.python.executor.BlueprintPythonService
import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
@@ -32,7 +35,8 @@ import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
@RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, PythonExecutorProperty::class])
+@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, BlueprintPythonService::class,
+ PythonExecutorProperty::class])
@TestPropertySource(properties =
["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf;./../../../../components/scripts/python/ccsdk_blueprints",
"blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"])
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt
new file mode 100644
index 00000000..cea02fb7
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt
@@ -0,0 +1,47 @@
+/*
+ * 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.functions.python.executor
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.plugin.BlueprintPythonHost
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.stereotype.Service
+
+@Service("jython-executor-service")
+class BlueprintPythonService(val pythonExecutorProperty: PythonExecutorProperty){
+
+ val log: Logger = LoggerFactory.getLogger(BlueprintPythonService::class.java)
+
+ inline fun <reified T> jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String,
+ dependencyInstanceNames: MutableMap<String, Any>?): T {
+
+ val blueprintBasePath: String = blueprintContext.rootPath
+ val pythonPath: MutableList<String> = arrayListOf()
+ pythonPath.add(blueprintBasePath)
+ pythonPath.addAll(pythonExecutorProperty.modulePaths)
+
+ var blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
+
+ val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations)
+ var pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
+
+ log.info("Component Object {}", pyObject)
+
+ return pyObject.__tojava__(T::class.java) as T
+ }
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
index 9e2ba0b9..4a3ad6b2 100644
--- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
@@ -1,6 +1,8 @@
/*
* 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
@@ -19,13 +21,11 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor
import com.fasterxml.jackson.databind.node.ArrayNode
import org.apache.commons.io.FilenameUtils
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils
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.slf4j.LoggerFactory
-import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Scope
@@ -33,23 +33,19 @@ import org.springframework.stereotype.Component
@Component("component-jython-executor")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExecutorProperty) : AbstractComponentFunction() {
+open class ComponentJythonExecutor(private var applicationContext: ApplicationContext,
+ private val blueprintPythonService: BlueprintPythonService) : AbstractComponentFunction() {
private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
private var componentFunction: AbstractComponentFunction? = null
- @Autowired
- lateinit var applicationContext: ApplicationContext
-
fun populateJythonComponentInstance(executionServiceInput: ExecutionServiceInput) {
val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
val operationAssignment: OperationAssignment = bluePrintContext
.nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, 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)")
@@ -64,22 +60,21 @@ open class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExe
checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty")
- val pythonPath: MutableList<String> = operationAssignment.implementation?.dependencies ?: arrayListOf()
- pythonPath.add(blueprintBasePath)
- pythonPath.addAll(pythonExecutorProperty.modulePaths)
-
- val jythonInstances: MutableMap<String, Any> = 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 jythonContextInstance: MutableMap<String, Any> = hashMapOf()
+ jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName)
+ jythonContextInstance["bluePrintRuntimeService"] = bluePrintRuntimeService
+ instanceDependenciesNode?.forEach { instanceName ->
+ val instance = instanceName.textValue()
+ val value = applicationContext.getBean(instance)
+ ?: throw BluePrintProcessorException("couldn't get the dependency instance($instance)")
+ jythonContextInstance[instance] = value
}
- componentFunction = PythonExecutorUtils.getPythonComponent(pythonExecutorProperty.executionPath,
- pythonPath, content, pythonClassName, jythonInstances)
+ componentFunction = blueprintPythonService.jythonInstance(bluePrintContext, pythonClassName,
+ content!!, jythonContextInstance)
}
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt
deleted file mode 100644
index 6618d13c..00000000
--- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.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.functions.python.executor
-
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils
-import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.slf4j.LoggerFactory
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.context.ApplicationContext
-import org.springframework.stereotype.Service
-
-@Service
-class JythonExecutionService(private val pythonExecutorProperty: PythonExecutorProperty) {
-
-
- private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
-
- @Autowired
- lateinit var applicationContext: ApplicationContext
-
-
- fun getJythonComponentFunction(pythonClassName: String, content: String, pythonPath: MutableList<String>,
- jythonContextInstance: MutableMap<String, Any>,
- dependencyInstanceNames: List<String>): AbstractComponentFunction {
-
- pythonPath.addAll(pythonExecutorProperty.modulePaths)
-
- dependencyInstanceNames.forEach { instanceName ->
- jythonContextInstance[instanceName] = applicationContext.getBean(instanceName)
-
- }
-
- return PythonExecutorUtils.getPythonComponent(pythonExecutorProperty.executionPath,
- pythonPath, content, pythonClassName, jythonContextInstance)
-
- }
-
-} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt
index be7374c5..6d17f932 100644
--- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt
@@ -1,6 +1,8 @@
/*
* 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
@@ -20,6 +22,8 @@ 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
@@ -32,11 +36,33 @@ open class PythonExecutorProperty {
lateinit var executionPath: String
@Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}")
lateinit var modulePaths: List<String>
-
}
class PythonExecutorConstants {
companion object {
const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies"
}
+}
+
+open class BluePrintPython(executablePath: String, blueprintPythonPlatform: MutableList<String>,
+ val argv: MutableList<String>){
+ 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/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonHost.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonHost.kt
new file mode 100644
index 00000000..ca0a7158
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonHost.kt
@@ -0,0 +1,47 @@
+/*
+ * 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.functions.python.executor.plugin
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BluePrintPython
+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<String, Any>
+ * @return pyObject PyObject
+ */
+ fun getPythonComponent(content: String?, interfaceName: String, properties: MutableMap<String, Any>?): PyObject {
+ bluePrintPython.content = content!!
+ bluePrintPython.pythonClassName = interfaceName
+ bluePrintPython.moduleName = "Blueprint Python Scripting [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/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonInterpreterProxy.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonInterpreterProxy.kt
new file mode 100644
index 00000000..ad35c91d
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonInterpreterProxy.kt
@@ -0,0 +1,41 @@
+/*
+ * 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.functions.python.executor.plugin
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BluePrintPython
+import org.python.core.PyObject
+import org.python.util.PythonInterpreter
+
+open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrintPython): PythonInterpreter(){
+
+ fun getPythonInstance(properties: MutableMap<String, Any>?): 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/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt
deleted file mode 100644
index 341ede58..00000000
--- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt
+++ /dev/null
@@ -1,78 +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.functions.python.executor.utils
-
-import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.python.core.PyObject
-import org.python.util.PythonInterpreter
-import org.slf4j.LoggerFactory
-import java.io.File
-import java.util.*
-
-class PythonExecutorUtils {
- companion object {
-
- private val log = LoggerFactory.getLogger(PythonExecutorUtils::class.java)
-
- fun getPythonComponent(executePath: String, pythonPath: MutableList<String>, content: String?, interfaceName: String,
- properties: MutableMap<String, Any>): AbstractComponentFunction {
-
- initPython(executePath, pythonPath, arrayListOf())
- val pythonInterpreter = PythonInterpreter()
-
- properties.forEach { (name, value) ->
- pythonInterpreter.set(name, value)
- }
-
- pythonInterpreter.exec("import sys")
-
- content?.let {
- pythonInterpreter.exec(content)
- }
-
- val initCommand = interfaceName.plus(" = ").plus(interfaceName).plus("()")
- pythonInterpreter.exec(initCommand)
- val pyObject: PyObject = pythonInterpreter.get(interfaceName)
-
- log.info("Component Object {}", pyObject)
-
- return pyObject.__tojava__(AbstractComponentFunction::class.java) as AbstractComponentFunction
- }
-
- private fun initPython(executablePath: String,
- pythonPath: MutableList<String>, argv: MutableList<String>) {
-
- val props = Properties()
- // Build up the python.path
- val sb = StringBuilder()
- sb.append(System.getProperty("java.class.path"))
-
- for (p in pythonPath) {
- sb.append(File.pathSeparator).append(p)
- }
- log.debug("Python Paths : $sb")
-
- props["python.import.site"] = "true"
- props.setProperty("python.path", sb.toString())
- props.setProperty("python.verbose", "error")
- props.setProperty("python.executable", executablePath)
-
- PythonInterpreter.initialize(System.getProperties(), props, argv.toTypedArray())
- }
-
- }
-} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonServiceTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonServiceTest.kt
new file mode 100644
index 00000000..0e856808
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonServiceTest.kt
@@ -0,0 +1,56 @@
+/*
+ * 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.functions.python.executor
+
+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 = [BlueprintPythonService::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 BlueprintPythonServiceTest {
+
+ @Autowired
+ private lateinit var blueprintPythonService: BlueprintPythonService
+
+ @Test
+ fun testGetAbstractPythonPlugin() {
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val dependencies: MutableMap<String, Any> = hashMapOf()
+
+ val content = JacksonUtils.getContent("./../../../../components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py")
+
+ val abstractComponentFunction = blueprintPythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SampleBlueprintComponent", content, dependencies)
+
+ assertNotNull(abstractComponentFunction, "failed to get python component")
+
+ abstractComponentFunction.process(ExecutionServiceInput())
+
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
index 837be81f..34d5119a 100644
--- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
@@ -42,21 +42,6 @@ class ComponentJythonExecutorTest {
@Test
fun testPythonComponentInjection() {
- /*
- val executionServiceInput = ExecutionServiceInput()
- executionServiceInput.payload = JsonNodeFactory.instance.objectNode()
-
- val commonHeader = CommonHeader()
- commonHeader.requestId = "1234"
- executionServiceInput.commonHeader = commonHeader
-
- val actionIdentifiers = ActionIdentifiers()
- actionIdentifiers.blueprintName = "baseconfiguration"
- actionIdentifiers.blueprintVersion = "1.0.0"
- actionIdentifiers.actionName = "activate"
- executionServiceInput.actionIdentifiers = actionIdentifiers
-
- */
val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
ExecutionServiceInput::class.java)!!
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt
deleted file mode 100644
index c4fd5467..00000000
--- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.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.functions.python.executor.utils
-
-import org.junit.Test
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
-import org.slf4j.LoggerFactory
-import kotlin.test.assertNotNull
-
-
-class PythonExecutorUtilsTest {
-
- private val log = LoggerFactory.getLogger(PythonExecutorUtils::class.java)
-
- @Test
- fun testGetPythonComponent() {
-
- val pythonPath: MutableList<String> = mutableListOf()
- pythonPath.add("./../../../../components/scripts/python/ccsdk_blueprints")
-
- val properties: MutableMap<String, Any> = hashMapOf()
- properties["logger"] = log
-
- val content = JacksonUtils.getContent("./../../../../components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py")
-
- val abstractComponentFunction = PythonExecutorUtils.getPythonComponent("./../../../../components/scripts/python/ccsdk_blueprints", pythonPath, content,
- "SampleBlueprintComponent", properties)
-
- assertNotNull(abstractComponentFunction, "failed to get python component")
-
- abstractComponentFunction.process(ExecutionServiceInput())
-
- }
-
-
-}
-
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
index b29149d8..1e15ba27 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
+++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
@@ -35,6 +35,10 @@
<version>${project.version}</version>
</dependency>-->
<dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>python-executor</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
<artifactId>blueprint-scripts</artifactId>
</dependency>
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
index a44d366c..0f1267cb 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications 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.
@@ -17,43 +18,54 @@
package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
+import com.fasterxml.jackson.annotation.JsonProperty
+
open class ResourceSourceProperties
open class InputResourceSource : ResourceSourceProperties() {
lateinit var key: String
+ @get:JsonProperty("key-dependencies")
lateinit var keyDependencies: MutableList<String>
}
open class DefaultResourceSource : ResourceSourceProperties() {
lateinit var key: String
+ @get:JsonProperty("key-dependencies")
lateinit var keyDependencies: MutableList<String>
}
open class DatabaseResourceSource : ResourceSourceProperties() {
lateinit var type: String
lateinit var query: String
+ @get:JsonProperty("input-key-mapping")
var inputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("output-key-mapping")
var outputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("key-dependencies")
lateinit var keyDependencies: MutableList<String>
}
open class RestResourceSource : ResourceSourceProperties() {
lateinit var type: String
+ @get:JsonProperty("url-path")
lateinit var urlPath: String
lateinit var path: String
+ @get:JsonProperty("expression-type")
lateinit var expressionType: String
+ @get:JsonProperty("input-key-mapping")
var inputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("output-key-mapping")
var outputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("key-dependencies")
lateinit var keyDependencies: MutableList<String>
}
open class CapabilityResourceSource : ResourceSourceProperties() {
lateinit var type: String
+ @get:JsonProperty("instance-name")
lateinit var instanceName: String
+ @get:JsonProperty("instance-dependencies")
var instanceDependencies: List<String>? = null
- lateinit var path: String
- lateinit var expressionType: String
- var inputKeyMapping: MutableMap<String, String>? = null
- var outputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("key-dependencies")
lateinit var keyDependencies: MutableList<String>
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt
index 1370a479..013039d6 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt
@@ -1,6 +1,8 @@
/*
* 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
@@ -16,17 +18,22 @@
package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
+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.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Service
+import java.io.File
@Service("resource-assignment-processor-capability")
open class CapabilityResourceAssignmentProcessor(private var applicationContext: ApplicationContext,
- private val bluePrintScriptsService: BluePrintScriptsService) :
+ private val bluePrintScriptsService: BluePrintScriptsService,
+ private val bluePrintPythonService: BlueprintPythonService) :
ResourceAssignmentProcessor() {
companion object {
@@ -70,7 +77,9 @@ open class CapabilityResourceAssignmentProcessor(private var applicationContext:
componentResourceAssignmentProcessor = applicationContext.getBean(instanceName, ResourceAssignmentProcessor::class.java)
}
CAPABILITY_TYPE_JYTHON_COMPONENT -> {
- TODO(" No implementation")
+ val content = getJythonContent(instanceName)
+ componentResourceAssignmentProcessor = getJythonResourceAssignmentProcessorInstance(instanceName,
+ content, capabilityResourceSourceProperty.instanceDependencies)
}
}
@@ -120,4 +129,53 @@ open class CapabilityResourceAssignmentProcessor(private var applicationContext:
return resourceAssignmentProcessor
}
+
+ private fun getJythonContent(instanceName: String): String {
+ val absolutePath = raRuntimeService.bluePrintContext().rootPath
+ .plus(File.separator)
+ .plus(BluePrintConstants.TOSCA_SCRIPTS_JYTHON_DIR)
+ .plus(File.separator)
+ .plus("$instanceName.py")
+
+ return JacksonUtils.getContent(absolutePath)
+
+ }
+
+ /**
+ * getJythonResourceAssignmentProcessorInstance Purpose: prepare the jython
+ * executor component as a resource assignment processor
+ *
+ * @param pythonClassName String
+ * @param content String
+ * @param dependencyInstances List<String>
+ * @return resourceAssignmentProcessor ResourceAssignmentProcessor
+ */
+ private fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String,
+ dependencyInstances: List<String>?):
+ ResourceAssignmentProcessor {
+ val jythonContextInstance: MutableMap<String, Any> = hashMapOf()
+ jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName)
+ jythonContextInstance["raRuntimeService"] = raRuntimeService
+ dependencyInstances?.forEach { instanceName ->
+ jythonContextInstance[instanceName] = applicationContext.getBean(instanceName)
+ }
+
+ return getJythonResourceAssignmentProcessorInstance(pythonClassName, content, jythonContextInstance)
+ }
+
+ fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String,
+ dependencyInstances: MutableMap<String, Any>):
+ ResourceAssignmentProcessor {
+
+ val resourceAssignmentProcessor = bluePrintPythonService
+ .jythonInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), pythonClassName,
+ content, dependencyInstances)
+
+ // Add additional Instance
+ if (dependencyInstances != null) {
+ resourceAssignmentProcessor.scriptPropertyInstances = dependencyInstances
+ }
+
+ return resourceAssignmentProcessor
+ }
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
index d6f46a6f..b07155a3 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
@@ -29,7 +29,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java)
lateinit var raRuntimeService: ResourceAssignmentRuntimeService
- lateinit var resourceDictionaries: Map<String, ResourceDefinition>
+ lateinit var resourceDictionaries: MutableMap<String, ResourceDefinition>
var scriptPropertyInstances: Map<String, Any> = hashMapOf()
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt
index c9d1c77d..3dda7955 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt
@@ -1,6 +1,8 @@
/*
* 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
@@ -18,19 +20,27 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
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 = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class,
- MockCapabilityService::class])
+ BlueprintPythonService::class, PythonExecutorProperty::class, MockCapabilityService::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 CapabilityResourceAssignmentProcessorTest {
@Autowired
@@ -72,6 +82,37 @@ class CapabilityResourceAssignmentProcessorTest {
println(processorName)
}
+ @Test
+ fun `test jython capability`() {
+
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+
+ capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
+
+ val resourceDefinition = JacksonUtils
+ .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
+ ResourceDefinition::class.java)!!
+ val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
+ resourceDefinitions[resourceDefinition.name] = resourceDefinition
+ capabilityResourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
+
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "country"
+ dictionaryName = "country"
+ dictionarySource = "capability"
+ property = PropertyDefinition().apply {
+ type = "string"
+ }
+ }
+
+ val processorName = capabilityResourceAssignmentProcessor.apply(resourceAssignment)
+ assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
+
+ }
+
}
open class MockCapabilityService {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
index aed61c46..e2785c8a 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
@@ -2,6 +2,8 @@
#
# 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
@@ -29,4 +31,8 @@ blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
blueprintsprocessor.restclient.primary-config-data.type=basic-auth
blueprintsprocessor.restclient.primary-config-data.url=http://127.0.0.1:9111
blueprintsprocessor.restclient.primary-config-data.userId=sampleuser
-blueprintsprocessor.restclient.primary-config-data.token=sampletoken \ No newline at end of file
+blueprintsprocessor.restclient.primary-config-data.token=sampletoken
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json
new file mode 100644
index 00000000..9d834433
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json
@@ -0,0 +1,18 @@
+{
+ "tags": "country",
+ "name": "country",
+ "updated-by": "brindasanth@onap.com",
+ "property": {
+ "description": "description",
+ "type": "string"
+ },
+ "sources": {
+ "capability": {
+ "properties": {
+ "type": "JYTHON-COMPONENT",
+ "instance-name": "SampleRAProcessor",
+ "instance-dependencies": []
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py
new file mode 100644
index 00000000..bcf450e8
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py
@@ -0,0 +1,13 @@
+from resource_assignment_processor_function import AbstractJythonComponentFunction
+from blueprint_constants import *
+
+
+class SampleJythonComponentNode(AbstractJythonComponentFunction):
+
+ def process(self, execution_request):
+ print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH
+ return None
+
+ def recover(self, runtime_exception, execution_request):
+ print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH
+ return None
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties
index 8a26ee6e..6d8b62ff 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties
@@ -1,6 +1,8 @@
#
# 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
@@ -24,5 +26,7 @@ blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
# Controller Blueprints Core Configuration
blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
-# executor
-blueprints.processor.functions.python.executor.executionPath="./target/"
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
index c50218bf..a2101251 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
@@ -150,6 +150,7 @@ object BluePrintConstants {
const val TOSCA_MAPPINGS_DIR: String = "Mappings"
const val TOSCA_TEMPLATES_DIR: String = "Templates"
const val TOSCA_SCRIPTS_KOTLIN_DIR: String = "$TOSCA_SCRIPTS_DIR/kotlin"
+ const val TOSCA_SCRIPTS_JYTHON_DIR: String = "$TOSCA_SCRIPTS_DIR/python"
const val METADATA_USER_GROUPS = "user-groups"
const val METADATA_TEMPLATE_NAME = "template_name"