K8S Profile modification by CDS 89/102189/3
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Sun, 23 Feb 2020 17:24:00 +0000 (18:24 +0100)
committerMarco Platania <platania@research.att.com>
Fri, 28 Feb 2020 13:55:08 +0000 (13:55 +0000)
This change implements the modification of K8s
profile by CDS. The script creates the content
of tar.gz file with profile base on the included
profile tempalte and template artifcts of the
profile. This version only builds the profile file.

Change-Id: If3aafdb660b6e63ebb33892f5e8593bd0b6be392
Issue-ID: INT-1458
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt

index 30a7b72..22e4b33 100644 (file)
@@ -26,6 +26,8 @@ import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientSer
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.RestLoggerService
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.ArchiveType
 import org.apache.commons.io.IOUtils
 import org.apache.commons.io.FilenameUtils
 import org.apache.http.client.entity.EntityBuilder
@@ -51,11 +53,6 @@ import java.nio.charset.Charset
 import java.util.Base64
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 
-import java.io.BufferedInputStream
-import java.io.FileInputStream
-import java.io.FileOutputStream
-import java.util.zip.GZIPInputStream
-
 open class K8sProfileUpload : AbstractScriptComponentFunction() {
 
     private val log = LoggerFactory.getLogger(K8sProfileUpload::class.java)!!
@@ -105,7 +102,7 @@ open class K8sProfileUpload : AbstractScriptComponentFunction() {
                 if (api.hasProfile(k8sRbProfileName)) {
                     log.info("Profile Already Existing - skipping upload")
                 } else {
-                    val profileFilePath = prepareProfileFile(k8sRbProfileName)
+                    val profileFilePath: Path = prepareProfileFile(k8sRbProfileName)
 
                     var profile = K8sProfile()
                     profile.profileName = k8sRbProfileName
@@ -132,6 +129,25 @@ open class K8sProfileUpload : AbstractScriptComponentFunction() {
         if (!profileFile.exists())
             throw BluePrintProcessorException("K8s Profile template file ${profileFilePath} does not exists")
 
+        val tempMainPath: File = createTempDir("k8s-profile-", "")
+        val tempProfilePath: File = createTempDir("${k8sRbProfileName}-", "", tempMainPath)
+        log.info("Decompressing profile to ${tempProfilePath.toString()}")
+
+        val decompressedProfile: File = BluePrintArchiveUtils.deCompress(profileFilePath.toFile(),
+                "${tempProfilePath.toString()}", ArchiveType.TarGz)
+
+        log.info("${profileFilePath.toString()} decompression completed")
+
+        //Here we can add extra files inside the archive
+        profileFilePath = Paths.get(tempMainPath.toString().plus(File.separator).plus("${k8sRbProfileName}.tar.gz"))
+
+        if (!BluePrintArchiveUtils.compress(decompressedProfile, profileFilePath.toFile(),
+                        ArchiveType.TarGz)) {
+            throw BluePrintProcessorException("Profile compression has failed")
+        }
+
+        log.info("${profileFilePath.toString()} compression completed")
+
         return profileFilePath
     }