From 341db21b2ac0a14a1ed2b8bf7930914dda054bfe Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 22 Nov 2019 18:06:08 -0500 Subject: Formatting Code base with ktlint No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331 --- .../python/executor/ComponentJythonExecutor.kt | 19 ++--- .../executor/ComponentRemotePythonExecutor.kt | 43 ++++++---- .../executor/ComponentRemotePythonExecutorDSL.kt | 93 ++++++++++++++-------- .../python/executor/JythonComponentFunction.kt | 3 +- 4 files changed, 98 insertions(+), 60 deletions(-) (limited to 'ms/blueprintsprocessor/functions/python-executor/src/main') diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt index e13c150ee..b0dcc6339 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt @@ -36,8 +36,10 @@ import org.springframework.stereotype.Component @Component("component-jython-executor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ComponentJythonExecutor(private var applicationContext: ApplicationContext, - private val blueprintJythonService: BlueprintJythonService) : AbstractComponentFunction() { +open class ComponentJythonExecutor( + private var applicationContext: ApplicationContext, + private val blueprintJythonService: BlueprintJythonService +) : AbstractComponentFunction() { private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java) @@ -51,27 +53,26 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo // Invoke Jython Component Script componentFunction.executeScript(executionServiceInput) - } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { bluePrintRuntimeService.getBluePrintError() - .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") + .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") } private fun populateJythonComponentInstance() { val bluePrintContext = bluePrintRuntimeService.bluePrintContext() val operationAssignment: OperationAssignment = bluePrintContext - .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName) + .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName) 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) @@ -80,7 +81,7 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo checkNotEmpty(content) { "artifact ($artifactName) content is empty" } 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})") val jythonInstance: MutableMap = hashMapOf() jythonInstance["log"] = LoggerFactory.getLogger(pythonClassName) @@ -101,4 +102,4 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo componentFunction.workflowName = workflowName componentFunction.scriptType = BluePrintConstants.SCRIPT_JYTHON } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt index 91d51757a..ddfaf9ac2 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt @@ -17,12 +17,22 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.* +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +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.StatusType import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceConstant import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.RemoteScriptExecutionService -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotBlank import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing +import org.onap.ccsdk.cds.controllerblueprints.core.rootFieldsToMap import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.ConfigurableBeanFactory @@ -33,8 +43,7 @@ import org.springframework.stereotype.Component @ConditionalOnBean(name = [ExecutionServiceConstant.SERVICE_GRPC_REMOTE_SCRIPT_EXECUTION]) @Component("component-remote-python-executor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ComponentRemotePythonExecutor(private val remoteScriptExecutionService: RemoteScriptExecutionService) - : AbstractComponentFunction() { +open class ComponentRemotePythonExecutor(private val remoteScriptExecutionService: RemoteScriptExecutionService) : AbstractComponentFunction() { private val log = LoggerFactory.getLogger(ComponentRemotePythonExecutor::class.java)!! @@ -103,9 +112,12 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic // If packages are defined, then install in remote server if (packages != null) { - val prepareEnvInput = PrepareRemoteEnvInput(requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, - blueprintVersion = blueprintVersion), + val prepareEnvInput = PrepareRemoteEnvInput( + requestId = processId, + remoteIdentifier = RemoteIdentifier( + blueprintName = blueprintName, + blueprintVersion = blueprintVersion + ), packages = packages ) val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput) @@ -128,18 +140,21 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf() val remoteExecutionInput = RemoteScriptExecutionInput( - requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), - command = scriptCommand, - properties = properties) + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), + command = scriptCommand, + properties = properties + ) val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response) if (remoteExecutionOutput.status != StatusType.SUCCESS) { setNodeOutputErrors(remoteExecutionOutput.status.name, logs, remoteExecutionOutput.payload) } else { - setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(), logs, - remoteExecutionOutput.payload) + setNodeOutputProperties( + remoteExecutionOutput.status.name.asJsonPrimitive(), logs, + remoteExecutionOutput.payload + ) } } } catch (e: Exception) { @@ -179,7 +194,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic /** * Utility function to set the output properties and errors of the executor node, in cas of errors */ - private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive() ) { + private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive()) { setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status.asJsonPrimitive()) log.info("Executor status : $status") setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message) diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt index c2055f9a5..6998f0229 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt @@ -33,36 +33,54 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils /** Component Extensions **/ fun BluePrintTypes.nodeTypeComponentRemotePythonExecutor(): NodeType { - return nodeType(id = "component-remote-python-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, - description = "This is Remote Python Execution Component.") { - - attribute(ComponentRemotePythonExecutor.ATTRIBUTE_PREPARE_ENV_LOG, BluePrintConstants.DATA_TYPE_STRING, - false) - attribute(ComponentRemotePythonExecutor.ATTRIBUTE_EXEC_CMD_LOG, BluePrintConstants.DATA_TYPE_LIST, - false) { + return nodeType( + id = "component-remote-python-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + description = "This is Remote Python Execution Component." + ) { + + attribute( + ComponentRemotePythonExecutor.ATTRIBUTE_PREPARE_ENV_LOG, BluePrintConstants.DATA_TYPE_STRING, + false + ) + attribute( + ComponentRemotePythonExecutor.ATTRIBUTE_EXEC_CMD_LOG, BluePrintConstants.DATA_TYPE_LIST, + false + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } - attribute(ComponentRemotePythonExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, - false) + attribute( + ComponentRemotePythonExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, + false + ) operation("ComponentRemotePythonExecutor", "ComponentRemotePythonExecutor Operation") { inputs { - property(ComponentRemotePythonExecutor.INPUT_ENDPOINT_SELECTOR, BluePrintConstants.DATA_TYPE_STRING, - false, "Remote Container or Server selector name.") { + property( + ComponentRemotePythonExecutor.INPUT_ENDPOINT_SELECTOR, BluePrintConstants.DATA_TYPE_STRING, + false, "Remote Container or Server selector name." + ) { defaultValue(ComponentRemotePythonExecutor.DEFAULT_SELECTOR) } - property(ComponentRemotePythonExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, - false, "Dynamic Json Content or DSL Json reference.") - - property(ComponentRemotePythonExecutor.INPUT_ARGUMENT_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, - false, "Argument Json Content or DSL Json reference.") - - property(ComponentRemotePythonExecutor.INPUT_COMMAND, BluePrintConstants.DATA_TYPE_STRING, - true, "Command to execute.") - - property(ComponentRemotePythonExecutor.INPUT_PACKAGES, BluePrintConstants.DATA_TYPE_LIST, - false, "Packages to install based on type.") { + property( + ComponentRemotePythonExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Dynamic Json Content or DSL Json reference." + ) + + property( + ComponentRemotePythonExecutor.INPUT_ARGUMENT_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Argument Json Content or DSL Json reference." + ) + + property( + ComponentRemotePythonExecutor.INPUT_COMMAND, BluePrintConstants.DATA_TYPE_STRING, + true, "Command to execute." + ) + + property( + ComponentRemotePythonExecutor.INPUT_PACKAGES, BluePrintConstants.DATA_TYPE_LIST, + false, "Packages to install based on type." + ) { entrySchema("dt-system-packages") } } @@ -71,9 +89,11 @@ fun BluePrintTypes.nodeTypeComponentRemotePythonExecutor(): NodeType { } fun BluePrintTypes.dataTypeDtSystemPackages(): DataType { - return dataType(id = "dt-system-packages", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT, - description = "This represent System Package Data Type") { + return dataType( + id = "dt-system-packages", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT, + description = "This represent System Package Data Type" + ) { property("type", BluePrintConstants.DATA_TYPE_LIST, true, "") { constrain { entrySchema(BluePrintConstants.DATA_TYPE_STRING) @@ -87,10 +107,12 @@ fun BluePrintTypes.dataTypeDtSystemPackages(): DataType { } /** Component Builder */ -fun BluePrintTypes.nodeTemplateComponentRemotePythonExecutor(id: String, - description: String, - block: ComponentRemotePythonExecutorNodeTemplateBuilder.() -> Unit) - : NodeTemplate { +fun BluePrintTypes.nodeTemplateComponentRemotePythonExecutor( + id: String, + description: String, + block: ComponentRemotePythonExecutorNodeTemplateBuilder.() -> Unit +): + NodeTemplate { return ComponentRemotePythonExecutorNodeTemplateBuilder(id, description).apply(block).build() } @@ -112,9 +134,11 @@ class DtSystemPackageDataTypeBuilder : PropertiesAssignmentBuilder() { } class ComponentRemotePythonExecutorNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplateOperationImplBuilder(id, "component-remote-python-executor", - "ComponentRemotePythonExecutor", description) { + AbstractNodeTemplateOperationImplBuilder( + id, "component-remote-python-executor", + "ComponentRemotePythonExecutor", description + ) { class InputsBuilder : PropertiesAssignmentBuilder() { @@ -161,5 +185,4 @@ class ComponentRemotePythonExecutorNodeTemplateBuilder(id: String, description: } class OutputsBuilder : PropertiesAssignmentBuilder() - -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt index 7e00206ca..891b09d88 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt @@ -29,5 +29,4 @@ open class JythonComponentFunction : AbstractScriptComponentFunction() { override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { throw BluePrintException("Not Implemented required") } - -} \ No newline at end of file +} -- cgit 1.2.3-korg