3bf07e79df790b17341267f63fea8e3ff6f59356
[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.scripts.capability.cli
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.componentScriptExecutor
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
22 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.artifactTypeTemplateVelocity
23 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTypeComponent
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
25 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBluePrintDefinitions
26
27 class CapabilityCliDefinitions : AbstractBluePrintDefinitions() {
28
29     override fun serviceTemplate(): ServiceTemplate {
30         return defaultServiceTemplate()
31     }
32 }
33
34 fun CapabilityCliDefinitions.defaultServiceTemplate() =
35         serviceTemplate(name = "capability-cli",
36                 version = "1.0.0",
37                 author = "Brinda Santh Muthuramalingam",
38                 tags = "brinda, tosca") {
39
40             dsl("device-properties", """{
41                   "type": "basic-auth",
42                   "host": { "get_input": "hostname"  },
43                   "username": { "get_input": "username" },
44                   "password": { "get_input": "password" }
45                 }""".trimIndent())
46
47             topologyTemplate {
48
49                 workflow(id = "check", description = "CLI Check Workflow") {
50                     inputs {
51                         property(id = "hostname", type = "string", required = true, description = "")
52                         property(id = "username", type = "string", required = true, description = "")
53                         property(id = "password", type = "string", required = true, description = "")
54                         property(id = "data", type = "json", required = true, description = "")
55                     }
56                     outputs {
57                         property(id = "status", required = true, type = "string", description = "") {
58                             value("success")
59                         }
60                     }
61                     step(id = "check", target = "check", description = "Calling check script node")
62                 }
63
64                 val checkComponent = componentScriptExecutor(id = "check", description = "") {
65                     inputs {
66                         type("kotlin")
67                         scriptClassReference("cba.scripts.capability.cli.Check")
68                     }
69                     outputs {
70                         status("success")
71                         responseData("""{ "data" : "Here I am "}""")
72                     }
73                     artifact(id = "command-template", type = "artifact-template-velocity",
74                             file = "Templates/check-command-template.vtl")
75                 }
76                 nodeTemplate(checkComponent)
77             }
78
79             artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
80             nodeType(BluePrintTypes.nodeTypeComponent())
81             nodeType(BluePrintTypes.componentScriptExecutor())
82
83         }