From 7466e4277c9fe098a61ae126d1892b3cd30d6f89 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 2 Dec 2019 19:04:13 -0500 Subject: Remote Script Executor Component Define and Implement component-remote-script-executor component and DSL. Get the timeout from model definitions fix the dat pattern issues Define API data extension functions. Issue-ID: CCSDK-1975 Signed-off-by: Brinda Santh Change-Id: I41a429eb21a050e5ab512a7a73a394b975543f31 --- .../grpc/service/GrpcLoggerService.kt | 4 +- .../message/service/MessageLoggerService.kt | 3 +- .../blueprintsprocessor/core/ApiDataExtensions.kt | 28 +++ .../blueprintsprocessor/core/utils/ApiDataUtils.kt | 204 +++++++++++++++++++++ .../core/utils/BluePrintMappings.kt | 130 ------------- .../blueprintsprocessor/core/utils/PayloadUtils.kt | 61 ++++-- .../core/utils/BluePrintMappingsTest.kt | 3 +- .../rest/service/RestLoggerService.kt | 7 +- 8 files changed, 284 insertions(+), 156 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/ApiDataUtils.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappings.kt (limited to 'ms/blueprintsprocessor/modules/commons') diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt index 510a21581..732f4fecf 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt @@ -23,6 +23,7 @@ import io.grpc.ServerCallHandler import org.onap.ccsdk.cds.blueprintsprocessor.grpc.getStringKey import org.onap.ccsdk.cds.blueprintsprocessor.grpc.putStringKeyValue import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_PARTNER_NAME import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_REQUEST_ID @@ -93,8 +94,7 @@ class GrpcLoggerService { fun grpcInvoking(requestHeader: Metadata) { requestHeader.putStringKeyValue(ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID()) requestHeader.putStringKeyValue(ONAP_INVOCATION_ID, UUID.randomUUID().toString()) - val partnerName = System.getProperty("APPNAME") ?: "BlueprintsProcessor" - requestHeader.putStringKeyValue(ONAP_PARTNER_NAME, partnerName) + requestHeader.putStringKeyValue(ONAP_PARTNER_NAME, BluePrintConstants.APP_NAME) } /** Used when server returns response */ diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt index 7ec70d91b..04b754b13 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/service/MessageLoggerService.kt @@ -84,8 +84,7 @@ class MessageLoggerService { val localhost = InetAddress.getLocalHost() requestHeader.addHeader(BluePrintConstants.ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID()) requestHeader.addHeader(BluePrintConstants.ONAP_INVOCATION_ID, UUID.randomUUID().toString()) - val partnerName = System.getProperty("APPNAME") ?: "BlueprintsProcessor" - requestHeader.addHeader(BluePrintConstants.ONAP_PARTNER_NAME, partnerName) + requestHeader.addHeader(BluePrintConstants.ONAP_PARTNER_NAME, BluePrintConstants.APP_NAME) requestHeader.addHeader("ClientIPAddress", localhost.hostAddress) } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/ApiDataExtensions.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/ApiDataExtensions.kt index af7109449..8e1b5b2ce 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/ApiDataExtensions.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/ApiDataExtensions.kt @@ -1,5 +1,6 @@ /* * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 AT&T Intellectual Property. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +17,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core +import com.fasterxml.jackson.databind.JsonNode +import com.google.protobuf.Struct +import com.google.protobuf.util.JsonFormat import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString import org.onap.ccsdk.cds.controllerblueprints.core.asType +import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import kotlin.reflect.KClass fun ExecutionServiceInput.payloadAsType(clazzType: KClass): T { @@ -25,3 +31,25 @@ fun ExecutionServiceInput.payloadAsType(clazzType: KClass): T { val requestJsonNode = this.payload.get("$actionName-request") return requestJsonNode.asType(clazzType.java) } + +/** Convert Proto Struct to Json string */ +fun Struct.asJson(): String { + return JsonFormat.printer().print(this) +} + +/** Convert Proto Struct to Json node */ +fun Struct.asJsonType(): JsonNode { + return this.asJson().jsonAsJsonType() +} + +/** Convert Json node to Proto Struct */ +fun JsonNode.asProtoStruct(): Struct { + return this.asJsonString(false).asProtoStruct() +} + +/** Convert Json string to Proto Struct */ +fun String.asProtoStruct(): Struct { + val struct = Struct.newBuilder() + JsonFormat.parser().merge(this, struct) + return struct.build() +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/ApiDataUtils.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/ApiDataUtils.kt new file mode 100644 index 000000000..24ed45c52 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/ApiDataUtils.kt @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2019 Bell Canada. + * Modifications Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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.cds.blueprintsprocessor.core.utils + +import com.fasterxml.jackson.databind.node.ObjectNode +import com.google.protobuf.Struct +import com.google.protobuf.util.JsonFormat +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType +import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag +import org.onap.ccsdk.cds.controllerblueprints.common.api.Status +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.controllerDate +import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp +import org.onap.ccsdk.cds.controllerblueprints.core.utils.toControllerDate +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput + +// ACTION IDENTIFIER + +fun org.onap.ccsdk.cds.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.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { + val actionIdentifier = org.onap.ccsdk.cds.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.cds.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.currentTimestamp() + if (this.flags != null) { + commonHeader.flag = this.flags!!.toProto() + } + return commonHeader.build() +} + +fun CommonHeader.toJava(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader { + val commonHeader = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader() + commonHeader.originatorId = this.originatorId + commonHeader.requestId = this.requestId + commonHeader.subRequestId = this.subRequestId + commonHeader.timestamp = if (!this.timestamp.isNullOrEmpty()) { + this.timestamp!!.toControllerDate() + } else { + controllerDate() + } + commonHeader.flags = this.flag?.toJava() + return commonHeader +} + +// FLAG + +fun org.onap.ccsdk.cds.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.cds.blueprintsprocessor.core.api.data.Flags { + val flag = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags() + flag.isForce = this.isForce + flag.ttl = this.ttl + return flag +} + +// STATUS + +fun org.onap.ccsdk.cds.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 = EventType.valueOf(this.eventType) + return status.build() +} + +// EXECUTION INPUT + +fun ExecutionServiceInput.toJava(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput { + val executionServiceInput = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput() + executionServiceInput.actionIdentifiers = this.actionIdentifiers.toJava() + executionServiceInput.commonHeader = this.commonHeader.toJava() + executionServiceInput.payload = JacksonUtils.jsonNode(JsonFormat.printer().print(this.payload)) as ObjectNode + return executionServiceInput +} + +// EXECUTION OUPUT + +fun org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput.toProto(): ExecutionServiceOutput { + val executionServiceOuput = ExecutionServiceOutput.newBuilder() + executionServiceOuput.actionIdentifiers = this.actionIdentifiers.toProto() + executionServiceOuput.commonHeader = this.commonHeader.toProto() + executionServiceOuput.status = this.status.toProto() + val struct = Struct.newBuilder() + JsonFormat.parser().merge(JacksonUtils.getJson(this.payload), struct) + executionServiceOuput.payload = struct.build() + return executionServiceOuput.build() +} + +/** Create proto common header with [requestId] [subRequestId] and [originator] */ +fun createCommonHeaderProto( + requestId: String, + subRequestId: String, + originator: String +) = CommonHeader.newBuilder() + .setTimestamp(currentTimestamp()) + .setOriginatorId(originator) + .setRequestId(requestId) + .setSubRequestId(subRequestId).build()!! + +/** Create proto action identifiers with [name] [version] and [action] */ +fun createActionIdentifiersProto( + name: String, + version: String, + action: String +) = ActionIdentifiers.newBuilder() + .setBlueprintName(name) + .setBlueprintVersion(version) + .setActionName(action) + .setMode(ACTION_MODE_SYNC) + .build()!! + +/** Create proto status with [message] and [code] */ +fun createStatus( + message: String, + code: Int +) = Status.newBuilder() + .setTimestamp(currentTimestamp()) + .setMessage(message) + .setCode(code) + .build()!! + +/** Create ExecutionServiceInput using [commonHeader], [actionIdentifier] and response payload [jsonContent] */ +fun createExecutionServiceInputProto( + commonHeader: CommonHeader, + actionIdentifier: ActionIdentifiers, + jsonContent: String +): ExecutionServiceInput { + + val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder + JsonFormat.parser().merge(jsonContent, payloadBuilder) + + return ExecutionServiceInput.newBuilder() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() +} + +/** Create ExecutionServiceOutput using [commonHeader], [actionIdentifier] [status]and + * response payload [jsonContent] + * */ +fun createExecutionServiceOutputProto( + commonHeader: CommonHeader, + actionIdentifier: ActionIdentifiers, + status: Status, + jsonContent: String +): ExecutionServiceOutput { + + val payloadBuilder = ExecutionServiceOutput.newBuilder().payloadBuilder + JsonFormat.parser().merge(jsonContent, payloadBuilder) + + return ExecutionServiceOutput.newBuilder() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setStatus(status) + .setPayload(payloadBuilder.build()) + .build() +} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappings.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappings.kt deleted file mode 100644 index 59114de86..000000000 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappings.kt +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.cds.blueprintsprocessor.core.utils - -import com.fasterxml.jackson.databind.node.ObjectNode -import com.google.common.base.Strings -import com.google.protobuf.Struct -import com.google.protobuf.util.JsonFormat -import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput -import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput -import java.text.SimpleDateFormat -import java.util.Date - -private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - -// ACTION IDENTIFIER - -fun org.onap.ccsdk.cds.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.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { - val actionIdentifier = org.onap.ccsdk.cds.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.cds.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.cds.blueprintsprocessor.core.api.data.CommonHeader { - val commonHeader = org.onap.ccsdk.cds.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.cds.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.cds.blueprintsprocessor.core.api.data.Flags { - val flag = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags() - flag.isForce = this.isForce - flag.ttl = this.ttl - return flag -} - -// STATUS - -fun org.onap.ccsdk.cds.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 = EventType.valueOf(this.eventType) - return status.build() -} - -// EXECUTION INPUT - -fun ExecutionServiceInput.toJava(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput { - val executionServiceInput = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput() - executionServiceInput.actionIdentifiers = this.actionIdentifiers.toJava() - executionServiceInput.commonHeader = this.commonHeader.toJava() - executionServiceInput.payload = JacksonUtils.jsonNode(JsonFormat.printer().print(this.payload)) as ObjectNode - return executionServiceInput -} - -// EXECUTION OUPUT - -fun org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput.toProto(): ExecutionServiceOutput { - val executionServiceOuput = ExecutionServiceOutput.newBuilder() - executionServiceOuput.actionIdentifiers = this.actionIdentifiers.toProto() - executionServiceOuput.commonHeader = this.commonHeader.toProto() - executionServiceOuput.status = this.status.toProto() - val struct = Struct.newBuilder() - JsonFormat.parser().merge(JacksonUtils.getJson(this.payload), struct) - executionServiceOuput.payload = struct.build() - return executionServiceOuput.build() -} diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt index d3669f634..426e43cda 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/PayloadUtils.kt @@ -18,29 +18,56 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.utils import com.fasterxml.jackson.databind.JsonNode 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.returnNullIfMissing import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -class PayloadUtils { +object PayloadUtils { - companion object { + fun prepareRequestPayloadStr(workflowName: String, jsonNode: JsonNode): String { + return prepareRequestPayload(workflowName, jsonNode).asJsonString(false) + } - fun prepareInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) { - val input = payload.get("$workflowName-request") - bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) - } + fun prepareRequestPayload(workflowName: String, jsonNode: JsonNode): JsonNode { + val objectNode = JacksonUtils.objectMapper.createObjectNode() + objectNode["$workflowName-request"] = jsonNode + return objectNode + } - fun prepareDynamicInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) { - val input = payload.get("$workflowName-request") - val propertyFields = input.get("$workflowName-properties") - prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService, propertyFields) - } + fun getResponseDataFromPayload(workflowName: String, responsePayload: JsonNode): JsonNode { + return responsePayload.get("$workflowName-response").returnNullIfMissing() + ?: throw BluePrintProcessorException("failed to get property($workflowName-response)") + } + + fun prepareInputsFromWorkflowPayload( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + payload: JsonNode, + workflowName: String + ) { + val input = payload.get("$workflowName-request") + bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) + } + + fun prepareDynamicInputsFromWorkflowPayload( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + payload: JsonNode, + workflowName: String + ) { + val input = payload.get("$workflowName-request") + val propertyFields = input.get("$workflowName-properties") + prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService, propertyFields) + } - fun prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode) { - payload.fields().forEach { property -> - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString() - bluePrintRuntimeService.put(path, property.value) - } + fun prepareDynamicInputsFromComponentPayload( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + payload: JsonNode + ) { + payload.fields().forEach { property -> + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString() + bluePrintRuntimeService.put(path, property.value) } } } diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt index 4de40d7bf..e8bdbf9ef 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/utils/BluePrintMappingsTest.kt @@ -8,6 +8,7 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag +import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp import org.springframework.test.context.junit4.SpringRunner import java.text.SimpleDateFormat @@ -98,7 +99,7 @@ class BluePrintMappingsTest { 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) + Assert.assertEquals(commonHeader.timestamp.currentTimestamp(), commonHeader2.timestamp) } @Test 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 dbb98f849..313710745 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 @@ -26,6 +26,7 @@ import kotlinx.coroutines.newCoroutineContext import kotlinx.coroutines.reactor.ReactorContext import kotlinx.coroutines.reactor.asCoroutineContext 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 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_PARTNER_NAME import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_REQUEST_ID @@ -57,8 +58,7 @@ class RestLoggerService { fun httpInvoking(headers: Array) { headers.plusElement(BasicHeader(ONAP_REQUEST_ID, MDC.get("InvocationID").defaultToUUID())) headers.plusElement(BasicHeader(ONAP_INVOCATION_ID, UUID.randomUUID().toString())) - val partnerName = System.getProperty("APPNAME") ?: "BlueprintsProcessor" - headers.plusElement(BasicHeader(ONAP_PARTNER_NAME, partnerName)) + headers.plusElement(BasicHeader(ONAP_PARTNER_NAME, BluePrintConstants.APP_NAME)) } } @@ -85,8 +85,7 @@ class RestLoggerService { val resHeaders = response.headers resHeaders[ONAP_REQUEST_ID] = MDC.get("RequestID") resHeaders[ONAP_INVOCATION_ID] = MDC.get("InvocationID") - val partnerName = System.getProperty("APPNAME") ?: "BlueprintsProcessor" - resHeaders[ONAP_PARTNER_NAME] = partnerName + resHeaders[ONAP_PARTNER_NAME] = BluePrintConstants.APP_NAME } catch (e: Exception) { log.warn("couldn't set response headers", e) } finally { -- cgit 1.2.3-korg