aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons
diff options
context:
space:
mode:
authorFrank Kimmlingen <frank.kimmlingen@telekom.de>2023-12-04 14:29:48 +0100
committerFrank Kimmlingen <frank.kimmlingen@telekom.de>2023-12-04 14:29:48 +0100
commit72ae79d15d6ebc9a06202733b2fd999fb30ea048 (patch)
treebf006fc677b8875ed0d32543136810834ec5f61f /ms/blueprintsprocessor/modules/commons
parentafc943b48bd231ef9a7eebb176e5a4b5ba6f8789 (diff)
BlueprintCompilerCacheMessageListener should also clean deploy folder
BlueprintCompilerCacheMessageListener do a cleanup of the deploy folder of the given artifactName:artifactVersion inside the deploy path. Issue-ID: CCSDK-3969 Signed-off-by: Frank Kimmlingen <frank.kimmlingen@telekom.de> Change-Id: I9cefc996feb0ddc4b20153159c59a5b89abb1b50
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons')
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListener.kt15
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/listeners/BlueprintCompilerCacheMessageListenerTest.kt68
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() }
+ }
+}