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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
|
/**
* Copyright 2016 ZTE Corporation.
*
* 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.
*/
package org.openo.commontosca.catalog.model.parser.yaml.zte.entity;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class ParseYamlResult {
private String toscaDefinitionsVersion;
private String description;
private JsonObject nodeTypes;
private JsonObject capabilityTypes;
private JsonObject relationshipTypes;
private JsonObject policyTypes;
private TopologyTemplate topologyTemplate;
private Map<String, String> metadata;
private JsonObject plans;
public String getToscaDefinitionsVersion() {
return toscaDefinitionsVersion;
}
public void setToscaDefinitionsVersion(String toscaDefinitionsVersion) {
this.toscaDefinitionsVersion = toscaDefinitionsVersion;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public JsonObject getNodeTypes() {
return nodeTypes;
}
public void setNodeTypes(JsonObject nodeTypes) {
this.nodeTypes = nodeTypes;
}
public List<NodeType> getNodeTypeList() {
return jsonObject2NodeTypes(nodeTypes);
}
private ArrayList<NodeType> jsonObject2NodeTypes(JsonObject nodeTypes) {
ArrayList<NodeType> nodeTypeList = new ArrayList<NodeType>();
Iterator<Entry<String, JsonElement>> iterator = nodeTypes.entrySet().iterator();
while (iterator.hasNext()) {
NodeType type = new NodeType();
Entry<String, JsonElement> next = iterator.next();
type.setType(next.getKey());
type.setValue(new Gson().fromJson(next.getValue(), NodeType.NodeTypeValue.class));
nodeTypeList.add(type);
}
return nodeTypeList;
}
public JsonObject getCapabilityTypes() {
return capabilityTypes;
}
public void setCapabilityTypes(JsonObject capabilityTypes) {
this.capabilityTypes = capabilityTypes;
}
public JsonObject getRelationshipTypes() {
return relationshipTypes;
}
public void setRelationshipTypes(JsonObject relationshipTypes) {
this.relationshipTypes = relationshipTypes;
}
public List<RelationshipType> getRelationshipTypeList() {
return jsonObject2RelationshipTypes(relationshipTypes);
}
private ArrayList<RelationshipType> jsonObject2RelationshipTypes(JsonObject relationshipTypes) {
ArrayList<RelationshipType> relationshipTypeList = new ArrayList<RelationshipType>();
Iterator<Entry<String, JsonElement>> iterator = relationshipTypes.entrySet().iterator();
while (iterator.hasNext()) {
RelationshipType type = new RelationshipType();
Entry<String, JsonElement> next = iterator.next();
type.setType(next.getKey());
type.setValue(new Gson().fromJson(next.getValue(), RelationshipType.RelationshipValue.class));
relationshipTypeList.add(type);
}
return relationshipTypeList;
}
public JsonObject getPolicyTypes() {
return policyTypes;
}
public void setPolicyTypes(JsonObject policyTypes) {
this.policyTypes = policyTypes;
}
public TopologyTemplate getTopologyTemplate() {
return topologyTemplate;
}
public void setTopologyTemplate(TopologyTemplate topologyTemplate) {
this.topologyTemplate = topologyTemplate;
}
public Map<String, String> getMetadata() {
return metadata;
}
public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}
public JsonObject getPlans() {
return plans;
}
public void setPlans(JsonObject plans) {
this.plans = plans;
}
public List<Plan> getPlanList() {
return jsonObject2PlanList(this.plans);
}
private List<Plan> jsonObject2PlanList(JsonObject plans) {
if (plans == null) {
return new ArrayList<>();
}
List<Plan> retList = new ArrayList<>();
Iterator<Entry<String, JsonElement>> iterator = plans.entrySet().iterator();
while (iterator.hasNext()) {
Plan ret = new Plan();
Entry<String, JsonElement> next = iterator.next();
ret.setName(next.getKey());
ret.setValue(new Gson().fromJson(next.getValue(), Plan.PlanValue.class));
retList.add(ret);
}
return retList;
}
public class TopologyTemplate {
private String description;
private List<Input> inputs;
private List<Output> outputs;
private List<NodeTemplate> nodeTemplates;
private SubstitutionMapping substitutionMappings;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<Input> getInputs() {
return inputs;
}
public void setInputs(List<Input> inputs) {
this.inputs = inputs;
}
public List<Output> getOutputs() {
return outputs;
}
public void setOutputs(List<Output> outputs) {
this.outputs = outputs;
}
public List<NodeTemplate> getNodeTemplates() {
return nodeTemplates;
}
public void setNodeTemplates(List<NodeTemplate> nodeTemplates) {
this.nodeTemplates = nodeTemplates;
}
public SubstitutionMapping getSubstitutionMappings() {
return substitutionMappings;
}
public void setSubstitutionMappings(SubstitutionMapping substitutionMappings) {
this.substitutionMappings = substitutionMappings;
}
public class Input {
private String name;
private String type;
private String description;
private String defaultValue;
private boolean required;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDefault() {
return defaultValue;
}
public void setDefault(String defaultValue) {
this.defaultValue = defaultValue;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
}
public class Output {
private String name;
private String description;
private Object value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
public class NodeTemplate {
private String name;
private String nodeType;
private JsonObject properties;
private JsonObject[] requirements;
private JsonObject capabilities;
private List<Relationship> relationships;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNodeType() {
return nodeType;
}
public void setNodeType(String nodeType) {
this.nodeType = nodeType;
}
public JsonObject getProperties() {
return properties;
}
public void setProperties(JsonObject properties) {
this.properties = properties;
}
public Map<String, Object> getPropertyList() {
return jsonObject2Properties(properties);
}
private Map<String, Object> jsonObject2Properties(JsonObject properties) {
Map<String, Object> ret = new HashMap<>();
Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, JsonElement> next = iterator.next();
ret.put(next.getKey(), next.getValue().getAsString());
}
return ret;
}
public JsonObject[] getRequirements() {
return requirements;
}
public void setRequirements(JsonObject[] requirements) {
this.requirements = requirements;
}
public JsonObject getCapabilities() {
return capabilities;
}
public void setCapabilities(JsonObject capabilities) {
this.capabilities = capabilities;
}
public List<Relationship> getRelationships() {
return relationships;
}
public void setRelationships(List<Relationship> relationships) {
this.relationships = relationships;
}
/**
* get scalable.
* @return NodeTemplateScalable
*/
public NodeTemplateScalable getScalable() {
if (capabilities == null) {
return null;
}
JsonElement scaleableJson = capabilities.get("scalable");
if (scaleableJson == null || !scaleableJson.isJsonObject()) {
return null;
}
JsonElement propertyJson = scaleableJson.getAsJsonObject().get("properties");
if (propertyJson == null || !propertyJson.isJsonObject()) {
return null;
}
NodeTemplateScalable scalable = new NodeTemplateScalable();
scalable
.setMin_instances(propertyJson.getAsJsonObject().get("min_instances").getAsString());
scalable
.setMax_instances(propertyJson.getAsJsonObject().get("max_instances").getAsString());
scalable.setDefault_instances(
propertyJson.getAsJsonObject().get("default_instances").getAsString());
return scalable;
}
public class Relationship {
private String targetNodeName;
private String type;
private String sourceNodeName;
public String getTargetNodeName() {
return targetNodeName;
}
public void setTargetNodeName(String targetNodeName) {
this.targetNodeName = targetNodeName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSourceNodeName() {
return sourceNodeName;
}
public void setSourceNodeName(String sourceNodeName) {
this.sourceNodeName = sourceNodeName;
}
}
public class NodeTemplateScalable {
private String minInstances;
private String maxInstances;
private String defaultInstances;
public String getMin_instances() {
return minInstances;
}
public void setMin_instances(String minInstances) {
this.minInstances = minInstances;
}
public String getMax_instances() {
return maxInstances;
}
public void setMax_instances(String maxInstances) {
this.maxInstances = maxInstances;
}
public String getDefault_instances() {
return defaultInstances;
}
public void setDefault_instances(String defaultInstances) {
this.defaultInstances = defaultInstances;
}
}
}
public class SubstitutionMapping {
private String nodeType;
private JsonObject requirements;
private JsonObject capabilities;
private JsonObject properties;
public String getNodeType() {
return nodeType;
}
public void setNodeType(String nodeType) {
this.nodeType = nodeType;
}
public JsonObject getRequirements() {
return requirements;
}
public void setRequirements(JsonObject requirements) {
this.requirements = requirements;
}
public Map<String, String[]> getRequirementList() {
return jsonObjects2Requirements(this.requirements);
}
private Map<String, String[]> jsonObjects2Requirements(JsonObject requirements) {
Map<String, String[]> ret = new HashMap<String, String[]>();
Iterator<Entry<String, JsonElement>> iterator = requirements.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, JsonElement> next = iterator.next();
if (next.getValue().isJsonPrimitive() || next.getValue().isJsonObject()) {
ret.put(next.getKey(), new String[] {next.getValue().getAsString()});
continue;
}
if (next.getValue().isJsonArray()) {
String[] value = parseListValue((JsonArray) next.getValue());
ret.put(next.getKey(), value);
}
}
return ret;
}
private String[] parseListValue(JsonArray jsonArray) {
String[] value = new String[jsonArray.size()];
for (int i = 0, size = jsonArray.size(); i < size; i++) {
value[i] = jsonArray.get(i).getAsString();
}
return value;
}
public JsonObject getCapabilities() {
return capabilities;
}
public void setCapabilities(JsonObject capabilities) {
this.capabilities = capabilities;
}
public Map<String, String[]> getCapabilityList() {
return jsonObject2Capabilities(this.capabilities);
}
private Map<String, String[]> jsonObject2Capabilities(JsonObject capabilities) {
Map<String, String[]> ret = new HashMap<String, String[]>();
Iterator<Entry<String, JsonElement>> iterator = capabilities.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, JsonElement> next = iterator.next();
if (next.getValue().isJsonPrimitive() || next.getValue().isJsonObject()) {
ret.put(next.getKey(), new String[] {next.getValue().getAsString()});
continue;
}
if (next.getValue().isJsonArray()) {
String[] value = parseListValue((JsonArray) next.getValue());
ret.put(next.getKey(), value);
}
}
return ret;
}
public JsonObject getProperties() {
return properties;
}
public void setProperties(JsonObject properties) {
this.properties = properties;
}
public Map<String, Object> getPropertyList() {
return jsonObject2Properties(properties);
}
private Map<String, Object> jsonObject2Properties(JsonObject properties) {
Map<String, Object> ret = new HashMap<>();
Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, JsonElement> next = iterator.next();
ret.put(next.getKey(), next.getValue().getAsString());
}
return ret;
}
}
}
public class RelationshipType {
private String type;
private RelationshipValue value;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public RelationshipValue getValue() {
return value;
}
public void setValue(RelationshipValue value) {
this.value = value;
}
public class RelationshipValue {
private String derivedFrom;
private String[] validTargetTypes;
public String getDerivedFrom() {
return derivedFrom;
}
public void setDerivedFrom(String derivedFrom) {
this.derivedFrom = derivedFrom;
}
public String[] getValid_target_types() {
return validTargetTypes;
}
public void setValid_target_types(String[] validTargetTypes) {
this.validTargetTypes = validTargetTypes;
}
}
}
public class NodeType {
private String type;
private NodeTypeValue value;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public NodeTypeValue getValue() {
return value;
}
public void setValue(NodeTypeValue value) {
this.value = value;
}
public class NodeTypeValue {
private String derivedFrom;
private JsonObject properties;
private JsonObject[] requirements;
private JsonObject capabilities;
public String getDerivedFrom() {
return derivedFrom;
}
public void setDerived_from(String derivedFrom) {
this.derivedFrom = derivedFrom;
}
public JsonObject getProperties() {
return properties;
}
public void setProperties(JsonObject properties) {
this.properties = properties;
}
public List<NodeTypeProperty> getPropertyList() {
return jsonObject2Properties(properties);
}
private List<NodeTypeProperty> jsonObject2Properties(JsonObject properties) {
List<NodeTypeProperty> propertieList = new ArrayList<NodeTypeProperty>();
Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator();
while (iterator.hasNext()) {
NodeTypeProperty type = new NodeTypeProperty();
Entry<String, JsonElement> next = iterator.next();
type.setKey(next.getKey());
type.setValue(new Gson().fromJson(next.getValue(), JsonObject.class));
propertieList.add(type);
}
return propertieList;
}
public class NodeTypeProperty {
private String key;
private JsonObject value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
/**
* get default value.
* @return default value
*/
public String getDefaultValue() {
JsonElement defaultValue = value.get("default");
if (defaultValue == null || defaultValue.isJsonObject()) {
return "";
}
return defaultValue.getAsString();
}
public JsonObject getValue() {
return value;
}
public void setValue(JsonObject value) {
this.value = value;
}
}
public JsonObject[] getRequirements() {
return requirements;
}
public void setRequirements(JsonObject[] requirements) {
this.requirements = requirements;
}
public JsonObject getCapabilities() {
return capabilities;
}
public void setCapabilities(JsonObject capabilities) {
this.capabilities = capabilities;
}
}
}
public class Plan {
private String name;
private PlanValue value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return value.getDescription();
}
public String getReference() {
return value.getReference();
}
public String getPlanLanguage() {
return value.getPlanLanguage();
}
public List<PlanValue.PlanInput> getInputList() {
return value.getInputList();
}
public PlanValue getValue() {
return value;
}
public void setValue(PlanValue value) {
this.value = value;
}
public class PlanValue {
private String description;
private String reference;
private String planLanguage;
private JsonObject inputs;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getPlanLanguage() {
return planLanguage;
}
public void setPlanLanguage(String planLanguage) {
this.planLanguage = planLanguage;
}
public JsonObject getInputs() {
return inputs;
}
public void setInputs(JsonObject inputs) {
this.inputs = inputs;
}
public List<PlanInput> getInputList() {
return jsonObject2PlanInputList(inputs);
}
private List<PlanInput> jsonObject2PlanInputList(JsonObject inputs) {
List<PlanInput> retList = new ArrayList<PlanInput>();
Iterator<Entry<String, JsonElement>> iterator = inputs.entrySet().iterator();
while (iterator.hasNext()) {
PlanInput ret = new PlanInput();
Entry<String, JsonElement> next = iterator.next();
ret.setName(next.getKey());
ret.setValue(new Gson().fromJson(next.getValue(), PlanInput.PlanInputValue.class));
retList.add(ret);
}
return retList;
}
public class PlanInput {
private String name;
private PlanInputValue value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return value.getType();
}
public String getDescription() {
return value.getDescription();
}
public String getDefault() {
return value.getDefaultValue();
}
public boolean isRequired() {
return value.isRequired();
}
public PlanInputValue getValue() {
return value;
}
public void setValue(PlanInputValue value) {
this.value = value;
}
public class PlanInputValue {
private String type;
private String description;
@SerializedName("default")
private String defaultValue;
private boolean required;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
}
}
}
}
}
|