**/tokens/*\r
\r
# Added for Intellij IDEA IDE\r
-**/*.ipr
-**/*.iws
+**/*.ipr\r
+**/*.iws\r
**/debug-logs/*\r
**/.idea/*\r
**/*.iml\r
**/blackDuckHub*\r
**/*.jsonld\r
**/.checkstyle\r
-**/.gitignore
-
-**/*py.class
+**/.gitignore\r
+\r
+**/*py.class\r
**/.DS_Store\r
+\r
+# To Remove Kotlin Script Generated Jars\r
+**/*cba-kts.jar
\ No newline at end of file
const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID"\r
const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion"\r
const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion"\r
- const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"
-
- const val STATUS_SUCCESS: String = "success"
- const val STATUS_PROCESSING: String = "processing"
- const val STATUS_FAILURE: String = "failure"
-
- const val TYPE_DEFAULT: String = "default"
+ const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"\r
+\r
+ const val STATUS_SUCCESS: String = "success"\r
+ const val STATUS_PROCESSING: String = "processing"\r
+ const val STATUS_FAILURE: String = "failure"\r
+\r
+ const val TYPE_DEFAULT: String = "default"\r
\r
const val DATA_TYPE_STRING: String = "string"\r
const val DATA_TYPE_INTEGER: String = "integer"\r
const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script"\r
const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python"\r
const val MODEL_TYPE_NODES_COMPONENT_JYTHON: String = "tosca.nodes.component.Jython"\r
+ const val MODEL_TYPE_NODES_COMPONENT_KOTLIN: String = "tosca.nodes.component.Kotlin"\r
const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript"\r
\r
const val MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION = "tosca.artifacts.Implementation"\r
const val TOSCA_SCRIPTS_DIR: String = "Scripts"\r
const val TOSCA_MAPPINGS_DIR: String = "Mappings"\r
const val TOSCA_TEMPLATES_DIR: String = "Templates"\r
+ const val TOSCA_SCRIPTS_KOTLIN_DIR: String = "$TOSCA_SCRIPTS_DIR/kotlin"\r
\r
const val METADATA_USER_GROUPS = "user-groups"\r
const val METADATA_TEMPLATE_NAME = "template_name"\r
--- /dev/null
+/*
+ * 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.controllerblueprints.core.interfaces
+
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+
+interface BluePrintScriptsService{
+
+ fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
+ reCompile: Boolean): T
+}
\ No newline at end of file
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
*/\r
+@file:Suppress("unused")\r
\r
package org.onap.ccsdk.apps.controllerblueprints.core.service\r
\r
import com.att.eelf.configuration.EELFLogger\r
import com.att.eelf.configuration.EELFManager\r
import com.fasterxml.jackson.databind.JsonNode\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
return JacksonUtils.getJson(serviceTemplate, pretty)\r
}\r
\r
+ fun name(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_NAME)\r
+ ?: throw BluePrintException("could't get template name from meta data")\r
+\r
+ fun version(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_VERSION)\r
+ ?: throw BluePrintException("could't get template version from meta data")\r
+\r
+ fun author(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR)\r
+ ?: throw BluePrintException("could't get template author from meta data")\r
+\r
// Workflow\r
val workflows: MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows\r
\r
val nodeTemplates: MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates\r
\r
fun nodeTemplateByName(name: String): NodeTemplate =\r
- nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)")
+ nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)")\r
\r
fun nodeTemplateForNodeType(name: String): MutableMap<String, NodeTemplate>? {\r
return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap()\r
--- /dev/null
+/*
+ * 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.
+ */
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+
+open class ScriptResourceAssignmentProcessor : ResourceAssignmentProcessor() {
+
+ lateinit var resourceAssignment: ResourceAssignment
+
+ override fun getName(): String {
+ return "resource-assignment-processor-custom-capability"
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+ this.resourceAssignment = resourceAssignment
+ }
+
+ override fun prepareResponse(): ResourceAssignment {
+ return resourceAssignment
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ TODO("To Implement")
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.
+ */
+
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
+
+open class SampleKotlinComponent : BlueprintFunctionNode<String, String> {
+
+ override fun getName(): String {
+ return "my Name"
+ }
+
+ override fun prepareRequest(executionRequest: String): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun process(executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun prepareResponse(): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun apply(t: String): String {
+ return "Successfully Executed Scripts"
+ }
+}
]
},
"instance-name": {
- "description": "Capability component instance reference name.",
+ "description": "Capability component instance reference name for JAVA-COMPONENT, Script Class name for KOTLIN-COMPONENT.",
"required": true,
"type": "string"
},
+ "instance-dependencies": {
+ "required": false,
+ "description": "Instance dependency Names to Inject to Kotlin / Jython Script.",
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
"input-key-mapping": {
"description": "Context name to input parameters name mapping.",
"required": false,
<artifactId>db-resources</artifactId>
<version>${project.version}</version>
</dependency>-->
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+ <artifactId>blueprint-scripts</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+@file:Suppress("unused")
package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
-open class ResourceSourceProperties {
-
-}
+open class ResourceSourceProperties
open class InputResourceSource : ResourceSourceProperties() {
lateinit var key: String
open class CapabilityResourceSource : ResourceSourceProperties() {
lateinit var type: String
lateinit var instanceName: String
+ var instanceDependencies: List<String>? = null
lateinit var path: String
lateinit var expressionType: String
var inputKeyMapping: MutableMap<String, String>? = null
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
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.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Service
@Service("resource-assignment-processor-capability")
-open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() {
+open class CapabilityResourceAssignmentProcessor(private var applicationContext: ApplicationContext,
+ private val bluePrintScriptsService: BluePrintScriptsService) :
+ ResourceAssignmentProcessor() {
companion object {
const val CAPABILITY_TYPE_KOTLIN_COMPONENT = "KOTLIN-COMPONENT"
const val CAPABILITY_TYPE_JYTHON_COMPONENT = "JYTHON-COMPONENT"
}
- @Autowired
- private lateinit var applicationContext: ApplicationContext
-
override fun getName(): String {
return "resource-assignment-processor-capability"
}
?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}")
val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource]
- ?: throw BluePrintProcessorException("couldn't get resource definition ${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})")
+ ?: throw BluePrintProcessorException("couldn't get resource definition " +
+ "${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})")
val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" }
- val capabilityResourceSourceProperty = JacksonUtils.getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java)
+ /**
+ * Get the Capability Resource Source Info from Property Definitions.
+ */
+ val capabilityResourceSourceProperty = JacksonUtils
+ .getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java)
val instanceType = capabilityResourceSourceProperty.type
val instanceName = capabilityResourceSourceProperty.instanceName
-
var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null
when (instanceType) {
- CAPABILITY_TYPE_KOTLIN_COMPONENT ->{
- TODO("NO implementation")
+ CAPABILITY_TYPE_KOTLIN_COMPONENT -> {
+ componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(instanceName,
+ capabilityResourceSourceProperty.instanceDependencies)
}
CAPABILITY_TYPE_JAVA_COMPONENT -> {
// Initialize Capability Resource Assignment Processor
TODO("To Implement")
}
+
+ private fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String,
+ instanceNames: List<String>? = null): ResourceAssignmentProcessor {
+ var scriptPropertyInstances: MutableMap<String, Any>? = null
+
+ if (instanceNames != null && instanceNames.isNotEmpty()) {
+ scriptPropertyInstances = hashMapOf()
+ instanceNames.forEach {
+ scriptPropertyInstances[it] = applicationContext.getBean(it)
+ ?: throw BluePrintProcessorException("couldn't get the dependency instance($it)")
+ }
+ }
+
+ return getKotlinResourceAssignmentProcessorInstance(scriptClassName, scriptPropertyInstances)
+
+ }
+
+ fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String,
+ scriptPropertyInstances: MutableMap<String, Any>? = null):
+ ResourceAssignmentProcessor {
+
+ val resourceAssignmentProcessor = bluePrintScriptsService
+ .scriptInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(),
+ scriptClassName, false)
+
+ // Add additional Instance
+ if (scriptPropertyInstances != null) {
+ resourceAssignmentProcessor.scriptPropertyInstances = scriptPropertyInstances
+ }
+
+ return resourceAssignmentProcessor
+ }
}
\ No newline at end of file
lateinit var raRuntimeService: ResourceAssignmentRuntimeService
lateinit var resourceDictionaries: Map<String, ResourceDefinition>
+ var scriptPropertyInstances: Map<String, Any> = hashMapOf()
+
+ /**
+ * This will be called from the scripts to serve instance from runtime to scripts.
+ */
+ open fun <T> scriptPropertyInstanceType(name: String): T {
+ return scriptPropertyInstances as? T
+ ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
+ }
+
open fun resourceDefinition(name: String): ResourceDefinition {
return resourceDictionaries[name]
?: throw BluePrintProcessorException("couldn't get resource definition for ($name)")
--- /dev/null
+/*
+ * 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.resource.resolution.processor
+
+import org.junit.Test
+import org.junit.runner.RunWith
+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.resource.dict.ResourceAssignment
+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.junit4.SpringRunner
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class,
+ MockCapabilityService::class])
+class CapabilityResourceAssignmentProcessorTest {
+
+ @Autowired
+ lateinit var capabilityResourceAssignmentProcessor: CapabilityResourceAssignmentProcessor
+
+ @Test
+ fun `test kotlin capability`() {
+
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+
+ capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
+ capabilityResourceAssignmentProcessor.resourceDictionaries = hashMapOf()
+
+
+ val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
+ scriptPropertyInstances["mock-service1"] = MockCapabilityService()
+ scriptPropertyInstances["mock-service2"] = MockCapabilityService()
+
+ val resourceAssignmentProcessor = capabilityResourceAssignmentProcessor
+ .getKotlinResourceAssignmentProcessorInstance(
+ "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances)
+
+ assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
+
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "ra-name"
+ dictionaryName = "ra-dict-name"
+ dictionarySource = "capability"
+ property = PropertyDefinition().apply {
+ type = "string"
+ }
+ }
+
+ val processorName = resourceAssignmentProcessor.apply(resourceAssignment)
+ assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
+ println(processorName)
+ }
+
+}
+
+open class MockCapabilityService {
+
+}
\ No newline at end of file
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.apps</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+ <artifactId>blueprint-scripts</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- Database -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-script-runtime</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-test-junit</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
package org.onap.ccsdk.apps.controllerblueprints.scripts
-import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
+import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.config.*
import org.slf4j.LoggerFactory
import java.io.File
// Compile Kotlin Sources
val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
- log.info("Generated jar(${compiledJarFile.absolutePath}) status : $compiled}")
-
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector,
environment.configuration.languageVersionSettings)
if (analyzerWithCompilerReport.hasErrors()) {
- return failure()
+ return ResultWithDiagnostics.Failure(messageCollector.diagnostics)
}
}
compiler(script, scriptCompilationConfiguration)
.onSuccess {
evaluator(it, configuration)
+ }.onFailure { failedResult ->
+ val messages = failedResult.reports?.joinToString("\n")
+ throw BluePrintProcessorException(messages)
}
}
}
-
-open class BluePrintScriptEvaluator<T>(private val scriptClassName: String) : ScriptEvaluator {
+open class BluePrintScriptEvaluator(private val scriptClassName: String) : ScriptEvaluator {
private val log = LoggerFactory.getLogger(BluePrintScriptEvaluator::class.java)!!
scriptEvaluationConfiguration: ScriptEvaluationConfiguration?
): ResultWithDiagnostics<EvaluationResult> =
try {
- log.info("Getting class name($scriptClassName) of type() from the compiled sources ")
+ log.debug("Getting script class name($scriptClassName) from the compiled sources ")
val bluePrintCompiledScript = compiledScript as BluePrintCompiledScript
bluePrintCompiledScript.scriptClassFQName = scriptClassName
args.addAll(it)
}
- val instance = scriptClass.java.newInstance() as? T
+ val instance = scriptClass.java.constructors.single().newInstance(*args.toArray())
?: throw BluePrintProcessorException("failed to create instance from the script")
- log.info("Created script instance successfully....")
+ log.info("Created script instance of type ${instance.javaClass}")
ResultWithDiagnostics.Success(EvaluationResult(ResultValue.Value(scriptClass.qualifiedName!!,
instance, "", instance),
import java.io.File
import kotlin.script.experimental.annotations.KotlinScript
-import kotlin.script.experimental.api.ScriptCompilationConfiguration
-import kotlin.script.experimental.api.SourceCode
-import kotlin.script.experimental.api.defaultImports
+import kotlin.script.experimental.api.*
import kotlin.script.experimental.jvm.jvm
-import kotlin.script.experimental.jvm.util.classpathFromClassloader
+import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
@KotlinScript(
fileExtension = "cba.kts",
object BluePrintScripCompilationConfiguration : ScriptCompilationConfiguration(
{
- defaultImports(
- "org.onap.ccsdk.apps.controllerblueprints.core.*",
- "org.onap.ccsdk.apps.controllerblueprints.core.data.*",
- "org.onap.ccsdk.apps.controllerblueprints.core.interfaces.*",
- "org.onap.ccsdk.apps.controllerblueprints.core.services.*",
- "org.onap.ccsdk.apps.controllerblueprints.core.utils.*")
jvm {
- classpathFromClassloader(BluePrintScripCompilationConfiguration::class.java.classLoader)
+ //classpathFromClassloader(BluePrintScripCompilationConfiguration::class.java.classLoader)
+ classpathFromClasspathProperty()
}
+ ide{
+ acceptedLocations(ScriptAcceptedLocation.Everywhere)
+ }
+
}
)
--- /dev/null
+/*
+ * 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.controllerblueprints.scripts
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.springframework.stereotype.Service
+import java.io.File
+import kotlin.script.experimental.api.ResultValue
+import kotlin.script.experimental.api.resultOrNull
+import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
+
+@Service
+open class BluePrintScriptsServiceImpl : BluePrintScriptsService {
+
+ override fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
+ reCompile: Boolean): T {
+
+ val kotlinScriptPath = blueprintContext.rootPath.plus(File.separator)
+ .plus(BluePrintConstants.TOSCA_SCRIPTS_KOTLIN_DIR)
+
+ val compiledJar = kotlinScriptPath.plus(File.separator)
+ .plus(getBluePrintScriptsJarName(blueprintContext))
+
+ val scriptSource = BluePrintSourceCode()
+
+ val sources: MutableList<String> = arrayListOf()
+ sources.add(kotlinScriptPath)
+ scriptSource.blueprintKotlinSources = sources
+ scriptSource.moduleName = "${blueprintContext.name()}-${blueprintContext.version()}-cba-kts"
+ scriptSource.targetJarFile = File(compiledJar)
+ scriptSource.regenerate = reCompile
+
+ val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>()
+ val scriptEvaluator = BluePrintScriptEvaluator(scriptClassName)
+
+ val compiledResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource, compilationConfiguration,
+ null)
+
+ val returnValue = compiledResponse.resultOrNull()?.returnValue as? ResultValue.Value
+
+ return returnValue?.value!! as T
+ }
+
+}
+
+fun getBluePrintScriptsJarName(blueprintContext: BluePrintContext): String {
+ return "${blueprintContext.name()}-${blueprintContext.version()}-cba-kts.jar"
+}
\ No newline at end of file
import org.apache.commons.io.FileUtils
-import org.junit.Ignore
import org.junit.Test
-import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
import java.io.File
import kotlin.script.experimental.jvm.util.classpathFromClass
import kotlin.script.experimental.jvm.util.classpathFromClassloader
class BlueprintScriptingHostTest {
- @Test
- @Ignore
- fun `test classpaths`() {
+ private fun viewClassPathInfo() {
println(" *********** classpathFromClass *********** ")
classpathFromClass(BlueprintScriptingHostTest::class.java.classLoader,
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>()
- val scriptEvaluator = BluePrintScriptEvaluator<BlueprintFunctionNode<String, String>>(scriptClassName)
+ val scriptEvaluator = BluePrintScriptEvaluator(scriptClassName)
val scriptSource2 = BluePrintSourceCode()
scriptSource2.moduleName = "blueprint-test-script"