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