From 125b60f22593467dd633c19a296b92ddcb4b260b Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Sat, 12 Jan 2019 15:48:20 -0500 Subject: Implement BluePrintCatalogService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ifcb0d730daec4da747d704c270b72b991e01f474 Issue-ID: CCSDK-908 Signed-off-by: Alexis de Talhouët --- .../db/resources/BlueprintCatalogServiceImpl.kt | 82 +++++++++++----------- .../resources/repository/ModelContentRepository.kt | 20 +++--- .../db/resources/repository/ModelRepository.kt | 18 ++--- 3 files changed, 60 insertions(+), 60 deletions(-) (limited to 'ms/controllerblueprints/modules/db-resources/src') diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt index 881e3bc4..3ba729d1 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt @@ -17,66 +17,66 @@ package org.onap.ccsdk.apps.controllerblueprints.db.resources -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import java.io.File +import java.nio.file.Path +import java.util.* import javax.persistence.MappedSuperclass @MappedSuperclass -abstract class BlueprintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration) : BluePrintCatalogService { - - override fun uploadToDataBase(file: String, validate: Boolean): String { - // The file name provided here is unique as we transform to UUID before storing - val blueprintFile = File(file) - val fileName = blueprintFile.name - val id = BluePrintFileUtils.stripFileExtension(fileName) - // If the file is directory - if (blueprintFile.isDirectory) { - - val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/$fileName") - // zip the directory - BluePrintArchiveUtils.compress(blueprintFile, zipFile, true) +abstract class BlueprintCatalogServiceImpl(private val blueprintValidator: BluePrintValidatorService) + : BluePrintCatalogService { - // Upload to the Data Base - saveToDataBase(blueprintFile, id, zipFile) + override fun saveToDatabase(blueprintFile: File, validate: Boolean): String { + val extractedDirectory: File + val archivedDirectory: File + val toDeleteDirectory: File + val blueprintId = UUID.randomUUID().toString() - // After Upload to Database delete the zip file - zipFile.delete() + if (blueprintFile.isDirectory) { + extractedDirectory = blueprintFile + archivedDirectory = File(":$blueprintFile.zip") + toDeleteDirectory = archivedDirectory + if (!BluePrintArchiveUtils.compress(blueprintFile, archivedDirectory, true)) { + throw BluePrintException("Fail to compress blueprint") + } } else { - // If the file is ZIP - // unzip the CBA file to validate before store in database - val targetDir = "${bluePrintLoadConfiguration.blueprintDeployPath}/$id/" - val extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir) + val targetDir = "${blueprintFile.parent}/${BluePrintFileUtils.stripFileExtension(blueprintFile.name)}" - // Upload to the Data Base - saveToDataBase(extractedDirectory, id, blueprintFile) + extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir) + archivedDirectory = blueprintFile + toDeleteDirectory = extractedDirectory + } - // After Upload to Database delete the zip file - blueprintFile.delete() - extractedDirectory.delete() + if (validate) { + blueprintValidator.validateBluePrints(extractedDirectory.path) } - return id - } + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, extractedDirectory.path) + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId - override fun downloadFromDataBase(name: String, version: String, path: String): String { - // If path ends with zip, then compress otherwise download as extracted folder + save(metadata, archivedDirectory) - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } + toDeleteDirectory.deleteRecursively() - override fun downloadFromDataBase(uuid: String, path: String): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + return blueprintId } - override fun prepareBluePrint(name: String, version: String): String { - val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version" - downloadFromDataBase(name, version, preparedPath) - return preparedPath - } + override fun getFromDatabase(name: String, version: String, extract: Boolean): Path = get(name, version, extract) + ?: throw BluePrintException("Could not find blueprint $name:$version from database") + + override fun deleteFromDatabase(name: String, version: String) = delete(name, version) + + abstract fun save(metadata: MutableMap, archiveFile: File) + abstract fun get(name: String, version: String, extract: Boolean): Path? + abstract fun delete(name: String, version: String) - abstract fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean? = false) } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt index 4965677e..680f1b2c 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt @@ -43,25 +43,24 @@ interface ModelContentRepository : JpaRepository { * * @param blueprintModel blueprintModel * @param contentType contentType - * @return Optional + * @return B? */ - fun findTopByBlueprintModelAndContentType(blueprintModel: T, - contentType: String): Optional + fun findTopByBlueprintModelAndContentType(blueprintModel: T, contentType: String): B? /** * This is a findByBlueprintModelAndContentType method * * @param blueprintModel blueprintModel * @param contentType contentType - * @return Optional + * @return List */ fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List /** * This is a findByBlueprintModel method * - * @param blueprintModel B - * @return Optional + * @param blueprintModel T + * @return List */ fun findByBlueprintModel(blueprintModel: T): List @@ -71,15 +70,14 @@ interface ModelContentRepository : JpaRepository { * @param blueprintModel blueprintModel * @param contentType contentType * @param name name - * @return Optional + * @return B? */ - fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, - contentType: String, name: String): Optional + fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, contentType: String, name: String): B? /** * This is a deleteByMdeleteByBlueprintModelodelName method * - * @param blueprintModel B + * @param blueprintModel T */ fun deleteByBlueprintModel(blueprintModel: T) @@ -90,4 +88,4 @@ interface ModelContentRepository : JpaRepository { */ override fun deleteById(@NotNull id: String) -} \ No newline at end of file +} diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt index c31f009a..e796c366 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt @@ -18,9 +18,10 @@ package org.onap.ccsdk.apps.controllerblueprints.db.resources.repository import org.jetbrains.annotations.NotNull -import java.util.Optional import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.repository.NoRepositoryBean +import java.util.* +import javax.transaction.Transactional /** * @param Model @@ -42,23 +43,23 @@ interface ModelRepository : JpaRepository { * * @param artifactName artifactName * @param artifactVersion artifactVersion - * @return Optional + * @return T? */ - fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): T? /** * This is a findTopByArtifactNameOrderByArtifactIdDesc method * * @param artifactName artifactName - * @return Optional + * @return T? */ - fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): Optional + fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): T? /** * This is a findTopByArtifactName method * * @param artifactName artifactName - * @return Optional + * @return List */ fun findTopByArtifactName(artifactName: String): List @@ -66,7 +67,7 @@ interface ModelRepository : JpaRepository { * This is a findByTagsContainingIgnoreCase method * * @param tags tags - * @return Optional + * @return List */ fun findByTagsContainingIgnoreCase(tags: String): List @@ -76,6 +77,7 @@ interface ModelRepository : JpaRepository { * @param artifactName artifactName * @param artifactVersion artifactVersion */ + @Transactional fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String) /** @@ -85,4 +87,4 @@ interface ModelRepository : JpaRepository { */ override fun deleteById(@NotNull id: String) -} +} \ No newline at end of file -- cgit 1.2.3-korg