3700a0bada9f71a451fed436e2e2ba02d336b143
[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.basicAuthSshProperties
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.artifactTypeTemplateVelocity
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getAttribute
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getInput
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTypeComponent
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
30 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBluePrintDefinitions
31
32 class CapabilityCliDefinitions : AbstractBluePrintDefinitions() {
33
34     override fun serviceTemplate(): ServiceTemplate {
35         return defaultServiceTemplate()
36     }
37 }
38
39 fun CapabilityCliDefinitions.defaultServiceTemplate() =
40     serviceTemplate(
41         name = "capability-cli",
42         version = "1.0.0",
43         author = "Brinda Santh Muthuramalingam",
44         tags = "brinda, tosca"
45     ) {
46
47         dsl("device-properties", BluePrintTypes.basicAuthSshProperties {
48             host(getInput("hostname"))
49             password(getInput("password"))
50             username(getInput("username"))
51         })
52
53         topologyTemplate {
54             workflow(id = "check", description = "CLI Check Workflow") {
55                 inputs {
56                     property(id = "hostname", type = "string", required = true, description = "")
57                     property(id = "username", type = "string", required = true, description = "")
58                     property(id = "password", type = "string", required = true, description = "")
59                     property(id = "data", type = "json", required = true, description = "")
60                 }
61                 outputs {
62                     property(id = "status", required = true, type = "string", description = "") {
63                         value("success")
64                     }
65                 }
66                 step(id = "check", target = "check", description = "Calling check script node")
67             }
68
69             val checkComponent = BluePrintTypes.nodeTemplateComponentScriptExecutor(id = "check", description = "") {
70                 definedOperation(description = "") {
71                     inputs {
72                         type("kotlin")
73                         scriptClassReference("cba.capability.cli.Check")
74                     }
75                     outputs {
76                         status(getAttribute("status"))
77                         responseData("""{ "data" : "Here I am "}""")
78                     }
79                 }
80                 artifact(
81                     id = "command-template", type = "artifact-template-velocity",
82                     file = "Templates/check-command-template.vtl"
83                 )
84             }
85             nodeTemplate(checkComponent)
86         }
87
88         /** Artifact Types */
89         artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
90         /** Node Types */
91         nodeType(BluePrintTypes.nodeTypeComponent())
92         nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
93         /** Relationship Types */
94         relationshipType(BluePrintTypes.relationshipTypeConnectsTo())
95
96     }