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
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)
}
val log = logger(BluePrintCompileCache::class)
private val classLoaderCache: LoadingCache<String, URLClassLoader> = CacheBuilder.newBuilder()
- .maximumSize(10)
+ .maximumSize(50)
.build(BluePrintClassLoader)
fun classLoader(key: String): URLClassLoader {
}
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 {
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.")
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)
/** 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})")
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()