From b9f077ae5da15ba45728f6902b82bcdbbb31f2cf Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Sun, 23 Feb 2020 18:24:00 +0100 Subject: [PATCH] K8S Profile modification by CDS 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 --- .../cba/Scripts/kotlin/KotlinK8sProfileUpload.kt | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt index 30a7b72e..22e4b33a 100644 --- a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt @@ -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 } -- 2.16.6