From 7bbeeda4e4ff25a073c9d1a8992fe68aaf470e6b Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 30 Aug 2019 12:24:19 -0400 Subject: Refactor catalog service to blueprint processor. Change-Id: Ia4bfc7c1b3ffb4020458f18deb71a2cf451ab65e Issue-ID: CCSDK-1663 Signed-off-by: Brinda Santh --- .../modules/commons/db-lib/pom.xml | 4 - .../db/BlueprintCatalogServiceImpl.kt | 87 +++++++++++++++++++++ .../db/BlueprintProcessorCatalogServiceImpl.kt | 1 - .../BlueprintProcessorModelContentRepository.kt | 1 - .../BlueprintProcessorModelRepository.kt | 1 - .../ControllerBlueprintModelContentRepository.kt | 1 - .../ControllerBlueprintModelRepository.kt | 1 - .../primary/repository/ModelContentRepository.kt | 91 ++++++++++++++++++++++ .../db/primary/repository/ModelRepository.kt | 90 +++++++++++++++++++++ .../db/BlueprintProcessorCatalogServiceImplTest.kt | 1 - .../load/ControllerBlueprintCatalogServiceImpl.kt | 2 +- .../modules/inbounds/resource-api/pom.xml | 4 - ms/blueprintsprocessor/parent/pom.xml | 5 -- 13 files changed, 269 insertions(+), 20 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt (limited to 'ms/blueprintsprocessor') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml index f6288d784..783d8efbe 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml @@ -33,10 +33,6 @@ org.onap.ccsdk.cds.controllerblueprints blueprint-core - - org.onap.ccsdk.cds.controllerblueprints - db-resources - org.onap.ccsdk.cds.controllerblueprints blueprint-validation diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt new file mode 100644 index 000000000..4a1e8f194 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/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 + +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/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt index ce2aa95b5..1509e11f1 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 @@ -28,7 +28,6 @@ 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.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl import org.slf4j.LoggerFactory import org.springframework.dao.DataIntegrityViolationException import org.springframework.stereotype.Service diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt index c914af8f3..e8cdee397 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt @@ -17,6 +17,5 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository 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.controllerblueprints.db.resources.repository.ModelContentRepository interface BlueprintProcessorModelContentRepository : ModelContentRepository \ 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/repository/BlueprintProcessorModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt index 4f22bf07d..e200184d6 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt @@ -16,6 +16,5 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel -import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelRepository interface BlueprintProcessorModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt index 59b82a3da..3dbaf7b58 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt @@ -17,6 +17,5 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository 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.controllerblueprints.db.resources.repository.ModelContentRepository interface ControllerBlueprintModelContentRepository : ModelContentRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt index c26475b1d..4e765cd28 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt @@ -16,6 +16,5 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel -import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelRepository interface ControllerBlueprintModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt new file mode 100644 index 000000000..59f2a20f5 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt @@ -0,0 +1,91 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository + +import org.jetbrains.annotations.NotNull +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.repository.NoRepositoryBean +import java.util.* + +/** + * @param Model + * @param ModelContent + */ +@NoRepositoryBean +interface ModelContentRepository : JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + override fun findById(@NotNull id: String): Optional + + /** + * This is a findTopByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return B? + */ + fun findTopByBlueprintModelAndContentType(blueprintModel: T, contentType: String): B? + + /** + * This is a findByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return List + */ + fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List + + /** + * This is a findByBlueprintModel method + * + * @param blueprintModel T + * @return List + */ + fun findByBlueprintModel(blueprintModel: T): List + + /** + * This is a findByBlueprintModelAndContentTypeAndName method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @param name name + * @return B? + */ + fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, contentType: String, name: String): B? + + /** + * This is a deleteByMdeleteByBlueprintModelodelName method + * + * @param blueprintModel T + */ + fun deleteByBlueprintModel(blueprintModel: T) + + /** + * This is a deleteById method + * + * @param id id + */ + override fun deleteById(@NotNull id: String) + +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt new file mode 100644 index 000000000..4ad14758c --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt @@ -0,0 +1,90 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository + +import org.jetbrains.annotations.NotNull +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.repository.NoRepositoryBean +import java.util.* +import javax.transaction.Transactional + +/** + * @param Model + */ +@NoRepositoryBean +interface ModelRepository : JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + override fun findById(@NotNull id: String): Optional + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return T? + */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): T? + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName artifactName + * @return T? + */ + fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): T? + + /** + * This is a findTopByArtifactName method + * + * @param artifactName artifactName + * @return List + */ + fun findTopByArtifactName(artifactName: String): List + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return List + */ + fun findByTagsContainingIgnoreCase(tags: String): List + + /** + * This is a deleteByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + */ + @Transactional + fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String) + + /** + * This is a deleteById method + * + * @param id id + */ + override fun deleteById(@NotNull id: String) + +} \ 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 1a1aa0b49..11cd90e7d 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 @@ -27,7 +27,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.ComponentScan diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt index e91f4918c..146eeeb4d 100755 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt @@ -26,7 +26,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPath -import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintCatalogServiceImpl 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.ControllerBlueprintModelRepository diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml index 53c1e975b..e343a6f3b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml @@ -37,10 +37,6 @@ blueprint-core