From b86061f187ef79e89af03bb832af5abb3bbcc8e5 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 4 Nov 2019 21:39:46 -0500 Subject: Extension support for db configuration. Issue-ID: CCSDK-1046 Signed-off-by: Brinda Santh Change-Id: I404855eac4520f79ac33f70710dcdb6ae285891d --- .../DatabaseResourceResolutionProcessorTest.kt | 3 +- .../db/BluePrintDBLibConfiguration.kt | 2 - .../blueprintsprocessor/db/BluePrintDBLibData.kt | 1 - .../db/primary/PrimaryDatabaseConfiguration.kt | 7 +- .../primary/service/BlueprintCatalogServiceImpl.kt | 87 +++++++++++ .../BlueprintProcessorCatalogServiceImpl.kt | 159 +++++++++++++++++++++ .../ControllerBlueprintCatalogServiceImpl.kt | 127 ++++++++++++++++ .../db/service/BlueprintCatalogServiceImpl.kt | 87 ----------- .../BlueprintProcessorCatalogServiceImpl.kt | 159 --------------------- .../ControllerBlueprintCatalogServiceImpl.kt | 127 ---------------- .../db/BlueprintProcessorCatalogServiceImplTest.kt | 4 +- .../src/test/resources/application-test.properties | 2 + 12 files changed, 385 insertions(+), 380 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/ControllerBlueprintCatalogServiceImpl.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt delete mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt delete mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt (limited to 'ms') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt index e6cf05955..547681d19 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt @@ -24,6 +24,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDatabaseConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockBlueprintProcessorCatalogServiceImpl import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockDatabaseConfiguration @@ -41,7 +42,7 @@ import kotlin.test.assertNotNull @ContextConfiguration(classes = [DatabaseResourceAssignmentProcessor::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibPropertySevice::class, BluePrintDBLibConfiguration::class, BluePrintCoreConfiguration::class, MockDatabaseConfiguration::class, MockBlueprintProcessorCatalogServiceImpl::class, - BlueprintPropertiesService::class]) + BlueprintPropertiesService::class, PrimaryDatabaseConfiguration::class]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class DatabaseResourceResolutionProcessorTest { diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt index 11abf7b2e..907e93bed 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt @@ -22,11 +22,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericServ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration @Configuration -@ComponentScan @EnableConfigurationProperties open class BluePrintDBLibConfiguration(private var bluePrintProperties: BluePrintProperties) { diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt index b1ac5cee4..fc43ce34d 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt @@ -22,7 +22,6 @@ open class DBDataSourceProperties { lateinit var username: String lateinit var password: String open lateinit var driverClassName: String - } open class PrimaryDataSourceProperties: DBDataSourceProperties() { diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt index a62867053..b17dcf0fc 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt @@ -18,7 +18,9 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties import org.slf4j.LoggerFactory +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Primary import org.springframework.data.jpa.repository.config.EnableJpaAuditing @@ -33,6 +35,9 @@ import java.util.* import javax.sql.DataSource @Configuration +@ConditionalOnProperty(name = ["blueprintsprocessor.db.primary.defaultConfig"], havingValue = "true", + matchIfMissing = true) +@ComponentScan @EnableJpaRepositories( basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.*", "org.onap.ccsdk.cds.controllerblueprints.*"], @@ -41,7 +46,7 @@ import javax.sql.DataSource ) @EnableJpaAuditing open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) { - val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! + private val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! @Primary @Bean("primaryEntityManager") diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt new file mode 100644 index 000000000..5700c2a46 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt @@ -0,0 +1,87 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service + +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +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.BluePrintMetadataUtils +import org.slf4j.LoggerFactory +import java.io.File +import java.nio.file.Path +import javax.persistence.MappedSuperclass + +@MappedSuperclass +abstract class BlueprintCatalogServiceImpl( + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintValidator: BluePrintValidatorService) : BluePrintCatalogService { + + 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) { + log.info("Save processing($processingId) Working Dir(${blueprintFile.absolutePath})") + workingDir = blueprintFile.absolutePath + archiveFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, processingId, "cba.zip") + + if (!BluePrintArchiveUtils.compress(blueprintFile, archiveFile)) { + throw BluePrintException("Fail to compress blueprint") + } + } else { + // Compressed File + log.info("Save processing($processingId) CBA(${blueprintFile.absolutePath})") + workingDir = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, processingId) + archiveFile = blueprintFile + // Decompress the CBA file to working Directory + blueprintFile.deCompress(workingDir) + } + + var valid = BluePrintConstants.FLAG_N + if (validate) { + blueprintValidator.validateBluePrints(workingDir!!) + valid = BluePrintConstants.FLAG_Y + } + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!) + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid + + save(metadata, archiveFile) + + return processingId + } + + 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 suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version) + + abstract suspend fun save(metadata: MutableMap, 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 diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt new file mode 100755 index 000000000..3ba25d8de --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt @@ -0,0 +1,159 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +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.scripts.BluePrintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import java.io.File +import java.nio.file.Path +import java.util.* + +// TODO("Duplicate : Merge BlueprintProcessorCatalogServiceImpl and ControllerBlueprintCatalogServiceImpl") +/** + * Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] + */ +@Service("blueprintsProcessorCatalogService") +class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelRepository: BlueprintModelRepository) + : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintRuntimeValidatorService) { + + private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) + + override suspend fun delete(name: String, version: String) { + // Clean blueprint script cache + val cacheKey = BluePrintFileUtils + .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, name, version)) + BluePrintCompileCache.cleanClassLoader(cacheKey) + log.info("removed cba file name($name), version($version) from cache") + // Cleaning Deployed Blueprint + deleteNBDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + log.info("removed cba file name($name), version($version) from deploy location") + // Cleaning Data Base + blueprintModelRepository + .deleteByArtifactNameAndArtifactVersion(name, version) + log.info("removed cba file name($name), version($version) from database") + } + + + override suspend fun get(name: String, version: String, extract: Boolean): Path? { + + val deployFile = normalizedFile(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + val cbaFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, + UUID.randomUUID().toString(), "cba.zip") + + if (extract && deployFile.exists()) { + log.info("cba file name($name), version($version) already present(${deployFile.absolutePath})") + } else { + deployFile.reCreateNBDirs() + cbaFile.parentFile.reCreateNBDirs() + + try { + log.info("getting cba file name($name), version($version) from db") + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + + cbaFile.writeBytes(this!!.content!!) + cbaFile.deCompress(deployFile) + log.info("cba file name($name), version($version) saved in (${deployFile.absolutePath})") + } + } + + check(deployFile.exists() && deployFile.list().isNotEmpty()) { + throw BluePrintProcessorException("file check failed") + } + } catch (e: Exception) { + deleteNBDir(deployFile.absolutePath) + throw BluePrintProcessorException("failed to get get cba file name($name), version($version) from db" + + " : ${e.message}") + } finally { + deleteNBDir(cbaFile.parentFile.absolutePath) + } + } + + return if (extract) { + deployFile.toPath() + } else { + cbaFile.toPath() + } + } + + override suspend fun save(metadata: MutableMap, 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) + val deployFile = + normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) + + val cacheKey = BluePrintFileUtils.compileCacheKey(deployFile) + BluePrintCompileCache.cleanClassLoader(cacheKey) + + deleteNBDir(deployFile).let { + if (it) log.info("Deleted deployed blueprint model :$artifactName::$artifactVersion") + else log.info("Fail to delete deployed blueprint model :$artifactName::$artifactVersion") + } + } + + val blueprintModel = BlueprintModel() + blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL + blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BluePrintConstants.FLAG_N + blueprintModel.artifactName = artifactName + blueprintModel.artifactVersion = artifactVersion + blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! + blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]!! + blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" + + val blueprintModelContent = BlueprintModelContent() + blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModelContent.contentType = "CBA_ZIP" + blueprintModelContent.name = "$artifactName:$artifactVersion" + blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" + blueprintModelContent.content = archiveFile.readBytes() + blueprintModelContent.blueprintModel = blueprintModel + + blueprintModel.blueprintModelContent = blueprintModelContent + + try { + blueprintModelRepository.saveAndFlush(blueprintModel) + } catch (ex: DataIntegrityViolationException) { + throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + + "is already exist in database: ${ex.message}", ex) + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/ControllerBlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/ControllerBlueprintCatalogServiceImpl.kt new file mode 100755 index 000000000..5b1d6c36c --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/ControllerBlueprintCatalogServiceImpl.kt @@ -0,0 +1,127 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +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.scripts.BluePrintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import java.io.File +import java.nio.file.Files +import java.nio.file.Path +import java.util.* + +//TODO("Duplicate : Merge BlueprintProcessorCatalogServiceImpl and ControllerBlueprintCatalogServiceImpl") +/** + * Similar implementation in [org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl] + */ +@Service("controllerBlueprintsCatalogService") +class ControllerBlueprintCatalogServiceImpl(bluePrintDesignTimeValidatorService: BluePrintValidatorService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelRepository: BlueprintModelRepository) + : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintDesignTimeValidatorService) { + + + private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString()) + + init { + log.info("BlueprintProcessorCatalogServiceImpl initialized") + } + + override suspend fun delete(name: String, version: String) { + // Cleaning Deployed Blueprint + deleteDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + // Cleaning Data Base + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) + } + + override suspend fun get(name: String, version: String, extract: Boolean): Path? { + val path = if (extract) { + normalizedPath(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + } else { + normalizedPath(bluePrintLoadConfiguration.blueprintArchivePath, UUID.randomUUID().toString(), "cba.zip") + } + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + path.toFile().writeBytes(this!!.content!!).let { + return path + } + } + } + return null + } + + override suspend fun save(metadata: MutableMap, 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})") + } + + // cleanup up deploy folder for the Blueprint + val blueprintDeploy = normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, + artifactName, artifactVersion) + val cacheKey = BluePrintFileUtils.compileCacheKey(blueprintDeploy) + BluePrintCompileCache.cleanClassLoader(cacheKey) + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { + log.info("Overwriting blueprint model :$artifactName::$artifactVersion") + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) + } + + val blueprintModel = BlueprintModel() + blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL + blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BluePrintConstants.FLAG_N + blueprintModel.artifactName = artifactName + blueprintModel.artifactVersion = artifactVersion + blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! + blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]!! + blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" + + val blueprintModelContent = BlueprintModelContent() + blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModelContent.contentType = "CBA_ZIP" + blueprintModelContent.name = "$artifactName:$artifactVersion" + blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" + blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) + blueprintModelContent.blueprintModel = blueprintModel + // Set the Blueprint Model Content into blueprintModel + blueprintModel.blueprintModelContent = blueprintModelContent + + try { + blueprintModelRepository.saveAndFlush(blueprintModel) + } catch (ex: DataIntegrityViolationException) { + throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + + "is already exist in database: ${ex.message}", ex) + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt deleted file mode 100644 index aef7c18a2..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.db.service - -import org.onap.ccsdk.cds.controllerblueprints.core.* -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -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.BluePrintMetadataUtils -import org.slf4j.LoggerFactory -import java.io.File -import java.nio.file.Path -import javax.persistence.MappedSuperclass - -@MappedSuperclass -abstract class BlueprintCatalogServiceImpl( - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintValidator: BluePrintValidatorService) : BluePrintCatalogService { - - 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) { - log.info("Save processing($processingId) Working Dir(${blueprintFile.absolutePath})") - workingDir = blueprintFile.absolutePath - archiveFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, processingId, "cba.zip") - - if (!BluePrintArchiveUtils.compress(blueprintFile, archiveFile)) { - throw BluePrintException("Fail to compress blueprint") - } - } else { - // Compressed File - log.info("Save processing($processingId) CBA(${blueprintFile.absolutePath})") - workingDir = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, processingId) - archiveFile = blueprintFile - // Decompress the CBA file to working Directory - blueprintFile.deCompress(workingDir) - } - - var valid = BluePrintConstants.FLAG_N - if (validate) { - blueprintValidator.validateBluePrints(workingDir!!) - valid = BluePrintConstants.FLAG_Y - } - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!) - val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid - - save(metadata, archiveFile) - - return processingId - } - - 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 suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version) - - abstract suspend fun save(metadata: MutableMap, 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 diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt deleted file mode 100755 index 5d04ddfdf..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.db.service - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository -import org.onap.ccsdk.cds.controllerblueprints.core.* -import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -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.scripts.BluePrintCompileCache -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils -import org.slf4j.LoggerFactory -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.stereotype.Service -import java.io.File -import java.nio.file.Path -import java.util.* - -// TODO("Duplicate : Merge BlueprintProcessorCatalogServiceImpl and ControllerBlueprintCatalogServiceImpl") -/** - * Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] - */ -@Service("blueprintsProcessorCatalogService") -class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintModelRepository: BlueprintModelRepository) - : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintRuntimeValidatorService) { - - private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) - - override suspend fun delete(name: String, version: String) { - // Clean blueprint script cache - val cacheKey = BluePrintFileUtils - .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, name, version)) - BluePrintCompileCache.cleanClassLoader(cacheKey) - log.info("removed cba file name($name), version($version) from cache") - // Cleaning Deployed Blueprint - deleteNBDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) - log.info("removed cba file name($name), version($version) from deploy location") - // Cleaning Data Base - blueprintModelRepository - .deleteByArtifactNameAndArtifactVersion(name, version) - log.info("removed cba file name($name), version($version) from database") - } - - - override suspend fun get(name: String, version: String, extract: Boolean): Path? { - - val deployFile = normalizedFile(bluePrintLoadConfiguration.blueprintDeployPath, name, version) - val cbaFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, - UUID.randomUUID().toString(), "cba.zip") - - if (extract && deployFile.exists()) { - log.info("cba file name($name), version($version) already present(${deployFile.absolutePath})") - } else { - deployFile.reCreateNBDirs() - cbaFile.parentFile.reCreateNBDirs() - - try { - log.info("getting cba file name($name), version($version) from db") - blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { - it.blueprintModelContent.run { - - cbaFile.writeBytes(this!!.content!!) - cbaFile.deCompress(deployFile) - log.info("cba file name($name), version($version) saved in (${deployFile.absolutePath})") - } - } - - check(deployFile.exists() && deployFile.list().isNotEmpty()) { - throw BluePrintProcessorException("file check failed") - } - } catch (e: Exception) { - deleteNBDir(deployFile.absolutePath) - throw BluePrintProcessorException("failed to get get cba file name($name), version($version) from db" + - " : ${e.message}") - } finally { - deleteNBDir(cbaFile.parentFile.absolutePath) - } - } - - return if (extract) { - deployFile.toPath() - } else { - cbaFile.toPath() - } - } - - override suspend fun save(metadata: MutableMap, 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) - val deployFile = - normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) - - val cacheKey = BluePrintFileUtils.compileCacheKey(deployFile) - BluePrintCompileCache.cleanClassLoader(cacheKey) - - deleteNBDir(deployFile).let { - if (it) log.info("Deleted deployed blueprint model :$artifactName::$artifactVersion") - else log.info("Fail to delete deployed blueprint model :$artifactName::$artifactVersion") - } - } - - val blueprintModel = BlueprintModel() - blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] - ?: BluePrintConstants.FLAG_N - blueprintModel.artifactName = artifactName - blueprintModel.artifactVersion = artifactVersion - blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! - blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]!! - blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" - - val blueprintModelContent = BlueprintModelContent() - blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModelContent.contentType = "CBA_ZIP" - blueprintModelContent.name = "$artifactName:$artifactVersion" - blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" - blueprintModelContent.content = archiveFile.readBytes() - blueprintModelContent.blueprintModel = blueprintModel - - blueprintModel.blueprintModelContent = blueprintModelContent - - try { - blueprintModelRepository.saveAndFlush(blueprintModel) - } catch (ex: DataIntegrityViolationException) { - throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + - "is already exist in database: ${ex.message}", ex) - } - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt deleted file mode 100755 index e7a8e31a7..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.db.service - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository -import org.onap.ccsdk.cds.controllerblueprints.core.* -import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -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.scripts.BluePrintCompileCache -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils -import org.slf4j.LoggerFactory -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.stereotype.Service -import java.io.File -import java.nio.file.Files -import java.nio.file.Path -import java.util.* - -//TODO("Duplicate : Merge BlueprintProcessorCatalogServiceImpl and ControllerBlueprintCatalogServiceImpl") -/** - * Similar implementation in [org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl] - */ -@Service("controllerBlueprintsCatalogService") -class ControllerBlueprintCatalogServiceImpl(bluePrintDesignTimeValidatorService: BluePrintValidatorService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintModelRepository: BlueprintModelRepository) - : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintDesignTimeValidatorService) { - - - private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString()) - - init { - log.info("BlueprintProcessorCatalogServiceImpl initialized") - } - - override suspend fun delete(name: String, version: String) { - // Cleaning Deployed Blueprint - deleteDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) - // Cleaning Data Base - blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) - } - - override suspend fun get(name: String, version: String, extract: Boolean): Path? { - val path = if (extract) { - normalizedPath(bluePrintLoadConfiguration.blueprintDeployPath, name, version) - } else { - normalizedPath(bluePrintLoadConfiguration.blueprintArchivePath, UUID.randomUUID().toString(), "cba.zip") - } - blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { - it.blueprintModelContent.run { - path.toFile().writeBytes(this!!.content!!).let { - return path - } - } - } - return null - } - - override suspend fun save(metadata: MutableMap, 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})") - } - - // cleanup up deploy folder for the Blueprint - val blueprintDeploy = normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, - artifactName, artifactVersion) - val cacheKey = BluePrintFileUtils.compileCacheKey(blueprintDeploy) - BluePrintCompileCache.cleanClassLoader(cacheKey) - - blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { - log.info("Overwriting blueprint model :$artifactName::$artifactVersion") - blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) - } - - val blueprintModel = BlueprintModel() - blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] - ?: BluePrintConstants.FLAG_N - blueprintModel.artifactName = artifactName - blueprintModel.artifactVersion = artifactVersion - blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! - blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]!! - blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" - - val blueprintModelContent = BlueprintModelContent() - blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModelContent.contentType = "CBA_ZIP" - blueprintModelContent.name = "$artifactName:$artifactVersion" - blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" - blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) - blueprintModelContent.blueprintModel = blueprintModel - // Set the Blueprint Model Content into blueprintModel - blueprintModel.blueprintModelContent = blueprintModelContent - - try { - blueprintModelRepository.saveAndFlush(blueprintModel) - } catch (ex: DataIntegrityViolationException) { - throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + - "is already exist in database: ${ex.message}", ex) - } - } -} \ No newline at end of file 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 8058dc26e..d912d8eae 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 @@ -22,8 +22,8 @@ import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.mock.MockBlueprintProcessorCatalogServiceImpl -import org.onap.ccsdk.cds.blueprintsprocessor.db.service.BlueprintCatalogServiceImpl -import org.onap.ccsdk.cds.blueprintsprocessor.db.service.BlueprintProcessorCatalogServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintCatalogServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintProcessorCatalogServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile 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 90cf03517..124e844cb 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 @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +blueprintsprocessor.db.primary.defaultConfig=true + blueprintsprocessor.db.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 blueprintsprocessor.db.username=sa blueprintsprocessor.db.password= -- cgit 1.2.3-korg