summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-21 08:35:36 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-21 08:49:33 -0500
commite4b48721c4a8b5f65add9e2d00025ecd54585e07 (patch)
treea71686030d5016264ab82558d5d4ef8a59e2a77c /ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin
parenta651a74ef5d0be67855b367f1569bdc1521bbedd (diff)
Map proto to pojo. implement blueprint processing
Change-Id: I16b06b4700a42d4a7066eb8c0779677fa28cd94b Issue-ID: CCSDK-951 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin')
-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
4 files changed, 187 insertions, 14 deletions
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