Add sample test dsl type cba
[ccsdk/cds.git] / components / model-catalog / blueprint-model / test-blueprint / resource-audit / Scripts / kotlin / cba / resource / audit / ResourceAuditDefinitions.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.resource.audit
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
20 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTemplateComponentScriptExecutor
21 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getAttribute
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getNodeTemplateAttribute
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTypeComponent
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
29 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBluePrintDefinitions
30
31 class ResourceAuditDefinitions : AbstractBluePrintDefinitions() {
32     override fun serviceTemplate(): ServiceTemplate {
33         return defaultServiceTemplate()
34     }
35 }
36
37 fun ResourceAuditDefinitions.defaultServiceTemplate() =
38         serviceTemplate(name = "resource-audit",
39                 version = "1.0.0",
40                 author = "Brinda Santh Muthuramalingam",
41                 tags = "brinda, tosca") {
42
43             topologyTemplate {
44
45                 workflow(id = "config-collect", description = "Collect the configuration for Device") {
46                     inputs {
47                         property(id = "device-id", type = BluePrintConstants.DATA_TYPE_STRING, required = true, description = "")
48                         property(id = "sources", type = BluePrintConstants.DATA_TYPE_LIST, required = true, description = "") {
49                             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
50                         }
51                     }
52                     outputs {
53                         property(id = "response-data", required = true, type = BluePrintConstants.DATA_TYPE_STRING, description = "") {
54                             value(getNodeTemplateAttribute(nodeTemplateId = "config-collector",
55                                     attributeId = ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA))
56                         }
57                         property(id = "status", required = true, type = BluePrintConstants.DATA_TYPE_STRING, description = "") {
58                             value(BluePrintConstants.STATUS_SUCCESS)
59                         }
60                     }
61                     step(id = "config-collector", target = "config-collector", description = "Collect the Configuration")
62                 }
63
64                 val configCollectorComponent = BluePrintTypes.nodeTemplateComponentScriptExecutor(
65                         id = "config-collector", description = "Config collector component") {
66
67                     definedOperation(description = "Config Collector Operation") {
68                         inputs {
69                             type(BluePrintConstants.SCRIPT_KOTLIN)
70                             scriptClassReference("cba.resource.audit.functions.ConfigCollector")
71                         }
72                         outputs {
73                             status(getAttribute(ComponentScriptExecutor.ATTRIBUTE_STATUS))
74                             responseData(getAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA))
75                         }
76                     }
77                 }
78                 nodeTemplate(configCollectorComponent)
79             }
80
81             nodeType(BluePrintTypes.nodeTypeComponent())
82             nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
83         }