API for list of workflow and I/O for a workflow name 45/100545/7
authorjananib <janani.b@huawei.com>
Mon, 24 Feb 2020 11:29:46 +0000 (16:59 +0530)
committerKAPIL SINGAL <ks220y@att.com>
Wed, 26 Feb 2020 16:06:18 +0000 (16:06 +0000)
REST API for CDS workflow

Issue-ID: CCSDK-422

Change-Id: Ia26287214941a20287c810dc27c030d974a8847a
Signed-off-by: jananib <janani.b@huawei.com>
ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt

index 5002810..e26af2b 100644 (file)
@@ -226,6 +226,8 @@ object BluePrintConstants {
     const val MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH = "artifact-directed-graph"
     const val MODEL_TYPE_ARTIFACT_COMPONENT_JAR = "artifact-component-jar"
 
+    const val TOSCA_SPEC = "TOSCA"
+
     val USE_SCRIPT_COMPILE_CACHE: Boolean = (System.getenv("USE_SCRIPT_COMPILE_CACHE") ?: "true").toBoolean()
 
     const val LOG_PROTECT: String = "log-protect"
index bb824ce..ff9aed6 100644 (file)
@@ -26,6 +26,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintMode
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
 import org.springframework.core.io.Resource
 import org.springframework.data.domain.Page
 import org.springframework.data.domain.PageRequest
@@ -208,4 +209,38 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     ) = mdcWebCoroutineScope {
         bluePrintModelHandler.deleteBlueprintModel(name, version)
     }
+
+    @PostMapping(
+            path = arrayOf("/workflow-spec"), produces = arrayOf(MediaType
+            .APPLICATION_JSON_VALUE),
+            consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
+    )
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
+    suspend fun workflowSpec(@RequestBody workFlowSpecReq: WorkFlowSpecRequest):
+            ResponseEntity<String> = mdcWebCoroutineScope {
+        var json = bluePrintModelHandler.prepareWorkFlowSpec(workFlowSpecReq)
+                .asJsonString()
+        ResponseEntity(json, HttpStatus.OK)
+    }
+
+    @GetMapping(
+            path = arrayOf("/workflows/blueprint-name/{name}/version/{version" +
+                    "}"),
+            produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)
+    )
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
+    suspend fun getWorkflowList(
+        @ApiParam(value = "Name of the CBA.", required = true)
+        @PathVariable(value = "name") name: String,
+        @ApiParam(value = "Version of the CBA.", required = true)
+        @PathVariable(value = "version") version: String
+    ): ResponseEntity<String> = mdcWebCoroutineScope {
+        var json = bluePrintModelHandler.getWorkflowNames(name, version)
+                .asJsonString()
+        ResponseEntity(json, HttpStatus.OK)
+    }
 }
index d0cb673..3698444 100644 (file)
@@ -22,6 +22,11 @@ import com.fasterxml.jackson.annotation.JsonInclude
 import com.fasterxml.jackson.annotation.JsonTypeInfo
 import com.fasterxml.jackson.annotation.JsonTypeName
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DATA_TYPE_JSON
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DEFAULT_VERSION_NUMBER
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.TOSCA_SPEC
+import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
+import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 import java.io.Serializable
 import java.util.Date
@@ -32,6 +37,33 @@ class BootstrapRequest {
     var loadCBA: Boolean = false
 }
 
+class WorkFlowsResponse {
+    lateinit var blueprintName: String
+    var version: String = DEFAULT_VERSION_NUMBER
+    var workflows: MutableSet<String> = mutableSetOf()
+}
+
+class WorkFlowSpecRequest {
+    lateinit var blueprintName: String
+    var version: String = DEFAULT_VERSION_NUMBER
+    var returnContent: String = DATA_TYPE_JSON
+    lateinit var workflowName: String
+    var specType: String = TOSCA_SPEC
+}
+
+class WorkFlowSpecResponse {
+    lateinit var blueprintName: String
+    var version: String = DEFAULT_VERSION_NUMBER
+    lateinit var workFlowData: WorkFlowData
+    var dataTypes: MutableMap<String, DataType>? = mutableMapOf()
+}
+
+class WorkFlowData {
+    lateinit var workFlowName: String
+    var inputs: MutableMap<String, PropertyDefinition>? = null
+    var outputs: MutableMap<String, PropertyDefinition>? = null
+}
+
 /**
  * ArtifactRequest.java Purpose: Provide Configuration Generator ArtifactRequest Model
  *
index 274650a..e983932 100644 (file)
@@ -25,10 +25,15 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintMod
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelSearchRepository
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.BootstrapRequest
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowData
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecRequest
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowsResponse
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BluePrintDatabaseLoadService
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
 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.DataType
 import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
 import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
@@ -37,7 +42,9 @@ import org.onap.ccsdk.cds.controllerblueprints.core.logger
 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.springframework.core.io.ByteArrayResource
 import org.springframework.core.io.Resource
 import org.springframework.data.domain.Page
@@ -89,6 +96,68 @@ open class BluePrintModelHandler(
         }
     }
 
+    @Throws(BluePrintException::class)
+    open suspend fun prepareWorkFlowSpec(req: WorkFlowSpecRequest):
+            WorkFlowSpecResponse {
+        val basePath = blueprintsProcessorCatalogService.getFromDatabase(req
+                .blueprintName, req.version)
+        log.info("blueprint base path $basePath")
+
+        val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(basePath.toString())
+        val workFlow = blueprintContext.workflowByName(req.workflowName)
+
+        val wfRes = WorkFlowSpecResponse()
+        wfRes.blueprintName = req.blueprintName
+        wfRes.version = req.version
+
+        val workFlowData = WorkFlowData()
+        workFlowData.workFlowName = req.workflowName
+        workFlowData.inputs = workFlow.inputs
+        workFlowData.outputs = workFlow.outputs
+
+        for ((k, v) in workFlow.inputs!!) {
+            addDataType(v.type, blueprintContext, wfRes)
+        }
+
+        for ((k, v) in workFlow.outputs!!) {
+            addDataType(v.type, blueprintContext, wfRes)
+        }
+        wfRes.workFlowData = workFlowData
+        return wfRes
+    }
+
+    private fun addDataType(name: String, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
+        var data = ctx.dataTypeByName(name)
+        if (data != null) {
+            res.dataTypes?.put(name, data)
+            addParentDataType(data, ctx, res)
+        }
+    }
+
+    private fun addParentDataType(data: DataType, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
+        for ((k, v) in data.properties!!) {
+            addDataType(v.type, ctx, res)
+        }
+    }
+
+    @Throws(BluePrintException::class)
+    open suspend fun getWorkflowNames(name: String, version: String): WorkFlowsResponse {
+        val basePath = blueprintsProcessorCatalogService.getFromDatabase(
+                name, version)
+        log.info("blueprint base path $basePath")
+
+        var res = WorkFlowsResponse()
+        res.blueprintName = name
+        res.version = version
+
+        val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(
+                basePath.toString())
+        if (blueprintContext.workflows() != null) {
+            res.workflows = blueprintContext.workflows()!!.keys
+        }
+        return res
+    }
+
     /**
      * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
      *