aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/blueprints
diff options
context:
space:
mode:
authorSebastien Premont-Tendland <sebastien.premont@bell.ca>2020-03-02 14:33:33 -0500
committerSebastien Premont-Tendland <sebastien.premont@bell.ca>2020-03-19 13:28:18 +0000
commit0562fc1c7378be67b571bb142489272a6b1b3814 (patch)
treebcf38c342cb21710725eb89c8b7cc25c91f13e66 /ms/blueprintsprocessor/modules/blueprints
parentfa12b4f311e77612e4e856b209a8c81c71f0b29d (diff)
Fix kotlin cache lazy loading
When USE_SCRIPT_COMPILATION_CACHE is set to false the classLoader is closed after the class is instantiated. This is causing an issue when lazy loading is happening during the script execution. Lazy loading occurs when a suspendible function returning something is called from "processNB", kotlin will create a second class that will be loaded during execution (needs to be in the classpath during execution). Issue-ID: CCSDK-2150 Signed-off-by: Sebastien Premont-Tendland <sebastien.premont@bell.ca> Change-Id: I64780287352d762325662e0e5d5b94038dedee7f
Diffstat (limited to 'ms/blueprintsprocessor/modules/blueprints')
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt2
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt13
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt7
3 files changed, 10 insertions, 12 deletions
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
index aa61b0c4d..0f7cb79f2 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
@@ -36,4 +36,6 @@ interface BluePrintScriptsService {
suspend fun <T> scriptInstance(cacheKey: String, scriptClassName: String): T
suspend fun <T> scriptInstance(scriptClassName: String): T
+
+ suspend fun cleanupInstance(blueprintBasePath: String)
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt
index a8c630387..a9684a14d 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt
@@ -25,11 +25,9 @@ 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.BluePrintConstants
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 org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
import java.io.File
import java.net.URLClassLoader
import java.util.ArrayList
@@ -58,13 +56,7 @@ open class BluePrintCompileService {
compile(bluePrintSourceCode)
}
- val classLoaderWithDependencies = if (BluePrintConstants.USE_SCRIPT_COMPILE_CACHE) {
- /** Get the class loader with compiled jar from cache */
- BluePrintCompileCache.classLoader(bluePrintSourceCode.cacheKey)
- } else {
- /** Get the class loader with compiled jar from disk */
- BluePrintFileUtils.getURLClassLoaderFromDirectory(bluePrintSourceCode.cacheKey)
- }
+ val classLoaderWithDependencies = BluePrintCompileCache.classLoader(bluePrintSourceCode.cacheKey)
/** Create the instance from the class loader */
return instance(classLoaderWithDependencies, kClassName, args)
@@ -126,9 +118,6 @@ open class BluePrintCompileService {
.single().newInstance(*args.toArray())
} ?: throw BluePrintException("failed to create class($kClassName) instance for constructor argument($args).")
- if (!BluePrintConstants.USE_SCRIPT_COMPILE_CACHE) {
- classLoader.close()
- }
return instance as T
}
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt
index f3eb1a2b9..fa8ca2719 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt
@@ -79,4 +79,11 @@ open class BluePrintScriptsServiceImpl : BluePrintScriptsService {
return Thread.currentThread().contextClassLoader.loadClass(scriptClassName).constructors
.single().newInstance(*args.toArray()) as T
}
+
+ override suspend fun cleanupInstance(blueprintBasePath: String) {
+ if (!BluePrintConstants.USE_SCRIPT_COMPILE_CACHE) {
+ log.info("Invalidating compile cache for blueprint ($blueprintBasePath)")
+ BluePrintCompileCache.cleanClassLoader(blueprintBasePath)
+ }
+ }
}