aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules
diff options
context:
space:
mode:
authorBrinda Santh <bs2796@att.com>2020-02-01 18:47:59 -0500
committerBrinda Santh <bs2796@att.com>2020-02-01 18:47:59 -0500
commitc6da9f5aaa7c29644ead22d5ba5fc8ef3ec5811a (patch)
tree60d328afa8a7516dec7a2da20bdcc76ee8644bf6 /ms/blueprintsprocessor/modules
parent5c094c6adc53d958b2079de67d9d26242e10d7ef (diff)
Expose rest API with non blocking call.
Convert Mono and Flux to coroutines Convert reactor mdc to coroutine mdc Issue-ID: CCSDK-2052 Signed-off-by: Brinda Santh <bs2796@att.com> Change-Id: Ic58c0b74866d28fd2d803b96626b08f8e8b2db56
Diffstat (limited to 'ms/blueprintsprocessor/modules')
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt28
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt57
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt33
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt61
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt116
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt13
6 files changed, 182 insertions, 126 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt
index 313710745..846a94a09 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt
@@ -21,10 +21,12 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.InternalCoroutinesApi
+import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.handleCoroutineException
import kotlinx.coroutines.newCoroutineContext
import kotlinx.coroutines.reactor.ReactorContext
import kotlinx.coroutines.reactor.asCoroutineContext
+import kotlinx.coroutines.withContext
import org.apache.http.message.BasicHeader
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID
@@ -95,6 +97,32 @@ class RestLoggerService {
}
/** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */
+suspend fun <T> mdcWebCoroutineScope(
+ block: suspend CoroutineScope.() -> T
+) = coroutineScope {
+ val reactorContext = this.coroutineContext[ReactorContext]
+ /** Populate MDC context only if present in Reactor Context */
+ val newContext = if (reactorContext != null &&
+ !reactorContext.context.isEmpty &&
+ reactorContext.context.hasKey(MDCContext)
+ ) {
+ val mdcContext = reactorContext.context.get<MDCContext>(MDCContext)
+ if (mdcContext != null)
+ newCoroutineContext(this.coroutineContext + reactorContext + mdcContext)
+ else
+ newCoroutineContext(this.coroutineContext + reactorContext)
+ } else this.coroutineContext
+ // Execute the block with new and old context
+ withContext(newContext) {
+ block()
+ }
+}
+
+@Deprecated(
+ message = "Now CDS supports Coruoutin rest controller",
+ replaceWith = ReplaceWith("mdcWebCoroutineScope")
+)
+/** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */
@UseExperimental(InternalCoroutinesApi::class)
fun <T> monoMdc(
context: CoroutineContext = EmptyCoroutineContext,
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
index 0eb29f4cc..bb824ce4d 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.monoMdc
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.springframework.core.io.Resource
import org.springframework.data.domain.Page
@@ -45,7 +45,6 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
-import reactor.core.publisher.Mono
/**
* BlueprintModelController Purpose: Handle controllerBlueprint API request
@@ -64,7 +63,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Mono<Unit> = monoMdc {
+ suspend fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Unit = mdcWebCoroutineScope {
bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest)
}
@@ -72,7 +71,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
+ suspend fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = mdcWebCoroutineScope {
bluePrintModelHandler.saveBlueprintModel(filePart)
}
@@ -98,9 +97,10 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@PreAuthorize("hasRole('USER')")
- fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> {
- return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
- }
+ suspend fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> =
+ mdcWebCoroutineScope {
+ bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
+ }
@GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@@ -118,20 +118,20 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@DeleteMapping("/{id}")
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun deleteBlueprint(@PathVariable(value = "id") id: String) {
- this.bluePrintModelHandler.deleteBlueprintModel(id)
+ suspend fun deleteBlueprint(@PathVariable(value = "id") id: String) = mdcWebCoroutineScope {
+ bluePrintModelHandler.deleteBlueprintModel(id)
}
@GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun getBlueprintByNameAndVersion(
+ suspend fun getBlueprintByNameAndVersion(
@PathVariable(value = "name") name: String,
@PathVariable(value = "version") version: String
- ):
- Mono<ResponseEntity<BlueprintModelSearch>> = monoMdc {
- var bluePrintModel: BlueprintModelSearch? = bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
+ ): ResponseEntity<BlueprintModelSearch> = mdcWebCoroutineScope {
+ val bluePrintModel: BlueprintModelSearch? =
+ bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
if (bluePrintModel != null)
ResponseEntity(bluePrintModel, HttpStatus.OK)
else
@@ -142,11 +142,10 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun downloadBlueprintByNameAndVersion(
+ suspend fun downloadBlueprintByNameAndVersion(
@PathVariable(value = "name") name: String,
@PathVariable(value = "version") version: String
- ):
- Mono<ResponseEntity<Resource>> = monoMdc {
+ ): ResponseEntity<Resource> = mdcWebCoroutineScope {
bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
}
@@ -154,17 +153,18 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
- return this.bluePrintModelHandler.getBlueprintModelSearch(id)
+ suspend fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch = mdcWebCoroutineScope {
+ bluePrintModelHandler.getBlueprintModelSearch(id)
}
@GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
- bluePrintModelHandler.downloadBlueprintModelFile(id)
- }
+ suspend fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> =
+ mdcWebCoroutineScope {
+ bluePrintModelHandler.downloadBlueprintModelFile(id)
+ }
@PostMapping(
"/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
@@ -173,7 +173,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
+ suspend fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity<Resource> = mdcWebCoroutineScope {
bluePrintModelHandler.enrichBlueprint(file)
}
@@ -181,16 +181,17 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
@ResponseBody
@Throws(BluePrintException::class)
@PreAuthorize("hasRole('USER')")
- fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
+ suspend fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = mdcWebCoroutineScope {
bluePrintModelHandler.publishBlueprint(file)
}
@GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@PreAuthorize("hasRole('USER')")
- fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
- return this.bluePrintModelHandler.searchBlueprintModels(tags)
- }
+ suspend fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> =
+ mdcWebCoroutineScope {
+ bluePrintModelHandler.searchBlueprintModels(tags)
+ }
@DeleteMapping("/name/{name}/version/{version}")
@ApiOperation(
@@ -199,12 +200,12 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
produces = MediaType.APPLICATION_JSON_VALUE
)
@PreAuthorize("hasRole('USER')")
- fun deleteBlueprint(
+ suspend fun deleteBlueprint(
@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
- ) = monoMdc {
+ ) = mdcWebCoroutineScope {
bluePrintModelHandler.deleteBlueprintModel(name, version)
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt
index adeb3cf89..1c550bb3e 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt
@@ -17,9 +17,9 @@
package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
-import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.DeleteMapping
@@ -32,34 +32,39 @@ import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
@RestController
-@RequestMapping(value = arrayOf("/api/v1/model-type"))
+@RequestMapping(value = ["/api/v1/model-type"])
open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
- @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
- fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking {
+ @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
+ suspend fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = mdcWebCoroutineScope {
modelTypeHandler.getModelTypeByName(name)
}
- @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
- fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking {
+ @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
+ suspend fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = mdcWebCoroutineScope {
modelTypeHandler.searchModelTypes(tags)
}
- @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
+ @GetMapping(path = ["/by-definition/{definitionType}"], produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
- fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking {
- modelTypeHandler.getModelTypeByDefinitionType(definitionType)
- }
+ suspend fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> =
+ mdcWebCoroutineScope {
+ modelTypeHandler.getModelTypeByDefinitionType(definitionType)
+ }
- @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE))
+ @PostMapping(
+ path = [""],
+ produces = [MediaType.APPLICATION_JSON_VALUE],
+ consumes = [MediaType.APPLICATION_JSON_VALUE]
+ )
@ResponseBody
@Throws(BluePrintException::class)
- fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking {
+ suspend fun saveModelType(@RequestBody modelType: ModelType): ModelType = mdcWebCoroutineScope {
modelTypeHandler.saveModel(modelType)
}
- @DeleteMapping(path = arrayOf("/{name}"))
- fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking {
+ @DeleteMapping(path = ["/{name}"])
+ suspend fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
modelTypeHandler.deleteByModelName(name)
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt
index 75403d479..7f569cfba 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt
@@ -16,9 +16,9 @@
package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
-import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
@@ -39,50 +39,67 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
@GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@Throws(BluePrintException::class)
- fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking {
- resourceDictionaryHandler.getResourceDictionaryByName(name)
- }
+ suspend fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary =
+ mdcWebCoroutineScope {
+ resourceDictionaryHandler.getResourceDictionaryByName(name)
+ }
- @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
+ @PostMapping(
+ path = [""],
+ produces = [MediaType.APPLICATION_JSON_VALUE],
+ consumes = [MediaType.APPLICATION_JSON_VALUE]
+ )
@ResponseBody
@Throws(BluePrintException::class)
- fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking {
- resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
- }
+ suspend fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary =
+ mdcWebCoroutineScope {
+ resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
+ }
- @PostMapping(path = ["/definition"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
+ @PostMapping(
+ path = ["/definition"],
+ produces = [MediaType.APPLICATION_JSON_VALUE],
+ consumes = [MediaType.APPLICATION_JSON_VALUE]
+ )
@ResponseBody
@Throws(BluePrintException::class)
- fun saveResourceDictionary(@RequestBody resourceDefinition: ResourceDefinition): ResourceDefinition = runBlocking {
- resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
- }
+ suspend fun saveResourceDictionary(@RequestBody resourceDefinition: ResourceDefinition): ResourceDefinition =
+ mdcWebCoroutineScope {
+ resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
+ }
@DeleteMapping(path = ["/{name}"])
- fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking {
+ suspend fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
resourceDictionaryHandler.deleteResourceDictionary(name)
}
- @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
+ @PostMapping(
+ path = ["/by-names"],
+ produces = [MediaType.APPLICATION_JSON_VALUE],
+ consumes = [MediaType.APPLICATION_JSON_VALUE]
+ )
@ResponseBody
- fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking {
- resourceDictionaryHandler.searchResourceDictionaryByNames(names)
- }
+ suspend fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> =
+ mdcWebCoroutineScope {
+ resourceDictionaryHandler.searchResourceDictionaryByNames(names)
+ }
@GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
- fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking {
- resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
- }
+ suspend fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> =
+ mdcWebCoroutineScope {
+ resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
+ }
@GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
- fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking {
+ suspend fun getResourceSourceMapping(): ResourceSourceMapping = mdcWebCoroutineScope {
resourceDictionaryHandler.getResourceSourceMapping()
}
@GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
- fun getResourceDictionaryDistinct(): List<String> = runBlocking {
+ suspend fun getResourceDictionaryDistinct(): List<String> = mdcWebCoroutineScope {
resourceDictionaryHandler.getResourceDictionaryDistinct()
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt
index 6b409dbef..c5bcd467b 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt
@@ -16,6 +16,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
+import kotlinx.coroutines.runBlocking
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
@@ -23,8 +24,8 @@ import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.annotation.Commit
import org.springframework.test.context.ContextConfiguration
@@ -39,10 +40,10 @@ import org.springframework.test.context.junit4.SpringRunner
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class ModelTypeControllerTest {
- private val log = LoggerFactory.getLogger(ModelTypeControllerTest::class.java)!!
+ private val log = logger(ModelTypeControllerTest::class.java)!!
@Autowired
- internal var modelTypeController: ModelTypeController? = null
+ lateinit var modelTypeController: ModelTypeController
private var modelName = "test-datatype"
@@ -50,73 +51,80 @@ class ModelTypeControllerTest {
@Commit
@Throws(Exception::class)
fun test01SaveModelType() {
- log.info("**************** test01SaveModelType ********************")
-
- val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json")
- var modelType = ModelType()
- modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
- modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
- modelType.description = "Definition for Sample Datatype "
- modelType.definition = JacksonUtils.jsonNode(content)
- modelType.modelName = modelName
- modelType.version = "1.0.0"
- modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," +
+ runBlocking {
+ log.info("**************** test01SaveModelType ********************")
+
+ val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json")
+ var modelType = ModelType()
+ modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
+ modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
+ modelType.description = "Definition for Sample Datatype "
+ modelType.definition = JacksonUtils.jsonNode(content)
+ modelType.modelName = modelName
+ modelType.version = "1.0.0"
+ modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," +
BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
- modelType.updatedBy = "xxxxxx@xxx.com"
- modelType = modelTypeController!!.saveModelType(modelType)
- log.info("Saved Mode {}", modelType.toString())
- Assert.assertNotNull("Failed to get Saved ModelType", modelType)
- Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName)
-
- val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName)
- Assert.assertNotNull(
- "Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")",
- dbModelType
- )
-
- // Model Update
- modelType.updatedBy = "bs2796@xxx.com"
- modelType = modelTypeController!!.saveModelType(modelType)
- Assert.assertNotNull("Failed to get Saved ModelType", modelType)
- Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy)
+ modelType.updatedBy = "xxxxxx@xxx.com"
+ modelType = modelTypeController.saveModelType(modelType)
+ log.info("Saved Mode {}", modelType.toString())
+ Assert.assertNotNull("Failed to get Saved ModelType", modelType)
+ Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName)
+
+ val dbModelType = modelTypeController.getModelTypeByName(modelType.modelName)
+ Assert.assertNotNull(
+ "Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")",
+ dbModelType
+ )
+
+ // Model Update
+ modelType.updatedBy = "bs2796@xxx.com"
+ modelType = modelTypeController.saveModelType(modelType)
+ Assert.assertNotNull("Failed to get Saved ModelType", modelType)
+ Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy)
+ }
}
@Test
@Throws(Exception::class)
fun test02SearchModelTypes() {
- log.info("*********************** test02SearchModelTypes ***************************")
-
- val tags = "test-datatype"
-
- val dbModelTypes = modelTypeController!!.searchModelTypes(tags)
- Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes)
- Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty())
+ runBlocking {
+ log.info("*********************** test02SearchModelTypes ***************************")
+ val tags = "test-datatype"
+ val dbModelTypes = modelTypeController.searchModelTypes(tags)
+ Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes)
+ Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty())
+ }
}
@Test
@Throws(Exception::class)
fun test03GetModelType() {
- log.info("************************* test03GetModelType *********************************")
- val dbModelType = modelTypeController!!.getModelTypeByName(modelName)
- Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
- Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName)
-
- val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
- Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
- Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
+ runBlocking {
+ log.info("************************* test03GetModelType *********************************")
+ val dbModelType = modelTypeController.getModelTypeByName(modelName)
+ Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
+ Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName)
+
+ val dbDatatypeModelTypes =
+ modelTypeController.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
+ Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
+ Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
+ }
}
@Test
@Commit
@Throws(Exception::class)
fun test04DeleteModelType() {
- log.info(
- "************************ test03DeleteModelType ***********************"
- )
- val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName)
- Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
- Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName)
-
- modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName)
+ runBlocking {
+ log.info("************************ test03DeleteModelType ***********************")
+ val dbResourceMapping = modelTypeController.getModelTypeByName(modelName)
+ Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
+ Assert.assertNotNull(
+ "Failed to get Id for api call getModelByName ",
+ dbResourceMapping!!.modelName
+ )
+ modelTypeController.deleteModelTypeByName(dbResourceMapping.modelName)
+ }
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
index 02d3f2026..8b268d6f8 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
@@ -17,14 +17,14 @@
package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
+import com.fasterxml.jackson.databind.JsonNode
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
-import kotlinx.coroutines.Dispatchers
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.monoMdc
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.logger
@@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
-import reactor.core.publisher.Mono
import java.util.concurrent.Phaser
import javax.annotation.PreDestroy
@@ -63,7 +62,7 @@ open class ExecutionServiceController {
)
@ResponseBody
@ApiOperation(value = "Health Check", hidden = true)
- fun executionServiceControllerHealthCheck() = monoMdc(Dispatchers.IO) {
+ suspend fun executionServiceControllerHealthCheck(): JsonNode = mdcWebCoroutineScope {
"Success".asJsonPrimitive()
}
@@ -76,16 +75,14 @@ open class ExecutionServiceController {
)
@ResponseBody
@PreAuthorize("hasRole('USER')")
- fun process(
+ suspend fun process(
@ApiParam(value = "ExecutionServiceInput payload.", required = true)
@RequestBody executionServiceInput: ExecutionServiceInput
- ):
- Mono<ResponseEntity<ExecutionServiceOutput>> = monoMdc(Dispatchers.IO) {
+ ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope {
if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.")
}
-
ph.register()
val processResult = executionServiceHandler.doProcess(executionServiceInput)
ph.arriveAndDeregister()