diff options
Diffstat (limited to 'ms/blueprintsprocessor')
2 files changed, 80 insertions, 3 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt index 3833379c9..849a7a00c 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt @@ -16,11 +16,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.listeners +import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BlueprintClusterMessageListener import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterJoinedEvent +import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty @@ -39,9 +41,16 @@ open class BlueprintCompilerCacheMessageListener(private val clusterService: Blu } override fun onMessage(message: BluePrintClusterMessage<String>?) { - message?.let { - log.info("Received ClusterMessage - Cleaning compile cache for blueprint (${it.payload})") - BluePrintCompileCache.cleanClassLoader(it.payload) + message?.let { bluePrintClusterMessage -> + log.info("Received ClusterMessage - Cleaning compile cache for blueprint (${bluePrintClusterMessage.payload})") + val payload = bluePrintClusterMessage.payload + BluePrintCompileCache.cleanClassLoader(payload) + runBlocking { + deleteNBDir(payload).let { success -> + if (success) log.info("Deleted deployed blueprint model :$payload") + else log.info("Fail to delete deployed blueprint model :$payload") + } + } } } } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListenerTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListenerTest.kt new file mode 100644 index 000000000..bcdb0853c --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListenerTest.kt @@ -0,0 +1,68 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.core.listeners + +import io.mockk.mockk +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.BlueprintClusterTopic +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterMessage +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.BluePrintClusterService +import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterMember +import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.reCreateNBDirs +import java.io.File +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class BlueprintCompilerCacheMessageListenerTest { + private val path = "deploy" + private val artifactName = "TEST_CBA" + private val artifactVersion = "1.0.0" + private val payload = "$path/$artifactName/$artifactVersion" + private val deployFile: File = normalizedFile(path, artifactName, artifactVersion) + + @BeforeTest + fun setUp() { + runBlocking { + println("creating ${deployFile.absolutePath}") + deployFile.reCreateNBDirs() + } + } + + @AfterTest + fun cleanup() { + runBlocking { + deleteNBDir(normalizedFile(path).absolutePath) + } + } + + @Test + fun `test deleteNBDir for given path`() { + runBlocking { + assertTrue { deployFile.exists() } + println("deleting ${deployFile.absolutePath}") + deleteNBDir(deployFile.absolutePath) + assertFalse { deployFile.exists() } + } + } + @Test + fun `test onMessage`() { + assertTrue { deployFile.exists() } + val messageListener = BlueprintCompilerCacheMessageListener(mockk<BluePrintClusterService>(relaxed = true)) + messageListener.onMessage( + BluePrintClusterMessage( + BlueprintClusterTopic.BLUEPRINT_CLEAN_COMPILER_CACHE, + payload, + 1, + ClusterMember( + id = "id", + name = "memberName", + memberAddress = "memberAdress" + ) + ) + ) + assertFalse { deployFile.exists() } + } +} |