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
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
|
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.mso.db.catalog;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.openecomp.mso.db.AbstractSessionFactoryManager;
import org.openecomp.mso.db.catalog.beans.AllottedResource;
import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
import org.openecomp.mso.db.catalog.beans.HeatFiles;
import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate;
import org.openecomp.mso.db.catalog.beans.HeatTemplate;
import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
import org.openecomp.mso.db.catalog.beans.Model;
import org.openecomp.mso.db.catalog.beans.ModelRecipe;
import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
import org.openecomp.mso.db.catalog.beans.NetworkResource;
import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
import org.openecomp.mso.db.catalog.beans.Service;
import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources;
import org.openecomp.mso.db.catalog.beans.ServiceToNetworks;
import org.openecomp.mso.db.catalog.beans.ServiceToResourceCustomization;
import org.openecomp.mso.db.catalog.beans.TempNetworkHeatTemplateLookup;
import org.openecomp.mso.db.catalog.beans.ToscaCsar;
import org.openecomp.mso.db.catalog.beans.VfModule;
import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
import org.openecomp.mso.db.catalog.beans.VfModuleToHeatFiles;
import org.openecomp.mso.db.catalog.beans.VnfComponent;
import org.openecomp.mso.db.catalog.beans.VnfComponentsRecipe;
import org.openecomp.mso.db.catalog.beans.VnfRecipe;
import org.openecomp.mso.db.catalog.beans.VnfResCustomToVfModuleCustom;
import org.openecomp.mso.db.catalog.beans.VnfResource;
import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
import org.openecomp.mso.db.catalog.utils.MavenLikeVersioningComparator;
import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
/**
* This class encapsulates all of the objects that can be queried from a Catalog database.
* Clients must use these methods to retrieve catalog objects. The session is not
* available for clients to do their own direct queries to the database.
*
*
*/
public class CatalogDatabase implements Closeable {
protected final AbstractSessionFactoryManager sessionFactoryCatalogDB;
private static final String NETWORK_TYPE = "networkType";
private static final String ACTION = "action";
private static final String VNF_TYPE = "vnfType";
private static final String SERVICE_TYPE = "serviceType";
private static final String MODEL_UUID= "modelUUID";
private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
private static final String MODEL_ID = "modelId";
private static final String MODEL_NAME = "modelName";
private static final String TYPE = "type";
private static final String MODEL_TYPE = "modelType";
private static final String MODEL_VERSION_ID = "modelVersionId";
private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId";
protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
protected Session session = null;
protected CatalogDatabase (AbstractSessionFactoryManager sessionFactoryCatalog) {
sessionFactoryCatalogDB = sessionFactoryCatalog;
}
public static CatalogDatabase getInstance() {
return new CatalogDatabase(new CatalogDbSessionFactoryManager ());
}
private Session getSession () {
if (session == null) {
try {
session = sessionFactoryCatalogDB.getSessionFactory ().openSession ();
session.beginTransaction ();
} catch (HibernateException he) {
LOGGER.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Error creating Hibernate Session: " + he, "", "", MsoLogger.ErrorCode.DataError, "Error creating Hibernate Session: " + he);
throw he;
}
}
return session;
}
/**
* Close an open Catalog Database session.
* This method should always be called when a client is finished using a
* CatalogDatabase instance.
*/
@Override
public void close () {
if (session != null) {
session.close ();
session = null;
}
}
/**
* Commits the current transaction on this session and starts a fresh one.
*/
public void commit () {
getSession ().getTransaction ().commit ();
getSession ().beginTransaction ();
}
/**
* Rolls back current transaction and starts a fresh one.
*/
public void rollback () {
getSession ().getTransaction ().rollback ();
getSession ().beginTransaction ();
}
/**
* Return all Heat Templates in the Catalog DB
*
* @return A list of HeatTemplate objects
*/
@SuppressWarnings("unchecked")
public List <HeatTemplate> getAllHeatTemplates() {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get all Heat templates");
String hql = "FROM HeatTemplate";
Query query = getSession().createQuery(hql);
List <HeatTemplate> result = query.list();
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatTemplates", null);
return result;
}
/**
* Fetch a specific Heat Template by ID.
*
* @param templateId template id
* @return HeatTemplate object or null if none found
*/
@Deprecated
public HeatTemplate getHeatTemplate(int templateId) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get Heat template with id " + templateId);
HeatTemplate template = (HeatTemplate) getSession().get(HeatTemplate.class, templateId);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
return template;
}
/**
* Return the newest version of a specific Heat Template (queried by Name).
*
* @param templateName template name
* @return HeatTemplate object or null if none found
*/
public HeatTemplate getHeatTemplate(String templateName) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Heat template with name " + templateName);
String hql = "FROM HeatTemplate WHERE templateName = :template_name";
Query query = getSession().createQuery (hql);
query.setParameter("template_name", templateName);
@SuppressWarnings("unchecked")
List <HeatTemplate> resultList = query.list();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found", "CatalogDB", "getHeatTemplate", null);
return null;
}
Collections.sort(resultList, new MavenLikeVersioningComparator());
Collections.reverse(resultList);
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
return resultList.get(0);
}
/**
* Return a specific version of a specific Heat Template (queried by Name).
*
* @param templateName
* @param version
* @return HeatTemplate object or null if none found
*/
public HeatTemplate getHeatTemplate(String templateName, String version) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Heat template with name " + templateName
+ " and version "
+ version);
String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version";
Query query = getSession().createQuery(hql);
query.setParameter("template_name", templateName);
query.setParameter("version", version);
@SuppressWarnings("unchecked")
List <HeatTemplate> resultList = query.list();
// See if something came back.
if (resultList.isEmpty()) {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No template found.", "CatalogDB", "getHeatTemplate", null);
return null;
}
// Name + Version is unique, so should only be one element
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
return resultList.get(0);
}
/**
* Return a specific Heat Template by ARTIFACT_UUID).
*
* @param artifactUuid
* @return HeatTemplate object or null if none found
*/
public HeatTemplate getHeatTemplateByArtifactUuid(String artifactUuid) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Heat template with artifactUuid " + artifactUuid);
// Will this work if the id is a string?
HeatTemplate template = (HeatTemplate) getSession ().get (HeatTemplate.class, artifactUuid);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
return template;
}
/**
* Return a specific Heat Template by ARTIFACT_UUID using standard query method. unique record expected.
*
* @param artifactUuid
* @return HeatTemplate object or null if none found
*/
public HeatTemplate getHeatTemplateByArtifactUuidRegularQuery(String artifactUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Heat template (regular query) with artifactUuid " + artifactUuid);
String hql = "FROM HeatTemplate WHERE artifactUuid = :artifactUuidValue";
HashMap<String, String> variables = new HashMap<>();
variables.put("artifactUuidValue", artifactUuid);
HeatTemplate template = (HeatTemplate) this.executeQuerySingleRow(hql, variables, true);
if (template == null) {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
} else {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
}
return template;
}
public List<HeatTemplateParam> getParametersForHeatTemplate(String heatTemplateArtifactUuid) {
LOGGER.debug ("Catalog database - getParametersForHeatTemplate with artifactUuid " + heatTemplateArtifactUuid);
String hql = "FROM HeatTemplateParams WHERE artifactUuid = :artifactUuidValue";
Query query = getSession().createQuery(hql);
query.setParameter ("artifactUuidValue", heatTemplateArtifactUuid);
List<HeatTemplateParam> resultList = new ArrayList<>();
try {
resultList = query.list ();
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching HeatTemplateParams for: heatTemplateArtifactUuid='" + heatTemplateArtifactUuid + "'" + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching HeatTemplateParams for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + heatTemplateArtifactUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching HeatTemplateParam for: artifactUuid='" + heatTemplateArtifactUuid + "'" + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching HeatTemplate for artifactUuid=" + heatTemplateArtifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + heatTemplateArtifactUuid);
throw e;
}
return resultList;
}
/**
* Return a specific Heat Environment by ARTIFACT_UUID using standard query method. unique record expected.
*
* @param artifactUuid
* @return HeatEnvironment object or null if none found
*/
public HeatEnvironment getHeatEnvironmentByArtifactUuid(String artifactUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Heat Environment with artifactUuid " + artifactUuid);
String hql = "FROM HeatEnvironment WHERE artifactUuid = :artifactUuidValue";
Query query = getSession().createQuery(hql);
query.setParameter("artifactUuidValue", artifactUuid);
HeatEnvironment environment = null;
try {
environment = (HeatEnvironment) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row for Envt - data integrity error: artifactUuid='" + artifactUuid +"'", nure);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for heatEnvironment artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid==" + artifactUuid);
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for envt: artifactUuid='" + artifactUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching envt for artifactUuid=" + artifactUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching envt for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching envt for artifactUuid=" + artifactUuid);
throw e;
}
if (environment == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironmentByArtifactUuid", null);
}
return environment;
}
/**
* Fetch a Service definition by InvariantUUID
*/
public Service getServiceByInvariantUUID (String modelInvariantUUID) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get service with Invariant UUID " + modelInvariantUUID);
String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid";
Query query = getSession().createQuery(hql);
query.setParameter ("model_invariant_uuid", modelInvariantUUID);
@SuppressWarnings("unchecked")
List <Service> resultList = query.list ();
// See if something came back.
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByName", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByName", null);
return resultList.get (0);
}
/**
* Fetch a Service definition
*/
public Service getService (String modelName) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get service with name " + modelName);
String hql = "FROM Service WHERE modelName = :MODEL_NAME";
Query query = getSession().createQuery(hql);
query.setParameter("MODEL_NAME", modelName);
Service service = null;
try {
service = (Service) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelName='" + modelName + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelName=" + modelName);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelName='" + modelName + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelName=" + modelName);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelName='" + modelName + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelName=" + modelName);
throw e;
}
if (service == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
}
return service;
}
public Service getServiceByModelUUID (String modelUUID) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get service with Model UUID " + modelUUID);
String hql = "FROM Service WHERE modelUUID = :MODEL_UUID";
HashMap<String, String> parameters = new HashMap<>();
parameters.put("MODEL_UUID", modelUUID);
Service service = this.executeQuerySingleRow(hql, parameters, true);
/*
try {
service = (Service) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelUUID='" + modelUUID + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelUUID=" + modelUUID);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelUUID='" + modelUUID + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUUID=" + modelUUID);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelUUID='" + modelUUID + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUUID=" + modelUUID, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUUID=" + modelUUID);
throw e;
}
*/
if (service == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getServiceByModelUUID", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelUUID", null);
}
return service;
}
/**
* Fetch the Common Service API definition using Http Method + serviceNameVersionId
*/
public Service getService(Map<String, String> map, String httpMethod) {
String serviceNameVersionId = map.get("serviceNameVersionId");
Query query;
String serviceId = "not_set";
String serviceVersion = "not_set";
if(serviceNameVersionId != null && serviceNameVersionId.length() > 0){
LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId);
String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method";
query = getSession().createQuery(hql);
query.setParameter("MODEL_UUID", serviceNameVersionId);
} else {
serviceId = map.get("serviceId");
serviceVersion = map.get("serviceVersion");
LOGGER.debug("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
query = getSession().createQuery(hql);
query.setParameter("service_id", serviceId);
query.setParameter("service_version", serviceVersion);
}
query.setParameter("http_method", httpMethod);
long startTime = System.currentTimeMillis();
Service service = null;
try {
service = (Service) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for service_id=" + serviceId);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for service_id=" + serviceId);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for service_id=" + serviceId);
throw e;
}
if (service == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
}
return service;
}
/**
* Return the newest version of a Service (queried by Name).
*
* @param modelName
* @return Service object or null if none found
*/
public Service getServiceByModelName(String modelName){
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get service with name " + modelName);
String hql = "FROM Service WHERE modelName = :MODEL_NAME";
Query query = getSession().createQuery(hql);
query.setParameter("MODEL_NAME", modelName);
@SuppressWarnings("unchecked")
List <Service> resultList = query.list();
// See if something came back.
if (resultList.isEmpty()) {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
return null;
}
Collections.sort(resultList, new MavenLikeVersioningComparator ());
Collections.reverse(resultList);
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
return resultList.get(0);
}
public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion);
String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR";
Query query = getSession().createQuery(hql);
query.setParameter("MODEL_INVARIANT_UUID", modelInvariantId);
query.setParameter("VERSION_STR", modelVersion);
Service result = null;
try {
result = (Service) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'", nure);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantId=" + modelInvariantId + " and modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId);
throw new Exception("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantId='" + modelInvariantId + "', modelVersion='" + modelVersion + "'");
}
// See if something came back.
if (result==null) {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null);
return null;
}
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null);
return result;
}
/**
* Return a newest version of Service recipe that matches a given SERVICE_ID and ACTION
*
* @param serviceModelUUID
* @param action *
* @return ServiceRecipe object or null if none found
*/
@Deprecated
public ServiceRecipe getServiceRecipe (int serviceModelUUID, String action) {
StringBuilder hql;
if(action == null){
hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
}else {
hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action ");
}
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + Integer.toString(serviceModelUUID)
+ " and action "
+ action
);
Query query = getSession ().createQuery (hql.toString ());
query.setParameter ("serviceModelUUID", serviceModelUUID);
if(action != null){
query.setParameter (ACTION, action);
}
@SuppressWarnings("unchecked")
List <ServiceRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
return resultList.get (0);
}
/**
* Return a newest version of Service recipe that matches a given SERVICE_MODEL_UUID and ACTION
*
* @param serviceModelUuid
* @param action *
* @return ServiceRecipe object or null if none found
*/
public ServiceRecipe getServiceRecipeByServiceModelUuid(String serviceModelUuid, String action) {
StringBuilder hql;
if(action == null){
hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
}else {
hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
}
long startTime = System.currentTimeMillis ();
LOGGER.debug("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
+ " and action "
+ action
);
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelUuid", serviceModelUuid);
if(action != null){
query.setParameter(ACTION, action);
}
@SuppressWarnings("unchecked")
List <ServiceRecipe> resultList = query.list();
if (resultList.isEmpty()) {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
return null;
}
Collections.sort(resultList, new MavenLikeVersioningComparator());
Collections.reverse(resultList);
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
return resultList.get(0);
}
public List<ServiceRecipe> getServiceRecipes(String serviceModelUuid) {
StringBuilder hql;
hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID");
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid);
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelUUID", serviceModelUuid);
@SuppressWarnings("unchecked")
List <ServiceRecipe> resultList = query.list();
if (resultList.isEmpty()) {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null);
return Collections.EMPTY_LIST;
}
Collections.sort(resultList, new MavenLikeVersioningComparator());
Collections.reverse(resultList);
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null);
return resultList;
}
/**
* Return the VNF component data - queried by the VNFs ID and the component type.
*
* @param vnfId
* @param type
* @return VnfComponent object or null if none found
*/
@Deprecated
public VnfComponent getVnfComponent (int vnfId, String type) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get VnfComponent where vnfId="+ vnfId+ " AND componentType="+ type);
String hql = "FROM VnfComponent WHERE vnfId = :vnf_id AND componentType = :type";
Query query = getSession ().createQuery (hql);
query.setParameter ("vnf_id", vnfId);
query.setParameter ("type", type);
VnfComponent result = null;
try {
result = (VnfComponent) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnf_id='" + vnfId + "', componentType='" + type + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnf_id=" + vnfId + " and componentType=" + type, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnf_id=" + vnfId);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnf_id=" + vnfId + " and componentType=" + type, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnf_id=" + vnfId);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: vnf_id='" + vnfId + "', componentType='" + type + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnf_id=" + vnfId + " and componentType=" + type, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnf_id=" + vnfId);
throw e;
}
if (result != null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponent", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No VNFComponent found", "CatalogDB", "getVnfComponent", null);
}
return result;
}
/**
* Return the newest version of a specific VNF resource (queried by Name).
*
* @param vnfType
* @return VnfResource object or null if none found
*/
public VnfResource getVnfResource (String vnfType) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get vnf resource with model_name " + vnfType);
String hql = "FROM VnfResource WHERE modelName = :vnf_name";
Query query = getSession ().createQuery (hql);
query.setParameter ("vnf_name", vnfType);
@SuppressWarnings("unchecked")
List <VnfResource> resultList = query.list ();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
return resultList.get (0);
}
/**
* Return the newest version of a specific VNF resource (queried by Name).
*
* @param vnfType
* @param version
* @return VnfResource object or null if none found
*/
public VnfResource getVnfResource (String vnfType, String serviceVersion) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion";
Query query = getSession ().createQuery (hql);
query.setParameter ("vnfName", vnfType);
query.setParameter ("serviceVersion", serviceVersion);
VnfResource resource = null;
try {
resource = (VnfResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: vnfType='" + vnfType + "', asdc_service_model_version='" + serviceVersion + "' " + he.getMessage());
LOGGER.debug(Arrays.toString(he.getStackTrace()));
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfType=" + vnfType);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "' " + e.getMessage());
LOGGER.debug(Arrays.toString(e.getStackTrace()));
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfType=" + vnfType);
throw e;
}
if (resource == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
}
return resource;
}
/**
* Return VnfResource (queried by modelCustomizationId).
*
* @param modelCustomizationId
* @return VnfResource object or null if none found
*/
public VnfResource getVnfResourceByModelCustomizationId (String modelCustomizationId) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
String hql = "SELECT vr "
+ "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc "
+ "WHERE vrc.modelCustomizationUuid = :modelCustomizationId";
Query query = getSession ().createQuery (hql);
query.setParameter ("modelCustomizationId", modelCustomizationId);
VnfResource resource = null;
try {
resource = (VnfResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationId=" + modelCustomizationId);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationId=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationId=" + modelCustomizationId);
throw e;
}
if (resource == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
}
return resource;
}
/**
* Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
*
* @return {@link VnfResourceCustomization} object or null if none found
*/
public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN "
+ "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src "
+ "WHERE src.serviceModelUUID = :modelVersionId)"
+ "AND vrc.modelInstanceName = :modelCustomizationName";
Query query = getSession ().createQuery (hql);
query.setParameter ("modelCustomizationName", modelCustomizationName);
query.setParameter ("modelVersionId", modelVersionId);
@SuppressWarnings("unchecked")
List <VnfResourceCustomization> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
return resultList.get (0);
}
/**
* Return the newest version of a specific VNF resource (queried by modelInvariantId).
*
* @param version
* @return VnfResource object or null if none found
*/
public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
Query query = getSession ().createQuery (hql);
query.setParameter ("modelInvariantUuid", modelInvariantUuid);
query.setParameter ("serviceVersion", modelVersion);
VnfResource resource = null;
try {
resource = (VnfResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', asdc_service_model_version='" + modelVersion + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid);
throw e;
}
if (resource == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResource", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null);
}
return resource;
}
/**
* Return the newest version of a specific VNF resource (queried by ID).
*
* @param id The vnf id
* @return VnfResource object or null if none found
*/
@Deprecated
public VnfResource getVnfResourceById (int id) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF resource with id " + id);
String hql = "FROM VnfResource WHERE id = :id";
Query query = getSession ().createQuery (hql);
query.setParameter ("id", id);
@SuppressWarnings("unchecked")
List <VnfResource> resultList = query.list ();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResource not found", "CatalogDB", "getVnfResourceById", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceById", null);
return resultList.get (0);
}
/**
* Return the newest version of a vfModule - 1607
*
*/
public VfModule getVfModuleModelName (String modelName) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
String hql = "FROM VfModule WHERE modelName = :model_name";
Query query = getSession ().createQuery (hql);
query.setParameter ("model_name", modelName);
@SuppressWarnings("unchecked")
List <VfModule> resultList = query.list ();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
return resultList.get (0);
}
public VfModule getVfModuleModelName (String modelName, String model_version) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
Query query = getSession ().createQuery (hql);
query.setParameter ("modelName", modelName);
query.setParameter ("model_version", model_version);
VfModule module = null;
try {
module = (VfModule) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + modelName);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: type='" + modelName + "', asdc_service_model_version='" + model_version + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + modelName);
throw e;
}
if (module == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
}
return module;
}
/**
* Need this for 1707 DHV. This may be a temporary solution. May
* change it to get resources using service's model name.
*
*@author cb645j
*
*/
public VfModuleCustomization getVfModuleCustomizationByModelName (String modelName) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name";
Query query = getSession ().createQuery (hql);
query.setParameter ("model_name", modelName);
@SuppressWarnings("unchecked")
List<VfModuleCustomization> resultList = query.list();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query ", "CatalogDB", "getVfModuleCustomizationByModelName", null);
return resultList.get(0);
}
/**
* Return the newest version of a specific Network resource (queried by Type).
*
* @param networkType
* @return NetworkResource object or null if none found
*/
public NetworkResource getNetworkResource (String networkType) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get network resource with type " + networkType);
String hql = "FROM NetworkResource WHERE model_name = :network_type";
Query query = getSession ().createQuery (hql);
query.setParameter ("network_type", networkType);
@SuppressWarnings("unchecked")
List <NetworkResource> resultList = query.list ();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
return resultList.get (0);
}
/**
* Return a VNF recipe that matches a given VNF_TYPE, ACTION, and, if specified, SERVICE_TYPE
*
* @param vnfType
* @param action
* @param serviceType The service Name, if null or empty is provided, it won't be taken into account
* @return VnfRecipe object or null if none found
*/
public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
boolean withServiceType = false;
StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
// If query c
if (serviceType == null || serviceType.isEmpty ()) {
hql.append ("AND serviceType is NULL ");
} else {
hql.append ("AND serviceType = :serviceType ");
withServiceType = true;
}
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
+ " and action "
+ action
+ " and service type "
+ serviceType);
Query query = getSession ().createQuery (hql.toString ());
query.setParameter (VNF_TYPE, vnfType);
query.setParameter (ACTION, action);
if (withServiceType) {
query.setParameter (SERVICE_TYPE, serviceType);
}
@SuppressWarnings("unchecked")
List <VnfRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
return resultList.get (0);
}
/**
* Return a VNF recipe that matches a given VNF_TYPE and ACTION
*
* @param vnfType
* @param action
* @return VnfRecipe object or null if none found
*/
public VnfRecipe getVnfRecipe (String vnfType, String action) {
StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
+ " and action "
+ action);
Query query = getSession ().createQuery (hql.toString ());
query.setParameter (VNF_TYPE, vnfType);
query.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <VnfRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
return resultList.get (0);
}
/**
* Return a VNF recipe that matches a given VF_MODULE_ID and ACTION
*
* @param vfModuleId
* @param action
* @return VnfRecipe object or null if none found
*/
public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
Query query = getSession ().createQuery (hql.toString ());
query.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
query.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <VnfRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
return resultList.get (0);
}
public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get vfModuleTypeByUuid with uuid=" + modelCustomizationUuid);
String hql = "FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid";
Query query = getSession().createQuery(hql);
query.setParameter("modelCustomizationUuid", modelCustomizationUuid);
VfModule module = null;
try {
module = (VfModule) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw e;
}
if (module == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleTypeByUuid", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleTypeByUuid", null);
}
return module;
}
@Deprecated
public VfModule getVfModuleType(String type) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get vfModuleType with type " + type);
String hql = "FROM VfModule WHERE type = :type";
Query query = getSession().createQuery(hql);
query.setParameter("type", type);
@SuppressWarnings("unchecked")
List<VfModule> resultList = query.list();
if (resultList.isEmpty()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleType", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
return resultList.get (0);
}
@Deprecated
public VfModule getVfModuleType(String type, String version) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get vfModuleType with type " + type + " and model_version " + version);
String hql = "FROM VfModule WHERE type = :type and version = :version";
Query query = getSession().createQuery(hql);
query.setParameter ("type", type);
query.setParameter ("version", version);
VfModule module = null;
try {
module = (VfModule) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: type='" + type + "', asdc_service_model_version='" + version + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type==" + type);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for type=" + type);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: type='" + type + "', asdc_service_model_version='" + version + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for type=" + type + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for type=" + type);
throw e;
}
if (module == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
}
return module;
}
public VnfResource getVnfResourceByServiceUuid(String serviceModelInvariantUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get vfModuleType with serviceModelInvariantUuid " + serviceModelInvariantUuid);
String hql = "FROM VnfResource WHERE serviceModelInvariantUuid = :serviceModelInvariantUuid";
Query query = getSession().createQuery(hql);
query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
VnfResource vnfResource = null;
try {
vnfResource = (VnfResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
throw e;
}
if (vnfResource == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
}
return vnfResource;
}
public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
Query query = getSession().createQuery(hql);
query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
VnfResource vnfResource = null;
try {
vnfResource = (VnfResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid);
throw e;
}
if (vnfResource == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
}
return vnfResource;
}
public VnfResource getVnfResourceByType(String vnfType) {
return this.getVnfResource(vnfType);
}
public VfModule getVfModuleByModelInvariantUuid(String modelInvariantUUID) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get vfModuleTypeByModelInvariantUuid with uuid " + modelInvariantUUID);
String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUUID ";
HashMap<String, String> parameters = new HashMap<>();
parameters.put("modelInvariantUUID", modelInvariantUUID);
List<VfModule> modules = this.executeQueryMultipleRows(hql, parameters, true);
VfModule module = null;
if (modules != null && ! modules.isEmpty()) {
Collections.sort (modules, new MavenLikeVersioningComparator ());
Collections.reverse (modules);
module = modules.get(0);
}
if (module == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuid", null);
}
return module;
}
public VfModuleCustomization getVfModuleByModelCustomizationUuid(String modelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get vfModuleTypeByModelCustomizationUuid with uuid " + modelCustomizationUuid);
String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid ";
Query query = getSession().createQuery(hql);
query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
VfModuleCustomization module = null;
try {
module = (VfModuleCustomization) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleModelInvariantUuid=" + modelCustomizationUuid , "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw e;
}
if (module == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationUuid", null);
}
return module;
}
public VfModule getVfModuleByModelInvariantUuidAndModelVersion(String modelInvariantUuid, String modelVersion) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVfModuleByModelInvariantUuidAndModelVersion with modelInvariantUuid: " + modelInvariantUuid + ", modelVersion: " + modelVersion);
String hql = "FROM VfModule WHERE modelInvariantUUID = :modelInvariantUuid and version = :modelVersion";
Query query = getSession().createQuery(hql);
query.setParameter ("modelInvariantUuid", modelInvariantUuid);
query.setParameter("modelVersion", modelVersion);
VfModule module = null;
try {
module = (VfModule) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModule ModelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for ModelInvariantUuid==" + modelInvariantUuid + " modelVersion==" + modelVersion);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelInvariantUuid='" + modelInvariantUuid + "', modelVersion='" +modelVersion + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantUuid=" + modelInvariantUuid + " modelVersion=" + modelVersion);
throw e;
}
if (module == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelInvariantUuidAndModelVersion", null);
}
return module;
}
/**
* Return the VfModuleCustomization object identified by the given modelCustomizationUuid 1707
*
* @param modelCustomizationUuid
* @return VfModuleCustomization or null if not found
*/
public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVfModuleCustomizationByModelCustomizationId with modelCustomizationUuid: " + modelCustomizationUuid);
String hql = "FROM VfModuleCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
Query query = getSession().createQuery(hql);
query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
VfModuleCustomization VfModuleCustomization = null;
try {
VfModuleCustomization = (VfModuleCustomization) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vfModuleCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw e;
}
if (VfModuleCustomization != null) {
LOGGER.debug("Found VMC of " + VfModuleCustomization.getModelCustomizationUuid() + ", now looking for vfModule=" + VfModuleCustomization.getVfModuleModelUuid());
VfModuleCustomization.setVfModule(this.getVfModuleByModelUuid(VfModuleCustomization.getVfModuleModelUuid()));
}
if (VfModuleCustomization == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByModelCustomizationId", null);
}
return VfModuleCustomization;
}
/**
* Return the VfModule object identified by the given modelUuid 1707
* per Mike Z. - this may return more than one row - and even if it does,
* the heat template will be the same - so just return any of the rows.
*
* @param modelUuid
* @return VfModule or null if not found
*/
public VfModule getVfModuleByModelUuid(String modelUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVfModuleByModelUuid with modelUuid: " + modelUuid);
String hql = "FROM VfModule WHERE modelUUID = :modelUuidValue";
Query query = getSession().createQuery(hql);
query.setParameter ("modelUuidValue", modelUuid);
List<VfModule> vfModules = null;
try {
vfModules = query.list ();
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VfModule for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelUuid=" + modelUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching VfModule for: modelUuid='" + modelUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelUuid=" + modelUuid);
throw e;
}
if (vfModules == null || vfModules.isEmpty()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelUuid", null);
return null;
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUuid", null);
}
return vfModules.get(0);
}
/**
* Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
* Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
*
* @param modelCustomizationUuid
* @return VnfResourceCustomization or null if not found
*/
public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUuid(String modelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVnfResourceByModelCustomizatonUuid with modelCustomizationUuid: " + modelCustomizationUuid);
String hql = "FROM VnfResourceCustomization WHERE modelCustomizationUuid = :modelCustomizationUuid";
Query query = getSession().createQuery(hql);
query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
VnfResourceCustomization vnfResourceCustomization = null;
try {
vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelCustomizationUuid='" + modelCustomizationUuid +"'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationUuid==" + modelCustomizationUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching VRC for: modelCustomizationUuid='" + modelCustomizationUuid + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw e;
}
if (vnfResourceCustomization != null) {
LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
}
if (vnfResourceCustomization == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationUuid", null);
}
return vnfResourceCustomization;
}
/**
* Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
* Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
*
* @param getVnfResourceCustomizationByModelVersionId
* @return VnfResourceCustomization or null if not found
*/
public VnfResourceCustomization getVnfResourceCustomizationByModelVersionId(String modelVersionId) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelVersionId with modelVersionId: " + modelVersionId);
String hql = "FROM VnfResourceCustomization WHERE vnfResourceModelUuid = :modelVersionId";
Query query = getSession().createQuery(hql);
query.setParameter ("modelVersionId", modelVersionId);
VnfResourceCustomization vnfResourceCustomization = null;
try {
vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId==" + modelVersionId);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId);
throw e;
}
if (vnfResourceCustomization != null) {
LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUuid()));
LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
}
if (vnfResourceCustomization == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelVersionId", null);
}
return vnfResourceCustomization;
}
/**
* Return the VfModule object identified by the given modelCustomizationId, modelVersionId 1707
*
* @param modelVersionId, modelCustomizationId
* @return VfModule or null if not found
*/
public VfModule getVfModuleByModelCustomizationIdAndVersion(String modelCustomizationId, String modelVersionId) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdAndVersion with modelVersionId: " + modelVersionId + " modelCustomizationId: " + modelCustomizationId);
// select * from vf_module vfm where vfm.MODEL_UUID IN (
// select vfmc.VF_MODULE_MODEL_UUID from vf_module_customization vfmc where vfmc.MODEL_CUSTOMIZATION_UUID='222bd8f2-341d-4419-aa0e-98398fa34050')
// and vfm.MODEL_UUID = 'fa1c8558-006c-4fb6-82f2-4fc0646d6b06';
String hql = "Select vfm FROM VfModule as vfm WHERE vfm.modelUUID IN ("
+ "SELECT vfmc.vfModuleModelUuid FROM VfModuleCustomization as vfmc "
+ "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId) "
+ "AND vfm.modelUUID = :modelVersionId";
Query query = getSession().createQuery(hql);
query.setParameter ("modelVersionId", modelVersionId);
query.setParameter ("modelCustomizationId", modelCustomizationId);
VfModule vfModule = null;
try {
vfModule = (VfModule) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelVersionId='" + modelVersionId +"' modelCustomizationId='" + modelCustomizationId + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching VRC for: modelVersionId='" + modelVersionId + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelVersionId=" + modelVersionId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelVersionId=" + modelVersionId + " modelCustomizationId=" + modelCustomizationId);
throw e;
}
if (vfModule == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdAndVersion", null);
}
return vfModule;
}
/**
* Return the VfModule object identified by the given modelCustomizationId, modelVersion, modelInvariantId 1707
*
* @param modelCustomizationId, modelVersion, modelInvariantId
* @return VfModule or null if not found
*/
public VfModule getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(String modelCustomizationId, String modelVersion, String modelInvariantId) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId with modelVersionId: " + modelVersion);
//select * from vf_module vfm left outer join vf_module_customization vfmc on vfmc.VF_MODULE_MODEL_UUID = vfm.MODEL_UUID
// where vfmc.MODEL_CUSTOMIZATION_UUID='52643a8e-7953-4e48-8eab-97165b2b3a4b' and vfm.MODEL_UUID = ''
String hql = "Select vfm FROM VfModule as vfm LEFT OUTER JOIN VfModuleCustomization as vfmc on vfmc.vfModuleModelUuid = vfm.modelUUID"
+ "WHERE vfmc.modelCustomizationUuid = :modelCustomizationId AND vfm.modelInvariantUUID = :modelInvariantId AND vfm.modelVersion = :modelVersion";
Query query = getSession().createQuery(hql);
query.setParameter ("modelInvariantId", modelInvariantId);
query.setParameter ("modelCustomizationId", modelCustomizationId);
query.setParameter ("modelVersion", modelVersion);
VfModule vfModule = null;
try {
vfModule = (VfModule) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelInvariantId='" + modelInvariantId +"' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId +"'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId=" + modelInvariantId + " modelVersion=" + modelVersion + " modelCustomizationId=" + modelCustomizationId);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantId=" + modelInvariantId + " modelVersion=" + modelVersion + " modelCustomizationId=" + modelCustomizationId);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId + "' modelVersion='" + modelVersion + "' modelCustomizationId='" + modelCustomizationId + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantId=" + modelInvariantId + " modelVersion=" + modelVersion + " modelCustomizationId=" + modelCustomizationId);
throw e;
}
if (vfModule == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId", null);
}
return vfModule;
}
/**
* Return the VnfResourceCustomization object identified by the given modelCustomizationName, modelInvariantId and modelVersion 1707
*
* @param modelInvariantId, modelVersion, modelCustomizationName
* @return VnfResourceCustomization or null if not found
*/
public VnfResourceCustomization getVnfResourceCustomizationByModelInvariantId(String modelInvariantId, String modelVersion, String modelCustomizationName) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVnfResourceCustomizationByModelInvariantId with modelInvariantId: " + modelInvariantId + ", modelVersion: "
+ modelVersion + ", modelCustomizationName: " + modelCustomizationName);
String hql = "SELECT VnfResourceCustomization FROM VnfResourceCustomization as vrc "
+ "LEFT OUTER JOIN VnfResource as vr "
+ "on vr.modelUuid =vrc.vnfResourceModelUuid "
+ "WHERE vr.modelInvariantUuid = :modelInvariantId AND vr.modelVersion = :modelVersion AND vrc.modelInstanceName = :modelCustomizationName";
Query query = getSession().createQuery(hql);
query.setParameter ("modelInvariantId", modelInvariantId);
query.setParameter("modelVersion", modelVersion);
query.setParameter("modelCustomizationName", modelCustomizationName);
VnfResourceCustomization vnfResourceCustomization = null;
try {
vnfResourceCustomization = (VnfResourceCustomization) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row in VRC - data integrity error: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' modelCustomizationName='" + modelCustomizationName + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceCustomization modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantId==" + modelInvariantId+"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "'");
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelInvariantId=" + modelInvariantId+"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "'");
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching VRC for: modelInvariantId='" + modelInvariantId +"' and modelVersion='" + modelVersion + "' " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching VRC for modelInvariantId=" + modelInvariantId, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for modelInvariantId=" + modelInvariantId+"' and modelVersion='" + modelVersion + "'modelCustomizationName='" + modelCustomizationName + "'");
throw e;
}
if (vnfResourceCustomization != null) {
LOGGER.debug("Found VRC of " + vnfResourceCustomization.getModelCustomizationUuid() + ", now looking for vnfResource=" + vnfResourceCustomization.getVnfResourceModelUuid() );
vnfResourceCustomization.setVnfResource(this.getVnfResourceByModelUuid(vnfResourceCustomization.getVnfResourceModelUUID()));
LOGGER.debug("Now looking for vfModules for " + vnfResourceCustomization.getModelCustomizationUuid());
vnfResourceCustomization.setVfModuleCustomizations(this.getAllVfModuleCustomizations(vnfResourceCustomization.getModelCustomizationUuid()));
}
if (vnfResourceCustomization == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelInvariantId", null);
}
return vnfResourceCustomization;
}
/**
* Return list of VnfResourceCustomization objects identified by the given modelCustomizationUuid 1707
*
* @param modelCustomizationUuid
* @return List<VfModuleCustomization> or null if not found
*/
public List<VfModuleCustomization> getVfModuleCustomizationByVnfModuleCustomizationUuid(String modelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get getVfModuleCustomizationByVnfModuleCustomizationUuid with modelCustomizationUuid: " + modelCustomizationUuid);
// select * from vf_module_customization as vfmc where vfmc.MODEL_CUSTOMIZATION_UUID IN(
// select vrcmc.VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID from vnf_res_custom_to_vf_module_custom as vrcmc
// where vrcmc.VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = 'd279139c-4b85-48ff-8ac4-9b83a6fc6da7')
String hql = "SELECT vfmc FROM VfModuleCustomization as vfmc where vfmc.modelCustomizationUuid "
+ "IN(select vrcmc.vfModuleCustModelCustomizationUuid from VnfResCustomToVfModuleCustom as vrcmc "
+ "WHERE vrcmc.vnfResourceCustModelCustomizationUuid = :modelCustomizationUuid)";
Query query = getSession().createQuery(hql);
query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
List<VfModuleCustomization> resultList = null;
try {
resultList = query.list();
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - while searching for: modelCustomizationUuid='" + modelCustomizationUuid + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModuleCustomizationByVnfModuleCustomizationUuid - searching for modelCustomizationUuid=" + modelCustomizationUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for modelCustomizationUuid=" + modelCustomizationUuid);
throw e;
}
if (resultList == null) {
resultList = new ArrayList<>();
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleCustomizationByVnfModuleCustomizationUuid", null);
return resultList;
}
/**
* Return the newest version of a specific VNF resource Customization (queried by modelCustomizationName and modelVersionId).
*
* @return {@link VnfResourceCustomization} object or null if none found
*/
public VnfResourceCustomization getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId (String modelCustomizationName, String modelVersionId) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " modelUUID " + modelVersionId);
String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.vnfResourceModelUuid IN "
+ "(SELECT vr.modelUuid FROM VnfResource vr "
+ "WHERE vr.modelUuid = :modelVersionId)"
+ "AND vrc.modelInstanceName = :modelCustomizationName";
Query query = getSession ().createQuery (hql);
query.setParameter ("modelCustomizationName", modelCustomizationName);
query.setParameter ("modelVersionId", modelVersionId);
@SuppressWarnings("unchecked")
List <VnfResourceCustomization> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId", null);
return resultList.get (0);
}
public ArrayList<VfModuleCustomization> getAllVfModuleCustomizations(String vnfResourceCustomizationMCU) {
LOGGER.debug ("Catalog database - getAllVfModuleCustomizations with vnfResourceCustomizationMCU " + vnfResourceCustomizationMCU);
List<VnfResCustomToVfModuleCustom> matches = this.getVRCtoVFMC(vnfResourceCustomizationMCU, null);
if (matches == null || matches.isEmpty()) {
LOGGER.debug("Found no vf modules for " + vnfResourceCustomizationMCU);
return new ArrayList<>();
}
ArrayList<VfModuleCustomization> list = new ArrayList<>();
for (VnfResCustomToVfModuleCustom v : matches) {
String m = v.getVfModuleCustModelCustomizationUuid();
LOGGER.debug("VfModule to match: " + m);
VfModuleCustomization c = this.getVfModuleCustomizationByModelCustomizationId(m);
if (c != null) {
list.add(c);
} else {
LOGGER.debug("**UNABLE to find vfModule " + m);
}
}
return list;
}
/**
* Return the VnfResourceCustomization object identified by the given modelCustomizationUuid 1707
* Note that the corresponding VnfResource Object will be put in the VnfResourceCustomization bean
*
* @param modelCustomizationUuid
* @return VnfResourceCustomization or null if not found
*/
public VnfResource getVnfResourceByModelUuid(String modelUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug ("Catalog database - get VnfResource with modelUuid " + modelUuid);
String hql = "FROM VnfResource WHERE modelUuid = :modelUuid";
Query query = getSession().createQuery(hql);
query.setParameter ("modelUuid", modelUuid);
VnfResource vnfResource = null;
try {
vnfResource = (VnfResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique Vnf_Resource row - data integrity error: modelUuid='" + modelUuid);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for Vnf Resource modelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResource modelUuid==" + modelUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: VnfResource modelUuid='" + modelUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResource modelUuid=" + modelUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: vnfResource ModelUuid='" + modelUuid + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for vnfResource ModelUuid=" + modelUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for vnfResource modelUuid=" + modelUuid);
throw e;
}
if (vnfResource == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelUuid", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelUuid", null);
}
return vnfResource;
}
public VnfResCustomToVfModuleCustom getVnfResCustomToVfModule(String vnfId, String vfId) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - getVnfResCustomToVfModule - vnfResourceCustModelCustUuid: " + vnfId + ", vfModuleCustModelCustomUuid=" + vfId);
StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom where vnfResourceCustModelCustomizationUuid = :vnfIdValue and vfModuleCustModelCustomizationUuid = :vfIdValue");
HashMap<String, String> parameters = new HashMap<>();
parameters.put("vnfIdValue", vnfId);
parameters.put("vfIdValue", vfId);
VnfResCustomToVfModuleCustom vrctvmc = this.executeQuerySingleRow(hql.toString(), parameters, true);
if (vrctvmc == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResCustomToVfModule", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResCustomToVfModule", null);
}
return vrctvmc;
}
public List<VfModule> getVfModulesForVnfResource(VnfResource vnfResource) {
if (vnfResource == null)
return Collections.EMPTY_LIST;
String vnfResourceModelUuid = vnfResource.getModelUuid();
LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResource: " + vnfResource.toString());
return this.getVfModulesForVnfResource(vnfResourceModelUuid);
}
public List<VfModule> getVfModulesForVnfResource(String vnfResourceModelUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - getVfModulesForVnfResource - vnfResourceModelUuid: " + vnfResourceModelUuid);
StringBuilder hql = new StringBuilder("FROM VfModule where vnfResourceModelUUId = :vnfResourceModelUUId");
Query query = getSession().createQuery(hql.toString());
query.setParameter("vnfResourceModelUUId", vnfResourceModelUuid);
List<VfModule> resultList = null;
try {
resultList = query.list();
if (resultList != null)
LOGGER.debug("\tQuery found " + resultList.size() + " records.");
else
LOGGER.debug("\tQuery found no records.");
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Exception - getVfModulesForVnfResource - while searching for: vnfResourceModelUUId='" + vnfResourceModelUuid + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception - getVfModulesForVnfResource - searching for vnfResourceModelUUId=" + vnfResourceModelUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for vnfResourceModelUUId=" + vnfResourceModelUuid);
throw e;
}
if (resultList == null) {
resultList = new ArrayList<>();
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModulesForVnfResource", null);
return resultList;
}
public Service getServiceByUuid (String serviceModelInvariantUuid) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get service with ModelInvariantUuid " + serviceModelInvariantUuid);
String hql = "FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid";
Query query = getSession ().createQuery (hql);
query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
Service service = null;
try {
service = (Service) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: serviceName='" + serviceModelInvariantUuid + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: serviceModelInvariantUuid='" + serviceModelInvariantUuid + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for serviceModelInvariantUuid=" + serviceModelInvariantUuid);
throw e;
}
if (service == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getService", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getService", null);
}
return service;
}
public NetworkResource getNetworkResourceById(Integer id) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getNetworkResource with id " + id);
String hql = "FROM NetworkResource WHERE id = :id";
Query query = getSession ().createQuery (hql);
query.setParameter ("id", id);
NetworkResource networkResource = null;
try {
networkResource = (NetworkResource) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: NETWORK_RESOURCE.id='" + id + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for NETWORK_RESOURCE.id=" + id);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.id=" + id);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.id=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.id=" + id);
throw e;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
return networkResource;
}
public NetworkResource getNetworkResourceById(String id) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getNetworkResource with model_uuid " + id);
String hql = "FROM NetworkResource WHERE modelUUID = :model_uuid";
Query query = getSession ().createQuery (hql);
query.setParameter ("model_uuid", id);
List<NetworkResource> networkResources = null;
try {
networkResources = query.list ();
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: NETWORK_RESOURCE.id='" + id + "' " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for NETWORK_RESOURCE.model_uuid=" + id, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for NETWORK_RESOURCE.model_uuid=" + id);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: NETWORK_RESOURCE.id='" + id + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for NETWORK_RESOURCE.model_uuid=" + id, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for NETWORK_RESOURCE.model_uuid=" + id);
throw e;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceById", null);
if (networkResources == null || networkResources.isEmpty())
return null;
else
return networkResources.get(0);
}
// 1707 API Spec
public static boolean isEmptyOrNull(String str) {
if (str == null)
return true;
if ("null".equals(str))
return true;
if ("".equals(str))
return true;
return false;
}
public List<ServiceToResourceCustomization> getSTR(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
LOGGER.debug("Catalog database: getSTR - smu=" + serviceModelUuid + ", rmcu=" + resourceModelCustomizationUuid + ", modelType = " + modelType);
if (isEmptyOrNull(serviceModelUuid) && isEmptyOrNull(resourceModelCustomizationUuid) && isEmptyOrNull(modelType))
return null;
StringBuilder hql = new StringBuilder("FROM ServiceToResourceCustomization WHERE ");
boolean first = true;
if (serviceModelUuid != null && !serviceModelUuid.equals("")) {
hql.append("serviceModelUUID = :smu");
first = false;
}
if (resourceModelCustomizationUuid != null && !resourceModelCustomizationUuid.equals("")) {
if (!first) {
hql.append(" AND ");
}
hql.append("resourceModelCustomizationUUID = :rmcu");
first = false;
}
if (modelType != null && !modelType.equals("")) {
if (!first) {
hql.append(" AND ");
first = false;
}
hql.append("modelType = :modelType");
first = false;
}
Query query = getSession().createQuery(hql.toString());
if (hql.toString().contains(":smu"))
query.setParameter("smu", serviceModelUuid);
if (hql.toString().contains(":rmcu"))
query.setParameter("rmcu", resourceModelCustomizationUuid);
if (hql.toString().contains(":modelType"))
query.setParameter("modelType", modelType);
LOGGER.debug("query - " + hql.toString());
@SuppressWarnings("unchecked")
List<ServiceToResourceCustomization> resultList = query.list();
if (resultList == null || resultList.isEmpty()) {
LOGGER.debug("Found no matches to the query - " + hql.toString());
return new ArrayList<>();
}
return resultList;
}
public List<VnfResCustomToVfModuleCustom> getVRCtoVFMC (String vrc_mcu, String vfmc_mcu) {
LOGGER.debug("Catalog database: getVRCtoVFMC - vrc_mcu=" + vrc_mcu + ", vfmc_mcu=" + vfmc_mcu);
if (isEmptyOrNull(vrc_mcu) && isEmptyOrNull(vfmc_mcu))
return null;
StringBuilder hql = new StringBuilder("FROM VnfResCustomToVfModuleCustom WHERE ");
boolean first = true;
if (vrc_mcu != null && !vrc_mcu.equals("")) {
hql.append("vnfResourceCustModelCustomizationUuid = :vrc_mcu");
first = false;
}
if (vfmc_mcu != null && !vfmc_mcu.equals("")) {
if (!first) {
hql.append(" AND ");
}
hql.append("vfModuleCustModelCustomizationUuid = :vfmc_mcu");
first = false;
}
Query query = getSession().createQuery(hql.toString());
if (hql.toString().contains(":vrc_mcu"))
query.setParameter("vrc_mcu", vrc_mcu);
if (hql.toString().contains(":vfmc_mcu"))
query.setParameter("vfmc_mcu", vfmc_mcu);
@SuppressWarnings("unchecked")
List<VnfResCustomToVfModuleCustom> resultList = query.list();
if (resultList == null || resultList.isEmpty()) {
LOGGER.debug("Found no matches to the query - " + hql.toString());
return new ArrayList<>();
}
return resultList;
}
@SuppressWarnings("unchecked")
public List <TempNetworkHeatTemplateLookup> getTempNetworkHeatTemplateLookup (String networkResourceModelName) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - GetTempNetworkHeatTemplateLookup for Network Name " + networkResourceModelName);
String hql = "FROM TempNetworkHeatTemplateLookup where networkResourceModelName = :networkResourceModelName";
Query query = getSession ().createQuery (hql);
query.setParameter ("networkResourceModelName", networkResourceModelName);
List <TempNetworkHeatTemplateLookup> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getTempNetworkHeatTemplateLookup", null);
return result;
}
// 1702 API Spec - Query for all networks in a Service:
public List<NetworkResourceCustomization> getAllNetworksByServiceModelUuid(String serviceModelUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getServiceNetworksByServiceModelUuid - " + serviceModelUuid);
List<ServiceToResourceCustomization> strMappings = this.getSTR(serviceModelUuid, null, "network");
if (strMappings == null || strMappings.isEmpty()) {
LOGGER.debug("Found NO matches for NRC with ServiceModelUuid=" + serviceModelUuid);
return new ArrayList<>();
}
LOGGER.debug("Found " + strMappings.size() + " entries in ServiceToResourceCustomizations.network with smu=" + serviceModelUuid);
ArrayList<NetworkResourceCustomization> masterList = new ArrayList<>();
for (ServiceToResourceCustomization stn : strMappings) {
String networkModelCustomizationUuid = stn.getResourceModelCustomizationUUID();
LOGGER.debug("Now searching for NetworkResourceCustomization for " + networkModelCustomizationUuid);
List<NetworkResourceCustomization> resultSet = this.getAllNetworksByNetworkModelCustomizationUuid(networkModelCustomizationUuid);
for (NetworkResourceCustomization nrc : resultSet) {
masterList.add(nrc);
}
}
LOGGER.debug("Returning " + masterList.size() + " NRC records");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByServiceModelUuid", null);
return masterList;
}
public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
return new ArrayList<>();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
String serviceNameVersionId = service.getModelUUID();
LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceNameVersionId);
// Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
}
public List<NetworkResourceCustomization> getAllNetworksByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
LOGGER.debug("Catalog database: getServiceNetworksByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
query.setParameter("serviceModelVersion", serviceModelVersion);
//TODO
//can fix this later - no time - could do a unique query here - but this should work
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
return new ArrayList<>();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
String serviceNameVersionId = service.getModelUUID();
// Service.serviceNameVersionId == ServiceToNetworks.serviceModelUuid
return this.getAllNetworksByServiceModelUuid(serviceNameVersionId);
}
public List<NetworkResourceCustomization> getAllNetworksByNetworkModelCustomizationUuid(String networkModelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllNetworksByNetworkModelCustomizationUuid - " + networkModelCustomizationUuid);
StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE modelCustomizationUuid = :networkModelCustomizationUuid");
//Query query = getSession().createQuery(hql.toString());
//query.setParameter("networkModelCustomizationUuid", networkModelCustomizationUuid);
//LOGGER.debug("QUERY: " + hql.toString() + ", networkModelCustomizationUuid=" + networkModelCustomizationUuid);
//@SuppressWarnings("unchecked")
//List<NetworkResourceCustomization> resultList = query.list();
HashMap<String, String> params = new HashMap<>();
params.put("networkModelCustomizationUuid", networkModelCustomizationUuid);
List<NetworkResourceCustomization> resultList = this.executeQueryMultipleRows(hql.toString(), params, true);
if (resultList.isEmpty()) {
LOGGER.debug("Unable to find an NMC with nmcu=" + networkModelCustomizationUuid);
return new ArrayList<>();
}
for (NetworkResourceCustomization nrc : resultList) {
nrc.setNetworkResource(this.getNetworkResourceById(nrc.getNetworkResourceModelUuid()));
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkModelCustomizationUuid", null);
return resultList;
}
public List<NetworkResourceCustomization> getAllNetworksByNetworkType(String networkType) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getServiceNetworksByNetworkType - " + networkType);
NetworkResource nr = this.getNetworkResource(networkType);
if (nr == null) {
return new ArrayList<>();
}
String networkResourceId = nr.getModelUUID();
LOGGER.debug("Now searching for NRC's with networkResourceId = " + networkResourceId);
StringBuilder hql = new StringBuilder("FROM NetworkResourceCustomization WHERE networkResourceModelUuid = :networkResourceId");
Query query = getSession().createQuery(hql.toString());
query.setParameter("networkResourceId", networkResourceId);
@SuppressWarnings("unchecked")
List<NetworkResourceCustomization> resultList = query.list();
if (resultList != null && ! resultList.isEmpty()) {
LOGGER.debug("Found " + resultList.size() + " results");
for (NetworkResourceCustomization nrc : resultList) {
nrc.setNetworkType(networkType);
nrc.setNetworkResource(nr);
}
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworksByNetworkType", null);
return resultList;
}
public ArrayList<VfModuleCustomization> getAllVfmcForVrc(VnfResourceCustomization vrc) {
LOGGER.debug("Catalog database: getAllVfmcForVrc - " + vrc.getModelCustomizationUuid());
List<VnfResCustomToVfModuleCustom> vfmcs = this.getVRCtoVFMC(vrc.getModelCustomizationUuid(), null);
if (vfmcs == null || vfmcs.isEmpty()) {
return new ArrayList<>();
}
ArrayList<VfModuleCustomization> vfModuleCusts = new ArrayList<>();
for (VnfResCustomToVfModuleCustom vfmc : vfmcs) {
VfModuleCustomization vfmcust = this.getVfModuleCustomizationByModelCustomizationId(vfmc.getVfModuleCustModelCustomizationUuid());
if (vfmcust != null) {
vfModuleCusts.add(vfmcust);
}
}
return vfModuleCusts;
}
//1702 API Spec cont'd - Query for all VnfResources in a Service:
//1707 modified for db refactoring
public List<VnfResourceCustomization> getAllVnfsByServiceModelUuid(String serviceModelUuid) {
LOGGER.debug("Catalog database: getAllVnfsByServiceModelUuid - " + serviceModelUuid);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelUuid", serviceModelUuid);
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("Unable to find a service with modelUuid=" + serviceModelUuid);
return new ArrayList<>();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
// Step 2 - Now query to get the related VnfResourceCustomizations
List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "vnf");
if (strcs.isEmpty()) {
LOGGER.debug("Unable to find any related vnfs to a service with modelUuid=" + serviceModelUuid);
return new ArrayList<>();
}
ArrayList<VnfResourceCustomization> allVrcs = new ArrayList<>();
for (ServiceToResourceCustomization strc : strcs) {
LOGGER.debug("Try to find VRC for mcu=" + strc.getResourceModelCustomizationUUID());
VnfResourceCustomization vrc = this.getVnfResourceCustomizationByModelCustomizationUuid(strc.getResourceModelCustomizationUUID());
if (vrc != null)
allVrcs.add(vrc);
}
return allVrcs;
}
public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
StringBuilder hqlService = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
Query query = getSession().createQuery(hqlService.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
@SuppressWarnings("unchecked")
List<Service> resultList = query.list();
if (resultList.isEmpty()) {
return new ArrayList<>();
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
Service service = resultList.get(0);
//now just call the method that takes the version - the service object will have the highest version
return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
}
public List<VnfResourceCustomization> getAllVnfsByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllVnfsByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
query.setParameter("serviceModelVersion", serviceModelVersion);
@SuppressWarnings("unchecked")
List<Service> resultList = query.list();
if (resultList.isEmpty()) {
return new ArrayList<>();
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
Service service = resultList.get(0);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByServiceModelInvariantUuid", null);
return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
}
public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName, String serviceVersion) {
LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName + ", version=" + serviceVersion);
if (serviceVersion == null || serviceVersion.equals("")) {
return this.getAllVnfsByServiceName(serviceName);
}
StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName and version = :serviceVersion");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceName", serviceName);
query.setParameter("serviceVersion", serviceVersion);
@SuppressWarnings("unchecked")
List<Service> resultList = query.list();
if (resultList.isEmpty()) {
return Collections.EMPTY_LIST;
}
Service service = resultList.get(0);
return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
}
public List<VnfResourceCustomization> getAllVnfsByServiceName(String serviceName) {
LOGGER.debug("Catalog database: getAllVnfsByServiceName - " + serviceName);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelName = :serviceName");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceName", serviceName);
@SuppressWarnings("unchecked")
List<Service> resultList = query.list();
if (resultList.isEmpty()) {
return Collections.EMPTY_LIST;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
Service service = resultList.get(0);
return this.getAllVnfsByServiceModelUuid(service.getModelUUID());
}
public List<VnfResourceCustomization> getAllVnfsByVnfModelCustomizationUuid(String vnfModelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllVnfsByVnfModelCustomizationUuid - " + vnfModelCustomizationUuid);
StringBuilder hql1 = new StringBuilder("FROM VnfResourceCustomization WHERE modelCustomizationUuid = :vrcmcu");
Query query1 = getSession().createQuery(hql1.toString());
query1.setParameter("vrcmcu", vnfModelCustomizationUuid);
@SuppressWarnings("unchecked")
List<VnfResourceCustomization> resultList1 = query1.list();
if (resultList1.isEmpty()) {
LOGGER.debug("Found no records matching " + vnfModelCustomizationUuid);
return Collections.EMPTY_LIST;
}
for (VnfResourceCustomization vrc : resultList1) {
VnfResource vr = this.getVnfResourceByModelUuid(vrc.getVnfResourceModelUuid());
vrc.setVnfResource(vr);
vrc.setVfModuleCustomizations(this.getAllVfmcForVrc(vrc));
}
LOGGER.debug("Returning " + resultList1.size() + " vnf modules");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfsByVnfModelCustomizationUuid", null);
return resultList1;
}
//1702 API Spec cont'd - Query for all allotted resources in a Service
public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelUuid(String serviceModelUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelUuid - " + serviceModelUuid);
List<ServiceToResourceCustomization> strcs = this.getSTR(serviceModelUuid, null, "allottedResource");
if (strcs == null || strcs.isEmpty()) {
LOGGER.debug("No AR entries found for " + serviceModelUuid);
return new ArrayList<>();
}
LOGGER.debug("Found " + strcs.size() + " entries in ServiceToResourceCustomizations with smu=" + serviceModelUuid + ", allottedResource");
ArrayList<AllottedResourceCustomization> masterList = new ArrayList<>();
for (ServiceToResourceCustomization star : strcs) {
String arModelCustomizationUuid = star.getResourceModelCustomizationUUID();
LOGGER.debug("Now searching for AllottedResourceCustomization for " + arModelCustomizationUuid);
List<AllottedResourceCustomization> resultSet = this.getAllAllottedResourcesByArModelCustomizationUuid(arModelCustomizationUuid);
for (AllottedResourceCustomization arc : resultSet) {
masterList.add(arc);
}
}
LOGGER.debug("Returning " + masterList.size() + " ARC records");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByServiceModelUuid", null);
return masterList;
}
public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("Could not find Service for " + serviceModelInvariantUuid);
return new ArrayList<>();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
String serviceModelUuid = service.getModelUUID();
LOGGER.debug("The highest version for the Service " + serviceModelInvariantUuid + " is " + serviceModelUuid);
return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
}
public List<AllottedResourceCustomization> getAllAllottedResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
LOGGER.debug("Catalog database: getAllAllottedResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
query.setParameter("serviceModelVersion", serviceModelVersion);
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("No Service found with smu=" + serviceModelInvariantUuid + " and smv=" + serviceModelVersion);
return new ArrayList<>();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
String serviceModelUuid = service.getModelUUID();
return this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
}
public List<AllottedResourceCustomization> getAllAllottedResourcesByArModelCustomizationUuid(String arModelCustomizationUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllAllottedResourcesByArModelCustomizationUuid - " + arModelCustomizationUuid);
StringBuilder hql = new StringBuilder("FROM AllottedResourceCustomization WHERE modelCustomizationUuid = :arModelCustomizationUuid");
Query query = getSession().createQuery(hql.toString());
query.setParameter("arModelCustomizationUuid", arModelCustomizationUuid);
@SuppressWarnings("unchecked")
List<AllottedResourceCustomization> resultList = query.list();
if (resultList.isEmpty()) {
LOGGER.debug("No ARC found with arc_mcu=" + arModelCustomizationUuid);
return new ArrayList<>();
}
// There should only be one - but we'll handle if multiple
for (AllottedResourceCustomization arc : resultList) {
AllottedResource ar = this.getAllottedResourceByModelUuid(arc.getArModelUuid());
arc.setAllottedResource(ar);
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllAllottedResourcesByArModelCustomizationUuid", null);
return resultList;
}
public AllottedResource getAllottedResourceByModelUuid(String arModelUuid) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Allotted Resource with modelUuid= " + arModelUuid);
String hql = "FROM AllottedResource WHERE modelUuid = :arModelUuid";
Query query = getSession ().createQuery (hql);
query.setParameter ("arModelUuid", arModelUuid);
@SuppressWarnings("unchecked")
List <AllottedResource> resultList = query.list ();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. AllottedResource not found", "CatalogDB", "getAllottedResourceByModelUuid", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllottedResourceByModelUuid", null);
return resultList.get (0);
}
//1702 API Spec cont'd - Query for all resources in a Service:
public ServiceMacroHolder getAllResourcesByServiceModelUuid(String serviceModelUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllResourcesByServiceModelUuid - " + serviceModelUuid);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelUUID = :serviceModelUuid");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelUuid", serviceModelUuid);
LOGGER.debug("Query: " + hql.toString() + ", smu=" + serviceModelUuid);
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("Unable to find a Service with serviceModelUuid=" + serviceModelUuid);
return new ServiceMacroHolder();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
ServiceMacroHolder smh = new ServiceMacroHolder(service);
ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(serviceModelUuid);
smh.setNetworkResourceCustomization(nrcList);
ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(serviceModelUuid);
smh.setAllottedResourceCustomization(arcList);
ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(serviceModelUuid);
smh.setVnfResourceCustomizations(vnfList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid", null);
return smh;
}
public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid);
return new ServiceMacroHolder();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
ServiceMacroHolder smh = new ServiceMacroHolder(service);
ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
smh.setNetworkResourceCustomization(nrcList);
ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
smh.setAllottedResourceCustomization(arcList);
ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
smh.setVnfResourceCustomizations(vnfList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelInvariantUuid", null);
return smh;
}
public ServiceMacroHolder getAllResourcesByServiceModelInvariantUuid(String serviceModelInvariantUuid, String serviceModelVersion) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database: getAllResourcesByServiceModelInvariantUuid - " + serviceModelInvariantUuid + ", version=" + serviceModelVersion);
StringBuilder hql = new StringBuilder("FROM Service WHERE modelInvariantUUID = :serviceModelInvariantUuid and version = :serviceModelVersion");
Query query = getSession().createQuery(hql.toString());
query.setParameter("serviceModelInvariantUuid", serviceModelInvariantUuid);
query.setParameter("serviceModelVersion", serviceModelVersion);
//TODO make this a unique query
@SuppressWarnings("unchecked")
List<Service> serviceList = query.list();
if (serviceList.isEmpty()) {
LOGGER.debug("Unable to find a Service with serviceModelInvariantUuid=" + serviceModelInvariantUuid + " and serviceModelVersion=" + serviceModelVersion);
return new ServiceMacroHolder();
}
Collections.sort (serviceList, new MavenLikeVersioningComparator ());
Collections.reverse (serviceList);
Service service = serviceList.get(0);
ServiceMacroHolder smh = new ServiceMacroHolder(service);
ArrayList<NetworkResourceCustomization> nrcList = (ArrayList<NetworkResourceCustomization>) this.getAllNetworksByServiceModelUuid(service.getModelUUID());
smh.setNetworkResourceCustomization(nrcList);
ArrayList<AllottedResourceCustomization> arcList = (ArrayList<AllottedResourceCustomization>) this.getAllAllottedResourcesByServiceModelUuid(service.getModelUUID());
smh.setAllottedResourceCustomization(arcList);
ArrayList<VnfResourceCustomization> vnfList = (ArrayList<VnfResourceCustomization>) this.getAllVnfsByServiceModelUuid(service.getModelUUID());
smh.setVnfResourceCustomizations(vnfList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllResourcesByServiceModelUuid with version", null);
return smh;
}
// 1707 New API queries
public NetworkResourceCustomization getSingleNetworkByModelCustomizationUuid(String modelCustomizationUuid) {
LOGGER.debug("Catalog database; getSingleNetworkByModelCustomizationUuid - " + modelCustomizationUuid);
List<NetworkResourceCustomization> resultList = this.getAllNetworksByNetworkModelCustomizationUuid(modelCustomizationUuid);
if (resultList == null || resultList.isEmpty()) {
return null;
}
return resultList.get(0);
}
public AllottedResourceCustomization getSingleAllottedResourceByModelCustomizationUuid(String modelCustomizationUuid) {
LOGGER.debug("Catalog database; getSingleAllottedResourceByModelCustomizationUuid - " + modelCustomizationUuid);
List<AllottedResourceCustomization> resultList = this.getAllAllottedResourcesByArModelCustomizationUuid(modelCustomizationUuid);
if (resultList == null || resultList.isEmpty()) {
return null;
}
return resultList.get(0);
}
@Deprecated
public VnfResource getSingleVnfResourceByModelCustomizationUuid(String modelCustomizationUuid) {
/*
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database; getSingleVnfResourceByModelCustomizationUuid - " + modelCustomizationUuid);
List<VnfResource> resultList = this.getAllVnfsByVnfModelCustomizationUuid(modelCustomizationUuid);
if (resultList == null || resultList.size() < 1) {
return null;
}
return resultList.get(0);
*/
return null;
}
private void populateNetworkResourceType(List<NetworkResourceCustomization> resultList) {
HashMap<String, NetworkResource> networkResources = new HashMap<String, NetworkResource>();
for (NetworkResourceCustomization nrc : resultList) {
String network_id = nrc.getNetworkResourceModelUuid();
if (network_id == null) {
nrc.setNetworkResource(null);
nrc.setNetworkType("UNKNOWN_NETWORK_ID_NULL");
continue;
}
if (networkResources.containsKey(network_id)) {
nrc.setNetworkResource(networkResources.get(network_id));
nrc.setNetworkType(networkResources.get(network_id).getModelName());
} else {
NetworkResource nr = this.getNetworkResourceById(network_id);
if (nr == null) {
nrc.setNetworkType("INVALID_NETWORK_TYPE_ID_NOT_FOUND");
} else {
nrc.setNetworkType(nr.getModelName());
nrc.setNetworkResource(nr);
networkResources.put(network_id, nr);
}
}
}
}
/**
* Return a VNF recipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME, and ACTION
* first query VF_MODULE table by type, and then use the ID to query
* VNF_RECIPE by VF_MODULE_ID and ACTION
*
* @param vnfType
* @parm vfModuleModelName
* @param action
* @return VnfRecipe object or null if none found
*/
public VnfRecipe getVfModuleRecipe (String vnfType, String vfModuleModelName, String action) {
String vfModuleType = vnfType + "::" + vfModuleModelName;
StringBuilder hql = new StringBuilder ("FROM VfModule WHERE type = :type ");
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType);
Query query = getSession ().createQuery (hql.toString ());
query.setParameter (TYPE, vfModuleType);
@SuppressWarnings("unchecked")
List <VfModule> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVfModuleRecipe", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
VfModule vfMod = resultList.get(0);
String vfModuleId = vfMod.getModelUUID();
StringBuilder hql1 = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
LOGGER.debug ("Catalog database - get VNF recipe with vf module id " + vfModuleId
+ " and action "
+ action);
Query query1 = getSession ().createQuery (hql1.toString ());
query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
query1.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <VnfRecipe> resultList1 = query1.list ();
if (resultList1.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVfModuleRecipe", null);
return null;
}
Collections.sort (resultList1, new MavenLikeVersioningComparator ());
Collections.reverse (resultList1);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVfModuleRecipe", null);
return resultList1.get (0);
}
/**
* Return a VNF Module List that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
* ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
*
* @param vnfModuleType
* @parm modelCustomizationUuid
* @param asdcServiceModelVersion
* @param modelVersion
* @param action
* @return VfModule list
*/
public List<VfModule> getVfModule (String vfModuleType, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
StringBuilder hql;
Query query;
if(modelCustomizationUuid != null){
hql = new StringBuilder ("FROM VfModule WHERE modelCustomizationUuid = :modelCustomizationUuid AND version = :version");
LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
query = getSession ().createQuery (hql.toString ());
query.setParameter ("modelCustomizationUuid", modelCustomizationUuid);
query.setParameter ("version", asdcServiceModelVersion);
}else{
hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion");
LOGGER.debug ("Catalog database - get VF MODULE with type " + vfModuleType + ", asdcServiceModelVersion " + asdcServiceModelVersion + ", modelVersion " + modelVersion);
query = getSession ().createQuery (hql.toString ());
query.setParameter (TYPE, vfModuleType);
query.setParameter ("version", asdcServiceModelVersion);
query.setParameter ("modelVersion", modelVersion);
}
@SuppressWarnings("unchecked")
List <VfModule> resultList = query.list ();
return resultList;
}
/**
* Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
* MODEL_CUSTOMIZATION_UUID, ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
* first query VF_MODULE table by type, and then use the ID to query
* VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
*
* @param vnfType
* @parm vfModuleModelName
* @param action
* @return VnfRecipe object or null if none found
*/
public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType, String vfModuleModelName, String modelCustomizationUuid, String asdcServiceModelVersion, String modelVersion, String action) {
String vfModuleType = vnfType + "::" + vfModuleModelName;
long startTime = System.currentTimeMillis ();
List <VfModule> resultList = getVfModule(vfModuleType, modelCustomizationUuid, asdcServiceModelVersion, modelVersion, action);
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
VfModule vfMod = resultList.get(0);
String vfModuleId = vfMod.getModelUUID();
StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
+ " and action "
+ action);
Query query1 = getSession ().createQuery (hql1.toString ());
query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
query1.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <VnfComponentsRecipe> resultList1 = query1.list ();
if (resultList1.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
return null;
}
Collections.sort (resultList1, new MavenLikeVersioningComparator ());
Collections.reverse (resultList1);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Different ORCHESTRATION URIs found for same VERSION and ID. No result returned.", "CatalogDB", "getVnfComponentsRecipe", null);
return null;
}
return resultList1.get (0);
}
/**
* Return a VNF COMPONENTSrecipe that matches a given VNF_TYPE, VF_MODULE_MODEL_NAME,
* ASDC_SERVICE_MODEL_VERSION, MODEL_VERSION, and ACTION
* first query VF_MODULE table by type, and then use the ID to query
* VNF_COMPONENTS_RECIPE by VF_MODULE_ID and ACTION
*
* @param vnfType
* @parm vfModuleModelName
* @param action
* @return VnfRecipe object or null if none found
*/
public VnfComponentsRecipe getVnfComponentsRecipeByVfModule(List <VfModule> resultList, String action) {
long startTime = System.currentTimeMillis ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF Module Entry not found", "CatalogDB", "getVnfComponentsRecipe", null);
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
VfModule vfMod = resultList.get(0);
String vfModuleId = vfMod.getModelName();
StringBuilder hql1 = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleId = :vfModuleId AND action = :action ");
LOGGER.debug ("Catalog database - get Vnf Components recipe with vf module id " + vfModuleId
+ " and action "
+ action);
Query query1 = getSession ().createQuery (hql1.toString ());
query1.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
query1.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <VnfComponentsRecipe> resultList1 = query1.list ();
if (resultList1.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfComponentsRecipe", null);
return null;
}
Collections.sort (resultList1, new MavenLikeVersioningComparator ());
Collections.reverse (resultList1);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe found", "CatalogDB", "getVnfComponentsRecipe", null);
if (resultList1.size() > 1 && (!resultList1. get (0).getOrchestrationUri().equals(resultList1.get (1).getOrchestrationUri ()))) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Different ORCHESTRATION URIs found for same VERSION and ID. No result returned.", "CatalogDB", "getVnfComponentsRecipe", null);
return null;
}
return resultList1.get (0);
}
/**
* Return all VNF Resources in the Catalog DB
*
* @return A list of VnfResource objects
*/
@SuppressWarnings("unchecked")
public List <VnfResource> getAllVnfResources () {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all VNF resources");
String hql = "FROM VnfResource";
Query query = getSession ().createQuery (hql);
List <VnfResource> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVnfResources", null);
return result;
}
/**
* Return VNF Resources in the Catalog DB that match a given VNF role
*
* @return A list of VnfResource objects
*/
@SuppressWarnings("unchecked")
@Deprecated // vnfRole is no longer in VnfResource
public List <VnfResource> getVnfResourcesByRole (String vnfRole) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all VNF resources for role " + vnfRole);
String hql = "FROM VnfResource WHERE vnfRole = :vnfRole";
Query query = getSession ().createQuery (hql);
query.setParameter ("vnfRole", vnfRole);
List <VnfResource> resources = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourcesByRole", null);
return resources;
}
/**
* Return VNF Resources in the Catalog DB that match a given VNF role
*
* @return A list of VnfResource objects
*/
@SuppressWarnings("unchecked")
public List<VnfResourceCustomization> getVnfResourceCustomizationsByRole(String vnfRole) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all VNF resource customizations for role " + vnfRole);
String hql = "FROM VnfResourceCustomization WHERE nfRole = :vnfRole";
Query query = getSession ().createQuery (hql);
query.setParameter ("vnfRole", vnfRole);
List <VnfResourceCustomization> resources = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationsByRole", null);
return resources;
}
/**
* Return all Network Resources in the Catalog DB
*
* @return A list of NetworkResource objects
*/
@SuppressWarnings("unchecked")
public List <NetworkResource> getAllNetworkResources () {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all network resources");
String hql = "FROM NetworkResource";
Query query = getSession ().createQuery (hql);
List <NetworkResource> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResources", null);
return result;
}
@SuppressWarnings("unchecked")
public List<NetworkResourceCustomization> getAllNetworkResourceCustomizations() {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all network resource customizations");
String hql = "FROM NetworkResourceCustomization";
Query query = getSession ().createQuery (hql);
List <NetworkResourceCustomization> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllNetworkResourceCustomizations", null);
return result;
}
/**
* Return all VF Modules in the Catalog DB
*
* @return A list of VfModule objects
*/
@SuppressWarnings("unchecked")
public List <VfModule> getAllVfModules () {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all vf modules");
String hql = "FROM VfModule";
Query query = getSession ().createQuery (hql);
List <VfModule> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModules", null);
return result;
}
@SuppressWarnings("unchecked")
public List <VfModuleCustomization> getAllVfModuleCustomizations () {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all vf module customizations");
String hql = "FROM VfModuleCustomization";
Query query = getSession ().createQuery (hql);
List <VfModuleCustomization> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllVfModuleCustomizations", null);
return result;
}
/**
* Return all HeatEnvironment in the Catalog DB
*
* @return A list of HeatEnvironment objects
*/
@SuppressWarnings("unchecked")
public List <HeatEnvironment> getAllHeatEnvironment () {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get all Heat environments");
String hql = "FROM HeatEnvironment";
Query query = getSession ().createQuery (hql);
List <HeatEnvironment> result = query.list ();
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getAllHeatEnvironment", null);
return result;
}
/**
* Fetch the Environment by Environment ID - 1510
*/
@Deprecated // no longer in heat envt table
public HeatEnvironment getHeatEnvironment (int id) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Heat environment with id " + id);
String hql = "FROM HeatEnvironment WHERE id = :idValue";
LOGGER.debug ("getHeatEnvironment called with id=" + id);
Query query = getSession ().createQuery (hql);
query.setParameter ("idValue", id);
@SuppressWarnings("unchecked")
List <HeatEnvironment> resultList = query.list ();
// See if something came back.
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat environment not found", "CatalogDB", "getHeatEnvironment", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatEnvironment", null);
return resultList.get (0);
}
/**
* Fetch the nested templates - 1510
*/
@Deprecated
public Map <String, Object> getNestedTemplates (int templateId) {
Map <String, Object> nestedTemplates;
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getNestedTemplates called with templateId " + templateId);
String hql = "FROM HeatNestedTemplate where parent_template_id = :parentIdValue";
Query query = getSession ().createQuery (hql);
query.setParameter ("parentIdValue", templateId);
@SuppressWarnings("unchecked")
List <HeatNestedTemplate> resultList = query.list ();
// If nothing comes back, there are no nested templates
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
LOGGER.debug ("No nestedTemplates found for templateId=" + templateId + ", " + hql);
return null;
}
// Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
nestedTemplates = new HashMap <> ();
for (HeatNestedTemplate hnt : resultList) {
LOGGER.debug ("Querying for " + hnt);
HeatTemplate ht = this.getHeatTemplate (hnt.getChildTemplateId ());
if (ht == null) {
LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
continue;
}
String providerResourceFile = hnt.getProviderResourceFile ();
String heatTemplateBody = ht.getTemplateBody ();
if (providerResourceFile != null && heatTemplateBody != null) {
nestedTemplates.put (providerResourceFile, heatTemplateBody);
} else {
LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
}
}
// Make sure we're not returning an empty map - if so, just return null
if (nestedTemplates.isEmpty ()) {
LOGGER.debug ("nestedTemplates is empty - just return null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
return nestedTemplates;
}
/**
* Return a Map<String, Object> for returning the child templates and their contents
*
* @param parentHeatTemplateId
* @return Map<String,Object> or null if none found
*/
public Map <String, Object> getNestedTemplates (String parentHeatTemplateId) {
Map <String, Object> nestedTemplates;
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getNestedTemplates called with parentTemplateId " + parentHeatTemplateId);
String hql = "FROM HeatNestedTemplate where parentTemplateId = :parentHeatTemplateId";
Query query = getSession ().createQuery (hql);
query.setParameter ("parentHeatTemplateId", parentHeatTemplateId);
@SuppressWarnings("unchecked")
List <HeatNestedTemplate> resultList = query.list ();
// If nothing comes back, there are no nested templates
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No nestedTemplate found", "CatalogDB", "getNestedTemplates", null);
LOGGER.debug ("No nestedTemplates found for templateId=" + parentHeatTemplateId + ", " + hql);
return null;
}
// Now, for each entry in NESTED_HEAT_TEMPLATES, we need to grab the template body from HEAT_TEMPLATE
nestedTemplates = new HashMap <> ();
for (HeatNestedTemplate hnt : resultList) {
LOGGER.debug ("Querying for " + hnt);
HeatTemplate ht = this.getHeatTemplateByArtifactUuid (hnt.getChildTemplateId ());
if (ht == null) {
LOGGER.debug ("No template found matching childTemplateId=" + hnt.getChildTemplateId ());
continue;
}
String providerResourceFile = hnt.getProviderResourceFile ();
String heatTemplateBody = ht.getTemplateBody ();
if (providerResourceFile != null && heatTemplateBody != null) {
nestedTemplates.put (providerResourceFile, heatTemplateBody);
} else {
LOGGER.debug ("providerResourceFile or heatTemplateBody were null - do not add to HashMap!");
}
}
// Make sure we're not returning an empty map - if so, just return null
if (nestedTemplates.isEmpty ()) {
LOGGER.debug ("nestedTemplates is empty - just return null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Nested template is empty", "CatalogDB", "getNestedTemplate", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedTemplate", null);
return nestedTemplates;
}
/*
* Fetch any files in the HEAT_FILES table 1510
*/
@Deprecated
public Map <String, HeatFiles> getHeatFiles (int vnfResourceId) {
Map <String, HeatFiles> heatFiles;
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getHeatFiles called with vnfResourceId " + vnfResourceId);
String hql = "FROM HeatFiles where vnf_resource_id = :vnfResourceIdValue";
Query query = getSession ().createQuery (hql);
query.setParameter ("vnfResourceIdValue", vnfResourceId);
@SuppressWarnings("unchecked")
List <HeatFiles> resultList = query.list ();
// If nothing comes back, there are no heat files
if (resultList.isEmpty ()) {
LOGGER.debug ("No heatFiles found for vnfResourceId=" + vnfResourceId);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heat files", "CatalogDB", "getHeatFiles", null);
return null;
}
// Now, we just need to return a HashMap (key=fileName, object=fileBody)
heatFiles = new HashMap <> ();
for (HeatFiles hf : resultList) {
LOGGER.debug ("Adding " + hf.getFileName () + "->" + hf.getFileBody ());
heatFiles.put (hf.getFileName (), hf);
}
// Make sure we're not returning an empty map - if so, just return null
if (heatFiles.isEmpty ()) {
LOGGER.debug ("heatFiles is empty - just return null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat files is empty", "CatalogDB", "getHeatFiles", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
return heatFiles;
}
// New 1607 - with modularization, use new table to determine which HEAT_FILES entries to attach
@Deprecated
public Map <String, HeatFiles> getHeatFilesForVfModule(int vfModuleId) {
/*
Map <String, HeatFiles> heatFiles = null;
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleId " + vfModuleId);
String hql = "FROM VfModuleToHeatFiles where vf_module_id = :vfModuleIdValue";
Query query = getSession ().createQuery (hql);
query.setParameter ("vfModuleIdValue", vfModuleId);
List<VfModuleToHeatFiles> mapList = query.list();
if (mapList.isEmpty()) {
LOGGER.debug ("No heatFiles found for vfModuleId=" + vfModuleId);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
return null;
}
//Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
heatFiles = new HashMap<String, HeatFiles>();
for (VfModuleToHeatFiles vmthf : mapList) {
int heatFilesId = vmthf.getHeatFilesId();
hql = "FROM HeatFiles where id = :id_value";
query = getSession().createQuery(hql);
query.setParameter("id_value", heatFilesId);
List<HeatFiles> fileList = query.list();
if (fileList.isEmpty()) {
// Should this throw an exception??
LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesId);
String errorString = "_ERROR|" + heatFilesId;
// The receiving code needs to know to throw an exception for this - or ignore it.
heatFiles.put(errorString, null);
} else {
// Should only ever have 1 result - add it to our Map
LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesId);
for (HeatFiles hf : fileList) {
LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
heatFiles.put(hf.getFileName(), hf);
}
}
}
if (heatFiles.isEmpty()) {
LOGGER.debug ("heatFiles is empty - just return null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
return heatFiles;
*/
return null;
}
/**
* Return a VfModuleToHeatFiles object
*
* @param vfModuleModelUuid, heatFilesArtifactUuid
* @return VfModuleToHeatFiles or null if none found
*/
public VfModuleToHeatFiles getVfModuleToHeatFilesEntry(String vfModuleModelUuid, String heatFilesArtifactUuid) {
LOGGER.debug ("Catalog database - getVfModuleToHeatFilesEntry with vfModuleModelUuid " + vfModuleModelUuid + ", heatFilesArtifactUuid=" + heatFilesArtifactUuid);
String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue and heatFilesArtifactUuid = :heatFilesArtifactUuidValue";
HashMap<String, String> parameters = new HashMap<>();
parameters.put("vfModuleModelUuidValue", vfModuleModelUuid);
parameters.put("heatFilesArtifactUuidValue", heatFilesArtifactUuid);
VfModuleToHeatFiles vmthf = null;
try {
vmthf = this.executeQuerySingleRow(hql, parameters, true);
} catch (Exception e) {
throw e;
}
return vmthf;
}
/**
* Return a ServiceToResourceCustomization object
*
* @param vfModuleModelUuid, heatFilesArtifactUuid
* @return VfModuleToHeatFiles or null if none found
*/
public ServiceToResourceCustomization getServiceToResourceCustomization(String serviceModelUuid, String resourceModelCustomizationUuid, String modelType) {
LOGGER.debug ("Catalog database - getServiceToResourceCustomization with serviceModelUuid=" + serviceModelUuid + ", resourceModelCustomizationUuid=" + resourceModelCustomizationUuid + ", modelType=" + modelType);
String hql = "FROM ServiceToResourceCustomization where serviceModelUUID = :serviceModelUuidValue and resourceModelCustomizationUUID = :resourceModelCustomizationUuidValue and modelType = :modelTypeValue ";
HashMap<String, String> parameters = new HashMap<>();
parameters.put("serviceModelUuidValue", serviceModelUuid);
parameters.put("resourceModelCustomizationUuidValue", resourceModelCustomizationUuid);
parameters.put("modelTypeValue", modelType);
ServiceToResourceCustomization strc = null;
try {
strc = this.executeQuerySingleRow(hql, parameters, true);
} catch (Exception e) {
throw e;
}
return strc;
}
/**
* Return a Map<String, HeatFiles> for returning the heat files associated with a vfModule 1707
*
* @param parentHeatTemplateId
* @return Map<String,Object> or null if none found
*/
public Map <String, HeatFiles> getHeatFilesForVfModule(String vfModuleModelUuid) {
Map <String, HeatFiles> heatFiles;
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getHeatFilesForVfModule called with vfModuleModelUuid " + vfModuleModelUuid);
String hql = "FROM VfModuleToHeatFiles where vfModuleModelUuid = :vfModuleModelUuidValue";
Query query = getSession ().createQuery (hql);
query.setParameter ("vfModuleModelUuidValue", vfModuleModelUuid);
@SuppressWarnings("unchecked")
List<VfModuleToHeatFiles> mapList = query.list();
if (mapList.isEmpty()) {
LOGGER.debug ("No heatFiles found for vfModuleModelUuid=" + vfModuleModelUuid);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. No heatfiles found for vfModule", "CatalogDB", "getHeatFilesForVfModule", null);
return null;
}
//Now the fun part - we have a list of the heat files we need to get - could clean this up with a join
heatFiles = new HashMap<>();
for (VfModuleToHeatFiles vmthf : mapList) {
String heatFilesUuid = vmthf.getHeatFilesArtifactUuid();
hql = "FROM HeatFiles where artifactUuid = :heatFilesUuidValue";
query = getSession().createQuery(hql);
query.setParameter("heatFilesUuidValue", heatFilesUuid);
@SuppressWarnings("unchecked")
List<HeatFiles> fileList = query.list();
if (fileList.isEmpty()) {
// Should this throw an exception??
LOGGER.debug("Unable to find a HEAT_FILES entry at " + heatFilesUuid);
String errorString = "_ERROR|" + heatFilesUuid;
// The receiving code needs to know to throw an exception for this - or ignore it.
heatFiles.put(errorString, null);
} else {
// Should only ever have 1 result - add it to our Map
LOGGER.debug("Retrieved " + fileList.size() + " heat file entry at " + heatFilesUuid);
for (HeatFiles hf : fileList) {
LOGGER.debug("Adding " + hf.getFileName() + "->" + hf.getFileBody());
heatFiles.put(hf.getFileName(), hf);
}
}
}
if (heatFiles.isEmpty()) {
LOGGER.debug ("heatFiles is empty - just return null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles is empty", "CatalogDB", "getHeatFilesForVfModule", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFilesForVfModule", null);
return heatFiles;
}
/**
* Get the heat template object based on asdc attributes
*
* @param templateName The template name, generally the yaml filename. "example.yaml"
* @param version The version as specified by ASDC. "1.1"
* @param asdcResourceName The ASDC resource name provided in the ASDC artifact
*
* @return The HeatTemplate
*/
@Deprecated // asdcResourceName is no longer in heatTeamplate
public HeatTemplate getHeatTemplate (String templateName, String version, String asdcResourceName) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getHeatTemplate with name " + templateName
+ " and version "
+ version
+ " and ASDC resource name "
+ asdcResourceName);
String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName";
Query query = getSession ().createQuery (hql);
query.setParameter ("template_name", templateName);
query.setParameter ("version", version);
query.setParameter ("asdcResourceName", asdcResourceName);
@SuppressWarnings("unchecked")
List <HeatTemplate> resultList = query.list ();
// See if something came back.
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Heat template not found", "CatalogDB", "getHeatTemplate", null);
return null;
}
// Name + Version is unique, so should only be one element
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
return resultList.get (0);
}
/**
* Save the Heat Template
*
* @param heat The heat template
* @param paramSet The list of heat template parameters
*/
public void saveHeatTemplate (HeatTemplate heat, Set <HeatTemplateParam> paramSet) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat Template with name " + heat.getTemplateName() + ", artifactUUID=" + heat.getArtifactUuid());
heat.setParameters(null);
try {
HeatTemplate heatTemp = this.getHeatTemplateByArtifactUuidRegularQuery(heat.getArtifactUuid());
if (heatTemp == null) {
this.getSession ().save (heat);
if (paramSet != null) {
StringBuilder sb = new StringBuilder("Parameters: ");
for (HeatTemplateParam param : paramSet) {
param.setHeatTemplateArtifactUuid(heat.getArtifactUuid());
sb.append(param.getParamName() + ", ");
}
LOGGER.debug(sb.toString());
heat.setParameters (paramSet);
try {
Session session = this.getSession();
if (!(session.isConnected() && session.isOpen())) {
LOGGER.debug("Initial session is not connected or open - get another");
session = this.getSession();
}
session.save(heat);
} catch (HibernateException he1) {
LOGGER.debug("Hibernate Exception encountered on first attempt at save(heat) - try again..." + he1.getMessage(), he1);
try {
Session session = this.getSession();
session.save(heat);
} catch (HibernateException he2) {
LOGGER.debug("Hibernate Exception encountered on second attempt at save(heat)" + he2.getMessage());
LOGGER.debug(Arrays.toString(he2.getStackTrace()));
throw he2;
} catch (Exception e2) {
LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(),e2);
LOGGER.debug(Arrays.toString(e2.getStackTrace()));
throw e2;
}
} catch (Exception e1) {
LOGGER.debug("General Exception encountered on first attempt at save(heat) - try again..." + e1.getMessage(), e1);
LOGGER.debug(Arrays.toString(e1.getStackTrace()));
try {
Session session = this.getSession();
session.save(heat);
} catch (HibernateException he2) {
LOGGER.debug("General Exception encountered on second attempt at save(heat)" + he2.getMessage(), he2);
LOGGER.debug(Arrays.toString(he2.getStackTrace()));
throw he2;
} catch (Exception e2) {
LOGGER.debug("General Exception encountered on second attempt at save(heat)..." + e2.getMessage(), e2);
LOGGER.debug(Arrays.toString(e2.getStackTrace()));
throw e2;
}
}
}
} else {
heat.setArtifactUuid(heatTemp.getArtifactUuid());
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
}
}
/**
* Retrieves a Heat environment from DB based on its unique key.
*
* @param name the environment artifact name
* @param version the environment resource version
* @param asdcResourceName the environment resource name
* @return the heat environment from DB or null if not found
*/
@Deprecated
public HeatEnvironment getHeatEnvironment (String name, String version, String asdcResourceName) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Heat environment with name " + name
+ " and version "
+ version
+ " and ASDC resource name "
+ asdcResourceName);
String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName";
Query query = getSession ().createQuery (hql);
query.setParameter ("name", name);
query.setParameter ("version", version);
query.setParameter ("asdcResourceName", asdcResourceName);
HeatEnvironment env = null;
try {
env = (HeatEnvironment) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + name + "', version='" + version + "' and asdcResourceName=" + asdcResourceName, nure);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for envName=" + name + " and version=" + version + " and asdcResourceName=" + asdcResourceName, "", "", MsoLogger.ErrorCode.DataError, "non unique result for envName=" + name);
env = null;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, he);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for envName=" + name + " and version=" + version + " and asdcResourceName=" + asdcResourceName, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for envName=" + name);
env = null;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: envName='" + name + "', asdc_service_model_version='" + version + "' and asdcResourceName=" + asdcResourceName, e);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for envName=" + name + " and version=" + version + " and asdcResourceName=" + asdcResourceName, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for envName=" + name);
env = null;
}
if (env == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
}
return env;
}
/**
* Retrieves a Heat environment from DB based on its unique key. 1707
*
* @param name the environment artifact name
* @param version the environment resource version
* @return the heat environment from DB or null if not found
*/
public HeatEnvironment getHeatEnvironment (String artifactUuid, String version) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Heat environment with uuid " + artifactUuid
+ " and version "
+ version);
String hql = "FROM HeatEnvironment WHERE artifactUuid=:artifactUuid AND version=:version";
Query query = getSession ().createQuery (hql);
query.setParameter ("artifactUuid", artifactUuid);
query.setParameter ("version", version);
HeatEnvironment env = null;
try {
env = (HeatEnvironment) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: envName='" + artifactUuid + "', version='" + version);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "non unique result for ArtifactUUID=" + artifactUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + he.getMessage() );
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUUID=" + artifactUuid + " and version=" + version , "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUUID=" + artifactUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: artifactUUID='" + artifactUuid + "', asdc_service_model_version='" + version + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUUID=" + artifactUuid + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUUID=" + artifactUuid);
throw e;
}
if (env == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplate", null);
} else {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplate", null);
}
return env;
}
/**
* Save the HeatEnvironment
*
* @param env The Environment
*/
public void saveHeatEnvironment (HeatEnvironment env) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat environment with name "
+ env.getEnvironment() + " and ArtifactUUID " + env.getArtifactUuid());
try {
HeatEnvironment dbEnv = getHeatEnvironment (env.getArtifactUuid(), env.getVersion ());
if (dbEnv == null) {
this.getSession ().save (env);
} else {
env.setArtifactUuid(dbEnv.getArtifactUuid());
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
}
}
/**
* Save the heatTemplate
*
* @param heat The heat template
*/
public void saveHeatTemplate (HeatTemplate heat) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat template with name " + heat.getTemplateName ());
try {
this.getSession ().update (heat);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatTemplate", null);
}
}
public void saveHeatFile (HeatFiles heatFile) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat file with name " + heatFile.getFileName ());
try {
this.getSession ().save (heatFile);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFile", null);
}
}
public void saveVnfRecipe (VnfRecipe vnfRecipe) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VNF recipe with VNF type " + vnfRecipe.getVnfType ());
try {
this.getSession ().save (vnfRecipe);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfRecipe", null);
}
}
public void saveVnfComponentsRecipe (VnfComponentsRecipe vnfComponentsRecipe) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VNF Component recipe with VNF type " + vnfComponentsRecipe.getVnfType ());
try {
this.getSession ().save (vnfComponentsRecipe);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfComponentsRecipe", null);
}
}
public void saveOrUpdateVnfResource (VnfResource vnfResource) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VNF Resource with VNF type " + vnfResource.getModelName());
try {
VnfResource existing = this.getVnfResourceByModelUuid(vnfResource.getModelUuid());
if (existing == null) {
LOGGER.debug("No existing entry found - attempting to save...");
this.getSession ().save (vnfResource);
} else {
LOGGER.debug("Existing vnf resource found!");
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResource", null);
}
}
public boolean saveVnfResourceCustomization (VnfResourceCustomization vnfResourceCustomization) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VNF Resource Customization with Name " + vnfResourceCustomization.getModelInstanceName());
try {
LOGGER.debug(vnfResourceCustomization.toString());
} catch (Exception e) {
LOGGER.debug("Unable to print VRC " + e.getMessage(), e);
}
try {
// Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
// List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
// Do any matching customization records exist?
// if(networkResourceList.size() == 0){
// networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUuid());
// this.getSession().flush();
// this.getSession().clear();
VnfResourceCustomization existing = this.getVnfResourceCustomizationByModelCustomizationUuid(vnfResourceCustomization.getModelCustomizationUuid());
if (existing == null) {
LOGGER.debug("No existing entry found...attempting to save...");
this.getSession ().save (vnfResourceCustomization);
return true;
}else {
try {
LOGGER.debug("Existing VRC entry found\n" + existing.toString());
} catch (Exception e) {
LOGGER.debug("Unable to print VRC2 " + e.getMessage(), e);
}
return false;
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceCustomization", null);
}
}
public void saveAllottedResourceCustomization (AllottedResourceCustomization resourceCustomization) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Allotted Resource with Name " + resourceCustomization.getModelInstanceName());
try {
List<AllottedResourceCustomization> allottedResourcesList = getAllAllottedResourcesByArModelCustomizationUuid(resourceCustomization.getModelCustomizationUuid());
if(allottedResourcesList.isEmpty()){
this.getSession ().save(resourceCustomization);
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
}
}
public void saveAllottedResource (AllottedResource allottedResource) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Allotted Resource with Name " + allottedResource.getModelName());
try {
AllottedResource existing = this.getAllottedResourceByModelUuid(allottedResource.getModelUuid());
if (existing == null) {
this.getSession ().save (allottedResource);
} else {
LOGGER.debug("Found existing allottedResource with this modelUuid - no need to save");
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
}
}
public void saveNetworkResource (NetworkResource networkResource) throws RecordNotFoundException {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Network Resource with Network Name " + networkResource.getModelName());
try {
// Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
// List<NetworkResource> networkResourceList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
// Do any matching customization records exist?
if(getNetworkResourceByModelUuid(networkResource.getModelUUID()) == null){
this.getSession ().save(networkResource);
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
}
}
public void saveToscaCsar (ToscaCsar toscaCsar) throws RecordNotFoundException {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Tosca Csar with Name " + toscaCsar.getName());
try {
if(getToscaCsar(toscaCsar.getArtifactChecksum()) == null){
this.getSession ().save (toscaCsar);
}
LOGGER.debug("Temporarily disabling saveToscaCsar pending further investigation 2017-06-02");
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveToscaCsar", null);
}
}
/**
* Return the newest version of a specific Tosca CSAR Record resource (queried by Name).
*
* @param ToscaCsar
* @return ToscaCsar object or null if none found
*/
public ToscaCsar getToscaCsar (String artifactChecksum) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactChecksum " + artifactChecksum);
String hql = "FROM ToscaCsar WHERE artifactChecksum = :artifactChecksum";
Query query = getSession ().createQuery (hql);
query.setParameter ("artifactChecksum", artifactChecksum);
@SuppressWarnings("unchecked")
List <ToscaCsar> resultList = query.list ();
// See if something came back. Name is unique, so
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsar", null);
return null;
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsar", null);
return resultList.get (0);
}
public void saveTempNetworkHeatTemplateLookup (TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save TempNetworkHeatTemplateLookup with Network Model Name " + tempNetworkHeatTemplateLookup.getNetworkResourceModelName() +
" and Heat Template Artifact UUID " + tempNetworkHeatTemplateLookup.getHeatTemplateArtifactUuid());
try {
this.getSession ().save (tempNetworkHeatTemplateLookup);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveTempNetworkHeatTemplateLookup", null);
}
}
public void saveVfModuleToHeatFiles (VfModuleToHeatFiles vfModuleToHeatFiles) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VfModuleToHeatFiles with VF Module UUID " + vfModuleToHeatFiles.getVfModuleModelUuid() +
" and Heat Files Artifact UUID " + vfModuleToHeatFiles.getHeatFilesArtifactUuid());
try {
this.getSession ().save (vfModuleToHeatFiles);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVFModuleToHeatFiles", null);
}
}
public void saveVnfResourceToVfModuleCustomization(VnfResourceCustomization vnfResourceCustomizationUUID, VfModuleCustomization vfModuleCustomizationUUID) throws RecordNotFoundException {
long startTime = System.currentTimeMillis ();
VnfResCustomToVfModuleCustom vnfResCustomToVfModuleCustom = new VnfResCustomToVfModuleCustom();
if(vnfResourceCustomizationUUID != null && vfModuleCustomizationUUID != null){
vnfResCustomToVfModuleCustom.setVnfResourceCustModelCustomizationUuid(vnfResourceCustomizationUUID.getModelCustomizationUuid());
vnfResCustomToVfModuleCustom.setVfModuleCustModelCustomizationUuid(vfModuleCustomizationUUID.getModelCustomizationUuid());
String vnfId = vnfResourceCustomizationUUID.getModelCustomizationUuid();
String vfId = vfModuleCustomizationUUID.getModelCustomizationUuid();
LOGGER.debug ("Catalog database - save VnfResCustomToVfModuleCustom with vnf=" + vnfId + ", vf=" + vfId);
try {
VnfResCustomToVfModuleCustom existing = this.getVnfResCustomToVfModule(vnfId, vfId);
if (existing == null) {
LOGGER.debug("No existing entry found - will now try to save");
this.getSession ().save (vnfResCustomToVfModuleCustom);
} else {
LOGGER.debug("Existing entry already found - no save needed");
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVnfResourceToVfModuleCustomization", null);
}
}
}
public void saveNetworkResourceCustomization (NetworkResourceCustomization networkResourceCustomization) throws RecordNotFoundException {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Network Resource Customization with Network Name " + networkResourceCustomization.getModelInstanceName());
try {
// Check if NetworkResourceCustomzation record already exists. If so, skip saving it.
List<NetworkResourceCustomization> networkResourceCustomizationList = getAllNetworksByNetworkModelCustomizationUuid(networkResourceCustomization.getModelCustomizationUuid());
// Do any matching customization records exist?
if(networkResourceCustomizationList.isEmpty()){
// Retreive the record from the Network_Resource table associated to the Customization record based on ModelName
// ?? is it modelInstanceName with 1707?
NetworkResource networkResource = getNetworkResource(networkResourceCustomization.getModelInstanceName());
if(networkResource == null){
throw new RecordNotFoundException("No record found in NETWORK_RESOURCE table for model name " + networkResourceCustomization.getModelInstanceName());
}
networkResourceCustomization.setNetworkResourceModelUuid(networkResource.getModelUUID());
this.getSession ().save(networkResourceCustomization);
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
}
}
@Deprecated // table is gone - mapped to ServiceToResource
public void saveServiceToNetworks (ServiceToNetworks serviceToNetworks) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save to ServiceToNetworks table with NetworkModelCustomizationUUID of " + serviceToNetworks.getNetworkModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToNetworks.getServiceModelUuid());
try {
this.getSession ().save(serviceToNetworks);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNetworkResourceCustomization", null);
}
}
public void saveServiceToResourceCustomization(ServiceToResourceCustomization serviceToResource) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save to ServiceToResourceCustomization table with ServiceModelUuid of " + serviceToResource.getServiceModelUUID() + ", ResourceModelUUID of " + serviceToResource.getResourceModelCustomizationUUID() + " and model_type=" + serviceToResource.getModelType());
ServiceToResourceCustomization strc = this.getServiceToResourceCustomization(serviceToResource.getServiceModelUUID(), serviceToResource.getResourceModelCustomizationUUID(), serviceToResource.getModelType());
try {
if (strc != null) {
LOGGER.debug("**This ServiceToResourceCustomization record already exists - no need to save");
} else {
this.getSession ().save(serviceToResource);
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToResourceCustomization", null);
}
}
@Deprecated // table is gone - mapped to ServiceToResourceCustomization
public void saveServiceToAllottedResources (ServiceToAllottedResources serviceToAllottedResources) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save to serviceToAllottedResources table with ARModelCustomizationUUID of " + serviceToAllottedResources.getArModelCustomizationUuid() + " and ServiceModelUUID of " + serviceToAllottedResources.getServiceModelUuid());
try {
this.getSession ().save(serviceToAllottedResources);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveServiceToAllottedResources", null);
}
}
public void saveService (Service service) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Service with ServiceName/Version/serviceUUID(SERVICE_NAME_VERSION_ID)" + service.getModelName()+"/"+service.getVersion()+"/"+service.getModelUUID());
try {
Service serviceInvariantDB = null;
// Retrieve existing service record by nameVersionId
Service serviceDB = this.getServiceByModelUUID(service.getModelUUID());
if (serviceDB == null) {
// Check to see if a record with the same modelInvariantId already exists. This tells us that a previous version exists and we can copy its recipe Record for the new service record.
serviceInvariantDB = this.getServiceByInvariantUUID(service.getModelInvariantUUID());
// Save the new Service record
this.getSession ().save (service);
}
if(serviceInvariantDB != null){ // existing modelInvariantId was found.
// copy the recipe record with the matching invariant id. We will duplicate this for the new service record
List<ServiceRecipe> serviceRecipes = getServiceRecipes(serviceInvariantDB.getModelUUID());
if(serviceRecipes != null && ! serviceRecipes.isEmpty()){
for(ServiceRecipe serviceRecipe : serviceRecipes){
if(serviceRecipe != null){
// Fetch the service record that we just added. We do this so we can extract its Id column value, this will be the foreign key we use in the service recipe table.
Service newService = this.getServiceByModelUUID(service.getModelUUID());
// Create a new ServiceRecipe record based on the existing one we just copied from the DB.
ServiceRecipe newServiceRecipe = new ServiceRecipe();
newServiceRecipe.setAction(serviceRecipe.getAction());
newServiceRecipe.setDescription(serviceRecipe.getDescription());
newServiceRecipe.setOrchestrationUri(serviceRecipe.getOrchestrationUri());
newServiceRecipe.setRecipeTimeout(serviceRecipe.getRecipeTimeout());
newServiceRecipe.setServiceParamXSD(serviceRecipe.getServiceParamXSD());
newServiceRecipe.setServiceModelUUID(newService.getModelUUID());
newServiceRecipe.setVersion(serviceRecipe.getVersion());
// Check recipe does not exist before inserting
ServiceRecipe recipe = getServiceRecipeByModelUUID(newServiceRecipe.getServiceModelUUID(), newServiceRecipe.getAction());
// Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
if(recipe == null){
this.getSession ().save (newServiceRecipe);
}
}
}
}
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateService", null);
}
}
public void saveOrUpdateVfModule (VfModule vfModule) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save or update VF Module with VF Model Name " + vfModule.getModelName());
VfModule vfModuleInvariantDB = null;
try {
LOGGER.debug("heat template id = " + vfModule.getHeatTemplateArtifactUUId() + ", vol template id = "+ vfModule.getVolHeatTemplateArtifactUUId());
LOGGER.debug(vfModule.toString());
} catch (Exception e) {
LOGGER.debug("unable to print vfmodule " + e.getMessage(), e);
}
try {
VfModule existing = this.getVfModuleByModelUUID(vfModule.getModelUUID());
if (existing == null) {
// Check to see if a record with the same modelInvariantId already exists. This tells us that a previous version exists and we can copy its recipe Record for the new service record.
vfModuleInvariantDB = this.getVfModuleByModelInvariantUuid(vfModule.getModelInvariantUUID());
LOGGER.debug("No existing entry found, attempting to save...");
this.getSession ().save (vfModule);
} else {
try {
LOGGER.debug("Found an existing vf module!\n" + existing.toString());
} catch (Exception e) {
LOGGER.debug("unable to print vfmodule2 " + e.getMessage(), e);
}
}
if(vfModuleInvariantDB != null){ // existing modelInvariantId was found.
// copy the recipe record with the matching invariant id. We will duplicate this for the new service record
List<VnfComponentsRecipe> vfRecipes = getVnfComponentRecipes(vfModuleInvariantDB.getModelUUID());
if(vfRecipes != null && ! vfRecipes.isEmpty()){
for(VnfComponentsRecipe vfRecipe : vfRecipes){
if(vfRecipe != null){
// Fetch the service record that we just added. We do this so we can extract its Id column value, this will be the foreign key we use in the service recipe table.
VfModule newRecipe = this.getVfModuleByModelUUID(vfModule.getModelUUID());
// Create a new ServiceRecipe record based on the existing one we just copied from the DB.
VnfComponentsRecipe newVnfRecipe = new VnfComponentsRecipe();
newVnfRecipe.setAction(vfRecipe.getAction());
newVnfRecipe.setDescription(vfRecipe.getDescription());
newVnfRecipe.setOrchestrationUri(vfRecipe.getOrchestrationUri());
newVnfRecipe.setRecipeTimeout(vfRecipe.getRecipeTimeout());
newVnfRecipe.setVnfComponentParamXSD(vfRecipe.getVnfComponentParamXSD());
newVnfRecipe.setVfModuleModelUUId(newRecipe.getModelUUID());
newVnfRecipe.setVersion(vfRecipe.getVersion());
newVnfRecipe.setVnfComponentType(vfRecipe.getVnfComponentType());
newVnfRecipe.setVnfType(vfRecipe.getVnfType());
// Check recipe does not exist before inserting
// VnfComponentsRecipe recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
List<VnfComponentsRecipe> recipe = getVnfComponentRecipes(newVnfRecipe.getVfModuleModelUUId());
// Save the new recipe record in the service_recipe table and associate it to the new service record that we just added.
// if(recipe == null){
this.getSession ().save (newVnfRecipe);
// }
}
}
}
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModule", null);
}
}
public void saveOrUpdateVfModuleCustomization (VfModuleCustomization vfModuleCustomization) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VF Module Customization with VF Customization Model Name UUID " + vfModuleCustomization.getVfModuleModelUuid());
try {
LOGGER.debug("env id = " + vfModuleCustomization.getHeatEnvironmentArtifactUuid() + ", vol Env=" + vfModuleCustomization.getVolEnvironmentArtifactUuid());
LOGGER.debug(vfModuleCustomization.toString());
} catch (Exception e) {
LOGGER.debug("unable to print vfmodulecust " + e.getMessage(), e);
}
try {
VfModuleCustomization existing = this.getVfModuleCustomizationByModelCustomizationId(vfModuleCustomization.getModelCustomizationUuid());
if (existing == null) {
LOGGER.debug("No existing entry found, attempting to save...");
this.getSession ().save (vfModuleCustomization);
} else {
try {
LOGGER.debug("Found an existing vf module customization entry\n" + existing.toString());
} catch (Exception e) {
LOGGER.debug("unable to print vfmodulecust2 " + e.getMessage(), e);
}
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVfModuleCustomization", null);
}
}
@Deprecated
public HeatNestedTemplate getNestedHeatTemplate(int parentTemplateId, int childTemplateId) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get nested Heat template with PerentId-Child Id "
+ parentTemplateId +"-"+childTemplateId);
try {
HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
// nestedTemplate.setParentTemplateId (parentTemplateId);
// nestedTemplate.setChildTemplateId (childTemplateId);
return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
}
}
// 1707 version
public HeatNestedTemplate getNestedHeatTemplate(String parentTemplateId, String childTemplateId) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get nested Heat template with PerentId="
+ parentTemplateId +", ChildId="+childTemplateId);
try {
HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
nestedTemplate.setParentTemplateId (parentTemplateId);
nestedTemplate.setChildTemplateId (childTemplateId);
return (HeatNestedTemplate)session.get (HeatNestedTemplate.class,nestedTemplate);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNestedHeatTemplate", null);
}
}
@Deprecated
public void saveNestedHeatTemplate (int parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
/*
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save nested Heat template with name "
+ childTemplate.getTemplateName ());
try {
saveHeatTemplate(childTemplate, childTemplate.getParameters());
if (getNestedHeatTemplate(parentTemplateId,childTemplate.getId()) == null) {
HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
nestedTemplate.setParentTemplateId (parentTemplateId);
nestedTemplate.setChildTemplateId (childTemplate.getId ());
nestedTemplate.setProviderResourceFile (yamlFile);
session.save (nestedTemplate);
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
}
*/
}
// 1707
public void saveNestedHeatTemplate (String parentTemplateId, HeatTemplate childTemplate, String yamlFile) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save nested Heat template with name "
+ childTemplate.getTemplateName () + ",parentId=" + parentTemplateId + ",childId=" + childTemplate.getArtifactUuid() + ", providerResourceFile=" + yamlFile);
try {
saveHeatTemplate(childTemplate, childTemplate.getParameters());
if (getNestedHeatTemplate(parentTemplateId,childTemplate.getArtifactUuid()) == null) {
HeatNestedTemplate nestedTemplate = new HeatNestedTemplate ();
nestedTemplate.setParentTemplateId (parentTemplateId);
nestedTemplate.setChildTemplateId (childTemplate.getArtifactUuid ());
nestedTemplate.setProviderResourceFile (yamlFile);
session.flush();
session.save (nestedTemplate);
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveNestedHeatTemplate", null);
}
}
@Deprecated
public HeatFiles getHeatFiles(int vnfResourceId,String fileName,String asdcResourceName, String version) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getHeatFiles with name " + fileName
+ " and vnfResourceID "
+ vnfResourceId
// + " and ASDC resource name "
+ asdcResourceName
+ " and version "
+ version);
String hql = "FROM HeatFiles WHERE fileName = :fileName AND vnfResourceId = :vnfResourceId AND asdcResourceName = :asdcResourceName AND version = :version";
Query query = getSession ().createQuery (hql);
query.setParameter ("fileName", fileName);
query.setParameter ("vnfResourceId", vnfResourceId);
query.setParameter ("asdcResourceName", asdcResourceName);
query.setParameter ("version", version);
@SuppressWarnings("unchecked")
HeatFiles heatFilesResult = null;
try {
heatFilesResult = (HeatFiles) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for fileName=" + fileName + " and vnfResourceId=" + vnfResourceId + " and asdcResourceName=" + asdcResourceName + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for fileName=" + fileName);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for fileName=" + fileName + " and vnfResourceId=" + vnfResourceId + " and asdcResourceName=" + asdcResourceName + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for fileName=" + fileName);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: fileName='" + fileName + "', vnfResourceId='" + vnfResourceId + "' and asdcResourceName=" + asdcResourceName + " and version=" + version + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for fileName=" + fileName + " and vnfResourceId=" + vnfResourceId + " and asdcResourceName=" + asdcResourceName + " and version=" + version, "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for fileName=" + fileName);
throw e;
}
// See if something came back.
if (heatFilesResult == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
return null;
}
// Name + Version is unique, so should only be one element
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
return heatFilesResult;
}
public HeatFiles getHeatFiles(String artifactUuid) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - getHeatFiles with artifactUuid " + artifactUuid);
String hql = "FROM HeatFiles WHERE artifactUuid = :artifactUuid";
Query query = getSession ().createQuery (hql);
query.setParameter ("artifactUuid", artifactUuid);
@SuppressWarnings("unchecked")
HeatFiles heatFilesResult = null;
try {
heatFilesResult = (HeatFiles) query.uniqueResult ();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: artifactUuid='" + artifactUuid );
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for artifactUuid=" + artifactUuid);
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while searching for: artifactUuid='" + artifactUuid + " " + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception searching for artifactUuid=" + artifactUuid, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for artifactUuid=" + artifactUuid);
throw he;
} catch (Exception e) {
LOGGER.debug("Generic Exception - while searching for: artifactUuid='" + artifactUuid + " " + e.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception searching for artifactUuid=" + artifactUuid , "", "", MsoLogger.ErrorCode.DataError, "Generic exception searching for artifactUuid=" + artifactUuid);
throw e;
}
// See if something came back.
if (heatFilesResult == null) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. HeatFiles not found", "CatalogDB", "getHeatFiles", null);
return null;
}
// Name + Version is unique, so should only be one element
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatFiles", null);
return heatFilesResult;
}
public void saveHeatFiles (HeatFiles childFile) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat File with name "
+ childFile.getFileName());
try {
// HeatFiles heatFiles = getHeatFiles (childFile.getVnfResourceId(), childFile.getFileName(), childFile.getAsdcResourceName (),childFile.getVersion());
HeatFiles heatFiles = getHeatFiles (childFile.getArtifactUuid());
if (heatFiles == null) {
// asdc_heat_files_save
this.getSession ().save (childFile);
} else {
/* replaced 'heatFiles' by 'childFile'
Based on following comment:
It must be childFile.setId instead of heatFiles.setId, we must return the ID if it exists in DB.
*/
childFile.setArtifactUuid(heatFiles.getArtifactUuid());
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveHeatFiles", null);
}
}
@Deprecated
public void saveVfModuleToHeatFiles (int parentVfModuleId, HeatFiles childFile) {
/*
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
+ childFile.getFileName());
try {
saveHeatFiles (childFile);
VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
vfModuleToHeatFile.setVfModuleId(parentVfModuleId);
vfModuleToHeatFile.setHeatFilesId(childFile.getId());
session.save (vfModuleToHeatFile);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
}
*/
}
public void saveVfModuleToHeatFiles (String parentVfModuleId, HeatFiles childFile) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save Heat File to VFmodule link "
+ childFile.getFileName());
try {
saveHeatFiles (childFile);
VfModuleToHeatFiles checkExistingEntry = this.getVfModuleToHeatFilesEntry(parentVfModuleId, childFile.getArtifactUuid());
if (checkExistingEntry == null) {
VfModuleToHeatFiles vfModuleToHeatFile = new VfModuleToHeatFiles ();
vfModuleToHeatFile.setVfModuleModelUuid(parentVfModuleId);
vfModuleToHeatFile.setHeatFilesArtifactUuid(childFile.getArtifactUuid());
session.flush();
session.save (vfModuleToHeatFile);
} else {
LOGGER.debug("**Found existing VfModuleToHeatFiles entry for " + checkExistingEntry.toString());
LOGGER.debug("No need to save...");
}
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveVfModuleToHeatFiles", null);
}
}
/**
* Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
*
* @param networkType
* @param action
* @param serviceType
* @return NetworkRecipe object or null if none found
*/
public NetworkResource getNetworkResourceByModelUuid(String modelUUID) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get network resource with modelUUID " + modelUUID);
try {
String hql = "FROM NetworkResource WHERE modelUUID=:modelUUID";
Query query = getSession ().createQuery (hql);
query.setParameter (MODEL_UUID, modelUUID);
@SuppressWarnings("unchecked")
List <NetworkResource> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} catch (Exception e) {
LOGGER.debug("Error trying to find Network Resource with " + modelUUID +", " + e.getMessage(),e);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelUuid", null);
}
return null;
}
/**
* Return a Network recipe that matches a given NETWORK_TYPE, ACTION, and, if specified, SERVICE_TYPE
*
* @param networkType
* @param action
* @param serviceType
* @return NetworkRecipe object or null if none found
*/
public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get network recipe with network type " + networkType
+ " and action "
+ action
+ " and service type "
+ serviceType);
try {
String hql;
if (serviceType == null) {
hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType IS NULL ";
} else {
hql = "FROM NetworkRecipe WHERE networkType = :networkType AND action = :action AND serviceType = :serviceType ";
}
Query query = getSession ().createQuery (hql);
query.setParameter (NETWORK_TYPE, networkType);
query.setParameter (ACTION, action);
if (serviceType != null) {
query.setParameter ("serviceType", serviceType);
}
@SuppressWarnings("unchecked")
List <NetworkRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
}
}
/**
* Return a Network recipe that matches a given MODEL_NAME and ACTION
*
* @param modelName
* @param action
* @return NetworkRecipe object or null if none found
*/
public NetworkRecipe getNetworkRecipe (String modelName, String action) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName
+ " and action "
+ action
);
try {
String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND action = :action";
Query query = getSession ().createQuery (hql);
query.setParameter (MODEL_NAME, modelName);
query.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <NetworkRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null);
}
}
/**
* Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID
*
* @param networkType
* @param action
* @param serviceType
* @return NetworkRecipe object or null if none found
*/
public NetworkResource getNetworkResourceByModelCustUuid(String modelCustomizationUuid) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get network resource with modelCustomizationUuid " + modelCustomizationUuid);
try {
String hql = "select n FROM NetworkResource n, NetworkResourceCustomization c WHERE n.modelUUID=c.networkResourceModelUuid and c.modelCustomizationUuid = :modelCustomizationUuid";
Query query = getSession ().createQuery (hql);
query.setParameter (MODEL_CUSTOMIZATION_UUID, modelCustomizationUuid);
@SuppressWarnings("unchecked")
List <NetworkResource> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} catch (Exception e) {
LOGGER.debug("Error trying to find Network Resource with " + modelCustomizationUuid +", " + e.getMessage(),e);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResourceByModelCustUuid", null);
}
return null;
}
/**
* Return a VnfComponents recipe that matches a given VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, and, if specified,
* SERVICE_TYPE
*
* @param vnfType
* @param vnfComponentType
* @param action
* @param serviceType
* @return VnfComponentsRecipe object or null if none found
*/
public VnfComponentsRecipe getVnfComponentsRecipe (String vnfType,
String vnfComponentType,
String action,
String serviceType) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Vnf Component recipe with network type " + vnfType
+ " and component type "
+ vnfComponentType
+ " and action "
+ action
+ " and service type "
+ serviceType);
try {
String hql;
if (serviceType == null) {
hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType IS NULL ";
} else {
hql = "FROM VnfComponentsRecipe WHERE vnfType = :vnfType AND vnfComponentType = :vnfComponentType AND action = :action AND serviceType = :serviceType ";
}
Query query = getSession ().createQuery (hql);
query.setParameter (VNF_TYPE, vnfType);
query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
query.setParameter (ACTION, action);
if (serviceType != null) {
query.setParameter ("serviceType", serviceType);
}
@SuppressWarnings("unchecked")
List <VnfComponentsRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipe", null);
}
}
/**
* Return a VnfComponents recipe that matches a given VF_MODULE_ID, VNF_COMPONENT_TYPE, ACTION
*
* @param vfModuleId
* @param vnfComponentType
* @param action
* @return VnfComponentsRecipe object or null if none found
*/
public VnfComponentsRecipe getVnfComponentsRecipeByVfModuleModelUUId (String vfModuleModelUUId,
String vnfComponentType,
String action) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Vnf Component recipe with vfModuleModelUUId " + vfModuleModelUUId
+ " and component type "
+ vnfComponentType
+ " and action "
+ action);
try {
String hql;
hql = "FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId AND vnfComponentType = :vnfComponentType AND action = :action ";
Query query = getSession ().createQuery (hql);
query.setParameter (VF_MODULE_MODEL_UUID, vfModuleModelUUId);
query.setParameter (VNF_COMPONENT_TYPE, vnfComponentType);
query.setParameter (ACTION, action);
@SuppressWarnings("unchecked")
List <VnfComponentsRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfComponentsRecipeByVfModuleModelUUId", null);
}
}
public List<VnfComponentsRecipe> getVnfComponentRecipes (String vfModuleModelUUId) {
StringBuilder hql = null;
hql = new StringBuilder ("FROM VnfComponentsRecipe WHERE vfModuleModelUUId = :vfModuleModelUUId");
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get Service recipe with vfModuleModelUUId " + vfModuleModelUUId);
Query query = getSession ().createQuery (hql.toString ());
query.setParameter ("vfModuleModelUUId", vfModuleModelUUId);
@SuppressWarnings("unchecked")
List <VnfComponentsRecipe> resultList = query.list ();
if (resultList.isEmpty ()) {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getVfModuleRecipes", null);
return Collections.EMPTY_LIST;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleRecipes", null);
return resultList;
}
public void saveOrUpdateVnfComponent (VnfComponent vnfComponent) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - save VnfComponent where vnfId="+ vnfComponent.getVnfId()+ " AND componentType="+ vnfComponent.getComponentType());
VnfComponent vnfComponentDb = this.getVnfComponent(vnfComponent.getVnfId(), vnfComponent.getComponentType());
try {
this.getSession ().save (vnfComponent);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfComponent", null);
}
}
/**
* Return a VfModule record that matches a given MODEL_NAME
*
* @param modelName
* @return VfModule object or null if none found
*/
public VfModule getVfModule (String modelName) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get vf module with model name " + modelName);
try {
String hql;
hql = "FROM VfModule WHERE modelName = :modelName";
Query query = getSession ().createQuery (hql);
query.setParameter (MODEL_NAME, modelName);
@SuppressWarnings("unchecked")
List <VfModule> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModule", null);
}
}
/**
* Return a VfModule record that matches a given MODEL_NAME
*
* @param modelName
* @return VfModule object or null if none found
*/
public VfModule getVfModuleByModelUUID (String modelUUID) {
long startTime = System.currentTimeMillis ();
LOGGER.debug ("Catalog database - get vf module with modelUUID " + modelUUID);
try {
String hql;
hql = "FROM VfModule WHERE modelUUID = :modelUUID";
Query query = getSession ().createQuery (hql);
query.setParameter (MODEL_UUID, modelUUID);
@SuppressWarnings("unchecked")
List <VfModule> resultList = query.list ();
if (resultList.isEmpty ()) {
return null;
}
Collections.sort (resultList, new MavenLikeVersioningComparator ());
Collections.reverse (resultList);
return resultList.get (0);
} finally {
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleByModelUUID", null);
}
}
/**
* Return a Service recipe that matches a given service ModelUUID and action
* (modelUUID) and ACTION
*
* @param modelUUID
* @param action
* @return ServiceRecipe object or null if none found
*/
public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Service recipe with modelUUID=" + modelUUID + " and action=" + action);
try {
String hql;
// based on the new SERVICE_RECIPE schema where SERVICE_MODEL_UUID == MODEL_UUID, a JOIN with the SERVICE table is no longer needed
// hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
// "SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
// "case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
// "FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
// "WHERE SR.serviceModelUUID = :modelUUID AND SR.action = :action";
hql = "FROM ServiceRecipe WHERE serviceModelUUID = :modelUUID AND action = :action";
Query query = getSession().createQuery(hql);
query.setParameter(MODEL_UUID, modelUUID);
query.setParameter(ACTION, action);
@SuppressWarnings("unchecked")
List<ServiceRecipe> recipeResultList = query.list();
if (recipeResultList.isEmpty()) {
LOGGER.debug("Catalog database - recipeResultList is null");
return null;
}
Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
Collections.reverse(recipeResultList);
LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
return recipeResultList.get(0);
} finally {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipeByModelUUID", null);
}
}
/**
* Return a Service recipe that matches a given SERVICE_NAME_VERSION_ID
* (MODEL_VERSION_ID) and ACTION
*
* @param modelVersionId
* @param action
* @return ServiceRecipe object or null if none found
*/
@Deprecated
public ServiceRecipe getServiceRecipe(String modelVersionId,
String action) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Service recipe with modeVersionId=" + modelVersionId
+ " and action=" + action);
try {
String hql;
// Note: Even with the implementation of the HQL JOIN below, the code for the two separate
// SELECTs will be retained/commented for now in the event some subsequent JOIN issue arises
// 1st query to get the Service record for the given SERVICE_NAME_VERSION_ID (MODEL_VERSION_ID)
/* hql = "FROM Service WHERE serviceNameVersionId = :serviceNameVersionId";
Query query = getSession().createQuery(hql);
query.setParameter(SERVICE_NAME_VERSION_ID, modelVersionId);
@SuppressWarnings("unchecked")
List<Service> serviceResultList = query.list();
if (serviceResultList.isEmpty()) {
LOGGER.debug("Catalog database - serviceResultList is null");
return null;
}
Collections.sort(serviceResultList, new MavenLikeVersioningComparator());
Collections.reverse(serviceResultList);
LOGGER.debug("Catalog database - serviceResultList contains " + serviceResultList.get(0).toString());
// 2nd query to get the ServiceRecipe record corresponding to the Service from the 1st query
hql = "FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID AND action = :action";
query = getSession().createQuery(hql);
// The SERVICE table 'id' field maps to the SERVICE_RECIPE table 'SERVICE_ID' field
query.setParameter(SERVICE_ID, serviceResultList.get(0).getId());
query.setParameter(ACTION, action);
*/
// The following SELECT performs a JOIN across the SERVICE and SERVICE_RECIPE tables. It required a new
// CTR in the ServiceRecipe Class to populate that object (the other option was to parse the Object[]
// returned by createQuery() and manually populate the ServiceRecipe object). Two of the 'int' fields in the
// SERVICE_RECIPE DB schema (the timeouts) permit NULL values which required some additional code in the
// SELECT to generate a default of 0 (needed by the CTR) in the cases where the value is NULL.
hql = "SELECT new ServiceRecipe(SR.id, SR.serviceModelUUID, SR.action, SR.description, " +
"SR.orchestrationUri, SR.serviceParamXSD, case when SR.recipeTimeout is null then 0 else SR.recipeTimeout end, " +
"case when SR.serviceTimeoutInterim is null then 0 else SR.serviceTimeoutInterim end, SR.created) " +
"FROM Service as S RIGHT OUTER JOIN S.recipes SR " +
"WHERE SR.serviceModelUUID = S.id AND S.serviceNameVersionId = :serviceNameVersionId AND SR.action = :action";
Query query = getSession().createQuery(hql);
query.setParameter(MODEL_UUID, modelVersionId);
query.setParameter(ACTION, action);
@SuppressWarnings("unchecked")
List<ServiceRecipe> recipeResultList = query.list();
if (recipeResultList.isEmpty()) {
LOGGER.debug("Catalog database - recipeResultList is null");
return null;
}
Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
Collections.reverse(recipeResultList);
LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
return recipeResultList.get(0);
} finally {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
}
}
/**
* Return a Model recipe that matches a given MODEL_TYPE, MODEL_VERSION_ID, ACTION
* Note: This method is not currently used but was retained in the event the
* architecture moves back to a MODEL/MODEL_RECIPE structure.
*
* @param modelType
* @param modelVersionId
* @param action
* @return ModelRecipe object or null if none found
*/
public ModelRecipe getModelRecipe(String modelType,
String modelVersionId,
String action) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - get Model recipe with modelType=" + modelType
+ " and modeVersionId=" + modelVersionId
+ " and action=" + action);
try {
String hql;
// TBD - at some point it would be desirable to figure out how to do a HQL JOIN across
// the MODEL and MODEL_RECIPE tables in HQL instead of 2 separate queries.
// There seems to be 2 issues: formatting a hql query that executes successfully
// and then being able to generate a result that will fit into the ModelRecipe class.
// 1st query to get the Model record for the given MODEL_TYPE and MODEL_VERSION_ID
hql = "FROM Model WHERE modelType = :modelType AND modelVersionId = :modelVersionId";
Query query = getSession().createQuery(hql);
query.setParameter(MODEL_TYPE, modelType);
query.setParameter(MODEL_VERSION_ID, modelVersionId);
@SuppressWarnings("unchecked")
List<Model> modelResultList = query.list();
if (modelResultList.isEmpty()) {
LOGGER.debug("Catalog database - modelResultList is null");
return null;
}
Collections.sort(modelResultList, new MavenLikeVersioningComparator());
Collections.reverse(modelResultList);
LOGGER.debug("Catalog database - modelResultList contains " + modelResultList.get(0).toString());
// 2nd query to get the ModelRecipe record corresponding to the Model from the 1st query
hql = "FROM ModelRecipe WHERE modelId = :modelId AND action = :action";
query = getSession().createQuery(hql);
// The MODEL table 'id' field maps to the MODEL_RECIPE table 'MODEL_ID' field
query.setParameter(MODEL_ID, modelResultList.get(0).getId());
query.setParameter(ACTION, action);
@SuppressWarnings("unchecked")
List<ModelRecipe> recipeResultList = query.list();
if (recipeResultList.isEmpty()) {
LOGGER.debug("Catalog database - recipeResultList is null");
return null;
}
Collections.sort(recipeResultList, new MavenLikeVersioningComparator());
Collections.reverse(recipeResultList);
LOGGER.debug("Catalog database - recipeResultList contains " + recipeResultList.get(0).toString());
return recipeResultList.get(0);
} finally {
LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getModelRecipe", null);
}
}
/**
* Verify the health of the DB.
*
* @return boolean value indicate whether DB is healthy
*/
public boolean healthCheck () {
long startTime = System.currentTimeMillis ();
Session session = this.getSession ();
// Query query = session.createQuery (" from ActiveRequests ");
Query query = session.createSQLQuery (" show tables ");
List<?> list = query.list();
LOGGER.debug("healthCheck CatalogDB - Successful");
return true;
}
public < E > E executeQuerySingleRow(String hql, HashMap<String, String> variables, boolean retry) {
long startTime = System.currentTimeMillis();
LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
Query query = getSession().createQuery(hql);
StringBuilder sb = new StringBuilder();
if (variables != null) {
for(Map.Entry<String, String> entry : variables.entrySet()){
sb.append(entry.getKey() + "=" + entry.getValue() + "\n");
query.setParameter(entry.getKey(), entry.getValue());
}
}
LOGGER.debug("Variables:\n" + sb.toString());
E theObject = null;
try {
theObject = (E) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for " + hql, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for " + hql );
throw nure;
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
if (retry) {
LOGGER.debug("***WILL RETRY***");
return this.executeQuerySingleRow(hql, variables, false);
} else {
throw he;
}
} catch (Exception e) {
LOGGER.debug("Generic Exception - while performing '" + hql + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
if (retry) {
LOGGER.debug("***WILL RETRY***");
return this.executeQuerySingleRow(hql, variables, false);
} else {
throw e;
}
}
if (theObject == null) {
LOGGER.debug("Returning null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
} else {
LOGGER.debug("Returning an Object");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
}
return theObject;
}
public < E > List<E> executeQueryMultipleRows(String hql, HashMap<String, String> variables, boolean retry) {
long startTime = System.currentTimeMillis ();
LOGGER.debug("Catalog database - executeQuery: " + hql + (retry ? ", retry=true" : ", retry=false"));
Query query = getSession().createQuery(hql);
StringBuilder sb = new StringBuilder();
if (variables != null) {
for(Map.Entry<String, String> entry : variables.entrySet()){
sb.append(entry.getKey() + "=" + entry.getValue()+ "\n");
query.setParameter(entry.getKey(), entry.getValue());
}
}
LOGGER.debug("Variables:\n" + sb.toString());
List<E> theObjects = null;
try {
theObjects = (List<E>) query.list ();
} catch (org.hibernate.HibernateException he) {
LOGGER.debug("Hibernate Exception - while performing " + hql + "; he message:" + he.getMessage());
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Hibernate exception while performing hql=" + hql, "", "", MsoLogger.ErrorCode.DataError, "Hibernate exception searching for hql=" + hql);
if (retry) {
LOGGER.debug("***WILL RETRY***");
return this.executeQuerySingleRow(hql, variables, false);
} else {
throw he;
}
} catch (Exception e) {
LOGGER.debug("Generic Exception - while performing '" + hql + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " Generic exception performing " + hql, "", "", MsoLogger.ErrorCode.DataError, "Generic exception performing " + hql);
if (retry) {
LOGGER.debug("***WILL RETRY***");
return this.executeQuerySingleRow(hql, variables, false);
} else {
throw e;
}
}
if (theObjects == null) {
LOGGER.debug("Returning null");
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "executeQuerySingleRow", null);
} else {
try {
LOGGER.debug("Returning theObjects:" + theObjects.size());
} catch (Exception e) {
LOGGER.debug("Returning theObjects",e);
}
LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "executeQuerySingleRow", null);
}
return theObjects;
}
}
|