aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-09-09 14:30:16 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2019-09-11 21:00:56 -0400
commita80bb83c9f6fd4c648abfb273d5b2b28d82a38fa (patch)
tree50758b10922f546f25e74632e38c6ec4d3fbc256 /ms/blueprintsprocessor
parent8b24f42bcba5220f72b6977441867f774aca57df (diff)
Implement GRPC response payload
Change-Id: I137cb9e2fa15c12f45a412d84e867f0613f15bf8 Issue-ID: CCSDK-1682 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt73
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt31
2 files changed, 76 insertions, 28 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
index c48f1dd98..08250ed9d 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
@@ -19,7 +19,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
import com.google.protobuf.ByteString
-import io.grpc.StatusException
+import com.google.protobuf.util.JsonFormat
import io.grpc.stub.StreamObserver
import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
@@ -27,6 +27,7 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.cds.controllerblueprints.common.api.Status
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
import org.onap.ccsdk.cds.controllerblueprints.core.emptyTONull
import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp
import org.onap.ccsdk.cds.controllerblueprints.management.api.*
@@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.stereotype.Service
+//TODO("Convert to coroutines handler")
@Service
open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: BluePrintModelHandler)
: BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() {
@@ -45,6 +47,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
StreamObserver<BluePrintManagementOutput>) {
runBlocking {
+ //TODO("catch if request id is missing")
log.info("request(${request.commonHeader.requestId})")
try {
/** Get the file byte array */
@@ -56,15 +59,16 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
when (uploadAction) {
UploadAction.DRAFT.toString() -> {
val blueprintModel = bluePrintModelHandler.upload(byteArray, false)
- responseObserver.onNext(successStatus(request.commonHeader))
+ responseObserver.onNext(successStatus(request.commonHeader, blueprintModel.asJsonString()))
}
UploadAction.PUBLISH.toString() -> {
val blueprintModel = bluePrintModelHandler.upload(byteArray, true)
- responseObserver.onNext(successStatus(request.commonHeader))
+ responseObserver.onNext(successStatus(request.commonHeader, blueprintModel.asJsonString()))
}
UploadAction.VALIDATE.toString() -> {
//TODO("Not Implemented")
- responseObserver.onError(failStatus("Not Implemented",
+ responseObserver.onNext(failStatus(request.commonHeader,
+ "Upload action($uploadAction) not implemented",
BluePrintProcessorException("Not Implemented")))
}
UploadAction.ENRICH.toString() -> {
@@ -72,13 +76,16 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
responseObserver.onNext(enrichmentStatus(request.commonHeader, enrichedByteArray))
}
else -> {
- responseObserver.onError(failStatus("Upload action($uploadAction) not implemented",
- BluePrintProcessorException("Upload action($uploadAction) not implemented")))
+ responseObserver.onNext(failStatus(request.commonHeader,
+ "Upload action($uploadAction) not implemented",
+ BluePrintProcessorException("Not implemented")))
}
}
- responseObserver.onCompleted()
} catch (e: Exception) {
- responseObserver.onError(failStatus("request(${request.commonHeader.requestId}): Failed to upload CBA", e))
+ responseObserver.onNext(failStatus(request.commonHeader,
+ "request(${request.commonHeader.requestId}): Failed to upload CBA", e))
+ } finally {
+ responseObserver.onCompleted()
}
}
}
@@ -96,9 +103,11 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
try {
bluePrintModelHandler.deleteBlueprintModel(blueprintName, blueprintVersion)
responseObserver.onNext(successStatus(request.commonHeader))
- responseObserver.onCompleted()
} catch (e: Exception) {
- responseObserver.onError(failStatus("request(${request.commonHeader.requestId}): Failed to delete $blueprint", e))
+ responseObserver.onNext(failStatus(request.commonHeader,
+ "request(${request.commonHeader.requestId}): Failed to delete $blueprint", e))
+ } finally {
+ responseObserver.onCompleted()
}
}
}
@@ -114,21 +123,37 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
.build())
.build()
- private fun successStatus(header: CommonHeader): BluePrintManagementOutput =
- BluePrintManagementOutput.newBuilder()
- .setCommonHeader(header)
- .setStatus(Status.newBuilder()
- .setTimestamp(currentTimestamp())
- .setMessage(BluePrintConstants.STATUS_SUCCESS)
- .setCode(200)
- .build())
- .build()
+ private fun successStatus(header: CommonHeader, propertyContent: String? = null): BluePrintManagementOutput {
+ // Populate Response Payload
+ val propertiesBuilder = BluePrintManagementOutput.newBuilder().propertiesBuilder
+ propertyContent?.let {
+ JsonFormat.parser().merge(propertyContent, propertiesBuilder)
+ }
+ return BluePrintManagementOutput.newBuilder()
+ .setCommonHeader(header)
+ .setProperties(propertiesBuilder.build())
+ .setStatus(Status.newBuilder()
+ .setTimestamp(currentTimestamp())
+ .setMessage(BluePrintConstants.STATUS_SUCCESS)
+ .setCode(200)
+ .build())
+ .build()
+ }
- private fun failStatus(message: String, e: Exception): StatusException {
+ private fun failStatus(header: CommonHeader, message: String, e: Exception): BluePrintManagementOutput {
log.error(message, e)
- return io.grpc.Status.INTERNAL
- .withDescription(message)
- .withCause(e)
- .asException()
+ return BluePrintManagementOutput.newBuilder()
+ .setCommonHeader(header)
+ .setStatus(Status.newBuilder()
+ .setTimestamp(currentTimestamp())
+ .setMessage(BluePrintConstants.STATUS_FAILURE)
+ .setErrorMessage(message)
+ .setCode(500)
+ .build())
+ .build()
+// return io.grpc.Status.INTERNAL
+// .withDescription(message)
+// .withCause(e)
+// .asException()
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
index 6e4e91abe..9f1bd9c7c 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
@@ -20,9 +20,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
import com.google.protobuf.ByteString
import io.grpc.testing.GrpcServerRule
+import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties
+import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.TokenAuthGrpcClientService
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
@@ -35,10 +39,7 @@ import org.springframework.context.annotation.ComponentScan
import org.springframework.test.annotation.DirtiesContext
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
-import kotlin.test.AfterTest
-import kotlin.test.BeforeTest
-import kotlin.test.assertEquals
-import kotlin.test.assertTrue
+import kotlin.test.*
@RunWith(SpringRunner::class)
@EnableAutoConfiguration
@@ -96,6 +97,28 @@ class BluePrintManagementGRPCHandlerTest {
assertEquals(200, output.status.code)
}
+ /** This is Integration test sample, Do not enable this test case in server build, this is for local desktop testing*/
+ private fun integrationTestGrpcManagement() {
+ runBlocking {
+ val tokenAuthGrpcClientProperties = TokenAuthGrpcClientProperties().apply {
+ host = "127.0.0.1"
+ port = 9111
+ type = GRPCLibConstants.TYPE_TOKEN_AUTH
+ token = "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="
+ }
+ val basicAuthGrpcClientService = TokenAuthGrpcClientService(tokenAuthGrpcClientProperties)
+ val channel = basicAuthGrpcClientService.channel()
+
+ val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(channel)
+
+ val bluePrintUploadInput = createUploadInputRequest("12345", UploadAction.DRAFT.toString())
+
+ val bluePrintManagementOutput = blockingStub.uploadBlueprint(bluePrintUploadInput)
+ assertNotNull(bluePrintManagementOutput, "failed to get response")
+ }
+ }
+
+
private fun createUploadInputRequest(id: String, action: String): BluePrintUploadInput {
val file = normalizedFile("./src/test/resources/test-cba.zip")
assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")