aboutsummaryrefslogtreecommitdiffstats
path: root/ajsc-aai/src/main/java/org/openecomp/aai/dbmodel/DbEdgeRules.java
blob: d29791ac4578908f9fd4b87652749a29857de64f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*-
 * ============LICENSE_START=======================================================
 * org.openecomp.aai
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.aai.dbmodel;

import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;

public class DbEdgeRules {

	/*
	 * The EdgeRules data is set up as a key (fromNodeTypeA|toNodeTypeB) mapped
	 * to a string which holds the info we need to build an edge from nodeTypeA
	 * to nodeTypeB. Note -- the MultiMap will let us define more than one type
	 * of edge between a given pair of nodeTypes, but for now we never define
	 * more than one.
	 * 
	 * The edgeInfo part is comma separated and looks like this:
	 * "edgeLabel,direction,multiplicityRule,isParent,usesResource,hasDelTarget,SVC-INFRA" This
	 * format is encoded into the EdgeInfoMap below. 
	 * MultiplicityRule can be either "Many2Many", "Many2One", "One2Many" or "One2One"
	 * The values for the things after multiplicityRule can be either "true", "false" or "reverse". "reverse" is
	 * really saying that this tag does apply, but the edge will be traversed
	 * the opposite way from the same tag that just has "true".
	 */
	public static final Map<Integer, String> EdgeInfoMap;
	static {
		EdgeInfoMap = new HashMap<Integer, String>();
		EdgeInfoMap.put(0, "edgeLabel");
		EdgeInfoMap.put(1, "direction");
		EdgeInfoMap.put(2, "multiplicityRule");
		EdgeInfoMap.put(3, "isParent");
		EdgeInfoMap.put(4, "usesResource");
		EdgeInfoMap.put(5, "hasDelTarget");
		EdgeInfoMap.put(6, "SVC-INFRA");
	}
	
	public static Integer firstTagIndex = 3;

