summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-03-29 12:55:06 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-29 12:55:06 +0000
commitcf6a08425cc50b871cec9ae386e617388816b27d (patch)
treeb28a25b623b143354364b4d778f01bdb4b0784c4 /ms/blueprintsprocessor/modules/commons
parent837f8493fe6c7cd0569c43105b923e42549dcf7b (diff)
parentc3811effed948926f8d94615df7530c99d490092 (diff)
Merge "Improve blueprint save"
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons')
-rwxr-xr-xms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt43
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt32
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties1
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt25
4 files changed, 72 insertions, 29 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
index 0a625007f..3234c9a3c 100755
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
@@ -18,13 +18,12 @@
package org.onap.ccsdk.cds.blueprintsprocessor.db
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository
-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.common.ApplicationConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration
import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils
@@ -35,16 +34,16 @@ import org.springframework.stereotype.Service
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
-import java.nio.file.Paths
+import java.util.*
/**
* Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl]
*/
@Service
class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService,
- private val blueprintConfig: BluePrintCoreConfiguration,
+ private val bluePrintPathConfiguration: BluePrintPathConfiguration,
private val blueprintModelRepository: BlueprintProcessorModelRepository)
- : BlueprintCatalogServiceImpl(bluePrintRuntimeValidatorService) {
+ : BlueprintCatalogServiceImpl(bluePrintPathConfiguration, bluePrintRuntimeValidatorService) {
private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString())
@@ -53,33 +52,47 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu
log.info("BlueprintProcessorCatalogServiceImpl initialized")
}
- override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version)
+ override suspend fun delete(name: String, version: String) {
+ // Cleaning Deployed Blueprint
+ deleteNBDir(bluePrintPathConfiguration.blueprintDeployPath, name, version)
+ // Cleaning Data Base
+ blueprintModelRepository
+ .deleteByArtifactNameAndArtifactVersion(name, version)
+ }
+
+
+ override suspend fun get(name: String, version: String, extract: Boolean): Path? {
+ val getId = UUID.randomUUID().toString()
+ var path = "${bluePrintPathConfiguration.blueprintArchivePath}/$getId/cba.zip"
- override fun get(name: String, version: String, extract: Boolean): Path? {
- var path = "${blueprintConfig.archivePath}/$name/$version.zip"
+ // TODO("Check first location for the file", If not get from database")
blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also {
it.blueprintModelContent.run {
- val file = File(path)
- file.parentFile.mkdirs()
- file.createNewFile()
+ val file = normalizedFile(path)
+ file.parentFile.reCreateDirs()
+
file.writeBytes(this!!.content!!).let {
if (extract) {
- path = "${blueprintConfig.archivePath}/$name/$version"
+ path = "${bluePrintPathConfiguration.blueprintDeployPath}/$name/$version"
BluePrintArchiveUtils.deCompress(file, path)
}
- return Paths.get(path)
+ return normalizedPath(path)
}
}
}
return null
}
- override fun save(metadata: MutableMap<String, String>, archiveFile: File) {
+ override suspend fun save(metadata: MutableMap<String, String>, archiveFile: File) {
val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
+ check(archiveFile.isFile && !archiveFile.isDirectory) {
+ throw BluePrintException("Not a valid Archive file(${archiveFile.absolutePath})")
+ }
+
blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
log.info("Overwriting blueprint model :$artifactName::$artifactVersion")
blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion)
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt
index a9a2ae73e..2fda15906 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt
@@ -15,16 +15,19 @@
*/
package org.onap.ccsdk.cds.blueprintsprocessor.db
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation.ComponentScan
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
-import java.io.File
-import java.nio.file.Paths
+import kotlin.test.AfterTest
+import kotlin.test.BeforeTest
import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
@@ -36,17 +39,30 @@ class BlueprintProcessorCatalogServiceImplTest {
@Autowired
lateinit var blueprintCatalog: BluePrintCatalogService
+ @BeforeTest
+ fun setup() {
+ deleteDir("target", "blueprints")
+ }
+
+ @AfterTest
+ fun cleanDir() {
+ deleteDir("target", "blueprints")
+ }
+
@Test
fun `test catalog service`() {
- val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
- assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
+ runBlocking {
+ //FIXME("Create ZIP from test blueprints")
+
+ val file = normalizedFile("./src/test/resources/test-cba.zip")
+ assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
- blueprintCatalog.saveToDatabase(file)
+ blueprintCatalog.saveToDatabase("1234", file)
- blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0")
+ blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0")
- blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0")
+ blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0")
- File("./src/test/resources/baseconfiguration").deleteRecursively()
+ }
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties
index 3ac7ec38b..9dda71eb2 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties
@@ -25,3 +25,4 @@ blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
# Controller Blueprints Core Configuration
blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
+blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt
index 03b847e51..5f1ae7d37 100644
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt
+++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/BluePrintCoreConfiguration.kt
@@ -16,23 +16,29 @@
package org.onap.ccsdk.cds.blueprintsprocessor.core
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration
import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.context.properties.bind.Bindable
import org.springframework.boot.context.properties.bind.Binder
import org.springframework.boot.context.properties.source.ConfigurationPropertySources
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.env.Environment
+import org.springframework.stereotype.Service
@Configuration
-open class BluePrintCoreConfiguration {
+open class BluePrintCoreConfiguration(private val bluePrintProperties: BlueprintProcessorProperties) {
- @Value("\${blueprintsprocessor.blueprintDeployPath}")
- lateinit var deployPath: String
+ companion object {
+ const val PREFIX_BLUEPRINT_PROCESSOR = "blueprintsprocessor"
+ }
- @Value("\${blueprintsprocessor.blueprintArchivePath}")
- lateinit var archivePath: String
+ @Bean
+ open fun bluePrintPathConfiguration(): BluePrintPathConfiguration {
+ return bluePrintProperties
+ .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BluePrintPathConfiguration::class.java)
+ }
}
@@ -46,4 +52,11 @@ open class BlueprintPropertyConfiguration {
val configurationPropertySource = ConfigurationPropertySources.get(environment)
return Binder(configurationPropertySource)
}
+}
+
+@Service
+open class BlueprintProcessorProperties(private var bluePrintPropertyBinder: Binder) {
+ fun <T> propertyBeanType(prefix: String, type: Class<T>): T {
+ return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get()
+ }
} \ No newline at end of file