4e0f0f18ac4a24346b562aa3b84eee42d18ea918
[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 org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
25
26 fun BluePrintTypes.nodeTypeSourceInput(): NodeType {
27     return nodeType(id = "source-input", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
28             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
29             description = "This is Input Resource Source Node Type") {}
30 }
31
32 fun BluePrintTypes.nodeTypeSourceDefault(): NodeType {
33     return nodeType(id = "source-default", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
34             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
35             description = "This is Default Resource Source Node Type") {}
36 }
37
38 fun BluePrintTypes.nodeTypeSourceDb(): NodeType {
39     return nodeType(id = "source-db", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
40             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
41             description = "This is Database Resource Source Node Type") {
42         property("type", BluePrintConstants.DATA_TYPE_STRING,
43                 true, "") {
44             defaultValue("SQL".asJsonPrimitive())
45             constrain {
46                 validValues(arrayListOf("SQL".asJsonPrimitive(), "PLSQL".asJsonPrimitive()))
47             }
48         }
49         property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
50                 false, "")
51         property("query", BluePrintConstants.DATA_TYPE_STRING,
52                 true, "")
53         property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
54                 true, "") {
55             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
56         }
57         property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
58                 false, "") {
59             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
60         }
61         property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
62                 true, "Resource Resolution dependency dictionary names.") {
63             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
64         }
65     }
66 }
67
68 fun BluePrintTypes.nodeTypeSourceRest(): NodeType {
69     return nodeType(id = "source-rest", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
70             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
71             description = "This is Rest Resource Source Node Type") {
72         property("type", BluePrintConstants.DATA_TYPE_STRING,
73                 true, "") {
74             defaultValue("JSON".asJsonPrimitive())
75             constrain {
76                 validValues(arrayListOf("JSON".asJsonPrimitive(), "XML".asJsonPrimitive()))
77             }
78         }
79         property("verb", BluePrintConstants.DATA_TYPE_STRING,
80                 true, "") {
81             defaultValue("GET".asJsonPrimitive())
82             constrain {
83                 validValues(arrayListOf("GET".asJsonPrimitive(), "POST".asJsonPrimitive(),
84                         "DELETE".asJsonPrimitive(), "PUT".asJsonPrimitive()))
85             }
86         }
87         property("payload", BluePrintConstants.DATA_TYPE_STRING,
88                 false, ""){
89             defaultValue("".asJsonPrimitive())
90         }
91         property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
92                 false, "")
93         property("url-path", BluePrintConstants.DATA_TYPE_STRING,
94                 true, "")
95         property("path", BluePrintConstants.DATA_TYPE_STRING,
96                 true, "")
97         property("expression-type", BluePrintConstants.DATA_TYPE_STRING,
98                 false, "") {
99             defaultValue("JSON_PATH".asJsonPrimitive())
100             constrain {
101                 validValues(arrayListOf("JSON_PATH".asJsonPrimitive(), "JSON_POINTER".asJsonPrimitive()))
102             }
103         }
104         property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
105                 true, "") {
106             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
107         }
108         property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
109                 false, "") {
110             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
111         }
112         property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
113                 true, "Resource Resolution dependency dictionary names.") {
114             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
115         }
116     }
117 }
118
119 fun BluePrintTypes.nodeTypeSourceCapability(): NodeType {
120     return nodeType(id = "source-capability", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
121             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
122             description = "This is Component Resource Source Node Type") {
123         property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
124                 true, "Request Id, Unique Id for the request.") {
125             defaultValue(BluePrintConstants.SCRIPT_KOTLIN)
126             constrain {
127                 validValues(arrayListOf(BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive(),
128                         BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
129                         BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive()))
130             }
131         }
132         property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
133                 true, "Kotlin Script class name or jython script name.")
134         property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
135                 false, "Dynamic Json Content or DSL Json reference.")
136         property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
137                 true, "Resource Resolution dependency dictionary names.") {
138             entrySchema(BluePrintConstants.DATA_TYPE_STRING)
139         }
140     }
141 }