2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 @file:Suppress("unused")
19 package internal.scripts
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.cliDeviceInfo
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.getSshClientService
24 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
25 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
26 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
28 import org.slf4j.LoggerFactory
30 open class TestCliScriptFunction : AbstractScriptComponentFunction() {
32 private val log = LoggerFactory.getLogger(TestCliScriptFunction::class.java)!!
34 override fun getName(): String {
35 return "TestCliScriptFunction"
38 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
39 log.info("Executing process ...")
42 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
43 log.info("Executing Recovery")
48 open class Check : AbstractScriptComponentFunction() {
50 private val log = LoggerFactory.getLogger(AbstractScriptComponentFunction::class.java)!!
52 override fun getName(): String {
56 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
57 // Get the Device Information from the DSL Model
58 val deviceInformation = cliDeviceInfo("device-properties")
60 // Get the Client Service
61 val sshClientService = getSshClientService(deviceInformation)
63 sshClientService.startSessionNB()
66 val commands = readLinesFromArtifact("command-template")
68 // Execute multiple Commands
69 val responseLog = sshClientService.executeCommandsNB(commands, 5000)
72 sshClientService.closeSessionNB()
74 // Set the Response Data
75 setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, responseLog.asJsonPrimitive())
77 log.info("Executing process")
80 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
81 log.info("Executing Recovery")