summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src/main
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-20 18:27:53 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-22 11:27:18 -0400
commit0e86613ab9cbe5c6b87746bb7bff09fc3a324d0b (patch)
tree0b4a8b3a1a8b2a706d97125498866d2d7e74d6e0 /ms/controllerblueprints/modules/service/src/main
parent1636ef122d95cde48b7802042311351b7e47c499 (diff)
Improve publish api
Change-Id: I245fc765bf4e7916c36126d7a9597e9db80a1713 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/main')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt6
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt5
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt57
-rwxr-xr-xms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt4
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt31
5 files changed, 54 insertions, 49 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt
index d6ce286fc..4974bcd12 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt
@@ -95,11 +95,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
bluePrintModelHandler.enrichBlueprint(file)
}
- @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
+ @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@Throws(BluePrintException::class)
- fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
- return this.bluePrintModelHandler.publishBlueprintModel(id)
+ fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking {
+ bluePrintModelHandler.publishBlueprint(file)
}
@GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt
index fb49dc465..da755d166 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt
@@ -35,7 +35,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())
- override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {
+ override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {
// Copy the Blueprint Content to Target Location
BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)
@@ -45,7 +45,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService
}
@Throws(BluePrintException::class)
- override fun enhance(basePath: String): BluePrintContext {
+ override suspend fun enhance(basePath: String): BluePrintContext {
log.info("Enhancing blueprint($basePath)")
val blueprintRuntimeService = BluePrintMetadataUtils
@@ -73,7 +73,6 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService
} catch (e: Exception) {
throw e
}
-
return blueprintRuntimeService.bluePrintContext()
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
index 4239abbab..11087bc52 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
@@ -19,11 +19,11 @@
package org.onap.ccsdk.apps.controllerblueprints.service.handler
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService
+import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
@@ -95,26 +95,6 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC
}
- /**
- * This is a publishBlueprintModel method to change the status published to YES
- *
- * @param id id
- * @return BlueprintModelSearch
- * @throws BluePrintException BluePrintException
- */
- @Throws(BluePrintException::class)
- open fun publishBlueprintModel(id: String): BlueprintModelSearch {
- val blueprintModelSearch: BlueprintModelSearch
- val dbBlueprintModel = blueprintModelSearchRepository.findById(id)
- if (dbBlueprintModel.isPresent) {
- blueprintModelSearch = dbBlueprintModel.get()
- } else {
- val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
- throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
- }
- blueprintModelSearch.published = ApplicationConstants.ACTIVE_Y
- return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch)
- }
/**
* This is a searchBlueprintModels method
@@ -296,9 +276,8 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC
@Throws(BluePrintException::class)
open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity<Resource> {
val enhanceId = UUID.randomUUID().toString()
- val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(enhanceId)
- val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(enhanceId)
-
+ val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, enhanceId)
+ val blueprintEnrichmentDir = normalizedPathName(bluePrintLoadConfiguration.blueprintEnrichmentPath, enhanceId)
try {
BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir)
@@ -309,7 +288,35 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC
} catch (e: IOException) {
throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
- String.format("I/O Error while uploading the CBA file: %s", e.message), e)
+ "Error in Enriching CBA: ${e.message}", e)
+ } finally {
+ BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir)
+ }
+ }
+
+ /**
+ * This is a publishBlueprintModel method to change the status published to YES
+ *
+ * @param filePart filePart
+ * @return BlueprintModelSearch
+ * @throws BluePrintException BluePrintException
+ */
+ @Throws(BluePrintException::class)
+ open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch {
+ val publishId = UUID.randomUUID().toString()
+ val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(publishId)
+ val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(publishId)
+ try {
+ val compressedFilePart = BluePrintEnhancerUtils
+ .extractCompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir)
+
+ val blueprintId = bluePrintCatalogService.saveToDatabase(compressedFilePart, true)
+
+ return blueprintModelSearchRepository.findById(blueprintId).get()
+
+ } catch (e: Exception) {
+ throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
+ "Error in Publishing CBA: ${e.message}", e)
} finally {
BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir)
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
index 892cdbd5b..17149e466 100755
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
@@ -1,6 +1,7 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
* Modifications Copyright © 2019 Bell Canada.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,7 +84,8 @@ class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrint
val blueprintModel = BlueprintModel()
blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
- blueprintModel.published = ApplicationConstants.ACTIVE_N
+ blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID]
+ ?: BluePrintConstants.FLAG_N
blueprintModel.artifactName = artifactName
blueprintModel.artifactVersion = artifactVersion
blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
index 02140ebf7..cf1bfb578 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
@@ -21,12 +21,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactive.awaitSingle
import kotlinx.coroutines.withContext
-import org.apache.commons.io.FileUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
-import org.onap.ccsdk.apps.controllerblueprints.core.deCompress
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
-import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
import org.springframework.core.io.ByteArrayResource
@@ -87,7 +84,7 @@ class BluePrintEnhancerUtils {
return artifactType
}
- suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File {
+ private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File {
// Delete the Directory
targetFile.deleteRecursively()
return filePart.transferTo(targetFile)
@@ -95,20 +92,23 @@ class BluePrintEnhancerUtils {
.awaitSingle()
}
- suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File {
+ suspend fun extractCompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File {
//Recreate the Base Directories
- Paths.get(archiveDir).toFile().reCreateDirs()
- Paths.get(enhanceDir).toFile().reCreateDirs()
-
- val filePartFile = Paths.get(archiveDir, "cba.zip").toFile()
+ normalizedFile(archiveDir).reCreateDirs()
+ normalizedFile(enhanceDir).reCreateDirs()
+ val filePartFile = normalizedFile(archiveDir, "cba.zip")
// Copy the File Part to ZIP
- copyFromFilePart(filePart, filePartFile)
+ return copyFromFilePart(filePart, filePartFile)
+ }
+
+ suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File {
+ val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir)
val deCompressFileName = Paths.get(enhanceDir).toUri().path
return filePartFile.deCompress(deCompressFileName)
}
suspend fun compressToFilePart(enhanceDir: String, archiveDir: String): ResponseEntity<Resource> {
- val compressedFile = Paths.get(archiveDir, "enhanced-cba.zip").toFile()
+ val compressedFile = normalizedFile(archiveDir, "enhanced-cba.zip")
BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile, true)
return prepareResourceEntity(compressedFile.name, compressedFile.readBytes())
}
@@ -121,11 +121,8 @@ class BluePrintEnhancerUtils {
}
suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) {
- val enrichDir = File(enhancementLocation)
- FileUtils.forceDeleteOnExit(enrichDir)
-
- val archiveDir = File(archiveLocation)
- FileUtils.forceDeleteOnExit(archiveDir)
+ deleteDir(archiveLocation)
+ deleteDir(enhancementLocation)
}
/**