Fix: Run both sonar and clm scans in parallel
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / cli-executor / src / main / kotlin / internal / scripts / InternalSimpleCli.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
4  *  Modifications Copyright © 2019 IBM, Bell Canada
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18
19 @file:Suppress("unused")
20
21 package internal.scripts
22
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.cliDeviceInfo
25 import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.getSshClientService
26 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
27 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
28 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
29 import org.slf4j.LoggerFactory
30
31 open class TestCliScriptFunction : AbstractScriptComponentFunction() {
32
33     private val log = LoggerFactory.getLogger(TestCliScriptFunction::class.java)!!
34
35     override fun getName(): String {
36         return "TestCliScriptFunction"
37     }
38
39     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
40         log.info("Executing process ...")
41     }
42
43     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
44         log.info("Executing Recovery")
45     }
46 }
47
48 open class Check : AbstractScriptComponentFunction() {
49
50     private val log = LoggerFactory.getLogger(AbstractScriptComponentFunction::class.java)!!
51
52     override fun getName(): String {
53         return "Check"
54     }
55
56     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
57         // Get the Device Information from the DSL Model
58         val deviceInformation = cliDeviceInfo("device-properties")
59
60         // Get the Client Service
61         val sshClientService = getSshClientService(deviceInformation)
62
63         sshClientService.startSessionNB()
64
65         // Read Commands
66         val commands = readLinesFromArtifact("command-template")
67
68         // Execute multiple Commands
69         val responseLog = sshClientService.executeCommandsNB(commands, 5000)
70
71         // Close Session
72         sshClientService.closeSessionNB()
73
74         // Set the Response Data
75         setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, responseLog.asJsonType())
76
77         log.info("Executing process")
78     }
79
80     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
81         log.info("Executing Recovery")
82     }
83 }