X-Git-Url: https://gerrit.onap.org/r/gitweb?p=demo.git;a=blobdiff_plain;f=heat%2FvFW_CNF_CDS%2Ftemplates%2Fcba%2FScripts%2Fkotlin%2FKotlinK8sProfileUpload.kt;h=22e4b33a06284bdec690ee88ceaf3cb6eb110a68;hp=30a7b72eae60ed33702e286e734219be49c9fcec;hb=b9f077ae5da15ba45728f6902b82bcdbbb31f2cf;hpb=83e1a98bc9656ecaa6b99446a73513e9d3419937 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 }