Fixed k8s profile upload for source with tar.gz file 35/113735/1
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Fri, 9 Oct 2020 21:19:07 +0000 (23:19 +0200)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Fri, 9 Oct 2020 21:19:50 +0000 (23:19 +0200)
Fixed k8s profile upload for source with tar.gz file
Change was tested with CBA https://gerrit.onap.org/r/c/demo/+/113732

Change-Id: I08aa834cc4fedaf77b4c660ec16dea930dade588
Issue-ID: CCSDK-2899
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadComponent.kt

index 6b575a6..76b7fae 100644 (file)
@@ -198,16 +198,13 @@ open class K8sProfileUploadComponent(
     private suspend fun prepareProfileFile(k8sRbProfileName: String, ks8ProfileSource: String, ks8ProfileLocation: String): Path {
         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
         val bluePrintBasePath: String = bluePrintContext.rootPath
-        val profileSourceFileFolderPath: String = bluePrintBasePath.plus(File.separator)
-            .plus(ks8ProfileLocation)
-        val profileFilePathTarGz: String = profileSourceFileFolderPath.plus(".tar.gz")
-        val profileFilePathTgz: String = profileSourceFileFolderPath.plus(".tgz")
+        val profileSourceFileFolderPath: Path = Paths.get(
+            bluePrintBasePath.plus(File.separator).plus(ks8ProfileLocation)
+        )
 
-        if (Paths.get(profileFilePathTarGz).toFile().exists())
-            return Paths.get(profileFilePathTarGz)
-        else if (Paths.get(profileFilePathTgz).toFile().exists())
-            return Paths.get(profileFilePathTgz)
-        else if (Paths.get(profileSourceFileFolderPath).toFile().exists()) {
+        if (profileSourceFileFolderPath.toFile().exists() && !profileSourceFileFolderPath.toFile().isDirectory)
+            return profileSourceFileFolderPath
+        else if (profileSourceFileFolderPath.toFile().exists()) {
             log.info("Profile building started from source $ks8ProfileSource")
             val properties: MutableMap<String, Any> = mutableMapOf()
             properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = false
@@ -227,12 +224,12 @@ open class K8sProfileUploadComponent(
 
             try {
                 val manifestFiles: ArrayList<File>? = readManifestFiles(
-                    Paths.get(profileSourceFileFolderPath).toFile(),
+                    profileSourceFileFolderPath.toFile(),
                     tempProfilePath
                 )
                 if (manifestFiles != null) {
                     templateLocation(
-                        Paths.get(profileSourceFileFolderPath).toFile(), resolutionResult.second,
+                        profileSourceFileFolderPath.toFile(), resolutionResult.second,
                         tempProfilePath, manifestFiles
                     )
                 } else
@@ -258,7 +255,7 @@ open class K8sProfileUploadComponent(
                 throw t
             }
         } else
-            throw BluePrintProcessorException("Profile source $ks8ProfileSource is missing in CBA folder")
+            throw BluePrintProcessorException("Profile source $ks8ProfileLocation is missing in CBA folder")
     }
 
     private fun readManifestFiles(profileSource: File, destinationFolder: File): ArrayList<File>? {