diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin')
13 files changed, 203 insertions, 136 deletions
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index bee919249..1abac7f3d 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.services.execution - import com.fasterxml.jackson.databind.JsonNode import kotlinx.coroutines.withTimeout import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput @@ -25,8 +24,15 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutp import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.getAsString +import org.onap.ccsdk.cds.controllerblueprints.core.getOptionalAsInt import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.cds.controllerblueprints.core.jsonPathParse +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBLines import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService import org.slf4j.LoggerFactory @@ -36,6 +42,7 @@ import org.slf4j.LoggerFactory * @author Brinda Santh */ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServiceInput, ExecutionServiceOutput> { + @Transient private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java) @@ -85,7 +92,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic check(operationName.isNotEmpty()) { "couldn't get Operation name for step($stepName)" } val operationResolvedProperties = bluePrintRuntimeService - .resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) + .resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) this.operationInputs.putAll(operationResolvedProperties) @@ -103,7 +110,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic try { // Resolve the Output Expression val stepOutputs = bluePrintRuntimeService - .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) + .resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) val stepOutputData = StepData().apply { name = stepName @@ -135,7 +142,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic fun getOperationInput(key: String): JsonNode { return operationInputs[key] - ?: throw BluePrintProcessorException("couldn't get the operation input($key) value.") + ?: throw BluePrintProcessorException("couldn't get the operation input($key) value.") } fun getOptionalOperationInput(key: String): JsonNode? { @@ -188,5 +195,4 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic val file = normalizedFile(bluePrintRuntimeService.bluePrintContext().rootPath, artifactDefinition.file) return file.readNBLines() } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt index f17085ef1..041588616 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt @@ -45,7 +45,7 @@ abstract class AbstractScriptComponentFunction : AbstractComponentFunction() { @Deprecated("Dependencies will be resolved dynamically") open fun <T> functionDependencyInstanceAsType(name: String): T { return functionDependencyInstances[name] as? T - ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") + ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") } fun checkDynamicProperties(key: String): Boolean { @@ -125,4 +125,4 @@ abstract class AbstractScriptComponentFunction : AbstractComponentFunction() { override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { throw BluePrintException("Not Implemented, child class will implement this") } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractServiceFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractServiceFunction.kt index 67ab9c4de..e573afd7a 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractServiceFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractServiceFunction.kt @@ -109,4 +109,4 @@ abstract class AbstractServiceFunction : BlueprintFunctionNode<ExecutionServiceI } return executionServiceInput.payload.jsonPathParse(".$requestExpression") } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt index 062d370bc..4c7d5d0ec 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt @@ -28,21 +28,29 @@ import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service @Service -class ComponentFunctionScriptingService(private val applicationContext: ApplicationContext, - private val blueprintJythonService: BlueprintJythonService) { +class ComponentFunctionScriptingService( + private val applicationContext: ApplicationContext, + private val blueprintJythonService: BlueprintJythonService +) { private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java) - suspend fun <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, - scriptType: String, - scriptClassReference: String, - instanceDependencies: List<String>): T { + suspend fun <T : AbstractScriptComponentFunction> scriptInstance( + componentFunction: AbstractComponentFunction, + scriptType: String, + scriptClassReference: String, + instanceDependencies: List<String> + ): T { - log.info("creating component function of script type($scriptType), reference name($scriptClassReference) and " + - "instanceDependencies($instanceDependencies)") + log.info( + "creating component function of script type($scriptType), reference name($scriptClassReference) and " + + "instanceDependencies($instanceDependencies)" + ) - val scriptComponent: T = scriptInstance(componentFunction.bluePrintRuntimeService.bluePrintContext(), - scriptType, scriptClassReference) + val scriptComponent: T = scriptInstance( + componentFunction.bluePrintRuntimeService.bluePrintContext(), + scriptType, scriptClassReference + ) checkNotNull(scriptComponent) { "failed to initialize script component" } @@ -60,14 +68,16 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat // Populate Instance Properties instanceDependencies.forEach { instanceDependency -> scriptComponent.functionDependencyInstances[instanceDependency] = applicationContext - .getBean(instanceDependency) + .getBean(instanceDependency) } return scriptComponent } - - suspend fun <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, - scriptClassReference: String): T { + suspend fun <T : BlueprintFunctionNode<*, *>> scriptInstance( + bluePrintContext: BluePrintContext, + scriptType: String, + scriptClassReference: String + ): T { var scriptComponent: T? = null when (scriptType) { @@ -77,8 +87,10 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat } BluePrintConstants.SCRIPT_KOTLIN -> { val bluePrintScriptsService: BluePrintScriptsService = BluePrintScriptsServiceImpl() - scriptComponent = bluePrintScriptsService.scriptInstance<T>(bluePrintContext.rootPath, - bluePrintContext.name(), bluePrintContext.version(), scriptClassReference, false) + scriptComponent = bluePrintScriptsService.scriptInstance<T>( + bluePrintContext.rootPath, + bluePrintContext.name(), bluePrintContext.version(), scriptClassReference, false + ) } BluePrintConstants.SCRIPT_JYTHON -> { scriptComponent = blueprintJythonService.jythonComponentInstance(bluePrintContext, scriptClassReference) as T @@ -89,5 +101,4 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat } return scriptComponent } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt index c66c3e913..09eee6717 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt @@ -28,8 +28,8 @@ import org.springframework.stereotype.Component */ @Component("component-script-executor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ComponentScriptExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) - : AbstractComponentFunction() { +open class ComponentScriptExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) : + AbstractComponentFunction() { companion object { const val INPUT_SCRIPT_TYPE = "script-type" @@ -53,8 +53,10 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService val scriptDependencies: MutableList<String> = arrayListOf() populateScriptDependencies(scriptDependencies) - scriptComponentFunction = componentFunctionScriptingService.scriptInstance(this, scriptType, - scriptClassReference, scriptDependencies) + scriptComponentFunction = componentFunctionScriptingService.scriptInstance( + this, scriptType, + scriptClassReference, scriptDependencies + ) // Handles both script processing and error handling scriptComponentFunction.executeScript(executionServiceInput) @@ -62,11 +64,10 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { bluePrintRuntimeService.getBluePrintError() - .addError("Failed in ComponentCliExecutor : ${runtimeException.message}") - + .addError("Failed in ComponentCliExecutor : ${runtimeException.message}") } open fun populateScriptDependencies(scriptDependencies: MutableList<String>) { /** Place holder for Child to add extra dependencies */ } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt index 89338b781..d4ca0f487 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt @@ -31,52 +31,72 @@ import kotlin.reflect.KClass /** Component Extensions **/ fun BluePrintTypes.nodeTypeComponentScriptExecutor(): NodeType { - return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, - description = "Generic Script Component Executor") { + return nodeType( + id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + description = "Generic Script Component Executor" + ) { attribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false) attribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true) operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") { inputs { - property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, - true, "Script Type") { + property( + ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, + true, "Script Type" + ) { defaultValue(BluePrintConstants.SCRIPT_INTERNAL) constrain { - validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), + validValues( + listOf( + BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(), - BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive())) + BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive() + ) + ) } } - property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, - true, "Kotlin Script class name or jython script name.") - property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, - false, "Dynamic Json Content or DSL Json reference.") + property( + ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, + true, "Kotlin Script class name or jython script name." + ) + property( + ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Dynamic Json Content or DSL Json reference." + ) } outputs { - property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, - false, "Output Response") - property(ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, - true, "Status of the Component Execution ( success or failure )") + property( + ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, + false, "Output Response" + ) + property( + ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true, "Status of the Component Execution ( success or failure )" + ) } } } } /** Component Builder */ -fun BluePrintTypes.nodeTemplateComponentScriptExecutor(id: String, - description: String, - block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit) - : NodeTemplate { +fun BluePrintTypes.nodeTemplateComponentScriptExecutor( + id: String, + description: String, + block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit +): + NodeTemplate { return ComponentScriptExecutorNodeTemplateBuilder(id, description).apply(block).build() } class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder, - ComponentScriptExecutorNodeTemplateBuilder.InputsBuilder, - ComponentScriptExecutorNodeTemplateBuilder.OutputsBuilder>(id, "component-script-executor", - "ComponentScriptExecutor", - description) { + AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder, + ComponentScriptExecutorNodeTemplateBuilder.InputsBuilder, + ComponentScriptExecutorNodeTemplateBuilder.OutputsBuilder>( + id, "component-script-executor", + "ComponentScriptExecutor", + description + ) { class InputsBuilder : PropertiesAssignmentBuilder() { @@ -117,4 +137,4 @@ class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData) } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ExecutionServiceConfiguration.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ExecutionServiceConfiguration.kt index 806c33039..3ff54076d 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ExecutionServiceConfiguration.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ExecutionServiceConfiguration.kt @@ -23,7 +23,6 @@ import org.springframework.context.annotation.Configuration @ComponentScan open class ExecutionServiceConfiguration - object ExecutionServiceConstant { const val SERVICE_GRPC_REMOTE_SCRIPT_EXECUTION = "grpc-remote-script-execution-service" -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt index d6146e111..3b83261e5 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt @@ -21,10 +21,19 @@ import com.google.protobuf.Struct import com.google.protobuf.Timestamp import com.google.protobuf.util.JsonFormat import io.grpc.ManagedChannel -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.* +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.PrepareRemoteEnvInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteIdentifier +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptExecutionInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptExecutionOutput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StatusType import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcClientService import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcLibPropertyService -import org.onap.ccsdk.cds.controllerblueprints.command.api.* +import org.onap.ccsdk.cds.controllerblueprints.command.api.CommandExecutorServiceGrpc +import org.onap.ccsdk.cds.controllerblueprints.command.api.ExecutionInput +import org.onap.ccsdk.cds.controllerblueprints.command.api.ExecutionOutput +import org.onap.ccsdk.cds.controllerblueprints.command.api.Identifiers +import org.onap.ccsdk.cds.controllerblueprints.command.api.Packages +import org.onap.ccsdk.cds.controllerblueprints.command.api.PrepareEnvInput import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory @@ -41,11 +50,13 @@ interface RemoteScriptExecutionService { } @Service(ExecutionServiceConstant.SERVICE_GRPC_REMOTE_SCRIPT_EXECUTION) -@ConditionalOnProperty(prefix = "blueprintprocessor.remoteScriptCommand", name = arrayOf("enabled"), - havingValue = "true", matchIfMissing = false) +@ConditionalOnProperty( + prefix = "blueprintprocessor.remoteScriptCommand", name = arrayOf("enabled"), + havingValue = "true", matchIfMissing = false +) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService) - : RemoteScriptExecutionService { +class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService) : + RemoteScriptExecutionService { private val log = LoggerFactory.getLogger(GrpcRemoteScriptExecutionService::class.java)!! @@ -70,8 +81,8 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi } } - override suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput) - : RemoteScriptExecutionOutput { + override suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): + RemoteScriptExecutionOutput { val grpResponse = commandExecutorServiceGrpc.prepareEnv(prepareEnvInput.asGrpcData()) checkNotNull(grpResponse.status) { @@ -84,8 +95,8 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi return remoteScriptExecutionOutput } - override suspend fun executeCommand(remoteExecutionInput: RemoteScriptExecutionInput) - : RemoteScriptExecutionOutput { + override suspend fun executeCommand(remoteExecutionInput: RemoteScriptExecutionInput): + RemoteScriptExecutionOutput { val grpResponse = commandExecutorServiceGrpc.executeCommand(remoteExecutionInput.asGrpcData()) @@ -103,7 +114,6 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi channel?.shutdownNow() } - fun PrepareRemoteEnvInput.asGrpcData(): PrepareEnvInput { val correlationId = this.correlationId ?: this.requestId @@ -116,33 +126,33 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi } return PrepareEnvInput.newBuilder() - .setIdentifiers(this.remoteIdentifier!!.asGrpcData()) - .setRequestId(this.requestId) - .setCorrelationId(correlationId) - .setTimeOut(this.timeOut.toInt()) - .addAllPackages(packageList) - .setProperties(this.properties.asGrpcData()) - .build() + .setIdentifiers(this.remoteIdentifier!!.asGrpcData()) + .setRequestId(this.requestId) + .setCorrelationId(correlationId) + .setTimeOut(this.timeOut.toInt()) + .addAllPackages(packageList) + .setProperties(this.properties.asGrpcData()) + .build() } fun RemoteScriptExecutionInput.asGrpcData(): ExecutionInput { val correlationId = this.correlationId ?: this.requestId return ExecutionInput.newBuilder() - .setRequestId(this.requestId) - .setCorrelationId(correlationId) - .setIdentifiers(this.remoteIdentifier!!.asGrpcData()) - .setCommand(this.command) - .setTimeOut(this.timeOut.toInt()) - .setProperties(this.properties.asGrpcData()) - .setTimestamp(Timestamp.getDefaultInstance()) - .build() + .setRequestId(this.requestId) + .setCorrelationId(correlationId) + .setIdentifiers(this.remoteIdentifier!!.asGrpcData()) + .setCommand(this.command) + .setTimeOut(this.timeOut.toInt()) + .setProperties(this.properties.asGrpcData()) + .setTimestamp(Timestamp.getDefaultInstance()) + .build() } fun RemoteIdentifier.asGrpcData(): Identifiers? { return Identifiers.newBuilder() - .setBlueprintName(this.blueprintName) - .setBlueprintVersion(this.blueprintVersion) - .build() + .setBlueprintName(this.blueprintName) + .setBlueprintVersion(this.blueprintVersion) + .build() } fun Map<String, JsonNode>.asGrpcData(): Struct { @@ -153,11 +163,10 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi fun ExecutionOutput.asJavaData(): RemoteScriptExecutionOutput { return RemoteScriptExecutionOutput( - requestId = this.requestId, - response = this.responseList, - status = StatusType.valueOf(this.status.name), - payload = payload.jsonAsJsonType() + requestId = this.requestId, + response = this.responseList, + status = StatusType.valueOf(this.status.name), + payload = payload.jsonAsJsonType() ) } - } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionService.kt index adb1d67d2..239ff00c5 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionService.kt @@ -20,10 +20,14 @@ import com.fasterxml.jackson.databind.JsonNode import com.github.marcoferrer.krotoplus.coroutines.client.ClientBidiCallChannel import com.github.marcoferrer.krotoplus.coroutines.client.clientCallBidiStreaming import io.grpc.ManagedChannel -import kotlinx.coroutines.* +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.consumeAsFlow +import kotlinx.coroutines.launch +import kotlinx.coroutines.withTimeout import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcClientService import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcLibPropertyService @@ -50,10 +54,12 @@ interface StreamingRemoteExecutionService<ReqT, ResT> { } @Service -@ConditionalOnProperty(prefix = "blueprintsprocessor.streamingRemoteExecution", name = ["enabled"], - havingValue = "true", matchIfMissing = false) -class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService) - : StreamingRemoteExecutionService<ExecutionServiceInput, ExecutionServiceOutput> { +@ConditionalOnProperty( + prefix = "blueprintsprocessor.streamingRemoteExecution", name = ["enabled"], + havingValue = "true", matchIfMissing = false +) +class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService) : + StreamingRemoteExecutionService<ExecutionServiceInput, ExecutionServiceOutput> { private val log = logger(StreamingRemoteExecutionServiceImpl::class) @@ -62,7 +68,6 @@ class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertySe private val commChannels: MutableMap<String, ClientBidiCallChannel<ExecutionServiceInput, ExecutionServiceOutput>> = hashMapOf() - /** * Open new channel to send and receive for grpc properties [selector] for [txId], * Create the only one GRPC channel per host port and reuse for further communication. @@ -84,7 +89,7 @@ class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertySe } val commChannel = commChannels[txId] - ?: throw BluePrintException("failed to create response subscription for transactionId($txId) channel") + ?: throw BluePrintException("failed to create response subscription for transactionId($txId) channel") log.info("created subscription for transactionId($txId)") @@ -97,7 +102,7 @@ class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertySe */ override suspend fun send(txId: String, input: ExecutionServiceInput) { val sendChannel = commChannels[txId]?.requestChannel - ?: throw BluePrintException("failed to get transactionId($txId) send channel") + ?: throw BluePrintException("failed to get transactionId($txId) send channel") coroutineScope { launch { sendChannel.send(input) @@ -114,15 +119,15 @@ class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertySe * so the correlation is sub request id to receive the response. */ @ExperimentalCoroutinesApi - override suspend fun sendNonInteractive(selector: Any, txId: String, input: ExecutionServiceInput, timeOutMill: Long) - : ExecutionServiceOutput { + override suspend fun sendNonInteractive(selector: Any, txId: String, input: ExecutionServiceInput, timeOutMill: Long): + ExecutionServiceOutput { var output: ExecutionServiceOutput? = null val flow = openSubscription(selector, txId) /** Send the request */ val sendChannel = commChannels[txId]?.requestChannel - ?: throw BluePrintException("failed to get transactionId($txId) send channel") + ?: throw BluePrintException("failed to get transactionId($txId) send channel") sendChannel.send(input) /** Receive the response with timeout */ @@ -145,7 +150,7 @@ class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertySe if (!it.requestChannel.isClosedForSend) it.requestChannel.close() /** If receive channel has to close immediately, once the subscription has cancelled, then enable this */ - //it.responseChannel.cancel(CancellationException("subscription cancelled")) + // it.responseChannel.cancel(CancellationException("subscription cancelled")) commChannels.remove(txId) log.info("closed subscription for transactionId($txId)") } @@ -182,7 +187,7 @@ class StreamingRemoteExecutionServiceImpl(private val bluePrintGrpcLibPropertySe suspend fun createGrpcChannel(grpcProperties: GrpcClientProperties): ManagedChannel { val grpcClientService: BluePrintGrpcClientService = bluePrintGrpcLibPropertyService - .blueprintGrpcClientService(grpcProperties) + .blueprintGrpcClientService(grpcProperties) return grpcClientService.channel() } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt index 814054804..dd4c0ec99 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt @@ -32,13 +32,19 @@ import org.springframework.stereotype.Service import java.io.File @Service -class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, - private val applicationContext: ApplicationContext) { +class BlueprintJythonService( + val pythonExecutorProperty: PythonExecutorProperty, + private val applicationContext: ApplicationContext +) { val log: Logger = LoggerFactory.getLogger(BlueprintJythonService::class.java) - inline fun <reified T> jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String, - dependencyInstanceNames: MutableMap<String, Any>?): T { + inline fun <reified T> jythonInstance( + blueprintContext: BluePrintContext, + pythonClassName: String, + content: String, + dependencyInstanceNames: MutableMap<String, Any>? + ): T { val blueprintBasePath: String = blueprintContext.rootPath val pythonPath: MutableList<String> = arrayListOf() @@ -59,8 +65,8 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, BlueprintFunctionNode<*, *> { val pythonFileName = bluePrintContext.rootPath - .plus(File.separator) - .plus(scriptClassReference) + .plus(File.separator) + .plus(scriptClassReference) val pythonClassName = FilenameUtils.getBaseName(pythonFileName) log.info("Getting Jython Script Class($pythonClassName)") @@ -70,8 +76,10 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, val jythonInstances: MutableMap<String, Any> = hashMapOf() jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) - return jythonInstance<BlueprintFunctionNode<*, *>>(bluePrintContext, pythonClassName, - content, jythonInstances) + return jythonInstance<BlueprintFunctionNode<*, *>>( + bluePrintContext, pythonClassName, + content, jythonInstances + ) } fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction { @@ -82,25 +90,27 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, val operationInputs: MutableMap<String, JsonNode> = abstractComponentFunction.operationInputs val operationAssignment: OperationAssignment = bluePrintContext - .nodeTemplateInterfaceOperation(abstractComponentFunction.nodeTemplateName, - abstractComponentFunction.interfaceName, abstractComponentFunction.operationName) + .nodeTemplateInterfaceOperation( + abstractComponentFunction.nodeTemplateName, + abstractComponentFunction.interfaceName, abstractComponentFunction.operationName + ) val blueprintBasePath: String = bluePrintContext.rootPath val artifactName: String = operationAssignment.implementation?.primary - ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") + ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) val pythonFileName = artifactDefinition.file - ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)") + ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)") val pythonClassName = FilenameUtils.getBaseName(pythonFileName) log.info("Getting Jython Script Class($pythonClassName)") val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) - checkNotEmpty(content){ "artifact ($artifactName) content is empty"} + checkNotEmpty(content) { "artifact ($artifactName) content is empty" } val pythonPath: MutableList<String> = operationAssignment.implementation?.dependencies ?: arrayListOf() pythonPath.add(blueprintBasePath) @@ -110,17 +120,17 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName) val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode - ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") + ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") instanceDependenciesNode.forEach { instanceName -> jythonInstances[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue()) } - val scriptComponentFunction = jythonInstance<AbstractComponentFunction>(bluePrintContext, pythonClassName, - content!!, jythonInstances) + val scriptComponentFunction = jythonInstance<AbstractComponentFunction>( + bluePrintContext, pythonClassName, + content!!, jythonInstances + ) return scriptComponentFunction - } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt index 78b7556f3..b348a9bef 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt @@ -19,7 +19,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.python.core.PyObject import org.python.util.PythonInterpreter -open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){ +open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython) { private val blueprintPythonInterpreterProxy: BlueprintPythonInterpreterProxy init { @@ -42,9 +42,9 @@ open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){ try { return blueprintPythonInterpreterProxy.getPythonInstance(properties) } catch (e: Exception) { - throw BluePrintProcessorException("Failed to execute Jython component ${e.toString()}", e) + throw BluePrintProcessorException("Failed to execute Jython component $e", e) } } - //TODO Check potential errors in python scripts + // TODO Check potential errors in python scripts } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt index 6e514de49..6f311bcd2 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt @@ -33,12 +33,13 @@ open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrin try { this.exec(bluePrintPython.content) } catch (e: PySyntaxError) { - throw BluePrintProcessorException("Error executing Jython code! Python error: '${e.toString()}'", e) + throw BluePrintProcessorException("Error executing Jython code! Python error: '$e'", e) } } val initCommand = bluePrintPython.pythonClassName.plus(" = ").plus( - bluePrintPython.pythonClassName).plus("()") + bluePrintPython.pythonClassName + ).plus("()") this.exec(initCommand) return this.get(bluePrintPython.pythonClassName) diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt index 658b0c291..0a220948d 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt @@ -32,6 +32,7 @@ open class PythonExecutorConfiguration @Configuration open class PythonExecutorProperty { + @Value("\${blueprints.processor.functions.python.executor.executionPath}") lateinit var executionPath: String @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}") @@ -44,8 +45,12 @@ class PythonExecutorConstants { } } -open class BluePrintPython(executablePath: String, blueprintPythonPlatform: MutableList<String>, - val argv: MutableList<String>){ +open class BluePrintPython( + executablePath: String, + blueprintPythonPlatform: MutableList<String>, + val argv: MutableList<String> +) { + lateinit var moduleName: String lateinit var pythonClassName: String lateinit var content: String @@ -65,4 +70,4 @@ open class BluePrintPython(executablePath: String, blueprintPythonPlatform: Muta props.setProperty("python.verbose", "error") props.setProperty("python.executable", executablePath) } -}
\ No newline at end of file +} |