summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules/service/src')
-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
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt17
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt15
7 files changed, 68 insertions, 67 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)
}
/**
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt
index e0ecf0397..74f225a5b 100644
--- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt
@@ -91,17 +91,18 @@ class BluePrintEnhancerServiceImplTest {
}
private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
+ runBlocking {
+ val targetPath = Paths.get("target", targetDirName).toUri().path
- val targetPath = Paths.get("target", targetDirName).toUri().path
-
- deleteTargetDirectory(targetPath)
+ deleteTargetDirectory(targetPath)
- val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
- Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
+ val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
+ Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
- // Validate the Generated BluePrints
- val valid = bluePrintValidatorService.validateBluePrints(targetPath)
- Assert.assertTrue("blueprint($basePath) validation failed ", valid)
+ // Validate the Generated BluePrints
+ val valid = bluePrintValidatorService.validateBluePrints(targetPath)
+ Assert.assertTrue("blueprint($basePath) validation failed ", valid)
+ }
}
private fun deleteTargetDirectory(targetPath: String) {
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
index 2e7ca2cdc..026561e10 100644
--- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
@@ -20,10 +20,7 @@ import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
-import org.onap.ccsdk.apps.controllerblueprints.core.compress
-import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir
-import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile
-import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs
+import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart
import java.nio.file.Paths
import java.util.*
@@ -34,10 +31,9 @@ class BluePrintEnhancerUtilsTest {
private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
private val blueprintArchivePath: String = "./target/blueprints/archive"
private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment"
- private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").toFile().normalize().absolutePath
+ private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").normalize().toUri().path
@Before
- @Throws(Exception::class)
fun setUp() {
val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs()
assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}")
@@ -49,20 +45,19 @@ class BluePrintEnhancerUtilsTest {
}
@After
- @Throws(Exception::class)
fun tearDown() {
deleteDir(blueprintArchivePath)
deleteDir(blueprintEnrichmentPath)
}
@Test
- fun testDecompressFilePart() {
+ fun testFilePartCompressionNDeCompression() {
val filePart = MockFilePart(zipBlueprintFileName)
runBlocking {
val enhanceId = UUID.randomUUID().toString()
- val blueprintArchiveLocation = "$blueprintArchivePath/$enhanceId"
- val blueprintEnrichmentLocation = "$blueprintEnrichmentPath/$enhanceId"
+ val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId)
+ val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId)
BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation)
BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation)
}