From 0094e13ddec035faf7f80943783943003f12889a Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Thu, 19 May 2022 11:05:13 -0400 Subject: CCSDK-3671 add workflows list for grpc Issue-ID: CCSDK-3671 1. added grpc 'getWorkflows' for BlueprintManagement 2. during CBA upload, the workflows get cached to BLUEPRINT_MODEL.workflows 3. reworked HTTP endpoint to use above "/workflows/blueprint-name/{name}/version/{version}" 4. If CDS is upgraded, with existing CBAs present, fallback by parsing the CBA instead of DB lookup Signed-off-by: Oleg Mitsura Change-Id: I68bebfe23c0b16ea288512f1087bfe1ceef57686 --- .../db/primary/domain/BlueprintModel.kt | 23 ++++++++++++++++++++++ .../primary/repository/BlueprintModelRepository.kt | 10 ++++++++++ .../primary/service/BlueprintCatalogServiceImpl.kt | 6 ++++-- .../BlueprintProcessorCatalogServiceImpl.kt | 8 ++++---- .../db/BlueprintProcessorCatalogServiceImplTest.kt | 11 +++++++---- 5 files changed, 48 insertions(+), 10 deletions(-) (limited to 'ms/blueprintsprocessor/modules/commons/db-lib') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt index 9f4d32e7a..1feac8cd2 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt @@ -19,12 +19,17 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain import com.fasterxml.jackson.annotation.JsonFormat import io.swagger.annotations.ApiModelProperty import org.hibernate.annotations.Proxy +import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.io.Serializable import java.util.Date +import javax.persistence.AttributeConverter import javax.persistence.CascadeType import javax.persistence.Column +import javax.persistence.Convert +import javax.persistence.Converter import javax.persistence.Entity import javax.persistence.EntityListeners import javax.persistence.FetchType @@ -123,8 +128,26 @@ class BlueprintModel : Serializable { @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL]) var blueprintModelContent: BlueprintModelContent? = null + // will be populated with workflow specs for each workflow (JSON object) + @Lob + @Convert(converter = WorkflowsConverter::class) + @Column(name = "workflows", nullable = false) + lateinit var workflows: Map + companion object { private const val serialVersionUID = 1L } + + @Converter + class WorkflowsConverter : AttributeConverter, String> { + override fun convertToDatabaseColumn(node: Map): String { + return JacksonUtils.getJson(node, true) + } + + override fun convertToEntityAttribute(dbData: String): Map { + if (dbData == null || "".equals(dbData)) return emptyMap() + return JacksonUtils.getMapFromJson(dbData, Workflow::class.java) + } + } } diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt index a6f0da1cc..67869d11f 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository +import com.fasterxml.jackson.databind.JsonNode import org.jetbrains.annotations.NotNull import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel import org.springframework.data.jpa.repository.JpaRepository @@ -59,6 +60,15 @@ interface BlueprintModelRepository : JpaRepository { @Query("SELECT m.id FROM BlueprintModel m WHERE m.artifactName = :artifactName AND m.artifactVersion = :artifactVersion") fun findIdByArtifactNameAndArtifactVersion(@Param("artifactName") artifactName: String, @Param("artifactVersion") artifactVersion: String): String? + /** + * Find the workflows for a given blueprint name/version + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return String? + */ + @Query("SELECT m.workflows from BlueprintModel m WHERE m.artifactName = :artifactName AND m.artifactVersion = :artifactVersion") + fun findWorkflowsByArtifactNameAndArtifactVersion(@Param("artifactName") artifactName: String, @Param("artifactVersion") artifactVersion: String): JsonNode? + /** * This is a findTopByArtifactNameOrderByArtifactIdDesc method * 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 index 9d1826395..06376346c 100644 --- 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 @@ -21,6 +21,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow import org.onap.ccsdk.cds.controllerblueprints.core.deCompress import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService @@ -71,10 +72,11 @@ abstract class BlueprintCatalogServiceImpl( val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!) val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + val workflows = bluePrintRuntimeService.bluePrintContext().workflows()!! metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid - save(metadata, archiveFile) + save(metadata, archiveFile, workflows) return processingId } @@ -87,7 +89,7 @@ abstract class BlueprintCatalogServiceImpl( override suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version) - abstract suspend fun save(metadata: MutableMap, archiveFile: File) + abstract suspend fun save(metadata: MutableMap, archiveFile: File, workflows: Map) abstract suspend fun get(name: String, version: String, extract: Boolean): Path? abstract suspend fun delete(name: String, version: String) } 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 index 9c007da31..c45a28a07 100755 --- 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 @@ -29,6 +29,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException 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.data.Workflow import org.onap.ccsdk.cds.controllerblueprints.core.deCompress import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService @@ -120,7 +121,7 @@ class BlueprintProcessorCatalogServiceImpl( } } - override suspend fun save(metadata: MutableMap, archiveFile: File) { + override suspend fun save(metadata: MutableMap, archiveFile: File, workflows: Map) { val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] @@ -152,9 +153,8 @@ class BlueprintProcessorCatalogServiceImpl( blueprintModel.artifactVersion = artifactVersion blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]!! - val description = - if (null != metadata[BluePrintConstants.METADATA_TEMPLATE_DESCRIPTION]) metadata[BluePrintConstants.METADATA_TEMPLATE_DESCRIPTION] else "" - blueprintModel.artifactDescription = description + blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" + blueprintModel.workflows = workflows val blueprintModelContent = BlueprintModelContent() blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] 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 b7b1f78cf..5f1d09578 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 @@ -102,10 +102,11 @@ class BlueprintProcessorCatalogServiceImplTest { runBlocking { val file = normalizedFile("./target/blueprints/generated-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + val ctx = bluePrintRuntimeService.bluePrintContext() + val metadata = ctx.metadata!! metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId - blueprintsProcessorCatalogService.save(metadata, file) + blueprintsProcessorCatalogService.save(metadata, file, ctx.workflows()!!) } } @@ -114,10 +115,12 @@ class BlueprintProcessorCatalogServiceImplTest { runBlocking { val file = normalizedFile("./target/blueprints/generated-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + + val ctx = bluePrintRuntimeService.bluePrintContext() + val metadata = ctx.metadata!! metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId - blueprintsProcessorCatalogService.save(metadata, file) + blueprintsProcessorCatalogService.save(metadata, file, ctx.workflows()!!) blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true) } -- cgit 1.2.3-korg