diff options
Diffstat (limited to 'ms/blueprintsprocessor/functions/cli-executor')
3 files changed, 56 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/CliComponentFunction.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/CliComponentFunction.kt index 6dcffca09..c7f35f7c8 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/CliComponentFunction.kt +++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/CliComponentFunction.kt @@ -22,6 +22,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Reso import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshLibConstants import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.BluePrintSshLibPropertyService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBLines +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService abstract class CliComponentFunction : AbstractScriptComponentFunction() { @@ -32,6 +35,18 @@ abstract class CliComponentFunction : AbstractScriptComponentFunction() { functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) + open suspend fun readCommandLinesFromArtifact(artifactName: String): List<String> { + val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) + val file = normalizedFile(bluePrintRuntimeService.bluePrintContext().rootPath, artifactDefinition.file) + return file.readNBLines() + } + + suspend fun generateMessage(artifactName: String, json: String): String { + val templateService = BluePrintTemplateService() + return templateService.generateContent(bluePrintRuntimeService, nodeTemplateName, artifactName, json, true) + } + + fun generateMessage(artifactName: String): String { return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) } diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt index 8c58272f1..0c1c52320 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt +++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt @@ -35,6 +35,7 @@ open class ComponentCliExecutor(private var componentFunctionScriptingService: C const val SCRIPT_TYPE = "script-type" const val SCRIPT_CLASS_REFERENCE = "script-class-reference" const val INSTANCE_DEPENDENCIES = "instance-dependencies" + const val RESPONSE_DATA = "response-data" } private lateinit var scriptComponent: CliComponentFunction diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts index 136d01143..18d4a4797 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts +++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts @@ -18,6 +18,8 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.CliComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.ComponentCliExecutor +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.slf4j.LoggerFactory open class TestCliScriptFunction : CliComponentFunction() { @@ -36,3 +38,41 @@ open class TestCliScriptFunction : CliComponentFunction() { log.info("Executing Recovery") } } + + +open class Check : CliComponentFunction() { + + private val log = LoggerFactory.getLogger(CliComponentFunction::class.java)!! + + override fun getName(): String { + return "Check" + } + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + // Get the Device Information from the DSL Model + val deviceInformation = bluePrintRuntimeService.resolveDSLExpression("device-properties") + + // Get the Client Service + val sshClientService = bluePrintSshLibPropertyService().blueprintSshClientService(deviceInformation) + + sshClientService.startSessionNB() + + // Read Commands + val commands = readCommandLinesFromArtifact("command-template") + + // Execute multiple Commands + val responseLog = sshClientService.executeCommandsNB(commands, 5000) + + // Close Session + sshClientService.closeSessionNB() + + // Set the Response Data + setAttribute(ComponentCliExecutor.RESPONSE_DATA, responseLog.asJsonPrimitive()) + + log.info("Executing process") + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Executing Recovery") + } +} |