diff options
Diffstat (limited to 'ms/controllerblueprints')
15 files changed, 219 insertions, 430 deletions
diff --git a/ms/controllerblueprints/README_FIRST.txt b/ms/controllerblueprints/README_FIRST.txt deleted file mode 100644 index e69de29bb..000000000 --- a/ms/controllerblueprints/README_FIRST.txt +++ /dev/null diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt new file mode 100644 index 000000000..baae3372d --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt @@ -0,0 +1,174 @@ +/* + * Copyright © 2019 IBM. + * + * 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.cds.controllerblueprints.core.scripts + +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope +import org.jetbrains.kotlin.cli.common.ExitCode +import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler +import org.jetbrains.kotlin.config.Services +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import java.io.File +import java.net.URLClassLoader +import java.util.* +import kotlin.script.experimental.api.SourceCode +import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty +import kotlin.system.measureTimeMillis + + +open class BluePrintCompileService { + val log = logger(BluePrintCompileService::class) + + companion object { + val classPaths = classpathFromClasspathProperty()?.joinToString(File.pathSeparator) { + it.absolutePath + } + } + + /** Compile the [bluePrintSourceCode] and get the [kClassName] instance for the constructor [args] */ + suspend fun <T> eval(bluePrintSourceCode: BluePrintSourceCode, kClassName: String, + args: ArrayList<Any?>?): T { + /** Compile the source code */ + compile(bluePrintSourceCode) + /** Get the class loader with compiled jar */ + val classLoaderWithDependencies = BluePrintCompileCache.classLoader(bluePrintSourceCode.cacheKey) + /* Create the instance from the class loader */ + return instance(classLoaderWithDependencies, kClassName, args) + } + + /** Compile [bluePrintSourceCode] and put into cache */ + suspend fun compile(bluePrintSourceCode: BluePrintSourceCode) { + //TODO("Include Multiple folders") + val sourcePath = bluePrintSourceCode.blueprintKotlinSources.first() + val compiledJarFile = bluePrintSourceCode.targetJarFile + + /** Check cache is present for the blueprint scripts */ + val hasCompiledCache = BluePrintCompileCache.hasClassLoader(bluePrintSourceCode.cacheKey) + + log.debug("Jar Exists : ${compiledJarFile.exists()}, Regenerate : ${bluePrintSourceCode.regenerate}," + + " Compiled hash(${bluePrintSourceCode.cacheKey}) : $hasCompiledCache") + + if (!compiledJarFile.exists() || bluePrintSourceCode.regenerate || !hasCompiledCache) { + log.info("compiling for cache key(${bluePrintSourceCode.cacheKey})") + coroutineScope { + val timeTaken = measureTimeMillis { + /** Create compile arguments */ + val args = mutableListOf<String>().apply { + add("-no-stdlib") + add("-no-reflect") + add("-module-name") + add(bluePrintSourceCode.moduleName) + add("-cp") + add(classPaths!!) + add(sourcePath) + add("-d") + add(compiledJarFile.absolutePath) + } + val deferredCompile = async { + val k2jvmCompiler = K2JVMCompiler() + /** Construct Arguments */ + val arguments = k2jvmCompiler.createArguments() + parseCommandLineArguments(args, arguments) + val messageCollector = CompilationMessageCollector() + /** Compile with arguments */ + val exitCode: ExitCode = k2jvmCompiler.exec(messageCollector, Services.EMPTY, arguments) + when (exitCode) { + ExitCode.OK -> { + checkFileExists(compiledJarFile) + { "couldn't generate compiled jar(${compiledJarFile.absolutePath})" } + } + else -> { + throw BluePrintException("$exitCode :${messageCollector.errors().joinToString("\n")}") + } + } + } + deferredCompile.await() + } + log.info("compiled in ($timeTaken)mSec for cache key(${bluePrintSourceCode.cacheKey})") + } + } + } + + /** create class [kClassName] instance from [classLoader] */ + fun <T> instance(classLoader: URLClassLoader, kClassName: String, args: ArrayList<Any?>? = arrayListOf()): T { + val kClazz = classLoader.loadClass(kClassName) + ?: throw BluePrintException("failed to load class($kClassName) from current class loader.") + + val instance = if (args.isNullOrEmpty()) { + kClazz.newInstance() + } else { + kClazz.constructors + .single().newInstance(*args.toArray()) + } ?: throw BluePrintException("failed to create class($kClassName) instance for constructor argument($args).") + return instance as T + } +} + +/** Compile source code information */ +open class BluePrintSourceCode : SourceCode { + lateinit var blueprintKotlinSources: MutableList<String> + lateinit var moduleName: String + lateinit var targetJarFile: File + lateinit var cacheKey: String + var regenerate: Boolean = false + + override val text: String + get() = "" + + override val locationId: String? = null + + override val name: String? + get() = moduleName +} + +/** Class to collect compilation Data */ +data class CompiledMessageData( + val severity: CompilerMessageSeverity, + val message: String, + val location: CompilerMessageLocation? +) + +/** Class to collect compilation results */ +class CompilationMessageCollector : MessageCollector { + + private val compiledMessages: MutableList<CompiledMessageData> = arrayListOf() + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { + synchronized(compiledMessages) { + compiledMessages.add(CompiledMessageData(severity, message, location)) + } + } + + override fun hasErrors() = + synchronized(compiledMessages) { + compiledMessages.any { it.severity.isError } + } + + override fun clear() { + synchronized(compiledMessages) { + compiledMessages.clear() + } + } + + fun errors(): List<CompiledMessageData> = compiledMessages.filter { it.severity == CompilerMessageSeverity.ERROR } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompiledScript.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompiledScript.kt deleted file mode 100644 index 2f131f6f6..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompiledScript.kt +++ /dev/null @@ -1,51 +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.cds.controllerblueprints.core.scripts - -import java.io.Serializable -import kotlin.reflect.KClass -import kotlin.script.experimental.api.* - -open class BluePrintCompiledScript<out BCS : String>( - val cacheKey: String, - val scriptCompilationConfiguration: ScriptCompilationConfiguration) : - CompiledScript<BCS>, Serializable { - - lateinit var scriptClassFQName: String - - override val compilationConfiguration: ScriptCompilationConfiguration - get() = scriptCompilationConfiguration - - override suspend fun getClass(scriptEvaluationConfiguration: ScriptEvaluationConfiguration?) - : ResultWithDiagnostics<KClass<*>> = try { - - /** Get the class loader from the cache */ - val classLoaderWithDependencies = BluePrintCompileCache.classLoader(cacheKey) - - val clazz = classLoaderWithDependencies.loadClass(scriptClassFQName).kotlin - clazz.asSuccess() - } catch (e: Throwable) { - ResultWithDiagnostics.Failure( - ScriptDiagnostic( - "Unable to instantiate class $scriptClassFQName", - exception = e - ) - ) - } - -} - diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt deleted file mode 100644 index 546631240..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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. - * 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.cds.controllerblueprints.core.scripts - -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.common.messages.AnalyzerWithCompilerReport -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity -import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles -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.onap.ccsdk.cds.controllerblueprints.core.checkFileExists -import org.slf4j.LoggerFactory -import kotlin.script.experimental.api.* -import kotlin.script.experimental.host.ScriptingHostConfiguration -import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty -import kotlin.script.experimental.jvmhost.KJvmCompilerProxy - -open class BluePrintsCompilerProxy(private val hostConfiguration: ScriptingHostConfiguration) : KJvmCompilerProxy { - - private val log = LoggerFactory.getLogger(BluePrintsCompilerProxy::class.java)!! - - override fun compile(script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration) - : ResultWithDiagnostics<CompiledScript<*>> { - - val messageCollector = ScriptDiagnosticsMessageCollector() - - fun failure(vararg diagnostics: ScriptDiagnostic): ResultWithDiagnostics.Failure = - ResultWithDiagnostics.Failure(*messageCollector.diagnostics.toTypedArray(), *diagnostics) - - // Compile the Code - try { - - log.trace("Scripting Host Configuration : $hostConfiguration") - - setIdeaIoUseFallback() - - val blueprintSourceCode = script as BluePrintSourceCode - - val compiledJarFile = blueprintSourceCode.targetJarFile - - /** Check cache is present for the blueprint scripts */ - val hasCompiledCache = BluePrintCompileCache.hasClassLoader(blueprintSourceCode.cacheKey) - - log.debug("Jar Exists : ${compiledJarFile.exists()}, Regenerate : ${blueprintSourceCode.regenerate}," + - " Compiled hash(${blueprintSourceCode.cacheKey}) : $hasCompiledCache") - - if (!compiledJarFile.exists() || blueprintSourceCode.regenerate || !hasCompiledCache) { - log.info("compiling for cache key(${blueprintSourceCode.cacheKey})") - - var environment: KotlinCoreEnvironment? = null - - val rootDisposable = Disposer.newDisposable() - - try { - - // Clean the cache, if present - if (hasCompiledCache) { - BluePrintCompileCache.cleanClassLoader(blueprintSourceCode.cacheKey) - } - - val compilerConfiguration = CompilerConfiguration().apply { - - put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) - put(CommonConfigurationKeys.MODULE_NAME, blueprintSourceCode.moduleName) - put(JVMConfigurationKeys.OUTPUT_JAR, compiledJarFile) - put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, false) - - // Load Current Class loader to Compilation Class loader - val currentClassLoader = classpathFromClasspathProperty() - currentClassLoader?.forEach { - add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(it)) - } - - // Add all Kotlin Sources - addKotlinSourceRoots(blueprintSourceCode.blueprintKotlinSources) - // for Kotlin 1.3.30 greater - //add(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS, ScriptingCompilerConfigurationComponentRegistrar()) - - languageVersionSettings = LanguageVersionSettingsImpl( - LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlags.skipMetadataVersionCheck to true) - ) - } - - //log.info("Executing with compiler configuration : $compilerConfiguration") - - environment = KotlinCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration, - EnvironmentConfigFiles.JVM_CONFIG_FILES) - - // Compile Kotlin Sources - val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment) - - val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector, - environment.configuration.languageVersionSettings) - - if (analyzerWithCompilerReport.hasErrors()) { - return ResultWithDiagnostics.Failure(messageCollector.diagnostics) - } - } finally { - rootDisposable.dispose() - } - } - - checkFileExists(compiledJarFile) { "couldn't generate compiled jar(${compiledJarFile.absolutePath})" } - - val compiledScript = BluePrintCompiledScript<String>(blueprintSourceCode.cacheKey, scriptCompilationConfiguration) - - return compiledScript.asSuccess() - - } catch (ex: Throwable) { - return failure(ex.asDiagnostics()) - } - } -} - -class ScriptDiagnosticsMessageCollector : MessageCollector { - - private val _diagnostics = arrayListOf<ScriptDiagnostic>() - - val diagnostics: List<ScriptDiagnostic> get() = _diagnostics - - override fun clear() { - _diagnostics.clear() - } - - override fun hasErrors(): Boolean = - _diagnostics.any { it.severity == ScriptDiagnostic.Severity.ERROR } - - - override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { - val mappedSeverity = when (severity) { - CompilerMessageSeverity.EXCEPTION, - CompilerMessageSeverity.ERROR -> ScriptDiagnostic.Severity.ERROR - CompilerMessageSeverity.STRONG_WARNING, - CompilerMessageSeverity.WARNING -> ScriptDiagnostic.Severity.WARNING - CompilerMessageSeverity.INFO -> ScriptDiagnostic.Severity.INFO - CompilerMessageSeverity.LOGGING -> ScriptDiagnostic.Severity.DEBUG - else -> null - } - if (mappedSeverity != null) { - val mappedLocation = location?.let { - if (it.line < 0 && it.column < 0) null // special location created by CompilerMessageLocation.create - else SourceCode.Location(SourceCode.Position(it.line, it.column)) - } - _diagnostics.add(ScriptDiagnostic(message, mappedSeverity, location?.path, mappedLocation)) - } - } -} - diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptingHost.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptingHost.kt deleted file mode 100644 index d35f2b49b..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptingHost.kt +++ /dev/null @@ -1,94 +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.cds.controllerblueprints.core.scripts - -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.slf4j.LoggerFactory -import java.util.* -import kotlin.reflect.full.createInstance -import kotlin.script.experimental.api.* -import kotlin.script.experimental.host.BasicScriptingHost -import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration -import kotlin.script.experimental.jvmhost.JvmScriptCompiler -import kotlin.script.experimental.jvmhost.impl.withDefaults - -val blueprintScriptCompiler = JvmScriptCompiler(defaultJvmScriptingHostConfiguration, - BluePrintsCompilerProxy(defaultJvmScriptingHostConfiguration.withDefaults())) - -open class BlueprintScriptingHost(evaluator: ScriptEvaluator) : BasicScriptingHost(blueprintScriptCompiler, evaluator) { - - override fun eval(script: SourceCode, compilationConfiguration: ScriptCompilationConfiguration, - evaluationConfiguration: ScriptEvaluationConfiguration?): ResultWithDiagnostics<EvaluationResult> = - - runInCoroutineContext { - blueprintScriptCompiler(script, compilationConfiguration) - .onSuccess { compiledScript -> - evaluator(compiledScript, evaluationConfiguration ?: ScriptEvaluationConfiguration.Default) - }.onFailure { failedResult -> - val messages = failedResult.reports.joinToString("\n") - throw BluePrintProcessorException(messages) - } - } -} - -open class BluePrintScriptEvaluator(private val scriptClassName: String) : ScriptEvaluator { - - private val log = LoggerFactory.getLogger(BluePrintScriptEvaluator::class.java)!! - - override suspend operator fun invoke(compiledScript: CompiledScript<*>, - scriptEvaluationConfiguration: ScriptEvaluationConfiguration - ): ResultWithDiagnostics<EvaluationResult> = - try { - log.debug("Getting script class name($scriptClassName) from the compiled sources ") - - val bluePrintCompiledScript = compiledScript as BluePrintCompiledScript - bluePrintCompiledScript.scriptClassFQName = scriptClassName - - when (val classResult = compiledScript.getClass(scriptEvaluationConfiguration)) { - is ResultWithDiagnostics.Failure -> classResult - is ResultWithDiagnostics.Success -> { - - val scriptClass = classResult.value - val args = ArrayList<Any?>() - scriptEvaluationConfiguration.get(ScriptEvaluationConfiguration.providedProperties)?.forEach { - args.add(it.value) - } - scriptEvaluationConfiguration.get(ScriptEvaluationConfiguration.implicitReceivers)?.let { - args.addAll(it) - } - scriptEvaluationConfiguration.get(ScriptEvaluationConfiguration.constructorArgs)?.let { - args.addAll(it) - } - - val instance = if (args.isNotEmpty()) { - scriptClass.java.constructors.single().newInstance(*args.toArray()) - ?: throw BluePrintProcessorException("failed to create instance from the script") - } else { - scriptClass.createInstance() - } - - log.debug("Created script instance of type ${instance.javaClass}") - - ResultWithDiagnostics.Success(EvaluationResult(ResultValue.Value(scriptClass.qualifiedName!!, - instance, "", instance), - scriptEvaluationConfiguration)) - } - } - } catch (e: Throwable) { - ResultWithDiagnostics.Failure(e.asDiagnostics("Error evaluating script")) - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsConfiguration.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsConfiguration.kt deleted file mode 100644 index e01923723..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsConfiguration.kt +++ /dev/null @@ -1,59 +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.cds.controllerblueprints.core.scripts - -import java.io.File -import kotlin.script.experimental.annotations.KotlinScript -import kotlin.script.experimental.api.* -import kotlin.script.experimental.jvm.jvm -import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty - -@KotlinScript( - fileExtension = "cba.kts", - compilationConfiguration = BluePrintScripCompilationConfiguration::class, - displayName = "Controller Blueprint Archive Kotlin Scripts" -) -abstract class BluePrintKotlinScript - -object BluePrintScripCompilationConfiguration : ScriptCompilationConfiguration( - { - jvm { - //classpathFromClassloader(BluePrintScripCompilationConfiguration::class.java.classLoader) - classpathFromClasspathProperty() - } - ide { - acceptedLocations(ScriptAcceptedLocation.Everywhere) - } - - } -) - -open class BluePrintSourceCode : SourceCode { - lateinit var blueprintKotlinSources: MutableList<String> - lateinit var moduleName: String - lateinit var targetJarFile: File - lateinit var cacheKey: String - var regenerate: Boolean = false - - override val text: String - get() = "" - - override val locationId: String? = null - - override val name: String? - get() = moduleName -} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt index 360035327..c067bf3d9 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt @@ -24,9 +24,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import java.util.* -import kotlin.script.experimental.api.ResultValue -import kotlin.script.experimental.api.resultOrNull -import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate open class BluePrintScriptsServiceImpl : BluePrintScriptsService { @@ -34,14 +31,8 @@ open class BluePrintScriptsServiceImpl : BluePrintScriptsService { val log = logger(BluePrintScriptsServiceImpl::class) override suspend fun <T> scriptInstance(bluePrintSourceCode: BluePrintSourceCode, scriptClassName: String): T { - val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>() - val scriptEvaluator = BluePrintScriptEvaluator(scriptClassName) - - val compiledResponse = BlueprintScriptingHost(scriptEvaluator) - .eval(bluePrintSourceCode, compilationConfiguration, null) - - val returnValue = compiledResponse.resultOrNull()?.returnValue as? ResultValue.Value - return returnValue?.value!! as T + val bluePrintCompileService = BluePrintCompileService() + return bluePrintCompileService.eval(bluePrintSourceCode, scriptClassName, null) } override suspend fun <T> scriptInstance(blueprintBasePath: String, artifactName: String, artifactVersion: String, diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt index 2f082db9c..097967313 100755 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt @@ -21,23 +21,12 @@ package org.onap.ccsdk.cds.controllerblueprints.core.utils import com.google.common.base.Predicates import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.slf4j.LoggerFactory -import java.io.BufferedInputStream -import java.io.ByteArrayOutputStream -import java.io.File -import java.io.FileOutputStream -import java.io.IOException -import java.io.OutputStream -import java.nio.charset.Charset -import java.nio.file.FileVisitResult -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.SimpleFileVisitor -import java.nio.file.attribute.BasicFileAttributes -import java.util.function.Predicate -import java.util.zip.Deflater -import java.util.zip.ZipEntry -import java.util.zip.ZipFile -import java.util.zip.ZipOutputStream +import java.io.* +import java.nio.charset.* +import java.nio.file.* +import java.nio.file.attribute.* +import java.util.function.* +import java.util.zip.* class BluePrintArchiveUtils { diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt index 17a7fd348..06f6f1d17 100755 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt @@ -32,10 +32,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.slf4j.LoggerFactory import java.io.File import java.io.FileFilter -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths -import java.nio.file.StandardOpenOption +import java.nio.file.* class BluePrintFileUtils { diff --git a/ms/controllerblueprints/modules/blueprint-proto/pom.xml b/ms/controllerblueprints/modules/blueprint-proto/pom.xml index eb4dd9f78..91097b9d9 100644 --- a/ms/controllerblueprints/modules/blueprint-proto/pom.xml +++ b/ms/controllerblueprints/modules/blueprint-proto/pom.xml @@ -66,19 +66,21 @@ </pluginArtifact> </configuration> </execution> -<!-- <execution>--> -<!-- <id>grpc-coroutines</id>--> -<!-- <goals>--> -<!-- <goal>compile-custom</goal>--> -<!-- </goals>--> -<!-- <configuration>--> -<!-- <pluginId>kroto-plus</pluginId>--> -<!-- <pluginArtifact>--> -<!-- com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:${kroto-plus.version}:jar:jvm8--> -<!-- </pluginArtifact>--> -<!-- <pluginParameter>ConfigPath=${project.basedir}/krotoPlusConfig.asciipb</pluginParameter>--> -<!-- </configuration>--> -<!-- </execution>--> + <!-- + <execution> + <id>grpc-coroutines</id> + <goals> + <goal>compile-custom</goal> + </goals> + <configuration> + <pluginId>kroto-plus</pluginId> + <pluginArtifact> + com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:${kroto-plus.version}:jar:jvm8 + </pluginArtifact> + <pluginParameter>ConfigPath=${project.basedir}/krotoPlusConfig.asciipb</pluginParameter> + </configuration> + </execution> + --> </executions> </plugin> <plugin> @@ -95,7 +97,7 @@ <sourceDirs> <sourceDir>${project.basedir}/target/generated-sources/protobuf/java</sourceDir> <sourceDir>${project.basedir}/target/generated-sources/protobuf/grpc-java</sourceDir> -<!-- <sourceDir>${project.basedir}/target/generated-sources/protobuf/kroto-plus</sourceDir>--> + <!--<sourceDir>${project.basedir}/target/generated-sources/protobuf/kroto-plus</sourceDir>--> </sourceDirs> </configuration> </execution> diff --git a/ms/controllerblueprints/modules/blueprint-validation/pom.xml b/ms/controllerblueprints/modules/blueprint-validation/pom.xml index 40fff14d4..5bc2e2a6b 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/pom.xml +++ b/ms/controllerblueprints/modules/blueprint-validation/pom.xml @@ -47,7 +47,6 @@ <artifactId>resource-dict</artifactId> </dependency> - <!--Testing dependencies--> <dependency> <groupId>org.jetbrains.kotlin</groupId> diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java index ce479d6df..16b02d86c 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils; - import com.fasterxml.jackson.databind.JsonNode; import org.junit.Assert; import org.junit.Test; @@ -27,11 +26,11 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment; import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * ResourceDictionaryUtilsTest. diff --git a/ms/controllerblueprints/parent/pom.xml b/ms/controllerblueprints/parent/pom.xml index 62f300c0a..c5e01a6b6 100644 --- a/ms/controllerblueprints/parent/pom.xml +++ b/ms/controllerblueprints/parent/pom.xml @@ -36,11 +36,17 @@ <guava.version>27.0.1-jre</guava.version> <kroto-plus.version>0.5.0</kroto-plus.version> <springfox.swagger2.version>2.9.2</springfox.swagger2.version> + <h2database.version>1.4.197</h2database.version> <onap.logger.slf4j>1.2.2</onap.logger.slf4j> <powermock.version>1.7.4</powermock.version> + <jinja.version>2.5.1</jinja.version> <velocity.version>1.7</velocity.version> + <json-smart.version>2.3</json-smart.version> + <commons-io-version>2.6</commons-io-version> + <commons-lang3-version>3.2.1</commons-lang3-version> + <commons-collections-version>3.2.2</commons-collections-version> </properties> <dependencyManagement> @@ -87,17 +93,17 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.2.1</version> + <version>${commons-lang3-version}</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> - <version>3.2.2</version> + <version>${commons-collections-version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> - <version>2.6</version> + <version>${commons-io-version}</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> @@ -114,6 +120,11 @@ <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> + <dependency> + <groupId>net.minidev</groupId> + <artifactId>json-smart</artifactId> + <version>${json-smart.version}</version> + </dependency> <!-- Kotlin Dependencies --> <dependency> @@ -219,7 +230,6 @@ <version>${h2database.version}</version> </dependency> - <!-- Application Components --> <dependency> <groupId>org.onap.ccsdk.cds.controllerblueprints</groupId> @@ -294,6 +304,10 @@ </exclusions> </dependency> <dependency> + <groupId>net.minidev</groupId> + <artifactId>json-smart</artifactId> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> diff --git a/ms/controllerblueprints/repoproject.txt b/ms/controllerblueprints/repoproject.txt deleted file mode 100644 index 91a5c8e67..000000000 --- a/ms/controllerblueprints/repoproject.txt +++ /dev/null @@ -1 +0,0 @@ -ST_SDNCMS diff --git a/ms/controllerblueprints/time.txt b/ms/controllerblueprints/time.txt deleted file mode 100644 index 6ed29fb4a..000000000 --- a/ms/controllerblueprints/time.txt +++ /dev/null @@ -1 +0,0 @@ -Current time : 17:38:06 |