aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
authorSteve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>2019-02-11 23:35:16 -0500
committerSteve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>2019-02-12 08:07:00 -0500
commit6cd702b68bb4e0a479dcaf27b5d75a65982f6fe5 (patch)
treec6bca1f1065190d6d9f174c26653b3565f9921fb /ms/blueprintsprocessor/functions/resource-resolution/src/main
parent071eb99857706fdb0b4e400c8f81a6cb4804b5d5 (diff)
Jython execution component and service
Change-Id: I2610e73a9c7ba073b5fa9d148dcd6fb5b9ad9ae3 Issue-ID: CCSDK-696 Signed-off-by: Steve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main')
-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
3 files changed, 77 insertions, 7 deletions
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 a44d366c3..0f1267cbb 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 1370a4796..013039d66 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 d6f46a6f3..b07155a32 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()