aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/db-resources
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-25 17:01:08 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-27 13:23:06 -0400
commitc3811effed948926f8d94615df7530c99d490092 (patch)
treedff68af7c67bc9db332fa43b7a882d1a1b05b4db /ms/controllerblueprints/modules/db-resources
parent10164a7ab851859bfd548e32b4fe3c0610f3d614 (diff)
Improve blueprint save
Change-Id: Ibac2ef9cd7e217db809a6a695ea0ee39a6bd2e21 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/db-resources')
-rw-r--r--ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt65
1 files changed, 33 insertions, 32 deletions
diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
index 3be56480f..9780bbd31 100644
--- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
+++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
@@ -18,69 +18,70 @@
package org.onap.ccsdk.cds.controllerblueprints.db.resources
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.*
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
-import java.util.*
import javax.persistence.MappedSuperclass
@MappedSuperclass
-abstract class BlueprintCatalogServiceImpl(private val blueprintValidator: BluePrintValidatorService)
- : BluePrintCatalogService {
+abstract class BlueprintCatalogServiceImpl(
+ private val bluePrintPathConfiguration: BluePrintPathConfiguration,
+ private val blueprintValidator: BluePrintValidatorService) : BluePrintCatalogService {
- override fun saveToDatabase(blueprintFile: File, validate: Boolean): String {
- val extractedDirectory: File
- val archivedDirectory: File
- val toDeleteDirectory: File
- val blueprintId = UUID.randomUUID().toString()
+ private val log = LoggerFactory.getLogger(BlueprintCatalogServiceImpl::class.java)!!
+
+ override suspend fun saveToDatabase(processingId: String, blueprintFile: File, validate: Boolean): String {
+
+ var archiveFile: File? = null
+ var workingDir: String? = null
if (blueprintFile.isDirectory) {
- extractedDirectory = blueprintFile
- archivedDirectory = File("$blueprintFile.zip")
- toDeleteDirectory = archivedDirectory
+ log.info("Save processing($processingId) Working Dir(${blueprintFile.absolutePath})")
+ workingDir = blueprintFile.absolutePath
+ archiveFile = normalizedFile(bluePrintPathConfiguration.blueprintArchivePath, processingId, "cba.zip")
- if (!BluePrintArchiveUtils.compress(blueprintFile, archivedDirectory, true)) {
+ if (!BluePrintArchiveUtils.compress(blueprintFile, archiveFile, true)) {
throw BluePrintException("Fail to compress blueprint")
}
} else {
- val targetDir = "${blueprintFile.parent}/${BluePrintFileUtils.stripFileExtension(blueprintFile.name)}"
-
- extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir)
- archivedDirectory = blueprintFile
- toDeleteDirectory = extractedDirectory
+ // Compressed File
+ log.info("Save processing($processingId) CBA(${blueprintFile.absolutePath})")
+ workingDir = normalizedPathName(bluePrintPathConfiguration.blueprintWorkingPath, processingId)
+ archiveFile = blueprintFile
+ // Decompress the CBA file to working Directory
+ blueprintFile.deCompress(workingDir)
}
var valid = BluePrintConstants.FLAG_N
if (validate) {
- blueprintValidator.validateBluePrints(extractedDirectory.path)
+ blueprintValidator.validateBluePrints(workingDir!!)
valid = BluePrintConstants.FLAG_Y
}
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, extractedDirectory.path)
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!)
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
- metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
+ metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId
metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid
- save(metadata, archivedDirectory)
-
- toDeleteDirectory.deleteRecursively()
+ save(metadata, archiveFile)
- return blueprintId
+ return processingId
}
- override fun getFromDatabase(name: String, version: String, extract: Boolean): Path = get(name, version, extract)
+ override suspend fun getFromDatabase(name: String, version: String, extract: Boolean): Path = get(name, version,
+ extract)
?: throw BluePrintException("Could not find blueprint $name:$version from database")
- override fun deleteFromDatabase(name: String, version: String) = delete(name, version)
+ override suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version)
- abstract fun save(metadata: MutableMap<String, String>, archiveFile: File)
- abstract fun get(name: String, version: String, extract: Boolean): Path?
- abstract fun delete(name: String, version: String)
+ abstract suspend fun save(metadata: MutableMap<String, String>, archiveFile: File)
+ abstract suspend fun get(name: String, version: String, extract: Boolean): Path?
+ abstract suspend fun delete(name: String, version: String)
} \ No newline at end of file