aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/selfservice-api
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-15 16:17:17 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-18 13:56:01 -0500
commitc96644c5d07d5634916db30f01c9ed5279791b38 (patch)
tree33449ce045cf9371cfa0ef5dd213e09c84540618 /ms/blueprintsprocessor/modules/inbounds/selfservice-api
parentbdf3467390d8f5884c9ea0b5691630e15e1a9760 (diff)
Add support for async REST
Change-Id: Ieb53cbd75c2e21355b153611f6490c1b2af6053b Issue-ID: CCSDK-662 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml4
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt6
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt42
3 files changed, 48 insertions, 4 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
index 7041dab3c..5562df62c 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
@@ -29,6 +29,10 @@
<dependencies>
<dependency>
+ <groupId>org.jetbrains.kotlinx</groupId>
+ <artifactId>kotlinx-coroutines-core</artifactId>
+ </dependency>
+ <dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId>
</dependency>
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
index 35d4e67c5..e4734c441 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
@@ -38,7 +38,6 @@ class ExecutionServiceController {
@Autowired
lateinit var executionServiceHandler: ExecutionServiceHandler
-
@RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
fun ping(): Mono<String> {
@@ -58,8 +57,7 @@ class ExecutionServiceController {
@RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE])
@ApiOperation(value = "Resolve Resource Mappings", notes = "Takes the blueprint information and process as per the payload")
@ResponseBody
- fun process(@RequestBody executionServiceInput: ExecutionServiceInput): Mono<ExecutionServiceOutput> {
- val executionServiceOutput = executionServiceHandler.process(executionServiceInput)
- return Mono.just(executionServiceOutput)
+ fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ return executionServiceHandler.process(executionServiceInput)
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
index 56903745d..0b361d8ae 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
@@ -16,11 +16,18 @@
package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status
import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.saveCBAFile
import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExecutionService
+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.utils.BluePrintFileUtils
@@ -50,7 +57,20 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC
}
fun process(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ return when {
+ executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> {
+ GlobalScope.launch(Dispatchers.Default) {
+ // TODO post result in DMaaP
+ val executionServiceOutput = doProcess(executionServiceInput)
+ }
+ response(executionServiceInput)
+ }
+ executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> doProcess(executionServiceInput)
+ else -> response(executionServiceInput, true)
+ }
+ }
+ fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
val requestId = executionServiceInput.commonHeader.requestId
log.info("processing request id $requestId")
@@ -66,4 +86,26 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC
return blueprintDGExecutionService.executeDirectedGraph(blueprintRuntimeService, executionServiceInput)
}
+
+ fun response(executionServiceInput: ExecutionServiceInput, failure: Boolean = false): ExecutionServiceOutput {
+ val executionServiceOutput = ExecutionServiceOutput()
+ executionServiceOutput.commonHeader = executionServiceInput.commonHeader
+ executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
+ executionServiceOutput.payload = executionServiceInput.payload
+
+ val status = Status()
+ if (failure) {
+ status.eventType = "EVENT-COMPONENT-FAILURE"
+ status.code = 500
+ status.message = BluePrintConstants.STATUS_FAILURE
+ } else {
+ status.eventType = "EVENT-COMPONENT-PROCESSING"
+ status.code = 200
+ status.message = BluePrintConstants.STATUS_PROCESSING
+ }
+
+ executionServiceOutput.status = status
+
+ return executionServiceOutput
+ }
} \ No newline at end of file