summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-02-15 09:15:35 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-02-17 09:46:44 -0500
commit2ba3b4353edf536ecd15b9fb8af5a326d0b34e01 (patch)
tree506594ee64cbf7935e5e79262292ab74dc13ab36 /ms/controllerblueprints/modules
parent826d1d8a514e0fa037380413eca9e6339ba16eb2 (diff)
restconf kotlin script support
Change-Id: I07eaa4a2422b461e1b7eb13ec04bf7d10ea08770 Issue-ID: CCSDK-1080 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt4
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt5
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintCompilerProxy.kt56
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt7
4 files changed, 46 insertions, 26 deletions
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 0c8209f49..8724a9f3f 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
@@ -46,6 +46,10 @@ object BluePrintConstants {
const val DATA_TYPE_MAP: String = "map"
const val DATA_TYPE_JSON: String = "json"
+ const val SCRIPT_KOTLIN = "kotlin"
+ const val SCRIPT_JYTHON = "jython"
+ const val SCRIPT_INTERNAL = "internal"
+
const val USER_SYSTEM: String = "System"
const val PATH_DIVIDER: String = "/"
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
index 124c167a8..ac682553b 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.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.
@@ -18,8 +19,10 @@ package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
-interface BluePrintScriptsService{
+interface BluePrintScriptsService {
fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
reCompile: Boolean): T
+
+ fun <T> scriptInstance(scriptClassName: String): T
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintCompilerProxy.kt b/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintCompilerProxy.kt
index ce9553c0e..572724d07 100644
--- a/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintCompilerProxy.kt
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintCompilerProxy.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.
@@ -65,40 +66,45 @@ open class BluePrintsCompilerProxy(private val hostConfiguration: ScriptingHostC
val rootDisposable = Disposer.newDisposable()
- val compilerConfiguration = CompilerConfiguration().apply {
+ try {
- put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
- put(CommonConfigurationKeys.MODULE_NAME, blueprintSourceCode.moduleName)
- put(JVMConfigurationKeys.OUTPUT_JAR, compiledJarFile)
- put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, false)
+ val compilerConfiguration = CompilerConfiguration().apply {
- // Load Current Class loader to Compilation Class loader
- val currentClassLoader = classpathFromClasspathProperty()
- currentClassLoader?.forEach {
- add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(it))
- }
+ put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
+ put(CommonConfigurationKeys.MODULE_NAME, blueprintSourceCode.moduleName)
+ put(JVMConfigurationKeys.OUTPUT_JAR, compiledJarFile)
+ put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, false)
- // Add all Kotlin Sources
- addKotlinSourceRoots(blueprintSourceCode.blueprintKotlinSources)
+ // Load Current Class loader to Compilation Class loader
+ val currentClassLoader = classpathFromClasspathProperty()
+ currentClassLoader?.forEach {
+ add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(it))
+ }
- languageVersionSettings = LanguageVersionSettingsImpl(
- LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlags.skipMetadataVersionCheck to true)
- )
- }
+ // Add all Kotlin Sources
+ addKotlinSourceRoots(blueprintSourceCode.blueprintKotlinSources)
- //log.info("Executing with compiler configuration : $compilerConfiguration")
+ languageVersionSettings = LanguageVersionSettingsImpl(
+ LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlags.skipMetadataVersionCheck to true)
+ )
+ }
- environment = KotlinCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration,
- EnvironmentConfigFiles.JVM_CONFIG_FILES)
+ //log.info("Executing with compiler configuration : $compilerConfiguration")
- // Compile Kotlin Sources
- val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
+ environment = KotlinCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration,
+ EnvironmentConfigFiles.JVM_CONFIG_FILES)
- val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector,
- environment.configuration.languageVersionSettings)
+ // Compile Kotlin Sources
+ val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
- if (analyzerWithCompilerReport.hasErrors()) {
- return ResultWithDiagnostics.Failure(messageCollector.diagnostics)
+ val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector,
+ environment.configuration.languageVersionSettings)
+
+ if (analyzerWithCompilerReport.hasErrors()) {
+ return ResultWithDiagnostics.Failure(messageCollector.diagnostics)
+ }
+ } finally {
+ rootDisposable.dispose()
}
}
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt
index e1365523d..4840fc9ba 100644
--- a/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BluePrintScriptsServiceImpl.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.
@@ -21,6 +22,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScripts
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.springframework.stereotype.Service
import java.io.File
+import java.util.*
import kotlin.script.experimental.api.ResultValue
import kotlin.script.experimental.api.resultOrNull
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
@@ -57,6 +59,11 @@ open class BluePrintScriptsServiceImpl : BluePrintScriptsService {
return returnValue?.value!! as T
}
+ override fun <T> scriptInstance(scriptClassName: String): T {
+ val args = ArrayList<Any?>()
+ return Thread.currentThread().contextClassLoader.loadClass(scriptClassName).constructors
+ .single().newInstance(*args.toArray()) as T
+ }
}
fun getBluePrintScriptsJarName(blueprintContext: BluePrintContext): String {