	public static final Multimap<String, String> EdgeRules = new ImmutableSetMultimap.Builder<String, String>()
			.putAll("cloud-region|l3-network",
					"uses,OUT,Many2Many,false,false,false,false")
			.putAll("cloud-region|tenant",
					"has,OUT,One2Many,true,false,false,reverse")
			.putAll("cloud-region|image",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("cloud-region|flavor",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("cloud-region|availability-zone",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("cloud-region|volume-group",
					"has,OUT,One2Many,true,true,false,false")
			.putAll("cloud-region|group-assignment",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("cloud-region|snapshot",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("customer|service-subscription",
					"subscribesTo,OUT,Many2Many,true,false,false,reverse")
			.putAll("generic-vnf|l-interface",
					"hasLInterface,OUT,Many2Many,true,false,false,true")
			.putAll("generic-vnf|availability-zone",
					"hasAvailabilityZone,OUT,Many2Many,false,false,false,true")
			.putAll("generic-vnf|lag-interface",
					"hasLAGInterface,OUT,Many2Many,true,false,false,true")
			.putAll("generic-vnf|l3-network",
					"usesL3Network,OUT,Many2Many,false,true,false,true")
			.putAll("generic-vnf|pserver",
					"runsOnPserver,OUT,Many2Many,false,true,false,true")
			.putAll("generic-vnf|vserver",
					"runsOnVserver,OUT,One2Many,false,true,false,true")
			.putAll("generic-vnf|service-instance",
					"hasInstance,OUT,Many2Many,false,true,false,true")
			.putAll("group-assignment|tenant",
					"has,OUT,Many2Many,false,false,false,false")
			.putAll("group-assignment|pserver",
					"has,OUT,One2Many,false,false,false,false")
			.putAll("image|metadata", "hasMetaData,OUT,Many2Many,true,false,false,false")
			.putAll("image|metadatum",
					"hasMetaDatum,OUT,Many2Many,true,false,false,false")
			.putAll("l-interface|l3-interface-ipv4-address-list",
					"hasIpAddress,OUT,Many2Many,true,false,false,true")
			.putAll("l-interface|l3-interface-ipv6-address-list",
					"hasIpAddress,OUT,Many2Many,true,false,false,true")
			.putAll("l-interface|logical-link",
					"usesLogicalLink,OUT,Many2Many,false,false,true,true")
			.putAll("l-interface|vlan","hasVlan,OUT,Many2Many,true,false,false,false")
			.putAll("l3-interface-ipv4-address-list|l3-network",
					"isMemberOf,OUT,Many2Many,false,false,false,true")
			.putAll("l3-interface-ipv6-address-list|l3-network",
					"isMemberOf,OUT,Many2Many,false,false,false,true")
			.putAll("l3-interface-ipv4-address-list|subnet",
					"isMemberOf,OUT,Many2Many,false,false,false,true")
			.putAll("l3-interface-ipv6-address-list|subnet",
					"isMemberOf,OUT,Many2Many,false,false,false,true")
			.putAll("l3-network|subnet",
					"hasSubnet,OUT,Many2Many,true,false,false,reverse")
			.putAll("l3-network|service-instance",
					"hasInstance,OUT,Many2Many,false,false,false,reverse")
			.putAll("l3-network|ctag-assignment",
					"hasCtagAssignment,OUT,Many2Many,true,false,false,true")
			.putAll("l3-network|segmentation-assignment",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("lag-interface|p-interface",
					"usesPInterface,OUT,Many2Many,false,true,false,true")
			.putAll("lag-interface|l-interface",
					"hasLInterface,OUT,Many2Many,true,false,false,true")		
			.putAll("logical-link|pnf",
					"bridgedTo,OUT,Many2Many,false,false,false,false")	
			.putAll("logical-link|logical-link",
					"uses,OUT,One2Many,false,false,false,true")	
			.putAll("model|model-element",
					"startsWith,OUT,One2Many,true,false,false,false")
			.putAll("model-element|model",
					"isA,OUT,Many2One,false,false,false,false")
			.putAll("model|metadatum",
					"hasMetaData,OUT,One2Many,true,false,false,false")
			.putAll("model-element|model-element",
					"connectsTo,OUT,One2Many,true,false,false,false")
			.putAll("model-element|model-constraint",
					"uses,OUT,One2Many,true,false,false,false")
			.putAll("model-element|constrained-element-set",
					"connectsTo,OUT,One2Many,true,false,false,false")
			.putAll("model-constraint|constrained-element-set",
					"uses,OUT,One2Many,true,false,false,false")
			.putAll("constrained-element-set|element-choice-set",
					"uses,OUT,One2Many,true,false,false,false")
			.putAll("element-choice-set|model-element",
					"has,OUT,One2Many,true,false,false,false")
			.putAll("named-query|model",
					"relatedTo,OUT,One2Many,false,false,false,false")
			.putAll("named-query|named-query-element",
					"startsWith,OUT,One2One,true,false,false,false")
			.putAll("named-query-element|named-query-element",
					"connectsTo,OUT,Many2Many,true,false,false,false")
			.putAll("named-query-element|model",
					"isA,OUT,Many2One,false,false,false,false")
			.putAll("named-query-element|property-constraint",
					"uses,OUT,One2Many,true,false,false,false")
			.putAll("named-query-element|related-lookup",
					"uses,OUT,One2Many,true,false,false,false")
			.putAll("p-interface|l-interface",
					"hasLInterface,OUT,Many2Many,true,false,false,true")
			.putAll("p-interface|physical-link",
					"usesPhysicalLink,OUT,Many2Many,false,false,true,false")
			.putAll("p-interface|logical-link",
                    "usesLogicalLink,OUT,Many2One,false,false,false,true")		
			.putAll("pserver|cloud-region","locatedIn,OUT,Many2One,false,false,false,true")
			.putAll("pserver|availability-zone","existsIn,OUT,Many2One,false,false,false,true")
			.putAll("pserver|lag-interface",
					"hasLAGInterface,OUT,Many2Many,true,false,false,true")
			.putAll("pserver|p-interface",
					"hasPinterface,OUT,Many2Many,true,true,false,true")
			.putAll("pnf|p-interface",
					"hasPinterface,OUT,Many2Many,true,true,false,true")
			.putAll("pnf|lag-interface",
					"has,OUT,One2Many,true,false,false,true")
			.putAll("service-instance|pnf",
					"uses,OUT,One2Many,false,true,false,false")	
			.putAll("service-subscription|service-instance",
					"hasInstance,OUT,Many2Many,true,false,false,reverse")
			.putAll("tenant|l3-network",
					"usesL3Network,OUT,Many2Many,false,false,false,false")
			.putAll("tenant|service-subscription",
					"relatedTo,OUT,Many2Many,false,false,false,false")
			.putAll("tenant|vserver", "owns,OUT,One2Many,true,false,false,reverse")
			.putAll("vlan|l3-interface-ipv4-address-list",
					"hasIpAddress,OUT,Many2Many,true,false,false,true")
			.putAll("vlan|l3-interface-ipv6-address-list",
					"hasIpAddress,OUT,Many2Many,true,false,false,true")
			.putAll("vserver|flavor", "hasFlavor,OUT,Many2One,false,false,false,true")
			.putAll("vserver|image", "hasImage,OUT,Many2One,false,false,false,true")
			.putAll("vserver|ipaddress",
					"hasIpAddress,OUT,Many2Many,true,true,false,false")
			.putAll("vserver|l-interface",
					"hasLInterface,OUT,Many2Many,true,false,false,true")
			.putAll("vserver|pserver",
					"runsOnPserver,OUT,Many2One,false,true,false,true")
			.putAll("vserver|volume", "hasVolume,OUT,Many2Many,true,true,false,true")
			.putAll("vserver|vnfc", "hosts,OUT,Many2Many,false,true,false,true")
			.putAll("vserver|snapshot", "uses,OUT,One2One,false,false,false,true")
            .putAll("service-instance|metadatum", "hasMetaData,OUT,Many2Many,true,false,false,false")
            .putAll("service-instance|logical-link", "uses,OUT,Many2Many,false,false,true,false")
			.putAll("service-instance|vlan", "dependsOn,OUT,One2Many,false,true,false,false")
			.putAll("service-instance|service-instance", "dependsOn,OUT,One2Many,false,true,false,false")
            .putAll("logical-link|generic-vnf", "bridgedTo,OUT,Many2Many,false,false,false,false")
            .putAll("logical-link|pserver", "bridgedTo,OUT,Many2Many,false,false,false,false")
            .putAll("volume-group|tenant", "belongsTo,OUT,Many2Many,false,false,false,true")
            .putAll("vf-module|volume-group", "uses,OUT,One2One,false,false,false,true")
            .putAll("vserver|vf-module", "isPartOf,OUT,Many2One,false,false,false,true")
            .putAll("vf-module|l3-network", "uses,OUT,Many2Many,false,false,false,true")
            .putAll("vf-module|vnfc", "uses,OUT,One2Many,false,false,true,true")
            .putAll("generic-vnf|vf-module", "has,OUT,One2Many,true,false,false,true")
            .putAll("generic-vnf|volume-group", "uses,OUT,One2Many,false,false,false,true")
            .putAll("generic-vnf|vnfc", "uses,OUT,One2Many,false,false,true,true")
            .putAll("vlan|logical-link", "usesLogicalLink,OUT,One2One,false,false,true,true")
			.build();

	public static final Multimap<String, String> DefaultDeleteScope = new ImmutableSetMultimap.Builder<String, String>()
			.putAll("customer", "CASCADE_TO_CHILDREN")
			.putAll("cloud-region", "THIS_NODE_ONLY")
			.putAll("service-subscription", "CASCADE_TO_CHILDREN")
			.putAll("service-instance", "CASCADE_TO_CHILDREN")
			.putAll("tenant", "CASCADE_TO_CHILDREN")
			.putAll("vserver", "CASCADE_TO_CHILDREN")
			.putAll("volume", "THIS_NODE_ONLY")
			.putAll("ipaddress", "THIS_NODE_ONLY")
			.putAll("image", "ERROR_4_IN_EDGES_OR_CASCADE")
			.putAll("pserver", "ERROR_4_IN_EDGES_OR_CASCADE")
			.putAll("availability-zone", "ERROR_IF_ANY_IN_EDGES")
			.putAll("flavor", "ERROR_IF_ANY_IN_EDGES")
			.putAll("metadata", "THIS_NODE_ONLY")
			.putAll("metadatum", "THIS_NODE_ONLY")
			.putAll("model", "ERROR_4_IN_EDGES_OR_CASCADE")
			.putAll("model-element", "CASCADE_TO_CHILDREN")
			.putAll("named-query", "CASCADE_TO_CHILDREN")
			.putAll("named-query-element", "CASCADE_TO_CHILDREN")
			.putAll("collect-lookup", "THIS_NODE_ONLY")
			.putAll("service", "ERROR_IF_ANY_IN_EDGES")
			.putAll("l-interface", "CASCADE_TO_CHILDREN")
			.putAll("vlan", "CASCADE_TO_CHILDREN")
			.putAll("p-interface", "CASCADE_TO_CHILDREN")
			.putAll("l3-interface-ipv6-address-list", "THIS_NODE_ONLY")
			.putAll("l3-interface-ipv4-address-list", "THIS_NODE_ONLY")
			.putAll("logical-link", "THIS_NODE_ONLY")
			.putAll("physical-link", "THIS_NODE_ONLY")
			.putAll("lag-interface", "CASCADE_TO_CHILDREN")
			.putAll("l3-network", "CASCADE_TO_CHILDREN")
			.putAll("subnet", "THIS_NODE_ONLY")
			.putAll("vnfc", "THIS_NODE_ONLY")
			.putAll("volume-group", "THIS_NODE_ONLY")
			.putAll("ctag-assignment", "THIS_NODE_ONLY")
			.putAll("pnf", "CASCADE_TO_CHILDREN")
			.putAll("vf-module", "THIS_NODE_ONLY")
			.putAll("snapshot", "THIS_NODE_ONLY")
			.putAll("group-assignment", "THIS_NODE_ONLY")
			.putAll("segmentation-assignment", "THIS_NODE_ONLY")
			.putAll("generic-vnf", "CASCADE_TO_CHILDREN").build();

	// NOTE -- Sorry, this is ugly, but we are mapping the nodeTypeCategory two
	// ways just to
	// make the code a little less bulky. But that means that we need to ensure
	// that
	// nodeTypeCategory and nodeTypeCatMap are kept in synch.

	// NodeTypeCategory: key is: nodeTypeCategory, value is:
	// "nodeTypes,keyProperties,AltKeyProps,depNode4UniquenessFlag"
	public static final Multimap<String, String> NodeTypeCategory = new ImmutableSetMultimap.Builder<String, String>()
			.putAll("vnf", "generic-vnf,vnf-id,,true").build();

	// NodeTypeCatMap: key is nodeType; value is: "nodeTypeCategory"
	// So -- we're assuming that a nodeType can only be in one nodeTypeCategory.
	public static final Map<String, String> NodeTypeCatMap;
	static {
		NodeTypeCatMap = new HashMap<String, String>();
		NodeTypeCatMap.put("generic-vnf", "vnf");
	}

	// ReservedPropNames: keys are property names of (node) properties that are
	// common to all nodes and
	// should not be removed if not passed in on an UPDATE request.
	public static final Map<String, String> ReservedPropNames;
	static {
		ReservedPropNames = new HashMap<String, String>();
		ReservedPropNames.put("source-of-truth", "");
		ReservedPropNames.put("last-mod-source-of-truth", "");
		ReservedPropNames.put("aai-created-ts", "");
		ReservedPropNames.put("aai-last-mod-ts", "");
	}
	
	// This just lists which node types can be connected to themselves recursively.
	// It's temporary - since DbEdgeRules is going to be overhauled in 16-10, this will
	// get generated automatically.   But for 1607, it can work like this.
	public static final Map<String, String> CanBeRecursiveNT;
	static {
		CanBeRecursiveNT = new HashMap<String, String>();
		CanBeRecursiveNT.put("model-element", "");
		CanBeRecursiveNT.put("named-query-element", "");
	}

}