Revert "Renaming Files having BluePrint to have Blueprint"
[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
33     override fun serviceTemplate(): ServiceTemplate {
34         return defaultServiceTemplate()
35     }
36 }
37
38 fun ResourceAuditDefinitions.defaultServiceTemplate() =
39     serviceTemplate(
40         name = "resource-audit",
41         version = "1.0.0",
42         author = "Brinda Santh Muthuramalingam",
43         tags = "brinda, tosca"
44     ) {
45
46         topologyTemplate {
47
48             workflow(id = "config-collect", description = "Collect the configuration for Device") {
49                 inputs {
50                     property(id = "device-id", type = BluePrintConstants.DATA_TYPE_STRING, required = true, description = "")
51                     property(id = "sources", type = BluePrintConstants.DATA_TYPE_LIST, required = true, description = "") {
52                         entrySchema(BluePrintConstants.DATA_TYPE_STRING)
53                     }
54                 }
55                 outputs {
56                     property(id = "response-data", required = true, type = BluePrintConstants.DATA_TYPE_STRING, description = "") {
57                         value(
58                             getNodeTemplateAttribute(
59                                 nodeTemplateId = "config-collector",
60                                 attributeId = ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA
61                             )
62                         )
63                     }
64                     property(id = "status", required = true, type = BluePrintConstants.DATA_TYPE_STRING, description = "") {
65                         value(BluePrintConstants.STATUS_SUCCESS)
66                     }
67                 }
68                 step(id = "config-collector", target = "config-collector", description = "Collect the Configuration")
69             }
70
71             val configCollectorComponent = BluePrintTypes.nodeTemplateComponentScriptExecutor(
72                 id = "config-collector",
73                 description = "Config collector component"
74             ) {
75
76                 definedOperation(description = "Config Collector Operation") {
77                     inputs {
78                         type(BluePrintConstants.SCRIPT_KOTLIN)
79                         scriptClassReference("cba.resource.audit.functions.ConfigCollector")
80                     }
81                     outputs {
82                         status(getAttribute(ComponentScriptExecutor.ATTRIBUTE_STATUS))
83                         responseData(getAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA))
84                     }
85                 }
86             }
87             nodeTemplate(configCollectorComponent)
88         }
89
90         nodeType(BluePrintTypes.nodeTypeComponent())
91         nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
92     }