From 3ce735a660cd4d387affe1e301471d3bd765e21c Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 7 Jan 2019 16:33:02 -0500 Subject: Add support for blueprintprocessor runtime DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - created db-resources module to store controller blueprint related controller blueprint repository and entities. Also create an abstract BlueprintCatalogServiceImpl so it can be used both by controllerblueprint and blueprintprocessor - created blueprint-validation to store the implementation of the validation interface. - change controllerblueprint service to levrage db-resources - implement CatalogService for blueprintprocessor db-lib by using db-resources. Change-Id: I0539e414e4ff3b7a6edf0f6304d6cbc5e6eac404 Issue-ID: CCSDK-664 Signed-off-by: Alexis de Talhouët --- .../modules/db-resources/pom.xml | 47 +++++++++++ .../db/resources/BlueprintCatalogServiceImpl.kt | 82 +++++++++++++++++++ .../resources/repository/ModelContentRepository.kt | 93 ++++++++++++++++++++++ .../db/resources/repository/ModelRepository.kt | 88 ++++++++++++++++++++ 4 files changed, 310 insertions(+) create mode 100644 ms/controllerblueprints/modules/db-resources/pom.xml create mode 100644 ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt create mode 100644 ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt (limited to 'ms/controllerblueprints/modules/db-resources') diff --git a/ms/controllerblueprints/modules/db-resources/pom.xml b/ms/controllerblueprints/modules/db-resources/pom.xml new file mode 100644 index 00000000..69e322e4 --- /dev/null +++ b/ms/controllerblueprints/modules/db-resources/pom.xml @@ -0,0 +1,47 @@ + + + + + 4.0.0 + + org.onap.ccsdk.apps.controllerblueprints + modules + 0.4.0-SNAPSHOT + + db-resources + Controller Blueprints DB Resources + + + + + + + org.onap.ccsdk.apps.controllerblueprints + core + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + 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 new file mode 100644 index 00000000..881e3bc4 --- /dev/null +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt @@ -0,0 +1,82 @@ +/* + * 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.apps.controllerblueprints.db.resources + +import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils +import java.io.File +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) + + // Upload to the Data Base + saveToDataBase(blueprintFile, id, zipFile) + + // After Upload to Database delete the zip file + zipFile.delete() + + } 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) + + // Upload to the Data Base + saveToDataBase(extractedDirectory, id, blueprintFile) + + // After Upload to Database delete the zip file + blueprintFile.delete() + extractedDirectory.delete() + } + + return id + } + + override fun downloadFromDataBase(name: String, version: String, path: String): String { + // If path ends with zip, then compress otherwise download as extracted folder + + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun downloadFromDataBase(uuid: String, path: String): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun prepareBluePrint(name: String, version: String): String { + val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version" + downloadFromDataBase(name, version, preparedPath) + return preparedPath + } + + 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 new file mode 100644 index 00000000..4965677e --- /dev/null +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt @@ -0,0 +1,93 @@ +/* + * 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.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 + +/** + * @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 Optional + */ + fun findTopByBlueprintModelAndContentType(blueprintModel: T, + contentType: String): Optional + + /** + * This is a findByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional + */ + fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List + + /** + * This is a findByBlueprintModel method + * + * @param blueprintModel B + * @return Optional + */ + fun findByBlueprintModel(blueprintModel: T): List + + /** + * This is a findByBlueprintModelAndContentTypeAndName method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @param name name + * @return Optional + */ + fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, + contentType: String, name: String): Optional + + /** + * This is a deleteByMdeleteByBlueprintModelodelName method + * + * @param blueprintModel B + */ + fun deleteByBlueprintModel(blueprintModel: T) + + /** + * This is a deleteById method + * + * @param id id + */ + 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 new file mode 100644 index 00000000..c31f009a --- /dev/null +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt @@ -0,0 +1,88 @@ +/* + * 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.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 + +/** + * @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 Optional + */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName artifactName + * @return Optional + */ + fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): Optional + + /** + * This is a findTopByArtifactName method + * + * @param artifactName artifactName + * @return Optional + */ + fun findTopByArtifactName(artifactName: String): List + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional + */ + fun findByTagsContainingIgnoreCase(tags: String): List + + /** + * This is a deleteByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + */ + fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String) + + /** + * This is a deleteById method + * + * @param id id + */ + override fun deleteById(@NotNull id: String) + +} -- cgit 1.2.3-korg