Ensure proper unloading of resources associated with the dynamic classloader for... 17/95517/1
authorSerge Simard <serge@agilitae.com>
Wed, 11 Sep 2019 17:38:15 +0000 (13:38 -0400)
committerSerge Simard <serge@agilitae.com>
Wed, 11 Sep 2019 17:40:21 +0000 (13:40 -0400)
Issue-ID: CCSDK-1692

Signed-off-by: Serge Simard <serge@agilitae.com>
Change-Id: Ic1c1bf263331bf4a43d855798d2d62ec97503ceb

ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerCache.kt

index 9ce45d1..3e0f351 100755 (executable)
@@ -117,6 +117,10 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu
             blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion)
             val deployFile =
                     normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion)
+
+            val cacheKey = BluePrintFileUtils.compileCacheKey(deployFile)
+            BluePrintCompileCache.cleanClassLoader(cacheKey)
+
             deleteNBDir(deployFile).let {
                 if (it) log.info("Deleted deployed blueprint model :$artifactName::$artifactVersion")
                 else log.info("Fail to delete deployed blueprint model :$artifactName::$artifactVersion")
index 66b5d00..4c02fda 100755 (executable)
@@ -21,14 +21,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.service
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.*
 import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
-import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
-import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPath
+import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.slf4j.LoggerFactory
 import org.springframework.dao.DataIntegrityViolationException
 import org.springframework.stereotype.Service
@@ -85,6 +84,12 @@ class ControllerBlueprintCatalogServiceImpl(bluePrintDesignTimeValidatorService:
             throw BluePrintException("Not a valid Archive file(${archiveFile.absolutePath})")
         }
 
+        // cleanup up deploy folder for the Blueprint
+        val blueprintDeploy = normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath,
+                                    artifactName, artifactVersion)
+        val cacheKey = BluePrintFileUtils.compileCacheKey(blueprintDeploy)
+        BluePrintCompileCache.cleanClassLoader(cacheKey)
+
         blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
             log.info("Overwriting blueprint model :$artifactName::$artifactVersion")
             blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion)
index fa6b0ab..f90e27f 100644 (file)
@@ -39,6 +39,10 @@ object BluePrintCompileCache {
 
     fun cleanClassLoader(key: String) {
         if(hasClassLoader(key)){
+            // Make sure to close all classloader loaded resources before we let go of it.
+            // This fixes a Delete failure message on filesystem that keeps locks on opened jars;
+            // like Windows and NFS.
+            classLoaderCache.get(key).close()
             classLoaderCache.invalidate(key)
             log.info("Cleaned compiled cache($key)")
         }else{