summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-05-17 10:07:14 -0400
committerSteve Siani <alphonse.steve.siani.djissitchi@ibm.com>2019-05-23 00:15:54 -0400
commitbcc6c4dfe9db06e0dab22472b11a4939255091e5 (patch)
tree62a4bbcf1ec53d9cbc165bcf7dfc9a04211f67de /ms/blueprintsprocessor
parent145662ff6a41e0e46a23e8eedf53f30581f8ab64 (diff)
Add cli test blueprints
Change-Id: Ieab385f5e4ae60cca3d86f22c4304e4867e6fa96 Issue-ID: CCSDK-1335 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor')
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/CliComponentFunction.kt15
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt1
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts40
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt16
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt6
-rw-r--r--ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt37
-rw-r--r--ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt20
7 files changed, 106 insertions, 29 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")
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
index 51062256d..ebff47899 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
@@ -46,10 +46,10 @@ interface ResourceResolutionService {
artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, String>
suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactPrefix: String, properties: Map<String, Any>): String
+ artifactPrefix: String, properties: Map<String, Any>): String
suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactMapping: String, artifactTemplate: String?): String
+ artifactMapping: String, artifactTemplate: String?): String
suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
resourceDefinitions: MutableMap<String, ResourceDefinition>,
@@ -89,7 +89,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
}
override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactPrefix: String, properties: Map<String, Any>): String {
+ artifactPrefix: String, properties: Map<String, Any>): String {
// Velocity Artifact Definition Name
val artifactTemplate = "$artifactPrefix-template"
@@ -110,7 +110,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactMapping: String, artifactTemplate: String?): String {
+ artifactMapping: String, artifactTemplate: String?): String {
val resolvedContent: String
log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)")
@@ -137,11 +137,9 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
// Check Template is there
if (artifactTemplate != null) {
- val blueprintTemplateService = BluePrintTemplateService(bluePrintRuntimeService, nodeTemplateName, artifactTemplate)
- val templateContent =
- bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
-
- resolvedContent = blueprintTemplateService.generateContent(templateContent, resolvedParamJsonContent)
+ val blueprintTemplateService = BluePrintTemplateService()
+ resolvedContent = blueprintTemplateService.generateContent(bluePrintRuntimeService, nodeTemplateName,
+ artifactTemplate, resolvedParamJsonContent)
} else {
resolvedContent = resolvedParamJsonContent
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
index 8dbd47cc2..3482d4534 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
@@ -25,6 +25,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.util
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
@@ -67,6 +68,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
?: throw BluePrintProcessorException("couldn't get resource definition for ($name)")
}
+ //TODO("Convert return Map<String, JsonNode>")
open fun resolveInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, Any> {
val resolvedInputKeyMapping = HashMap<String, Any>()
if (MapUtils.isNotEmpty(inputKeyMapping)) {
@@ -80,12 +82,14 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
return resolvedInputKeyMapping
}
+ //TODO("Convert keyMapping = MutableMap<String, JsonNode>")
open suspend fun resolveFromInputKeyMapping(valueToResolve: String, keyMapping: MutableMap<String, Any>):
String {
if (valueToResolve.isEmpty() || !valueToResolve.contains("$")) {
return valueToResolve
}
- return BluePrintVelocityTemplateService.generateContent(valueToResolve, additionalContext = keyMapping)
+ //TODO("Optimize to JSON Node directly")
+ return BluePrintVelocityTemplateService.generateContent(valueToResolve, keyMapping.asJsonNode().toString())
}
final override suspend fun applyNB(resourceAssignment: ResourceAssignment): Boolean {
diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt
index 67d5d5153..adbde0f87 100644
--- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt
+++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt
@@ -36,6 +36,7 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B
private lateinit var sshClient: SshClient
private lateinit var clientSession: ClientSession
+ var channel: ChannelExec? = null
override suspend fun startSessionNB(): ClientSession {
sshClient = SshClient.setUpDefaultClient()
@@ -69,31 +70,29 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B
override suspend fun executeCommandNB(command: String, timeOut: Long): String {
log.debug("Executing host($clientSession) command($command)")
- var channel: ChannelExec? = null
- try {
- channel = clientSession.createExecChannel(command)
- //TODO("Convert to streaming ")
- val outputStream = ByteArrayOutputStream()
- channel.out = outputStream
- channel.err = outputStream
- channel.open().await()
- val waitMask = channel.waitFor(Collections.unmodifiableSet(EnumSet.of(ClientChannelEvent.CLOSED)), timeOut)
- if (waitMask.contains(ClientChannelEvent.TIMEOUT)) {
- throw BluePrintProcessorException("Failed to retrieve command result in time: $command")
- }
- val exitStatus = channel.exitStatus
- ClientChannel.validateCommandExitStatusCode(command, exitStatus!!)
- return outputStream.toString()
- } finally {
- if (channel != null)
- channel.close()
+ channel = clientSession.createExecChannel(command)
+ checkNotNull(channel) { "failed to create Channel for the command : $command" }
+
+ //TODO("Convert to streaming ")
+ val outputStream = ByteArrayOutputStream()
+ channel!!.out = outputStream
+ channel!!.err = outputStream
+ channel!!.open().await()
+ val waitMask = channel!!.waitFor(Collections.unmodifiableSet(EnumSet.of(ClientChannelEvent.CLOSED)), timeOut)
+ if (waitMask.contains(ClientChannelEvent.TIMEOUT)) {
+ throw BluePrintProcessorException("Failed to retrieve command result in time: $command")
}
+ val exitStatus = channel!!.exitStatus
+ ClientChannel.validateCommandExitStatusCode(command, exitStatus!!)
+ return outputStream.toString()
}
override suspend fun closeSessionNB() {
+ if (channel != null)
+ channel!!.close()
if (sshClient.isStarted) {
sshClient.stop()
- log.debug("SSH Client Service stopped successfully")
}
+ log.debug("SSH Client Service stopped successfully")
}
}
diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt
index 9971c500f..1950b71aa 100644
--- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt
+++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt
@@ -16,16 +16,23 @@
package org.onap.ccsdk.cds.blueprintsprocessor.ssh.service
+import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BasicAuthSshClientProperties
import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshClientProperties
import org.onap.ccsdk.cds.blueprintsprocessor.ssh.SshLibConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.springframework.stereotype.Service
@Service(SshLibConstants.SERVICE_BLUEPRINT_SSH_LIB_PROPERTY)
open class BluePrintSshLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
+ fun blueprintSshClientService(jsonNode: JsonNode): BlueprintSshClientService {
+ val restClientProperties = sshClientProperties(jsonNode)
+ return blueprintSshClientService(restClientProperties)
+ }
+
fun blueprintSshClientService(selector: String): BlueprintSshClientService {
val prefix = "${SshLibConstants.PROPERTY_SSH_CLIENT_PREFIX}$selector"
val sshClientProperties = sshClientProperties(prefix)
@@ -44,6 +51,19 @@ open class BluePrintSshLibPropertyService(private var bluePrintProperties: BlueP
}
}
+ fun sshClientProperties(jsonNode: JsonNode): SshClientProperties {
+ val type = jsonNode.get("type").textValue()
+ return when (type) {
+ SshLibConstants.TYPE_BASIC_AUTH -> {
+ JacksonUtils.readValue(jsonNode,
+ BasicAuthSshClientProperties::class.java)!!
+ }
+ else -> {
+ throw BluePrintProcessorException("SSH adaptor($type) is not supported")
+ }
+ }
+ }
+
private fun blueprintSshClientService(sshClientProperties: SshClientProperties): BlueprintSshClientService {
when (sshClientProperties) {