Fix compiler cache to hold for next transaction. 08/92408/2
authorBrinda Santh <brindasanth@in.ibm.com>
Wed, 31 Jul 2019 19:49:27 +0000 (15:49 -0400)
committerBrinda Santh Muthuramalingam <brindasanth@in.ibm.com>
Wed, 31 Jul 2019 22:23:14 +0000 (22:23 +0000)
Change-Id: Ibede4a378980717d49708f7665ab295534a092a0
Issue-ID: CCSDK-1046
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerCache.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt

index 094fb68..a81d35e 100644 (file)
@@ -30,6 +30,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfigur
 import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
+import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.slf4j.LoggerFactory
 import org.springframework.http.codec.multipart.FilePart
@@ -63,6 +65,10 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP
             throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
                 "Error in Upload CBA: ${e.message}", e)
         } finally {
+            // Clean blueprint script cache
+            val cacheKey = BluePrintFileUtils
+                    .compileCacheKey(normalizedPathName(bluePrintPathConfiguration.blueprintWorkingPath,saveId))
+            BluePrintCompileCache.cleanClassLoader(cacheKey)
             deleteNBDir(blueprintArchive)
             deleteNBDir(blueprintWorking)
         }
index db139eb..fa6b0ab 100644 (file)
@@ -30,7 +30,7 @@ object BluePrintCompileCache {
     val log = logger(BluePrintCompileCache::class)
 
     private val classLoaderCache: LoadingCache<String, URLClassLoader> = CacheBuilder.newBuilder()
-            .maximumSize(10)
+            .maximumSize(50)
             .build(BluePrintClassLoader)
 
     fun classLoader(key: String): URLClassLoader {
@@ -38,8 +38,12 @@ object BluePrintCompileCache {
     }
 
     fun cleanClassLoader(key: String) {
-        classLoaderCache.invalidate(key)
-        log.info("Cleaned script cache($key)")
+        if(hasClassLoader(key)){
+            classLoaderCache.invalidate(key)
+            log.info("Cleaned compiled cache($key)")
+        }else{
+            log.warn("No compiled cache($key) present to clean.")
+        }
     }
 
     fun hasClassLoader(key: String): Boolean {
@@ -52,7 +56,7 @@ object BluePrintClassLoader : CacheLoader<String, URLClassLoader>() {
     val log = logger(BluePrintClassLoader::class)
 
     override fun load(key: String): URLClassLoader {
-        log.info("loading cache key($key)")
+        log.info("loading compiled cache($key)")
         val keyPath = normalizedFile(key)
         if (!keyPath.exists()) {
             throw BluePrintException("failed to load cache($key), missing files.")
@@ -61,7 +65,7 @@ object BluePrintClassLoader : CacheLoader<String, URLClassLoader>() {
         keyPath.walkTopDown()
                 .filter { it.name.endsWith("cba-kts.jar") }
                 .forEach {
-                    log.debug("Adding (${it.absolutePath}) to cache key($key)")
+                    log.debug("Adding (${it.absolutePath}) to cache($key)")
                     urls.add(it.toURI().toURL())
                 }
         return URLClassLoader(urls.toTypedArray(), this.javaClass.classLoader)
index e231f6d..5466312 100644 (file)
@@ -63,6 +63,9 @@ open class BluePrintsCompilerProxy(private val hostConfiguration: ScriptingHostC
             /** 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})")
 
index 3a1edcc..669ab3f 100644 (file)
@@ -186,7 +186,7 @@ class BluePrintMetadataUtils {
             val bluePrintScriptsService = BluePrintScriptsServiceImpl()
             val bluePrintDefinitions = bluePrintScriptsService
                     .scriptInstance<BluePrintDefinitions>(normalizedBasePath, toscaMetaData.templateName!!,
-                            toscaMetaData.templateVersion!!, definitionClassName, true)
+                            toscaMetaData.templateVersion!!, definitionClassName, false)
             // Get the Service Template
             val serviceTemplate = bluePrintDefinitions.serviceTemplate()