698bf330f7d446515202e08748a4ba4477790f64
[ccsdk/cds.git] /
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package cba.capability.cli
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTemplateComponentScriptExecutor
20 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor
21 import org.onap.ccsdk.cds.blueprintsprocessor.ssh.relationshipTemplateSshClient
22 import org.onap.ccsdk.cds.blueprintsprocessor.ssh.relationshipTypeConnectsToSshClient
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.artifactTypeTemplateVelocity
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getAttribute
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getInput
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTypeComponent
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
31 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBluePrintDefinitions
32
33 class CapabilityCliDefinitions : AbstractBluePrintDefinitions() {
34
35     override fun serviceTemplate(): ServiceTemplate {
36         return defaultServiceTemplate()
37     }
38 }
39
40 fun CapabilityCliDefinitions.defaultServiceTemplate() =
41     serviceTemplate(
42         name = "capability-cli",
43         version = "1.0.0",
44         author = "Brinda Santh Muthuramalingam",
45         tags = "brinda, tosca"
46     ) {
47         topologyTemplate {
48             workflow(id = "check", description = "CLI Check Workflow") {
49                 inputs {
50                     property(id = "hostname", type = "string", required = true, description = "")
51                     property(id = "username", type = "string", required = true, description = "")
52                     property(id = "password", type = "string", required = true, description = "")
53                     property(id = "data", type = "json", required = true, description = "")
54                 }
55                 outputs {
56                     property(id = "status", required = true, type = "string", description = "") {
57                         value("success")
58                     }
59                 }
60                 step(id = "check", target = "check", description = "Calling check script node")
61             }
62
63             /** Check component Node Template */
64             nodeTemplateComponentScriptExecutor(id = "check", description = "") {
65                 definedOperation(description = "") {
66                     inputs {
67                         type(BluePrintConstants.SCRIPT_KOTLIN)
68                         scriptClassReference(Check::class)
69                     }
70                     outputs {
71                         status(getAttribute("status"))
72                         responseData("""{ "data" : "Here I am "}""")
73                     }
74                 }
75                 artifact(
76                     id = "command-template", type = "artifact-template-velocity",
77                     file = "Templates/check-command-template.vtl"
78                 )
79             }
80
81             /** Connection Configuration through Relationship **/
82             relationshipTemplateSshClient("ssh-connection-config", "Device connection config") {
83                 basicAuth {
84                     host(getInput("hostname"))
85                     password(getInput("password"))
86                     username(getInput("username"))
87                 }
88             }
89         }
90
91         /** Artifact Types */
92         artifactTypeTemplateVelocity()
93         /** Node Types */
94         nodeTypeComponent()
95         nodeTypeComponentScriptExecutor()
96         /** Relationship Types */
97         relationshipTypeConnectsToSshClient()
98         relationshipTypeConnectsTo()
99     }