diff options
author | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-01-07 16:33:02 -0500 |
---|---|---|
committer | Alexis de Talhouët <alexis.de_talhouet@bell.ca> | 2019-01-09 22:11:43 +0000 |
commit | 7f6c527bac8c0c60a2988e59ff7251178f904cdd (patch) | |
tree | 5fc60442bc92250646ad9b104fb04174a44fc1e1 /ms/controllerblueprints/modules/db-resources/src | |
parent | 88734c15a7822df7d27c23bcb08a3e808dd6634b (diff) |
Add support for blueprintprocessor runtime DB
- 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 <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/controllerblueprints/modules/db-resources/src')
3 files changed, 263 insertions, 0 deletions
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 000000000..881e3bc40 --- /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 000000000..4965677ef --- /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 <T> Model + * @param <B> ModelContent + */ +@NoRepositoryBean +interface ModelContentRepository<T, B> : JpaRepository<B, String> { + + /** + * This is a findById method + * + * @param id id + * @return Optional<T> + */ + @NotNull + override fun findById(@NotNull id: String): Optional<B> + + /** + * This is a findTopByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional<B> + */ + fun findTopByBlueprintModelAndContentType(blueprintModel: T, + contentType: String): Optional<B> + + /** + * This is a findByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional<BlueprintModelContent> + */ + fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List<B> + + /** + * This is a findByBlueprintModel method + * + * @param blueprintModel B + * @return Optional<T> + */ + fun findByBlueprintModel(blueprintModel: T): List<B> + + /** + * This is a findByBlueprintModelAndContentTypeAndName method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @param name name + * @return Optional<B> + */ + fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, + contentType: String, name: String): Optional<B> + + /** + * 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 000000000..c31f009a6 --- /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 <T> Model + */ +@NoRepositoryBean +interface ModelRepository<T> : JpaRepository<T, String> { + + /** + * This is a findById method + * + * @param id id + * @return Optional<T> + */ + @NotNull + override fun findById(@NotNull id: String): Optional<T> + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional<T> + */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<T> + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName artifactName + * @return Optional<T> + */ + fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): Optional<T> + + /** + * This is a findTopByArtifactName method + * + * @param artifactName artifactName + * @return Optional<T> + */ + fun findTopByArtifactName(artifactName: String): List<T> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional<ModelType> + */ + fun findByTagsContainingIgnoreCase(tags: String): List<T> + + /** + * 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) + +} |