summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor')
-rw-r--r--ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt26
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt4
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt22
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt7
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt168
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt5
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt55
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt172
8 files changed, 436 insertions, 23 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt
index 438e755cf..41bbd1dfd 100644
--- a/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt
+++ b/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt
@@ -95,3 +95,29 @@ open class Status {
@get:ApiModelProperty(required = true)
var message: String = "success"
}
+
+open class BluePrintManagementInput {
+ @get:ApiModelProperty(required = true)
+ lateinit var commonHeader: CommonHeader
+ @get:ApiModelProperty(required = false)
+ lateinit var blueprintName: String
+ @get:ApiModelProperty(required = false)
+ lateinit var blueprintVersion: String
+ @get:ApiModelProperty(required = true)
+ lateinit var fileChunk: FileChunk
+}
+
+open class FileChunk {
+ @get:ApiModelProperty(required = true)
+ lateinit var chunk: ByteArray
+}
+
+open class BluePrintManagementOutput {
+ @get:ApiModelProperty(required = true)
+ lateinit var commonHeader: CommonHeader
+ @get:ApiModelProperty(required = true)
+ var status: Status = Status()
+}
+
+
+
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt
index aa01f2204..2cd7a810e 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt
@@ -22,12 +22,12 @@ import io.grpc.stub.StreamObserver
import org.apache.commons.io.FileUtils
import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.currentTimestamp
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Status
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementOutput
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc
-import org.onap.ccsdk.apps.controllerblueprints.management.api.CommonHeader
-import org.onap.ccsdk.apps.controllerblueprints.management.api.Status
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import java.io.File
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt
index 4ca0cfa92..453306de4 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt
@@ -18,6 +18,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
import io.grpc.stub.StreamObserver
import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toJava
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toProto
import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput
@@ -30,27 +32,29 @@ class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: Blu
: BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() {
private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java)
-
override fun process(responseObserver: StreamObserver<ExecutionServiceOutput>?): StreamObserver<ExecutionServiceInput> {
return object : StreamObserver<ExecutionServiceInput> {
-
override fun onNext(executionServiceInput: ExecutionServiceInput) {
- TODO("Handle Processing Response")
-// executionServiceHandler.process(executionServiceInput)
-// responseObserver.onNext(executionServiceOuput)
+ try {
+ val output = executionServiceHandler.process(executionServiceInput.toJava())
+ .toProto(executionServiceInput.payload)
+ responseObserver?.onNext(output)
+ } catch (e: Exception) {
+ onError(e)
+ }
}
override fun onError(error: Throwable) {
- log.warn("Fail to process message", error)
+ log.debug("Fail to process message", error)
+ responseObserver?.onError(io.grpc.Status.INTERNAL
+ .withDescription(error.message)
+ .asException())
}
override fun onCompleted() {
responseObserver?.onCompleted()
}
}
-
}
-
-
} \ No newline at end of file
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 0b361d8ae..ec605c1d3 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
@@ -66,11 +66,11 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC
response(executionServiceInput)
}
executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> doProcess(executionServiceInput)
- else -> response(executionServiceInput, true)
+ else -> response(executionServiceInput, "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", true)
}
}
- fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ private fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
val requestId = executionServiceInput.commonHeader.requestId
log.info("processing request id $requestId")
@@ -87,13 +87,14 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC
return blueprintDGExecutionService.executeDirectedGraph(blueprintRuntimeService, executionServiceInput)
}
- fun response(executionServiceInput: ExecutionServiceInput, failure: Boolean = false): ExecutionServiceOutput {
+ fun response(executionServiceInput: ExecutionServiceInput, errorMessage: String = "", failure: Boolean = false): ExecutionServiceOutput {
val executionServiceOutput = ExecutionServiceOutput()
executionServiceOutput.commonHeader = executionServiceInput.commonHeader
executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
executionServiceOutput.payload = executionServiceInput.payload
val status = Status()
+ status.errorMessage = errorMessage
if (failure) {
status.eventType = "EVENT-COMPONENT-FAILURE"
status.code = 500
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt
new file mode 100644
index 000000000..220a6fd68
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 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.blueprintsprocessor.selfservice.api.utils
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import com.fasterxml.jackson.databind.node.ObjectNode
+import com.google.common.base.Strings
+import com.google.protobuf.Struct
+import com.google.protobuf.Value
+import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Status
+import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
+import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput
+import java.text.SimpleDateFormat
+import java.util.*
+
+private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+
+// STRUCT
+
+fun Struct.toJava(): ObjectNode {
+ val objectNode = JsonNodeFactory.instance.objectNode()
+ return getNode(objectNode)
+}
+
+fun Struct.getNode(objectNode: ObjectNode): ObjectNode {
+ this.fieldsMap.forEach {
+ when (it.value.kindCase.name) {
+ "BOOL_VALUE" -> objectNode.put(it.key, it.value.boolValue)
+ "KIND_NOT_SET" -> objectNode.put(it.key, it.value.toByteArray())
+ "LIST_VALUE" -> {
+ val arrayNode = JsonNodeFactory.instance.arrayNode()
+ it.value.listValue.valuesList.forEach { arrayNode.addPOJO(it.getValue()) }
+ objectNode.put(it.key, arrayNode)
+ }
+ "NULL_VALUE" -> objectNode.put(it.key, JsonNodeFactory.instance.nullNode())
+ "NUMBER_VALUE" -> objectNode.put(it.key, it.value.numberValue)
+ "STRING_VALUE" -> objectNode.put(it.key, it.value.stringValue)
+ "STRUCT_VALUE" -> objectNode.put(it.key, it.value.structValue.getNode(JsonNodeFactory.instance.objectNode()))
+ }
+ }
+ return objectNode
+}
+
+fun Value.getValue(): Any {
+ return when (this.kindCase.name) {
+ "BOOL_VALUE" -> this.boolValue
+ "KIND_NOT_SET" -> this.toByteArray()
+ "LIST_VALUE" -> listOf(this.listValue.valuesList.forEach { it.getValue() })
+ "NULL_VALUE" -> JsonNodeFactory.instance.nullNode()
+ "NUMBER_VALUE" -> this.numberValue
+ "STRING_VALUE" -> this.stringValue
+ "STRUCT_VALUE" -> this.structValue.getNode(JsonNodeFactory.instance.objectNode())
+ else -> {
+ "undefined"
+ }
+ }
+}
+
+// ACTION IDENTIFIER
+
+fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers.toProto(): ActionIdentifiers {
+ val actionIdentifier = ActionIdentifiers.newBuilder()
+ actionIdentifier.actionName = this.actionName
+ actionIdentifier.blueprintName = this.blueprintName
+ actionIdentifier.blueprintVersion = this.blueprintVersion
+ actionIdentifier.mode = this.mode
+ return actionIdentifier.build()
+}
+
+fun ActionIdentifiers.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers {
+ val actionIdentifier = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers()
+ actionIdentifier.actionName = this.actionName
+ actionIdentifier.blueprintName = this.blueprintName
+ actionIdentifier.blueprintVersion = this.blueprintVersion
+ actionIdentifier.mode = this.mode
+ return actionIdentifier
+}
+
+// COMMON HEADER
+
+fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader.toProto(): CommonHeader {
+ val commonHeader = CommonHeader.newBuilder()
+ commonHeader.originatorId = this.originatorId
+ commonHeader.requestId = this.requestId
+ commonHeader.subRequestId = this.subRequestId
+ commonHeader.timestamp = this.timestamp.toString()
+ commonHeader.flag = this.flags?.toProto()
+ return commonHeader.build()
+}
+
+fun CommonHeader.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader {
+ val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader()
+ commonHeader.originatorId = this.originatorId
+ commonHeader.requestId = this.requestId
+ commonHeader.subRequestId = this.subRequestId
+ commonHeader.timestamp = if (!Strings.isNullOrEmpty(this.timestamp)) {
+ formatter.parse(this.timestamp)
+ } else {
+ Date()
+ }
+ commonHeader.flags = this.flag?.toJava()
+ return commonHeader
+}
+
+// FLAG
+
+fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags.toProto(): Flag {
+ val flag = Flag.newBuilder()
+ flag.isForce = this.isForce
+ flag.ttl = this.ttl
+ return flag.build()
+}
+
+fun Flag.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags {
+ val flag = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags()
+ flag.isForce = this.isForce
+ flag.ttl = this.ttl
+ return flag
+}
+
+// STATUS
+
+fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status.toProto(): Status {
+ val status = Status.newBuilder()
+ status.code = this.code
+ status.errorMessage = this.errorMessage
+ status.message = this.message
+ status.timestamp = this.timestamp.toString()
+ status.eventType = this.eventType
+ return status.build()
+}
+
+// EXECUTION INPUT
+
+fun ExecutionServiceInput.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput {
+ val executionServiceInput = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput()
+ executionServiceInput.actionIdentifiers = this.actionIdentifiers.toJava()
+ executionServiceInput.commonHeader = this.commonHeader.toJava()
+ executionServiceInput.payload = this.payload.toJava()
+ return executionServiceInput
+}
+
+// EXECUTION OUPUT
+
+fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput.toProto(payload: Struct): ExecutionServiceOutput {
+ val executionServiceOuput = ExecutionServiceOutput.newBuilder()
+ executionServiceOuput.actionIdentifiers = this.actionIdentifiers.toProto()
+ executionServiceOuput.commonHeader = this.commonHeader.toProto()
+ executionServiceOuput.status = this.status.toProto()
+ executionServiceOuput.payload = payload
+ return executionServiceOuput.build()
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
index a48e699cb..668d3dbf0 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
@@ -23,9 +23,9 @@ import org.apache.commons.io.FileUtils
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc
-import org.onap.ccsdk.apps.controllerblueprints.management.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -87,7 +87,8 @@ class BluePrintManagementGRPCHandlerTest {
val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
- val commonHeader = CommonHeader.newBuilder()
+ val commonHeader = CommonHeader
+ .newBuilder()
.setTimestamp("2012-04-23T18:25:43.511Z")
.setOriginatorId("System")
.setRequestId(id)
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
index 280227d06..01984b21d 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
@@ -19,15 +19,20 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
import com.google.protobuf.util.JsonFormat
+import io.grpc.stub.StreamObserver
import io.grpc.testing.GrpcServerRule
+import org.junit.Assert
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
-import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
+import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput
+import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation.ComponentScan
@@ -43,6 +48,7 @@ import kotlin.test.BeforeTest
@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
@TestPropertySource(locations = ["classpath:application-test.properties"])
class BluePrintProcessingGRPCHandlerTest {
+ private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)
@get:Rule
val grpcServerRule = GrpcServerRule().directExecutor()
@@ -50,17 +56,35 @@ class BluePrintProcessingGRPCHandlerTest {
@Autowired
lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
+ lateinit var requestObs: StreamObserver<ExecutionServiceInput>
+
@BeforeTest
fun init() {
- // Create a server, add service, start, and register for automatic graceful shutdown.
grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
+
+ val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel)
+
+ requestObs = blockingStub.process(object : StreamObserver<ExecutionServiceOutput> {
+ override fun onNext(executionServiceOuput: ExecutionServiceOutput) {
+ log.debug("onNext {}", executionServiceOuput)
+ if ("1234".equals(executionServiceOuput.commonHeader.requestId)) {
+ Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage)
+ }
+ }
+
+ override fun onError(error: Throwable) {
+ log.debug("Fail to process message", error)
+ Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message)
+ }
+
+ override fun onCompleted() {
+ log.info("Done")
+ }
+ })
}
@Test
fun testSelfServiceGRPCHandler() {
-
- val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
-
val commonHeader = CommonHeader.newBuilder()
.setTimestamp("2012-04-23T18:25:43.511Z")
.setOriginatorId("System")
@@ -76,8 +100,25 @@ class BluePrintProcessingGRPCHandlerTest {
.setPayload(payloadBuilder.build())
.build()
-// val response = blockingStub.process(input)
-// assertNotNull(response, "Response is null")
+ requestObs.onNext(input)
+
+ val commonHeader2 = CommonHeader.newBuilder()
+ .setTimestamp("2012-04-23T18:25:43.511Z")
+ .setOriginatorId("System")
+ .setRequestId("2345")
+ .setSubRequestId("1234-56").build()
+
+ val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build()
+
+ val input2 = ExecutionServiceInput.newBuilder()
+ .setCommonHeader(commonHeader2)
+ .setActionIdentifiers(actionIdentifier)
+ .setPayload(payloadBuilder.build())
+ .build()
+
+ requestObs.onNext(input2)
+
+ requestObs.onCompleted()
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt
new file mode 100644
index 000000000..f2048c391
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt
@@ -0,0 +1,172 @@
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.protobuf.ListValue
+import com.google.protobuf.NullValue
+import com.google.protobuf.Struct
+import com.google.protobuf.Value
+import com.google.protobuf.util.JsonFormat
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags
+import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag
+import org.springframework.test.context.junit4.SpringRunner
+import java.text.SimpleDateFormat
+
+@RunWith(SpringRunner::class)
+class BluePrintMappingsTest {
+
+ val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ val dateString = "2019-01-16T18:25:43.511Z"
+ val dateForTest = formatter.parse(dateString)
+
+ val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build()
+
+ fun createFlag(): Flags {
+ val flag = Flags()
+ flag.isForce = false
+ flag.ttl = 1
+ return flag
+ }
+
+ @Test
+ fun flagToJavaTest() {
+ val flag2 = flag.toJava()
+
+ Assert.assertEquals(flag.isForce, flag2.isForce)
+ Assert.assertEquals(flag.ttl, flag2.ttl)
+ }
+
+ @Test
+ fun flagToProtoTest() {
+ val flag = createFlag()
+ val flag2 = flag.toProto()
+
+ Assert.assertEquals(flag.isForce, flag2.isForce)
+ Assert.assertEquals(flag.ttl, flag2.ttl)
+ }
+
+ fun createStatus(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status {
+ val status = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status()
+ status.code = 400
+ status.errorMessage = "Concurrent modification exception"
+ status.eventType = "Update"
+ status.message = "Error uploading data"
+ status.timestamp = dateForTest
+ return status
+ }
+
+ @Test
+ fun statusToProtoTest() {
+ val status = createStatus()
+ val status2 = status.toProto()
+
+ Assert.assertEquals(status.code, status2.code)
+ Assert.assertEquals(status.errorMessage, status2.errorMessage)
+ Assert.assertEquals(status.eventType, status2.eventType)
+ Assert.assertEquals(status.message, status2.message)
+ Assert.assertEquals(status.timestamp.toString(), status2.timestamp)
+ }
+
+ @Test
+ fun commonHeaderToJavaTest() {
+ val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build()
+
+ val commonHeader = CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString).setFlag(flag).build()
+ val commonHeader2 = commonHeader.toJava()
+
+ Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId)
+ Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId)
+ Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId)
+ Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp))
+ }
+
+ fun createCommonHeader(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader {
+ val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader()
+ commonHeader.flags = createFlag()
+ commonHeader.originatorId = "1234"
+ commonHeader.requestId = "2345"
+ commonHeader.subRequestId = "0123"
+ commonHeader.timestamp = dateForTest
+ return commonHeader
+ }
+
+ @Test
+ fun commonHeaderToProtoTest() {
+ val commonHeader = createCommonHeader()
+ val commonHeader2 = commonHeader.toProto()
+ Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId)
+ Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId)
+ Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId)
+ Assert.assertEquals(commonHeader.timestamp.toString(), commonHeader2.timestamp)
+ }
+
+ @Test
+ fun actionIdentifierToJavaTest() {
+ val actionIdentifiers = ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0").setMode("Execution").build()
+ val actionIdentifiers2 = actionIdentifiers.toJava()
+
+ Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName)
+ Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName)
+ Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion)
+ Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode)
+ }
+
+ fun createActionIdentifier(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers {
+ val ac = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers()
+ ac.mode = "mode"
+ ac.blueprintVersion = "version"
+ ac.blueprintName = "name"
+ ac.actionName = "action"
+ return ac
+ }
+
+ @Test
+ fun actionIdentifierToProtoTest() {
+ val actionIdentifiers = createActionIdentifier()
+ val actionIdentifiers2 = actionIdentifiers.toProto()
+
+ Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName)
+ Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName)
+ Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion)
+ Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode)
+ }
+
+ @Test
+ fun testStructToJava() {
+ val struct = Struct.newBuilder().putAllFields(createValues()).build()
+ val struct2 = struct.toJava()
+
+ val mapper = ObjectMapper()
+
+ Assert.assertEquals(JsonFormat.printer().print(struct).replace(" ", ""),
+ mapper.writerWithDefaultPrettyPrinter().writeValueAsString(struct2).replace(" ", ""))
+ }
+
+ fun createValues(): Map<String, Value> {
+ val map = mutableMapOf<String, Value>()
+
+ val boolValue = Value.newBuilder().setBoolValue(true).build()
+ val stringValue = Value.newBuilder().setStringValue("string").build()
+ val doubleValue = Value.newBuilder().setNumberValue(Double.MAX_VALUE).build()
+ val jsonValue = Value.newBuilder().setStringValue("{\"bblah\": \"bbblo\"}").build()
+ val listValue = Value.newBuilder().setListValue(ListValue.newBuilder().addValues(boolValue).addValues(boolValue).build()).build()
+ val nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()
+
+ map.put("bool", boolValue)
+ map.put("string", stringValue)
+ map.put("doublbe", doubleValue)
+ map.put("json", jsonValue)
+ map.put("list", listValue)
+ map.put("null", nullValue)
+
+ val structValue = Value.newBuilder().setStructValue(Struct.newBuilder().putAllFields(map).build()).build()
+
+ map.put("struct", structValue)
+
+ return map
+ }
+} \ No newline at end of file