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
|
/*-
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.be.components.impl;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.distribution.engine.INotificationData;
import org.openecomp.sdc.be.components.distribution.engine.VfModuleArtifactPayload;
import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.path.ForwardingPathValidator;
import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.datamodel.ServiceRelations;
import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionReqInfo;
import org.openecomp.sdc.be.impl.ForwardingPathUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
import org.openecomp.sdc.be.model.DistributionTransitionEnum;
import org.openecomp.sdc.be.model.GroupInstance;
import org.openecomp.sdc.be.model.GroupInstanceProperty;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceAuditData;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fj.data.Either;
@org.springframework.stereotype.Component("serviceBusinessLogic")
public class ServiceBusinessLogic extends ComponentBusinessLogic {
private static final String STATUS_SUCCESS_200 = "200";
private static final String STATUS_DEPLOYED = "DEPLOYED";
@Autowired
private IElementOperation elementDao;
@Autowired
private IDistributionEngine distributionEngine;
@Autowired
private AuditCassandraDao auditCassandraDao;
@Autowired
private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
@Autowired
private GroupBusinessLogic groupBusinessLogic;
@Autowired
private ICacheMangerOperation cacheManagerOperation;
@Autowired
private ServiceDistributionValidation serviceDistributionValidation;
private static final Logger log = LoggerFactory.getLogger(ServiceBusinessLogic.class);
private static final String INITIAL_VERSION = "0.1";
@Autowired
private ForwardingPathOperation forwardingPathOperation;
@Autowired
private ForwardingPathValidator forwardingPathValidator;
public ServiceBusinessLogic() {
log.debug("ServiceBusinessLogic started");
}
public Either<Service, ResponseFormat> changeServiceDistributionState(String serviceId, String state, LifecycleChangeInfoWithAction commentObj, User user) {
Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "change Service Distribution State", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
log.debug("check request state");
Either<DistributionTransitionEnum, ResponseFormat> validateEnum = validateTransitionEnum(state, user);
if (validateEnum.isRight()) {
return Either.right(validateEnum.right().value());
}
DistributionTransitionEnum distributionTransition = validateEnum.left().value();
AuditingActionEnum auditAction = distributionTransition == DistributionTransitionEnum.APPROVE ? AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_APPROV : AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REJECT;
Either<String, ResponseFormat> commentResponse = validateComment(commentObj, user, auditAction);
if (commentResponse.isRight()) {
return Either.right(commentResponse.right().value());
}
String comment = commentResponse.left().value();
Either<Service, ResponseFormat> validateService = validateServiceDistributionChange(user, serviceId, auditAction, comment);
if (validateService.isRight()) {
return Either.right(validateService.right().value());
}
Service service = validateService.left().value();
Either<User, ResponseFormat> validateUser = validateUserDistributionChange(user, service, auditAction, comment);
if (validateUser.isRight()) {
return Either.right(validateUser.right().value());
}
user = validateUser.left().value();
// lock resource
Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service, "ChangeServiceDistributionState");
if (lockResult.isRight()) {
ResponseFormat responseFormat = lockResult.right().value();
createAudit(user, auditAction, comment, service, responseFormat);
return Either.right(responseFormat);
}
try {
DistributionStatusEnum newState;
if (distributionTransition == DistributionTransitionEnum.APPROVE) {
newState = DistributionStatusEnum.DISTRIBUTION_APPROVED;
} else {
newState = DistributionStatusEnum.DISTRIBUTION_REJECTED;
}
Either<Service, StorageOperationStatus> result = toscaOperationFacade.updateDistributionStatus(service, user, newState);
if (result.isRight()) {
titanDao.rollback();
BeEcompErrorManager.getInstance().logBeSystemError("ChangeServiceDistributionState");
log.debug("service {} is change destribuation status failed", service.getUniqueId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, service.getVersion(), service.getName());
createAudit(user, auditAction, comment, service, responseFormat);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
titanDao.commit();
Service updatedService = result.left().value();
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
log.debug("audit before sending response");
componentsUtils.auditComponent(responseFormat, user, updatedService, auditAction, ComponentTypeEnum.SERVICE, ResourceAuditData.newBuilder().build(), comment);
return Either.left(result.left().value());
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
public Either<List<Map<String, Object>>, ResponseFormat> getComponentAuditRecords(String componentVersion, String componentUUID, String userId) {
Either<User, ResponseFormat> resp = validateUserExists(userId, "get Component Audit Records", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
Either<List<Map<String, Object>>, ActionStatus> result;
try {
// Certified Version
if (componentVersion.endsWith(".0")) {
Either<List<ResourceAdminEvent>, ActionStatus> eitherAuditingForCertified = auditCassandraDao.getByServiceInstanceId(componentUUID);
if (eitherAuditingForCertified.isLeft()) {
result = Either.left(getAuditingFieldsList(eitherAuditingForCertified.left().value()));
} else {
result = Either.right(eitherAuditingForCertified.right().value());
}
}
// Uncertified Version
else {
result = getAuditRecordsForUncertifiedComponent(componentUUID, componentVersion);
}
} catch (Exception e) {
log.debug("get Audit Records failed with exception {}", e);
result = Either.right(ActionStatus.GENERAL_ERROR);
}
if (result.isRight()) {
return Either.right(componentsUtils.getResponseFormat(result.right().value()));
} else {
return Either.left(result.left().value());
}
}
private Either<List<Map<String, Object>>, ActionStatus> getAuditRecordsForUncertifiedComponent(String componentUUID, String componentVersion) {
// First Query
Either<List<ResourceAdminEvent>, ActionStatus> eitherprevVerAudit = auditCassandraDao.getAuditByServiceIdAndPrevVersion(componentUUID, componentVersion);
if (eitherprevVerAudit.isRight()) {
return Either.right(eitherprevVerAudit.right().value());
}
// Second Query
Either<List<ResourceAdminEvent>, ActionStatus> eitherCurrVerAudit = auditCassandraDao.getAuditByServiceIdAndCurrVersion(componentUUID, componentVersion);
if (eitherCurrVerAudit.isRight()) {
return Either.right(eitherCurrVerAudit.right().value());
}
List<Map<String, Object>> prevVerAuditList = getAuditingFieldsList(eitherprevVerAudit.left().value());
List<Map<String, Object>> currVerAuditList = getAuditingFieldsList(eitherCurrVerAudit.left().value());
List<Map<String, Object>> duplicateElements = new ArrayList<Map<String, Object>>();
duplicateElements.addAll(prevVerAuditList);
duplicateElements.retainAll(currVerAuditList);
List<Map<String, Object>> joinedNonDuplicatedList = new ArrayList<Map<String, Object>>();
joinedNonDuplicatedList.addAll(prevVerAuditList);
joinedNonDuplicatedList.removeAll(duplicateElements);
joinedNonDuplicatedList.addAll(currVerAuditList);
return Either.left(joinedNonDuplicatedList);
}
private List<Map<String, Object>> getAuditingFieldsList(List<? extends AuditingGenericEvent> prevVerAuditList) {
List<Map<String, Object>> prevVerAudit = new ArrayList<Map<String, Object>>();
for (AuditingGenericEvent auditEvent : prevVerAuditList) {
auditEvent.fillFields();
prevVerAudit.add(auditEvent.getFields());
}
return prevVerAudit;
}
/**
* createService
*
* @param service
* - Service
* @param user
* - modifier data (userId)
* @return Either<Service, responseFormat>
*/
public Either<Service, ResponseFormat> createService(Service service, User user) {
// get user details
Either<User, ResponseFormat> eitherCreator = validateUser(user, "Create Service", service, AuditingActionEnum.CREATE_RESOURCE, false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
user = eitherCreator.left().value();
// validate user role
Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, service, new ArrayList<Role>(), AuditingActionEnum.CREATE_RESOURCE, null);
if (validateRes.isRight()) {
return Either.right(validateRes.right().value());
}
service.setCreatorUserId(user.getUserId());
// warn on overridden fields
checkFieldsForOverideAttampt(service);
// enrich object
log.debug("enrich service with version and state");
service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
service.setVersion(INITIAL_VERSION);
service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel());
service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
Either<Service, ResponseFormat> createServiceResponse = validateServiceBeforeCreate(service, user, AuditingActionEnum.CREATE_RESOURCE);
if (createServiceResponse.isRight()) {
return createServiceResponse;
}
return createServiceByDao(service, AuditingActionEnum.CREATE_RESOURCE, user);
}
private void checkFieldsForOverideAttampt(Service service) {
checkComponentFieldsForOverrideAttempt(service);
if (service.getDistributionStatus() != null) {
log.info("Distribution Status cannot be defined by user. This field will be overridden by the application");
}
}
private Either<Service, ResponseFormat> createServiceByDao(Service service, AuditingActionEnum actionEnum, User user) {
log.debug("send service {} to dao for create", service.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
Either<Boolean, ResponseFormat> lockResult = lockComponentByName(service.getSystemName(), service, "Create Service");
if (lockResult.isRight()) {
ResponseFormat responseFormat = lockResult.right().value();
componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
return Either.right(responseFormat);
}
log.debug("System name locked is {}, status = {}", service.getSystemName(), lockResult);
try {
createMandatoryArtifactsData(service, user);
createServiceApiArtifactsData(service, user);
setToscaArtifactsPlaceHolders(service, user);
Either<Resource, ResponseFormat> genericServiceEither = fetchAndSetDerivedFromGenericType(service);
if (genericServiceEither.isRight())
return Either.right(genericServiceEither.right().value());
generateAndAddInputsFromGenericTypeProperties(service, genericServiceEither.left().value());
Either<Service, StorageOperationStatus> dataModelResponse = toscaOperationFacade.createToscaComponent(service);
// service created successfully!!!
if (dataModelResponse.isLeft()) {
log.debug("Service created successfully!!!");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
ASDCKpiApi.countCreatedServicesKPI();
return Either.left(dataModelResponse.left().value());
}
ResponseFormat responseFormat = componentsUtils.getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), service, ComponentTypeEnum.SERVICE);
log.debug("audit before sending response");
componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
return Either.right(responseFormat);
} finally {
graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Service);
}
}
@SuppressWarnings("unchecked")
private void createServiceApiArtifactsData(Service service, User user) {
// create mandatory artifacts
// TODO it must be removed after that artifact uniqueId creation will be
// moved to ArtifactOperation
String serviceUniqueId = service.getUniqueId();
Map<String, ArtifactDefinition> artifactMap = service.getServiceApiArtifacts();
if (artifactMap == null)
artifactMap = new HashMap<String, ArtifactDefinition>();
Map<String, Object> serviceApiArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceApiArtifacts();
List<String> exludeServiceCategory = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeServiceCategory();
List<CategoryDefinition> categories = service.getCategories();
boolean isCreateArtifact = true;
if (categories != null && exludeServiceCategory != null && !exludeServiceCategory.isEmpty()) {
for (String exlude : exludeServiceCategory) {
if (exlude.equalsIgnoreCase(categories.get(0).getName())) {
isCreateArtifact = false;
break;
}
}
}
if (serviceApiArtifacts != null && isCreateArtifact) {
Set<String> keys = serviceApiArtifacts.keySet();
for (String serviceApiArtifactName : keys) {
Map<String, Object> artifactInfoMap = (Map<String, Object>) serviceApiArtifacts.get(serviceApiArtifactName);
ArtifactDefinition artifactDefinition = createArtifactDefinition(serviceUniqueId, serviceApiArtifactName, artifactInfoMap, user, true);
artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.SERVICE_API);
artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
}
service.setServiceApiArtifacts(artifactMap);
}
}
private Either<Service, ResponseFormat> validateServiceBeforeCreate(Service service, User user, AuditingActionEnum actionEnum) {
Either<Boolean, ResponseFormat> validationResponse = validateServiceFieldsBeforeCreate(user, service, actionEnum);
if (validationResponse.isRight()) {
return Either.right(validationResponse.right().value());
}
service.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
service.setContactId(service.getContactId().toLowerCase());
// Generate invariant UUID - must be here and not in operation since it
// should stay constant during clone
String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
service.setInvariantUUID(invariantUUID);
return Either.left(service);
}
private Either<Boolean, ResponseFormat> validateServiceFieldsBeforeCreate(User user, Service service, AuditingActionEnum actionEnum) {
Either<Boolean, ResponseFormat> componentsFieldsValidation = validateComponentFieldsBeforeCreate(user, service, actionEnum);
if (componentsFieldsValidation.isRight()) {
return componentsFieldsValidation;
}
log.debug("validate service name uniqueness");
Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, service, actionEnum);
if (serviceNameUniquenessValidation.isRight()) {
return serviceNameUniquenessValidation;
}
log.debug("validate category");
Either<Boolean, ResponseFormat> categoryValidation = validateServiceCategory(user, service, actionEnum);
if (categoryValidation.isRight()) {
return categoryValidation;
}
// validate project name (ProjectCode) - mandatory in service
log.debug("validate projectName");
Either<Boolean, ResponseFormat> projectCodeValidation = validateProjectCode(user, service, actionEnum);
if (projectCodeValidation.isRight()) {
return projectCodeValidation;
}
log.debug("validate service type");
Either<Boolean, ResponseFormat> serviceTypeValidation = validateServiceTypeAndCleanup(user, service, actionEnum);
if (serviceTypeValidation.isRight()) {
return serviceTypeValidation;
}
log.debug("validate service role");
Either<Boolean, ResponseFormat> serviceRoleValidation = validateServiceRoleAndCleanup(user, service, actionEnum);
if (serviceRoleValidation.isRight()) {
return serviceRoleValidation;
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateServiceCategory(User user, Service service, AuditingActionEnum actionEnum) {
log.debug("validate Service category");
if (service.getCategories() == null || service.getCategories().size() == 0) {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
return Either.right(errorResponse);
}
Either<Boolean, ResponseFormat> validatCategory = validateServiceCategory(service.getCategories());
if (validatCategory.isRight()) {
ResponseFormat responseFormat = validatCategory.right().value();
componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
return Either.right(responseFormat);
}
return Either.left(true);
}
public Either<Map<String, Boolean>, ResponseFormat> validateServiceNameExists(String serviceName, String userId) {
Either<User, ResponseFormat> resp = validateUserExists(userId, "validate Service Name Exists", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateComponentNameUniqueness(serviceName, null, ComponentTypeEnum.SERVICE);
// DE242223
titanDao.commit();
if (dataModelResponse.isLeft()) {
Map<String, Boolean> result = new HashMap<>();
result.put("isValid", dataModelResponse.left().value());
log.debug("validation was successfully performed.");
return Either.left(result);
}
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()));
return Either.right(responseFormat);
}
public void setElementDao(IElementOperation elementDao) {
this.elementDao = elementDao;
}
public void setCassandraAuditingDao(AuditCassandraDao auditingDao) {
this.auditCassandraDao = auditingDao;
}
public ArtifactsBusinessLogic getArtifactBl() {
return artifactsBusinessLogic;
}
public void setArtifactBl(ArtifactsBusinessLogic artifactBl) {
this.artifactsBusinessLogic = artifactBl;
}
public Either<Service, ResponseFormat> updateServiceMetadata(String serviceId, Service serviceUpdate, User user) {
Either<User, ResponseFormat> eitherCreator = validateUser(user, "updateServiceMetadata", serviceUpdate, null, false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
user = eitherCreator.left().value();
// validate user role
Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, serviceUpdate, new ArrayList<>(), null, null);
if (validateRes.isRight()) {
return Either.right(validateRes.right().value());
}
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
}
Service currentService = storageStatus.left().value();
if (!ComponentValidationUtils.canWorkOnComponent(currentService, user.getUserId())) {
log.info("Restricted operation for user: {}, on service: {}", user.getUserId(), currentService.getCreatorUserId());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
Either<Service, ResponseFormat> validationRsponse = validateAndUpdateServiceMetadata(user, currentService, serviceUpdate);
if (validationRsponse.isRight()) {
log.info("service update metadata: validations field.");
return validationRsponse;
}
Service serviceToUpdate = validationRsponse.left().value();
// lock resource
Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, currentService, "Update Service Metadata");
if (lockResult.isRight()) {
return Either.right(lockResult.right().value());
}
try {
Either<Service, StorageOperationStatus> updateResponse = toscaOperationFacade.updateToscaElement(serviceToUpdate);
if (updateResponse.isRight()) {
titanDao.rollback();
BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
titanDao.commit();
return Either.left(updateResponse.left().value());
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
public Either<Set<String>, ResponseFormat> deleteForwardingPaths(String serviceId, Set<String> pathIdsToDelete, User user, boolean lock) {
Service serviceToDelete = initServiceToDeletePaths(serviceId, pathIdsToDelete);
Either<User, ResponseFormat> eitherCreator = validateUser(user, "deleteForwardingPaths", serviceToDelete, null, false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
user = eitherCreator.left().value();
// validate user role
Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, serviceToDelete, new ArrayList<>(), null, null);
if (validateRes.isRight()) {
return Either.right(validateRes.right().value());
}
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
}
Service service = storageStatus.left().value();
Either<Set<String>, StorageOperationStatus> result = null;
if (lock) {
Either<Boolean, ResponseFormat> lockResult = lockComponent(service.getUniqueId(), service, "Delete Forwarding Path on Service");
if (lockResult.isRight()) {
titanDao.rollback();
return Either.right(componentsUtils.getResponseFormat(componentsUtils
.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
}
}
try{
result = forwardingPathOperation.deleteForwardingPath(service ,pathIdsToDelete);
if (result.isRight()) {
log.debug("Failed to lock service {}. Response is {}. ", service.getName(), result.right().value());
titanDao.rollback();
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE)));
}
titanDao.commit();
log.debug("The service with system name {} locked. ", service.getSystemName());
} catch (Exception e){
log.error("Exception occurred during delete forwarding path : {}", e.getMessage(), e);
titanDao.rollback();
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
graphLockOperation.unlockComponent(service.getUniqueId(), NodeTypeEnum.Service);
}
return Either.left(result.left().value());
}
private Service initServiceToDeletePaths(String serviceId, Collection<String> pathIdsToDelete) {
Service serviceToDelete = new Service();
serviceToDelete.setUniqueId(serviceId);
serviceToDelete.setForwardingPaths(new HashMap<>());
pathIdsToDelete.forEach(pathIdToDelete -> serviceToDelete.getForwardingPaths().put(pathIdToDelete, new ForwardingPathDataDefinition()));
return serviceToDelete;
}
public Either<Service, ResponseFormat> updateForwardingPath(String serviceId, Service serviceUpdate, User user, boolean lock) {
return createOrUpdateForwardingPath(serviceId, serviceUpdate, user, true,"updateForwardingPath", lock);
}
public Either<Service, ResponseFormat> createForwardingPath(String serviceId, Service serviceUpdate, User user, boolean lock) {
return createOrUpdateForwardingPath(serviceId, serviceUpdate, user, false, "createForwardingPath", lock);
}
private ForwardingPathDataDefinition getTrimmedValues(ForwardingPathDataDefinition path){
ForwardingPathDataDefinition dataDefinition = new ForwardingPathDataDefinition(path.getName());
dataDefinition.setName(Strings.nullToEmpty(path.getName()).trim());
dataDefinition.setProtocol(Strings.nullToEmpty(path.getProtocol()).trim());
dataDefinition.setDestinationPortNumber(Strings.nullToEmpty(path.getDestinationPortNumber()).trim());
dataDefinition.setUniqueId(path.getUniqueId());
dataDefinition.setPathElements(path.getPathElements());
dataDefinition.setDescription(path.getDescription());
dataDefinition.setToscaResourceName(path.getToscaResourceName());
return dataDefinition;
}
private Either<Service, ResponseFormat> createOrUpdateForwardingPath(String serviceId, Service serviceUpdate, User user, boolean isUpdate, String errorContext, boolean lock) {
Either<Service, ResponseFormat> eitherCreator1 = validateUserAndRole(serviceUpdate, user, errorContext);
if (eitherCreator1 != null) return eitherCreator1;
Map<String, ForwardingPathDataDefinition> forwardingPaths = serviceUpdate.getForwardingPaths();
Map<String, ForwardingPathDataDefinition> trimmedForwardingPaths =
forwardingPaths.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
entry -> new ForwardingPathDataDefinition(getTrimmedValues(entry.getValue()))));
Either<Boolean, ResponseFormat> booleanResponseFormatEither = forwardingPathValidator.validateForwardingPaths(trimmedForwardingPaths.values(),
serviceId, isUpdate);
if(booleanResponseFormatEither.isRight()){
return Either.right(booleanResponseFormatEither.right().value());
}
Either<Service, StorageOperationStatus> serviceStorageOperationStatusEither = toscaOperationFacade.getToscaElement(serviceId);
if(serviceStorageOperationStatusEither.isRight()){
StorageOperationStatus errorStatus = serviceStorageOperationStatusEither.right().value();
log.debug("Failed to fetch service information by service id, error {}", errorStatus);
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
}
Service storedService = serviceStorageOperationStatusEither.left().value();
Set<ForwardingPathDataDefinition> forwardingPathDataDefinitions = trimmedForwardingPaths.entrySet().stream().map(entry -> entry.getValue())
.collect(Collectors.toSet());
Either<ForwardingPathDataDefinition, StorageOperationStatus> result;
Either<Component, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade.getLatestByName(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME);
if (forwardingPathOrigin.isRight()) {
StorageOperationStatus errorStatus = forwardingPathOrigin.right().value();
log.debug("Failed to fetch normative forwarding path resource by tosca name, error {}", errorStatus);
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
}
Component component = forwardingPathOrigin.left().value();
final String toscaResourceName;
if ( component.getComponentType() == ComponentTypeEnum.RESOURCE) {
toscaResourceName = ((Resource) component).getToscaResourceName();
} else {
toscaResourceName = "";
}
Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
lockResult =
lockComponent(storedService.getUniqueId(), storedService, "Add or Update Forwarding Path on Service");
if (lockResult.isRight()) {
log.debug("Failed to lock service {}. Response is {}. ", storedService.getName(),
lockResult.right().value().getFormattedMessage());
return Either.right(lockResult.right().value());
} else {
log.debug("The service with system name {} locked. ", storedService.getSystemName());
}
}
Map<String, ForwardingPathDataDefinition> resultMap = new HashMap<>();
try {
trimmedForwardingPaths.values().forEach(fp -> fp.setToscaResourceName(toscaResourceName));
try {
for (ForwardingPathDataDefinition forwardingPathDataDefinition : trimmedForwardingPaths.values()) {
if (isUpdate) {
result = forwardingPathOperation.updateForwardingPath(serviceId, forwardingPathDataDefinition);
} else {
result = forwardingPathOperation.addForwardingPath(serviceId, forwardingPathDataDefinition);
}
if (result.isRight()) {
titanDao.rollback();
return Either.right(componentsUtils.getResponseFormat(
componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.SERVICE),
""));
} else {
ForwardingPathDataDefinition fpDataDefinition = result.left().value();
resultMap.put(fpDataDefinition.getUniqueId(), forwardingPathDataDefinition);
}
}
} catch (Exception e) {
titanDao.rollback();
log.error("Exception occurred during add or update forwarding path property values: {}", e.getMessage(),
e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
titanDao.commit();
} finally {
if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedService.getUniqueId(), NodeTypeEnum.Service);
}
}
Service service = createServiceWithForwardingPathForResponse(serviceId, resultMap);
return Either.left(service);
}
private Service createServiceWithForwardingPathForResponse(String serviceId, Map<String,ForwardingPathDataDefinition> forwardingPathDataDefinitionMap) {
Service service = new Service();
service.setUniqueId(serviceId);
service.setForwardingPaths(forwardingPathDataDefinitionMap);
return service;
}
private Either<Service, ResponseFormat> validateUserAndRole(Service serviceUpdate, User user, String errorContext) {
Either<User, ResponseFormat> eitherCreator = validateUser(user, errorContext, serviceUpdate, null, false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
user = eitherCreator.left().value();
// validate user role
Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, serviceUpdate, new ArrayList<>(), null, null);
if (validateRes.isRight()) {
return Either.right(validateRes.right().value());
}
return null;
}private Either<Service, ResponseFormat> validateAndUpdateServiceMetadata(User user, Service currentService, Service serviceUpdate) {
boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentService.getVersion());
Either<Boolean, ResponseFormat> response = validateAndUpdateCategory(user, currentService, serviceUpdate, hasBeenCertified, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
String creatorUserIdUpdated = serviceUpdate.getCreatorUserId();
String creatorUserIdCurrent = currentService.getCreatorUserId();
if (creatorUserIdUpdated != null && !creatorUserIdCurrent.equals(creatorUserIdUpdated)) {
log.info("update srvice: recived request to update creatorUserId to {} the field is not updatable ignoring.", creatorUserIdUpdated);
}
String creatorFullNameUpdated = serviceUpdate.getCreatorFullName();
String creatorFullNameCurrent = currentService.getCreatorFullName();
if (creatorFullNameUpdated != null && !creatorFullNameCurrent.equals(creatorFullNameUpdated)) {
log.info("update srvice: recived request to update creatorFullName to {} the field is not updatable ignoring.", creatorFullNameUpdated);
}
String lastUpdaterUserIdUpdated = serviceUpdate.getLastUpdaterUserId();
String lastUpdaterUserIdCurrent = currentService.getLastUpdaterUserId();
if (lastUpdaterUserIdUpdated != null && !lastUpdaterUserIdCurrent.equals(lastUpdaterUserIdUpdated)) {
log.info("update srvice: recived request to update lastUpdaterUserId to {} the field is not updatable ignoring.", lastUpdaterUserIdUpdated);
}
String lastUpdaterFullNameUpdated = serviceUpdate.getLastUpdaterFullName();
String lastUpdaterFullNameCurrent = currentService.getLastUpdaterFullName();
if (lastUpdaterFullNameUpdated != null && !lastUpdaterFullNameCurrent.equals(lastUpdaterFullNameUpdated)) {
log.info("update srvice: recived request to update lastUpdaterFullName to {} the field is not updatable ignoring.", lastUpdaterFullNameUpdated);
}
response = validateAndUpdateServiceName(user, currentService, serviceUpdate, hasBeenCertified, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
DistributionStatusEnum distributionStatusUpdated = serviceUpdate.getDistributionStatus();
DistributionStatusEnum distributionStatusCurrent = currentService.getDistributionStatus();
if (distributionStatusUpdated != null && !distributionStatusUpdated.name().equals(distributionStatusCurrent != null ? distributionStatusCurrent.name() : null)) {
log.info("update service: received request to update distributionStatus to {}. the field is read only, ignoring.", distributionStatusUpdated);
}
if (serviceUpdate.getProjectCode() != null) {
response = validateAndUpdateProjectCode(user, currentService, serviceUpdate, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
}
response = validateAndUpdateIcon(user, currentService, serviceUpdate, hasBeenCertified, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
Long creationDateUpdated = serviceUpdate.getCreationDate();
Long creationDateCurrent = currentService.getCreationDate();
if (creationDateUpdated != null && !creationDateCurrent.equals(creationDateUpdated)) {
log.info("update srvice: recived request to update creationDate to {} the field is not updatable ignoring.", creationDateUpdated);
}
String versionUpdated = serviceUpdate.getVersion();
String versionCurrent = currentService.getVersion();
if (versionUpdated != null && !versionCurrent.equals(versionUpdated)) {
log.info("update srvice: recived request to update version to {} the field is not updatable ignoring.", versionUpdated);
}
response = validateAndUpdateDescription(user, currentService, serviceUpdate, hasBeenCertified, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
response = validateAndUpdateTags(user, currentService, serviceUpdate, hasBeenCertified, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
response = validateAndUpdateContactId(user, currentService, serviceUpdate, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
Long lastUpdateDateUpdated = serviceUpdate.getLastUpdateDate();
Long lastUpdateDateCurrent = currentService.getLastUpdateDate();
if (lastUpdateDateUpdated != null && !lastUpdateDateCurrent.equals(lastUpdateDateUpdated)) {
log.info("update srvice: recived request to update lastUpdateDate to {} the field is not updatable ignoring.", lastUpdateDateUpdated);
}
LifecycleStateEnum lifecycleStateUpdated = serviceUpdate.getLifecycleState();
LifecycleStateEnum lifecycleStateCurrent = currentService.getLifecycleState();
if (lifecycleStateUpdated != null && !lifecycleStateCurrent.name().equals(lifecycleStateUpdated.name())) {
log.info("update srvice: recived request to update lifecycleState to {} the field is not updatable ignoring.", lifecycleStateUpdated);
}
Boolean isHighestVersionUpdated = serviceUpdate.isHighestVersion();
Boolean isHighestVersionCurrent = currentService.isHighestVersion();
if (isHighestVersionUpdated != null && !isHighestVersionCurrent.equals(isHighestVersionUpdated)) {
log.info("update srvice: recived request to update isHighestVersion to {} the field is not updatable ignoring.", isHighestVersionUpdated);
}
String uuidUpdated = serviceUpdate.getUUID();
String uuidCurrent = currentService.getUUID();
if (!uuidCurrent.equals(uuidUpdated)) {
log.info("update service: recived request to update uuid to {} the field is not updatable ignoring.", uuidUpdated);
}
response = validateAndUpdateServiceType(user, currentService, serviceUpdate, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
response = validateAndUpdateServiceRole(user, currentService, serviceUpdate, null);
if (response.isRight()) {
ResponseFormat errorResponse = response.right().value();
return Either.right(errorResponse);
}
String currentInvariantUuid = currentService.getInvariantUUID();
String updatedInvariantUuid = serviceUpdate.getInvariantUUID();
if ((updatedInvariantUuid != null) && (!updatedInvariantUuid.equals(currentInvariantUuid))) {
log.warn("Product invariant UUID is automatically set and cannot be updated");
serviceUpdate.setInvariantUUID(currentInvariantUuid);
}
validateAndUpdateEcompNaming(currentService, serviceUpdate);
currentService.setEnvironmentContext(serviceUpdate.getEnvironmentContext());
return Either.left(currentService);
}
private void validateAndUpdateEcompNaming(Service currentService, Service serviceUpdate) {
Boolean isEcompoGeneratedCurr = currentService.isEcompGeneratedNaming();
Boolean isEcompoGeneratedUpdate = serviceUpdate.isEcompGeneratedNaming();
if (isEcompoGeneratedUpdate != null && isEcompoGeneratedCurr.equals(isEcompoGeneratedUpdate)) {
currentService.setEcompGeneratedNaming(isEcompoGeneratedUpdate);
}
String namingPolicyUpd = serviceUpdate.getNamingPolicy();
if (!currentService.isEcompGeneratedNaming()) {
if (ValidationUtils.validateStringNotEmpty(namingPolicyUpd)) {
log.warn("NamingPolicy must be empty for EcompGeneratedNaming=false");
currentService.setNamingPolicy("");
} else {
currentService.setNamingPolicy(namingPolicyUpd);
}
}else{
currentService.setNamingPolicy(namingPolicyUpd);
}
}
private Either<Boolean, ResponseFormat> validateAndUpdateContactId(User user, Service currentService, Service serviceUpdate, AuditingActionEnum audatingAction) {
String contactIdUpdated = serviceUpdate.getContactId();
String contactIdCurrent = currentService.getContactId();
if (!contactIdCurrent.equals(contactIdUpdated)) {
Either<Boolean, ResponseFormat> validatContactId = validateContactId(user, serviceUpdate, audatingAction);
if (validatContactId.isRight()) {
ResponseFormat errorRespons = validatContactId.right().value();
return Either.right(errorRespons);
}
currentService.setContactId(contactIdUpdated.toLowerCase());
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateAndUpdateTags(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
List<String> tagsUpdated = serviceUpdate.getTags();
List<String> tagsCurrent = currentService.getTags();
if (tagsUpdated == null || tagsUpdated.isEmpty()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_TAGS);
componentsUtils.auditComponentAdmin(responseFormat, user, serviceUpdate, audatingAction, ComponentTypeEnum.SERVICE);
return Either.right(responseFormat);
}
if (!(tagsCurrent.containsAll(tagsUpdated) && tagsUpdated.containsAll(tagsCurrent))) {
Either<Boolean, ResponseFormat> validatResponse = validateTagsListAndRemoveDuplicates(user, serviceUpdate, audatingAction);
if (validatResponse.isRight()) {
ResponseFormat errorRespons = validatResponse.right().value();
return Either.right(errorRespons);
}
currentService.setTags(tagsUpdated);
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
String descriptionUpdated = serviceUpdate.getDescription();
String descriptionCurrent = currentService.getDescription();
if (!descriptionCurrent.equals(descriptionUpdated)) {
Either<Boolean, ResponseFormat> validateDescriptionResponse = validateDescriptionAndCleanup(user, serviceUpdate, audatingAction);
if (validateDescriptionResponse.isRight()) {
ResponseFormat errorRespons = validateDescriptionResponse.right().value();
return Either.right(errorRespons);
}
currentService.setDescription(serviceUpdate.getDescription());
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateAndUpdateProjectCode(User user, Service currentService, Service serviceUpdate, AuditingActionEnum audatingAction) {
String projectCodeUpdated = serviceUpdate.getProjectCode();
String projectCodeCurrent = currentService.getProjectCode();
if (!projectCodeCurrent.equals(projectCodeUpdated)) {
Either<Boolean, ResponseFormat> validatProjectCodeResponse = validateProjectCode(user, serviceUpdate, audatingAction);
if (validatProjectCodeResponse.isRight()) {
ResponseFormat errorRespons = validatProjectCodeResponse.right().value();
return Either.right(errorRespons);
}
currentService.setProjectCode(projectCodeUpdated);
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateAndUpdateIcon(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
String iconUpdated = serviceUpdate.getIcon();
String iconCurrent = currentService.getIcon();
if (!iconCurrent.equals(iconUpdated)) {
if (!hasBeenCertified) {
Either<Boolean, ResponseFormat> validatIconResponse = validateIcon(user, serviceUpdate, audatingAction);
if (validatIconResponse.isRight()) {
ResponseFormat errorRespons = validatIconResponse.right().value();
return Either.right(errorRespons);
}
currentService.setIcon(iconUpdated);
} else {
log.info("icon {} cannot be updated once the service has been certified once.", iconUpdated);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_ICON_CANNOT_BE_CHANGED);
return Either.right(errorResponse);
}
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateAndUpdateServiceName(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum auditingAction) {
String serviceNameUpdated = serviceUpdate.getName();
String serviceNameCurrent = currentService.getName();
if (!serviceNameCurrent.equals(serviceNameUpdated)) {
if (!hasBeenCertified) {
Either<Boolean, ResponseFormat> validatServiceNameResponse = validateComponentName(user, serviceUpdate, auditingAction);
if (validatServiceNameResponse.isRight()) {
ResponseFormat errorRespons = validatServiceNameResponse.right().value();
return Either.right(errorRespons);
}
Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, serviceUpdate, auditingAction);
if (serviceNameUniquenessValidation.isRight()) {
return serviceNameUniquenessValidation;
}
currentService.setName(serviceNameUpdated);
currentService.getComponentMetadataDefinition().getMetadataDataDefinition().setNormalizedName(ValidationUtils.normaliseComponentName(serviceNameUpdated));
currentService.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName(ValidationUtils.convertToSystemName(serviceNameUpdated));
} else {
log.info("service name {} cannot be updated once the service has been certified once.", serviceNameUpdated);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NAME_CANNOT_BE_CHANGED);
return Either.right(errorResponse);
}
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateAndUpdateServiceType(User user, Service currentService, Service updatedService, AuditingActionEnum auditingAction) {
String updatedServiceType = updatedService.getServiceType();
String currentServiceType = currentService.getServiceType();
if (!currentServiceType.equals(updatedServiceType)) {
Either<Boolean, ResponseFormat> validateServiceType = validateServiceTypeAndCleanup(user, updatedService , auditingAction);
if (validateServiceType.isRight()) {
ResponseFormat errorResponse = validateServiceType.right().value();
componentsUtils.auditComponentAdmin(errorResponse, user, updatedService, auditingAction, ComponentTypeEnum.SERVICE);
return Either.right(errorResponse);
}
currentService.setServiceType(updatedServiceType);
}
return Either.left(true);
}
protected Either<Boolean, ResponseFormat> validateServiceTypeAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
String serviceType = ((Service)component).getServiceType();
if (serviceType != null){
serviceType = cleanUpText(serviceType);
Either<Boolean, ResponseFormat> validateServiceType = validateServiceType(serviceType);
if (validateServiceType.isRight()) {
ResponseFormat responseFormat = validateServiceType.right().value();
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, ComponentTypeEnum.SERVICE);
return Either.right(responseFormat);
}
return Either.left(true);
} else {
return Either.left(false);
}
}
private Either<Boolean, ResponseFormat> validateServiceType(String serviceType) {
if (serviceType.equals("")){
return Either.left(true);
} else {
if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
log.info("service type exceeds limit.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH);
return Either.right(errorResponse);
}
if (!ValidationUtils.validateIsEnglish(serviceType)) {
log.info("service type is not valid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_SERVICE_TYPE);
return Either.right(errorResponse);
}
return Either.left(true);
}
}
private Either<Boolean, ResponseFormat> validateAndUpdateServiceRole(User user, Service currentService, Service updatedService, AuditingActionEnum auditingAction) {
String updatedServiceRole = updatedService.getServiceRole();
String currentServiceRole = currentService.getServiceRole();
if (!currentServiceRole.equals(updatedServiceRole)) {
Either<Boolean, ResponseFormat> validateServiceRole = validateServiceRoleAndCleanup(user, updatedService , auditingAction);
if (validateServiceRole.isRight()) {
ResponseFormat errorResponse = validateServiceRole.right().value();
componentsUtils.auditComponentAdmin(errorResponse, user, updatedService, auditingAction, ComponentTypeEnum.SERVICE);
return Either.right(errorResponse);
}
currentService.setServiceRole(updatedServiceRole);
}
return Either.left(true);
}
protected Either<Boolean, ResponseFormat> validateServiceRoleAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
String serviceRole = ((Service)component).getServiceRole();
if (serviceRole != null){
serviceRole = cleanUpText(serviceRole);
Either<Boolean, ResponseFormat> validateServiceRole = validateServiceRole(serviceRole);
if (validateServiceRole.isRight()) {
ResponseFormat responseFormat = validateServiceRole.right().value();
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, ComponentTypeEnum.SERVICE);
return Either.right(responseFormat);
}
return Either.left(true);
} else {
return Either.left(false);
}
}
private Either<Boolean, ResponseFormat> validateServiceRole(String serviceRole) {
if (serviceRole.equals("")){
return Either.left(true);
} else {
if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
log.info("service role exceeds limit.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_ROLE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_ROLE_MAX_LENGTH);
return Either.right(errorResponse);
}
if (!ValidationUtils.validateIsEnglish(serviceRole)) {
log.info("service role is not valid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_SERVICE_ROLE);
return Either.right(errorResponse);
}
return Either.left(true);
}
}
private Either<Boolean, ResponseFormat> validateAndUpdateCategory(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
List<CategoryDefinition> categoryUpdated = serviceUpdate.getCategories();
List<CategoryDefinition> categoryCurrent = currentService.getCategories();
Either<Boolean, ResponseFormat> validatCategoryResponse = validateServiceCategory(user, serviceUpdate, audatingAction);
if (validatCategoryResponse.isRight()) {
ResponseFormat errorRespons = validatCategoryResponse.right().value();
return Either.right(errorRespons);
}
if (!categoryCurrent.get(0).getName().equals(categoryUpdated.get(0).getName())) {
if (!hasBeenCertified) {
currentService.setCategories(categoryUpdated);
} else {
log.info("category {} cannot be updated once the service has been certified once.", categoryUpdated);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CATEGORY_CANNOT_BE_CHANGED);
return Either.right(errorResponse);
}
}
return Either.left(true);
}
public Either<Boolean, ResponseFormat> validateServiceCategory(List<CategoryDefinition> list) {
if (list != null) {
if (list.size() > 1) {
log.debug("Must be only one category for service");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.SERVICE.getValue());
return Either.right(responseFormat);
}
CategoryDefinition category = list.get(0);
if (category.getSubcategories() != null) {
log.debug("Subcategories cannot be defined for service");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CANNOT_CONTAIN_SUBCATEGORY);
return Either.right(responseFormat);
}
if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
log.debug("Resource category is empty");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
return Either.right(responseFormat);
}
log.debug("validating service category {} against valid categories list", list);
Either<List<CategoryDefinition>, ActionStatus> categorys = elementDao.getAllServiceCategories();
if (categorys.isRight()) {
log.debug("failed to retrive service categories from Titan");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(categorys.right().value());
return Either.right(responseFormat);
}
List<CategoryDefinition> categoryList = categorys.left().value();
for (CategoryDefinition value : categoryList) {
if (value.getName().equals(category.getName())) {
return Either.left(true);
}
}
log.debug("Category {} is not part of service category group. Service category valid values are {}", list, categoryList);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue()));
}
return Either.left(false);
}
public Either<ServiceRelations, ResponseFormat> getServiceComponentsRelations(String serviceId, User user) {
Either<Service, ResponseFormat> serviceResponseFormatEither = getService(serviceId, user);
if (serviceResponseFormatEither.isRight()){
return Either.right(serviceResponseFormatEither.right().value());
}
final ServiceRelations serviceRelations = new ForwardingPathUtils().convertServiceToServiceRelations(serviceResponseFormatEither.left().value());
return Either.left(serviceRelations);
}public ResponseFormat deleteService(String serviceId, User user) {
ResponseFormat responseFormat;
String ecompErrorContext = "delete service";
Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
if (eitherCreator.isRight()) {
return eitherCreator.right().value();
}
user = eitherCreator.left().value();
Either<Service, StorageOperationStatus> serviceStatus = toscaOperationFacade.getToscaElement(serviceId);
if (serviceStatus.isRight()) {
log.debug("failed to get service {}", serviceId);
return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceStatus.right().value()), "");
}
Service service = serviceStatus.left().value();
StorageOperationStatus result = StorageOperationStatus.OK;
Either<Boolean, ResponseFormat> lockResult = lockComponent(service, "Mark service to delete");
if (lockResult.isRight()) {
result = StorageOperationStatus.GENERAL_ERROR;
return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
}
try {
result = markComponentToDelete(service);
if (result.equals(StorageOperationStatus.OK)) {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
} else {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, service.getName());
}
return responseFormat;
} finally {
if (result == null || !result.equals(StorageOperationStatus.OK)) {
log.warn("operation failed. do rollback");
BeEcompErrorManager.getInstance().logBeSystemError("Delete Service");
titanDao.rollback();
} else {
log.debug("operation success. do commit");
titanDao.commit();
}
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
public ResponseFormat deleteServiceByNameAndVersion(String serviceName, String version, User user) {
ResponseFormat responseFormat;
String ecompErrorContext = "delete service";
Either<User, ResponseFormat> validateEmptyResult = validateUserNotEmpty(user, ecompErrorContext);
if (validateEmptyResult.isRight()) {
return validateEmptyResult.right().value();
}
Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
if (eitherCreator.isRight()) {
return eitherCreator.right().value();
}
user = eitherCreator.left().value();
Either<Service, ResponseFormat> getResult = getServiceByNameAndVersion(serviceName, version, user.getUserId());
if (getResult.isRight()) {
return getResult.right().value();
}
Service service = getResult.left().value();
StorageOperationStatus result = StorageOperationStatus.OK;
Either<Boolean, ResponseFormat> lockResult = lockComponent(service, "Mark service to delete");
if (lockResult.isRight()) {
result = StorageOperationStatus.GENERAL_ERROR;
return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
}
try {
result = markComponentToDelete(service);
if (result.equals(StorageOperationStatus.OK)) {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
} else {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, service.getName());
}
return responseFormat;
} finally {
if (result == null || !result.equals(StorageOperationStatus.OK)) {
log.warn("operation failed. do rollback");
BeEcompErrorManager.getInstance().logBeSystemError("Delete Service");
titanDao.rollback();
} else {
log.debug("operation success. do commit");
titanDao.commit();
}
graphLockOperation.unlockComponent(service.getUniqueId(), NodeTypeEnum.Service);
}
}
public Either<Service, ResponseFormat> getService(String serviceId, User user) {
String ecompErrorContext = "Get service";
Either<User, ResponseFormat> validateEmptyResult = validateUserNotEmpty(user, ecompErrorContext);
if (validateEmptyResult.isRight()) {
return Either.right(validateEmptyResult.right().value());
}
Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
log.debug("failed to get service by id {}", serviceId);
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), serviceId));
}
if(!(storageStatus.left().value() instanceof Service)){
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND), serviceId));
}
Service service = storageStatus.left().value();
return Either.left(service);
}
public Either<Service, ResponseFormat> getServiceByNameAndVersion(String serviceName, String serviceVersion, String userId) {
Either<User, ResponseFormat> resp = validateUserExists(userId, "get Service By Name And Version", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, serviceVersion);
if (storageStatus.isRight()) {
log.debug("failed to get service by name {} and version {}", serviceName, serviceVersion);
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), serviceName));
}
Service service = storageStatus.left().value();
return Either.left(service);
}
@SuppressWarnings("unchecked")
private void createMandatoryArtifactsData(Service service, User user) {
// create mandatory artifacts
// TODO it must be removed after that artifact uniqueId creation will be
// moved to ArtifactOperation
String serviceUniqueId = service.getUniqueId();
Map<String, ArtifactDefinition> artifactMap = service.getArtifacts();
if (artifactMap == null)
artifactMap = new HashMap<String, ArtifactDefinition>();
Map<String, Object> informationalServiceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getInformationalServiceArtifacts();
List<String> exludeServiceCategory = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeServiceCategory();
String category = service.getCategories().get(0).getName();
boolean isCreateArtifact = true;
if (category != null && exludeServiceCategory != null && !exludeServiceCategory.isEmpty()) {
for (String exlude : exludeServiceCategory) {
if (exlude.equalsIgnoreCase(category)) {
isCreateArtifact = false;
break;
}
}
}
if (informationalServiceArtifacts != null && isCreateArtifact) {
Set<String> keys = informationalServiceArtifacts.keySet();
for (String informationalServiceArtifactName : keys) {
Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalServiceArtifacts.get(informationalServiceArtifactName);
ArtifactDefinition artifactDefinition = createArtifactDefinition(serviceUniqueId, informationalServiceArtifactName, artifactInfoMap, user, false);
artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
}
service.setArtifacts(artifactMap);
}
}
private ArtifactDefinition createArtifactDefinition(String serviceId, String logicalName, Map<String, Object> artifactInfoMap, User user, Boolean isServiceApi) {
ArtifactDefinition artifactInfo = artifactsBusinessLogic.createArtifactPlaceHolderInfo(serviceId, logicalName, artifactInfoMap, user, ArtifactGroupTypeEnum.INFORMATIONAL);
if (isServiceApi) {
artifactInfo.setMandatory(false);
artifactInfo.setServiceApi(true);
}
return artifactInfo;
}
private Either<DistributionTransitionEnum, ResponseFormat> validateTransitionEnum(String distributionTransition, User user) {
DistributionTransitionEnum transitionEnum = null;
transitionEnum = DistributionTransitionEnum.getFromDisplayName(distributionTransition);
if (transitionEnum == null) {
BeEcompErrorManager.getInstance().logBeSystemError("Change Service Distribution");
log.info("state operation is not valid. operations allowed are: {}", DistributionTransitionEnum.valuesAsString());
ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
return Either.right(error);
}
return Either.left(transitionEnum);
}
private Either<String, ResponseFormat> validateComment(LifecycleChangeInfoWithAction comment, User user, AuditingActionEnum auditAction) {
String data = comment.getUserRemarks();
if (data == null || data.trim().isEmpty()) {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Change Service Distribution");
log.debug("user comment cannot be empty or null.");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
data = ValidationUtils.removeNoneUtf8Chars(data);
data = ValidationUtils.removeHtmlTags(data);
data = ValidationUtils.normaliseWhitespace(data);
data = ValidationUtils.stripOctets(data);
if (!ValidationUtils.validateLength(data, ValidationUtils.COMMENT_MAX_LENGTH)) {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Change Service Distribution");
log.debug("user comment exceeds limit.");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, "comment", String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
}
if (!ValidationUtils.validateIsEnglish(data)) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
return Either.left(data);
}
private Either<Service, ResponseFormat> validateServiceDistributionChange(User user, String serviceId, AuditingActionEnum auditAction, String comment) {
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceId);
log.debug("audit before sending response");
componentsUtils.auditComponent(responseFormat, user, auditAction, serviceId, ComponentTypeEnum.SERVICE, comment);
return Either.right(responseFormat);
}
Service service = storageStatus.left().value();
if (service.getLifecycleState() != LifecycleStateEnum.CERTIFIED) {
log.info("service {} is not available for distribution. Should be in certified state", service.getUniqueId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION, service.getVersion(), service.getName());
createAudit(user, auditAction, comment, service, responseFormat);
return Either.right(responseFormat);
}
return Either.left(service);
}
private Either<User, ResponseFormat> validateUserDistributionChange(User user, Service service, AuditingActionEnum auditAction, String comment) {
log.debug("get user from DB");
// get user details
Either<User, ResponseFormat> eitherCreator = validateUser(user, "Activate Distribution", service, auditAction, false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
user = eitherCreator.left().value();
// validate user role
List<Role> roles = new ArrayList<>();
roles.add(Role.ADMIN);
roles.add(Role.GOVERNOR);
roles.add(Role.OPS);
Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, service, roles, auditAction, comment);
if (validateRes.isRight()) {
return Either.right(validateRes.right().value());
}
return Either.left(user);
}
private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component, ResponseFormat responseFormat) {
log.debug("audit before sending response");
componentsUtils.auditComponent(responseFormat, user, component, auditAction, ComponentTypeEnum.SERVICE,
ResourceAuditData.newBuilder().state(component.getLifecycleState().name()).version(component.getVersion()).build(), comment);
}
private String getEnvNameFromConfiguration() {
String configuredEnvName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0);
log.trace("Update environment name to be {}", configuredEnvName);
return configuredEnvName;
}
public Either<String, ResponseFormat> activateServiceOnTenantEnvironment(String serviceId, String envId, User modifier, ServiceDistributionReqInfo data) {
Either<ActivationRequestInformation, ResponseFormat> activationRequestInformationEither = serviceDistributionValidation.validateActivateServiceRequest(serviceId, envId, modifier, data);
if (activationRequestInformationEither.isRight()) {
return Either.right(activationRequestInformationEither.right().value());
}
ActivationRequestInformation activationRequestInformation = activationRequestInformationEither.left().value();
Either<String, ResponseFormat> result = null;
ResponseFormat response = null;
String did = ThreadLocalsHolder.getUuid();
Service service = activationRequestInformation.getServiceToActivate();
StorageOperationStatus readyForDistribution = distributionEngine.verifyServiceHasDeploymentArtifacts(service);
if (readyForDistribution.equals(StorageOperationStatus.OK)) {
result = buildAndSendServiceNotification(service, envId, did, activationRequestInformation.getWorkloadContext(), modifier);
} else {
response = componentsUtils.getResponseFormatByDE(componentsUtils.convertFromStorageResponse(readyForDistribution), service.getName(), envId);
result = Either.right(response);
}
return result;
}
public Either<String, ResponseFormat> buildAndSendServiceNotification(Service service, String envId, String did, String workloadContext, User modifier) {
String envName = getEnvNameFromConfiguration();
INotificationData notificationData = distributionEngine.buildServiceForDistribution(service, did, workloadContext);
ActionStatus notifyServiceResponse = distributionEngine.notifyService(did, service, notificationData, envId, envName, modifier.getUserId(), modifier.getFullName());
if (notifyServiceResponse == ActionStatus.OK) {
return Either.left(did);
} else {
BeEcompErrorManager.getInstance().logBeSystemError("Activate Distribution - send notification");
log.debug("distributionEngine.notifyService response is: {}", notifyServiceResponse);
ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.INVALID_RESPONSE_FROM_PROXY);
return Either.right(error);
}
}
public Either<Service, ResponseFormat> activateDistribution(String serviceId, String envName, User modifier, HttpServletRequest request) {
Either<User, ResponseFormat> eitherCreator = validateUserExists(modifier.getUserId(), "activate Distribution", false);
if (eitherCreator.isRight()) {
return Either.right(eitherCreator.right().value());
}
User user = eitherCreator.left().value();
Either<Service, ResponseFormat> result = null;
ResponseFormat response = null;
Service updatedService = null;
String did = ThreadLocalsHolder.getUuid();
// DE194021
String configuredEnvName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0);
if (configuredEnvName != null && false == envName.equals(configuredEnvName)) {
log.trace("Update environment name to be {} instead of {}", configuredEnvName, envName);
envName = configuredEnvName;
}
// DE194021
ServletContext servletContext = request.getSession().getServletContext();
boolean isDistributionEngineUp = getHealthCheckBL(servletContext).isDistributionEngineUp(); // DE
if (!isDistributionEngineUp) {
BeEcompErrorManager.getInstance().logBeSystemError("Distribution Engine is DOWN");
log.debug("Distribution Engine is DOWN");
response = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
return Either.right(response);
}
Either<Service, StorageOperationStatus> serviceRes = toscaOperationFacade.getToscaElement(serviceId);
if (serviceRes.isRight()) {
log.debug("failed retrieving service");
response = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceRes.right().value(), ComponentTypeEnum.SERVICE), serviceId);
componentsUtils.auditComponent(response, user, null, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, ComponentTypeEnum.SERVICE,
ResourceAuditData.newBuilder().build(), did);
return Either.right(response);
}
Service service = serviceRes.left().value();
String dcurrStatus = service.getDistributionStatus().name();
String updatedStatus = dcurrStatus;
StorageOperationStatus readyForDistribution = distributionEngine.isReadyForDistribution(service, envName);
if (readyForDistribution.equals(StorageOperationStatus.OK)) {
INotificationData notificationData = distributionEngine.buildServiceForDistribution(service, did, null);
ActionStatus notifyServiceResponse = distributionEngine.notifyService(did, service, notificationData, envName, user.getUserId(), user.getFullName());
if (notifyServiceResponse == ActionStatus.OK) {
Either<Service, ResponseFormat> updateStateRes = updateDistributionStatusForActivation(service, user, DistributionStatusEnum.DISTRIBUTED);
if (updateStateRes.isLeft() && updateStateRes.left().value() != null) {
updatedService = updateStateRes.left().value();
updatedStatus = updatedService.getDistributionStatus().name();
} else {
// The response is not relevant
updatedService = service;
}
ASDCKpiApi.countActivatedDistribution();
response = componentsUtils.getResponseFormat(ActionStatus.OK);
result = Either.left(updatedService);
} else {
BeEcompErrorManager.getInstance().logBeSystemError("Activate Distribution - send notification");
log.debug("distributionEngine.notifyService response is: {}", notifyServiceResponse);
response = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
result = Either.right(response);
}
} else {
response = componentsUtils.getResponseFormatByDE(componentsUtils.convertFromStorageResponse(readyForDistribution), service.getName(), envName);
result = Either.right(response);
}
componentsUtils.auditComponent(response, user, service, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, ComponentTypeEnum.SERVICE,
ResourceAuditData.newBuilder().distributionStatus(dcurrStatus).build(),
ResourceAuditData.newBuilder().distributionStatus(updatedStatus).build(), service.getName(),
null, null, did);
return result;
}
// convert to private after deletion of temp url
public Either<Service, ResponseFormat> updateDistributionStatusForActivation(Service service, User user, DistributionStatusEnum state) {
Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "update Distribution Status For Activation", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
String serviceId = service.getUniqueId();
Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service, "updateDistributionStatusForActivation");
if (lockResult.isRight()) {
return Either.right(lockResult.right().value());
}
try {
Either<Service, StorageOperationStatus> result = toscaOperationFacade.updateDistributionStatus(service, user, state);
if (result.isRight()) {
titanDao.rollback();
BeEcompErrorManager.getInstance().logBeSystemError("updateDistributionStatusForActivation");
log.debug("service {} change distribution status failed", serviceId);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
titanDao.commit();
return Either.left(result.left().value());
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
public Either<Service, ResponseFormat> markDistributionAsDeployed(String serviceId, String did, User user) {
Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "mark Distribution As Deployed", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
log.debug("mark distribution deployed");
AuditingActionEnum auditAction = AuditingActionEnum.DISTRIBUTION_DEPLOY;
Either<Service, StorageOperationStatus> getServiceResponse = toscaOperationFacade.getToscaElement(serviceId);
if (getServiceResponse.isRight()) {
BeEcompErrorManager.getInstance().logBeComponentMissingError("markDistributionAsDeployed", ComponentTypeEnum.SERVICE.getValue(), serviceId);
log.debug("service {} not found", serviceId);
ResponseFormat responseFormat = auditDeployError(did, user, auditAction, null, componentsUtils.convertFromStorageResponse(getServiceResponse.right().value(), ComponentTypeEnum.SERVICE), "");
return Either.right(responseFormat);
}
Service service = getServiceResponse.left().value();
Either<User, ResponseFormat> validateRoleForDeploy = validateRoleForDeploy(did, user, auditAction, service);
if (validateRoleForDeploy.isRight()) {
return Either.right(validateRoleForDeploy.right().value());
}
user = validateRoleForDeploy.left().value();
return checkDistributionAndDeploy(did, user, auditAction, service);
}
public Either<Service, ResponseFormat> generateVfModuleArtifacts(Service service, User modifier, boolean shouldLock, boolean inTransaction) {
Function<ComponentInstance, List<ArtifactGenerator<ArtifactDefinition>>> artifactTaskGeneratorCreator = ri ->
// Only one VF Module Artifact per instance - add it to a list of one
buildArtifactGenList(service, modifier, shouldLock, inTransaction, ri);
return generateDeploymentArtifacts(service, artifactTaskGeneratorCreator);
}
private List<ArtifactGenerator<ArtifactDefinition>> buildArtifactGenList(Service service, User modifier, boolean shouldLock, boolean inTransaction, ComponentInstance ri) {
List<ArtifactGenerator<ArtifactDefinition>> asList = new ArrayList<ArtifactGenerator<ArtifactDefinition>>();
if (ri.getOriginType() == OriginTypeEnum.VF) {
asList = Arrays.asList(new VfModuleArtifacGenerator(modifier, ri, service, shouldLock, inTransaction));
}
return asList;
}
private List<GroupInstance> collectGroupsInstanceForCompInstance(ComponentInstance currVF, Wrapper<ResponseFormat> responseWrapper) {
Map<String, ArtifactDefinition> deploymentArtifacts = currVF.getDeploymentArtifacts();
if(currVF.getGroupInstances() != null){
currVF.getGroupInstances().stream().forEach(gi -> gi.alignArtifactsUuid(deploymentArtifacts));
}
return currVF.getGroupInstances();
}
private ArtifactDefinition getVfModuleInstArtifactForCompInstance(ComponentInstance currVF, Service service, User modifier, List<GroupInstance> groupsForCurrVF, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper) {
ArtifactDefinition vfModuleAertifact = null;
if (MapUtils.isNotEmpty(currVF.getDeploymentArtifacts())) {
Optional<ArtifactDefinition> optionalVfModuleArtifact = currVF.getDeploymentArtifacts().values().stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.name())).findAny();
if (optionalVfModuleArtifact.isPresent()) {
vfModuleAertifact = optionalVfModuleArtifact.get();
}
}
if (vfModuleAertifact == null) {
Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact = createVfModuleArtifact(modifier, currVF, service, payloadWrapper.getInnerElement());
if (createVfModuleArtifact.isLeft()) {
vfModuleAertifact = createVfModuleArtifact.left().value();
} else {
responseWrapper.setInnerElement(createVfModuleArtifact.right().value());
}
}
return vfModuleAertifact;
}
private void fillVfModuleInstHeatEnvPayload(List<GroupInstance> groupsForCurrVF, Wrapper<String> payloadWrapper) {
// Converts GroupDefinition to VfModuleArtifactPayload which is the
// format used in the payload
List<VfModuleArtifactPayload> vfModulePayloadForCurrVF = new ArrayList<VfModuleArtifactPayload>();
if (groupsForCurrVF != null) {
for (GroupInstance groupInstance : groupsForCurrVF) {
VfModuleArtifactPayload modulePayload = new VfModuleArtifactPayload(groupInstance);
vfModulePayloadForCurrVF.add(modulePayload);
}
Collections.sort(vfModulePayloadForCurrVF, (art1, art2) -> VfModuleArtifactPayload.compareByGroupName(art1, art2));
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
String vfModulePayloadString = gson.toJson(vfModulePayloadForCurrVF);
payloadWrapper.setInnerElement(vfModulePayloadString);
}
}
private Either<ArtifactDefinition, ResponseFormat> generateVfModuleInstanceArtifact(User modifier, ComponentInstance currVFInstance, Service service, boolean shouldLock, boolean inTransaction) {
ArtifactDefinition vfModuleAertifact = null;
Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
Wrapper<String> payloadWrapper = new Wrapper<>();
List<GroupInstance> groupsForCurrVF = collectGroupsInstanceForCompInstance(currVFInstance, responseWrapper);
if (responseWrapper.isEmpty()) {
fillVfModuleInstHeatEnvPayload(groupsForCurrVF, payloadWrapper);
}
if (responseWrapper.isEmpty() && payloadWrapper.getInnerElement() != null) {
vfModuleAertifact = getVfModuleInstArtifactForCompInstance(currVFInstance, service, modifier, groupsForCurrVF, payloadWrapper, responseWrapper);
}
if (responseWrapper.isEmpty() && vfModuleAertifact != null) {
vfModuleAertifact = fillVfModulePayload(modifier, currVFInstance, vfModuleAertifact, shouldLock, inTransaction, payloadWrapper, responseWrapper, service);
}
Either<ArtifactDefinition, ResponseFormat> result;
if (responseWrapper.isEmpty()) {
result = Either.left(vfModuleAertifact);
} else {
result = Either.right(responseWrapper.getInnerElement());
}
return result;
}
private ArtifactDefinition fillVfModulePayload(User modifier, ComponentInstance currVF, ArtifactDefinition vfModuleArtifact, boolean shouldLock, boolean inTransaction, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper, Service service) {
ArtifactDefinition result = null;
Either<ArtifactDefinition, ResponseFormat> eitherPayload = artifactsBusinessLogic.generateArtifactPayload(vfModuleArtifact, ComponentTypeEnum.RESOURCE_INSTANCE, service, currVF.getName(), modifier, shouldLock, inTransaction, () -> System.currentTimeMillis(),
() -> Either.left(artifactsBusinessLogic.createEsArtifactData(vfModuleArtifact, payloadWrapper.getInnerElement().getBytes(StandardCharsets.UTF_8))), currVF.getUniqueId());
if (eitherPayload.isLeft()) {
result = eitherPayload.left().value();
} else {
responseWrapper.setInnerElement(eitherPayload.right().value());
}
if (result == null) {
result = vfModuleArtifact;
}
return result;
}
private Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact(User modifier, ComponentInstance currVF, Service service, String vfModulePayloadString) {
ArtifactDefinition vfModuleArtifactDefinition = new ArtifactDefinition();
String newCheckSum = null;
vfModuleArtifactDefinition.setDescription("Auto-generated VF Modules information artifact");
vfModuleArtifactDefinition.setArtifactDisplayName("Vf Modules Metadata");
vfModuleArtifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.getType());
vfModuleArtifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
vfModuleArtifactDefinition.setArtifactLabel("vfModulesMetadata");
vfModuleArtifactDefinition.setTimeout(0);
vfModuleArtifactDefinition.setArtifactName(currVF.getNormalizedName() + "_modules.json");
vfModuleArtifactDefinition.setPayloadData(vfModulePayloadString);
if (vfModulePayloadString != null) {
newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(vfModulePayloadString.getBytes());
}
vfModuleArtifactDefinition.setArtifactChecksum(newCheckSum);
Either<ArtifactDefinition, StorageOperationStatus> addArifactToComponent = artifactToscaOperation.addArifactToComponent(vfModuleArtifactDefinition, service.getUniqueId(), NodeTypeEnum.ResourceInstance, true, currVF.getUniqueId());
Either<ArtifactDefinition, ResponseFormat> result;
if (addArifactToComponent.isLeft()) {
result = Either.left(addArifactToComponent.left().value());
} else {
result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArifactToComponent.right().value())));
}
return result;
}
public Either<Service, ResponseFormat> generateHeatEnvArtifacts(Service service, User modifier, boolean shouldLock, boolean inTransaction) {
Function<ComponentInstance, List<ArtifactGenerator<ArtifactDefinition>>> artifactTaskGeneratorCreator = resourceInstance ->
// Get All Deployment Artifacts
service.getComponentInstances().stream().filter(ri -> ri != null && ri == resourceInstance).filter(ri -> ri.getDeploymentArtifacts() != null).flatMap(ri -> ri.getDeploymentArtifacts().values().stream()).
// Filter in Only Heat Env
filter(depArtifact -> ArtifactTypeEnum.HEAT_ENV.getType().equals(depArtifact.getArtifactType())).
// Create ArtifactGenerator from those Artifacts
map(depArtifact -> new HeatEnvArtifactGenerator(depArtifact, service, resourceInstance.getName(), modifier, shouldLock, inTransaction, resourceInstance.getUniqueId())).collect(Collectors.toList());
return generateDeploymentArtifacts(service, artifactTaskGeneratorCreator);
}
private <CallVal> Either<Service, ResponseFormat> generateDeploymentArtifacts(Service service, Function<ComponentInstance, List<ArtifactGenerator<CallVal>>> artifactTaskGeneratorCreator) {
// Get Flat List of (Callable) ArtifactGenerator for all the RI in the
// service
if (service.getComponentInstances() != null) {
List<ArtifactGenerator<CallVal>> artifactGenList = service.getComponentInstances().stream().flatMap(ri -> artifactTaskGeneratorCreator.apply(ri).stream()).collect(Collectors.toList());
if (artifactGenList != null && !artifactGenList.isEmpty()) {
for (ArtifactGenerator<CallVal> entry : artifactGenList) {
Either<CallVal, ResponseFormat> callRes;
try {
callRes = entry.call();
if (callRes.isRight()) {
log.debug("Failed to generate artifact error : {}", callRes.right().value());
return Either.right(callRes.right().value());
}
} catch (Exception e) {
log.debug("Failed to generate artifact exception : {}", e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
}
}
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaFullElement(service.getUniqueId());
if (storageStatus.isRight()) {
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
}
Service currentService = storageStatus.left().value();
return Either.left(currentService);
}
abstract class ArtifactGenerator<CallVal> implements Callable<Either<CallVal, ResponseFormat>> {
}
class HeatEnvArtifactGenerator extends ArtifactGenerator<ArtifactDefinition> {
ArtifactDefinition artifactDefinition;
Service service;
String resourceInstanceName;
User modifier;
String instanceId;
boolean shouldLock;
boolean inTransaction;
HeatEnvArtifactGenerator(ArtifactDefinition artifactDefinition, Service service, String resourceInstanceName, User modifier, boolean shouldLock, boolean inTransaction, String instanceId) {
this.artifactDefinition = artifactDefinition;
this.service = service;
this.resourceInstanceName = resourceInstanceName;
this.modifier = modifier;
this.shouldLock = shouldLock;
this.instanceId = instanceId;
this.inTransaction = inTransaction;
}
@Override
public Either<ArtifactDefinition, ResponseFormat> call() throws Exception {
return artifactsBusinessLogic.forceGenerateHeatEnvArtifact(artifactDefinition, ComponentTypeEnum.RESOURCE_INSTANCE, service, resourceInstanceName, modifier, shouldLock, inTransaction, instanceId);
}
public ArtifactDefinition getArtifactDefinition() {
return artifactDefinition;
}
}
class VfModuleArtifacGenerator extends ArtifactGenerator<ArtifactDefinition> {
private User user;
private ComponentInstance componentInstance;
private Service service;
boolean shouldLock;
boolean inTransaction;
@Override
public Either<ArtifactDefinition, ResponseFormat> call() throws Exception {
return generateVfModuleInstanceArtifact(user, componentInstance, service, shouldLock, inTransaction);
}
private VfModuleArtifacGenerator(User user, ComponentInstance componentInstance, Service service, boolean shouldLock, boolean inTransaction) {
super();
this.user = user;
this.componentInstance = componentInstance;
this.service = service;
this.shouldLock = shouldLock;
this.inTransaction = inTransaction;
}
}
private synchronized Either<Service, ResponseFormat> checkDistributionAndDeploy(String did, User user, AuditingActionEnum auditAction, Service service) {
boolean isDeployed = isDistributionDeployed(did, service);
if (isDeployed) {
return Either.left(service);
}
Either<Boolean, ResponseFormat> distributionSuccess = checkDistributionSuccess(did, user, auditAction, service);
if (distributionSuccess.isRight()) {
return Either.right(distributionSuccess.right().value());
}
log.debug("mark distribution {} as deployed - success", did);
componentsUtils.auditServiceDistributionDeployed(auditAction, service.getName(), service.getVersion(), service.getUUID(), did, STATUS_DEPLOYED, "OK", user);
return Either.left(service);
}
private boolean isDistributionDeployed(String did, Service service) {
Either<List<DistributionDeployEvent>, ActionStatus> alreadyDeployed = auditCassandraDao.getDistributionDeployByStatus(did, AuditingActionEnum.DISTRIBUTION_DEPLOY.getName(), STATUS_DEPLOYED);
boolean isDeployed = false;
if (alreadyDeployed.isLeft() && !alreadyDeployed.left().value().isEmpty()) {
// already deployed
log.debug("distribution {} is already deployed", did);
isDeployed = true;
}
return isDeployed;
}
protected Either<Boolean, ResponseFormat> checkDistributionSuccess(String did, User user, AuditingActionEnum auditAction, Service service) {
log.trace("checkDistributionSuccess");
// get all "DRequest" records for this distribution
Either<List<ResourceAdminEvent>, ActionStatus> distRequestsResponse = auditCassandraDao.getDistributionRequest(did, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName());
if (distRequestsResponse.isRight()) {
ResponseFormat error = auditDeployError(did, user, auditAction, service, distRequestsResponse.right().value());
return Either.right(error);
}
List<ResourceAdminEvent> distributionRequests = distRequestsResponse.left().value();
if (distributionRequests.isEmpty()) {
BeEcompErrorManager.getInstance().logBeDistributionMissingError("markDistributionAsDeployed", did);
log.info("distribution {} is not found", did);
ResponseFormat error = auditDeployError(did, user, auditAction, service, ActionStatus.DISTRIBUTION_REQUESTED_NOT_FOUND);
return Either.right(error);
}
boolean isRequestSucceeded = false;
for (ResourceAdminEvent event : distributionRequests) {
String eventStatus = event.getStatus();
if (eventStatus != null && eventStatus.equals(STATUS_SUCCESS_200)) {
isRequestSucceeded = true;
break;
}
}
// get all "DNotify" records for this distribution
Either<List<DistributionNotificationEvent>, ActionStatus> distNotificationsResponse = auditCassandraDao.getDistributionNotify(did, AuditingActionEnum.DISTRIBUTION_NOTIFY.getName());
if (distNotificationsResponse.isRight()) {
ResponseFormat error = auditDeployError(did, user, auditAction, service, distNotificationsResponse.right().value());
return Either.right(error);
}
List<DistributionNotificationEvent> distributionNotifications = distNotificationsResponse.left().value();
boolean isNotificationsSucceeded = false;
for (DistributionNotificationEvent event : distributionNotifications) {
String eventStatus = event.getStatus();
if (eventStatus != null && eventStatus.equals(STATUS_SUCCESS_200)) {
isNotificationsSucceeded = true;
break;
}
}
// if request failed OR there are notifications that failed
if (!(isRequestSucceeded && isNotificationsSucceeded)) {
log.info("distribution {} has failed", did);
ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
auditDeployError(did, user, auditAction, service, ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
return Either.right(error);
}
return Either.left(true);
}
private ResponseFormat auditDeployError(String did, User user, AuditingActionEnum auditAction, Service service, ActionStatus status, String... params) {
ResponseFormat error = componentsUtils.getResponseFormat(status, params);
String message = "";
if (error.getMessageId() != null) {
message = error.getMessageId() + ": ";
}
message += error.getFormattedMessage();
if (service != null) {
componentsUtils.auditServiceDistributionDeployed(auditAction, service.getName(), service.getVersion(), service.getUUID(), did, error.getStatus().toString(), message, user);
} else {
componentsUtils.auditServiceDistributionDeployed(auditAction, "", "", "", did, error.getStatus().toString(), message, user);
}
return error;
}
private Either<User, ResponseFormat> validateRoleForDeploy(String did, User user, AuditingActionEnum auditAction, Service service) {
Either<User, ActionStatus> eitherCreator = userAdmin.getUser(user.getUserId(), false);
if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
BeEcompErrorManager.getInstance().logBeUserMissingError("Deploy Service", user.getUserId());
log.debug("validateRoleForDeploy method - user is not listed. userId= {}", user.getUserId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, user.getUserId());
auditDeployError(did, user, auditAction, service, ActionStatus.USER_NOT_FOUND);
return Either.right(responseFormat);
}
user = eitherCreator.left().value();
log.debug("validate user role");
List<Role> roles = new ArrayList<>();
roles.add(Role.ADMIN);
roles.add(Role.OPS);
Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, service, roles, auditAction, null);
if (validateRes.isRight()) {
log.info("role {} is not allowed to perform this action", user.getRole());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
auditDeployError(did, user, auditAction, service, ActionStatus.RESTRICTED_OPERATION);
return Either.right(responseFormat);
}
return Either.left(user);
}
@Override
public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
}
@Override
public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
return deleteMarkedComponents(ComponentTypeEnum.SERVICE);
}
private HealthCheckBusinessLogic getHealthCheckBL(ServletContext context) {
WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
HealthCheckBusinessLogic healthCheckBl = webApplicationContext.getBean(HealthCheckBusinessLogic.class);
return healthCheckBl;
}
@Override
public ComponentInstanceBusinessLogic getComponentInstanceBL() {
return componentInstanceBusinessLogic;
}
@Override
public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
Either<User, ResponseFormat> resp = validateUserExists(userId, "Get Component Instances", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
Either<Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
if (getComponentRes.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getComponentRes.right().value()));
return Either.right(responseFormat);
}
List<ComponentInstance> componentInstances = getComponentRes.left().value().getComponentInstances();
return Either.left(componentInstances);
}
public ICacheMangerOperation getCacheManagerOperation() {
return cacheManagerOperation;
}
public void setCacheManagerOperation(ICacheMangerOperation cacheManagerOperation) {
this.cacheManagerOperation = cacheManagerOperation;
}
public void setForwardingPathOperation(ForwardingPathOperation forwardingPathOperation) {
this.forwardingPathOperation = forwardingPathOperation;
}
@Override
public void setToscaOperationFacade(ToscaOperationFacade toscaOperationFacade) {
this.toscaOperationFacade = toscaOperationFacade;
}/**
* updates group instance with new property values in case of successful update of group instance related component instance will be updated with new modification time and related service will be updated with new last update date
*
* @param modifier
* @param serviceId
* @param componentInstanceId
* @param groupInstanceId
* @param newProperties
* @return
*/
public Either<List<GroupInstanceProperty>, ResponseFormat> updateGroupInstancePropertyValues(User modifier, String serviceId, String componentInstanceId, String groupInstanceId, List<GroupInstanceProperty> newProperties) {
Either<List<GroupInstanceProperty>, ResponseFormat> actionResult = null;
Either<ImmutablePair<Component, User>, ResponseFormat> validateUserAndComponentRes;
Component component = null;
Either<Boolean, ResponseFormat> lockResult = null;
log.debug("Going to update group instance {} of service {} with new property values. ", groupInstanceId, serviceId);
try {
validateUserAndComponentRes = validateUserAndComponent(serviceId, modifier);
if (validateUserAndComponentRes.isRight()) {
log.debug("Cannot update group instance {} of service {} with new property values. Validation failed. ", groupInstanceId, serviceId);
actionResult = Either.right(validateUserAndComponentRes.right().value());
}
if (actionResult == null) {
component = validateUserAndComponentRes.left().value().getKey();
lockResult = lockComponentByName(component.getSystemName(), component, "Update Group Instance on Service");
if (lockResult.isRight()) {
log.debug("Failed to lock service {}. Response is {}. ", component.getName(), lockResult.right().value().getFormattedMessage());
actionResult = Either.right(lockResult.right().value());
} else {
log.debug("The service with system name {} locked. ", component.getSystemName());
}
}
if (actionResult == null) {
actionResult = validateAndUpdateGroupInstancePropertyValuesAndContainingParents(component, componentInstanceId, groupInstanceId, newProperties);
if (actionResult.isRight()) {
log.debug("Failed to validate and update group instance {} property values and containing parents. The message is {}. ", groupInstanceId, actionResult.right().value().getFormattedMessage());
}
}
} catch (Exception e) {
log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e);
actionResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponentByName(component.getSystemName(), component.getUniqueId(), NodeTypeEnum.Service);
}
}
return actionResult;
}
private Either<List<GroupInstanceProperty>, ResponseFormat> validateAndUpdateGroupInstancePropertyValuesAndContainingParents(Component component, String componentInstanceId, String groupInstanceId, List<GroupInstanceProperty> newProperties) {
Either<List<GroupInstanceProperty>, ResponseFormat> actionResult = null;
Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat> findGroupInstanceRes;
Either<ImmutablePair<ComponentMetadataData, ComponentInstanceData>, ResponseFormat> updateParentsModificationTimeRes;
ComponentInstance relatedComponentInstance = null;
GroupInstance oldGroupInstance = null;
Either<GroupInstance, ResponseFormat> updateGroupInstanceResult = null;
GroupInstance updatedGroupInstance = null;
boolean inTransaction = true;
boolean shouldCloseTransaction = true;
findGroupInstanceRes = findGroupInstanceOnRelatedComponentInstance(component, componentInstanceId, groupInstanceId);
if (findGroupInstanceRes.isRight()) {
log.debug("Group instance {} not found. ", groupInstanceId);
actionResult = Either.right(findGroupInstanceRes.right().value());
}
if (actionResult == null) {
oldGroupInstance = findGroupInstanceRes.left().value().getValue();
relatedComponentInstance = findGroupInstanceRes.left().value().getKey();
updateGroupInstanceResult = groupBusinessLogic.validateAndUpdateGroupInstancePropertyValues(component.getUniqueId(), componentInstanceId, oldGroupInstance, newProperties, inTransaction);
if (updateGroupInstanceResult.isRight()) {
log.debug("Failed to update group instance {} property values. ", oldGroupInstance.getName());
actionResult = Either.right(updateGroupInstanceResult.right().value());
}
}
if (actionResult == null) {
updatedGroupInstance = updateGroupInstanceResult.left().value();
if (!oldGroupInstance.getModificationTime().equals(updatedGroupInstance.getModificationTime())) {
updateParentsModificationTimeRes = updateParentsModificationTimeAndCustomizationUuid(component, relatedComponentInstance, updatedGroupInstance, inTransaction, shouldCloseTransaction);
if (updateParentsModificationTimeRes.isRight()) {
log.debug("Failed to update modification time. ", oldGroupInstance.getName());
actionResult = Either.right(updateParentsModificationTimeRes.right().value());
}
}
}
if (actionResult == null) {
actionResult = Either.left(updatedGroupInstance.convertToGroupInstancesProperties());
}
return actionResult;
}
private Either<ImmutablePair<ComponentMetadataData, ComponentInstanceData>, ResponseFormat> updateParentsModificationTimeAndCustomizationUuid(Component component, ComponentInstance relatedComponentInstance, GroupInstance updatedGroupInstance,
boolean inTranscation, boolean shouldCloseTransaction) {
Either<ImmutablePair<ComponentMetadataData, ComponentInstanceData>, ResponseFormat> actionResult;
Either<ComponentMetadataData, StorageOperationStatus> serviceMetadataUpdateResult;
Either<ComponentInstanceData, ResponseFormat> updateComponentInstanceRes = componentInstanceBusinessLogic.updateComponentInstanceModificationTimeAndCustomizationUuid(relatedComponentInstance, NodeTypeEnum.ResourceInstance,
updatedGroupInstance.getModificationTime(), inTranscation);
if (updateComponentInstanceRes.isRight()) {
log.debug("Failed to update component instance {} after update of group instance {}. ", relatedComponentInstance.getName(), updatedGroupInstance.getName());
actionResult = Either.right(updateComponentInstanceRes.right().value());
} else {
serviceMetadataUpdateResult = toscaOperationFacade.updateComponentLastUpdateDateOnGraph(component, updatedGroupInstance.getModificationTime());
if (serviceMetadataUpdateResult.isRight()) {
log.debug("Failed to update service {} after update of component instance {} with new property values of group instance {}. ", component.getName(), relatedComponentInstance.getName(), updatedGroupInstance.getName());
actionResult = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceMetadataUpdateResult.right().value())));
} else {
actionResult = Either.left(new ImmutablePair<>(serviceMetadataUpdateResult.left().value(), updateComponentInstanceRes.left().value()));
}
}
return actionResult;
}
private Either<ImmutablePair<Component, User>, ResponseFormat> validateUserAndComponent(String serviceId, User modifier) {
Either<ImmutablePair<Component, User>, ResponseFormat> result = null;
Either<Component, ResponseFormat> validateComponentExistsRes = null;
User currUser = null;
Component component = null;
Either<User, ResponseFormat> validationUserResult = validateUserIgnoreAudit(modifier, "updateGroupInstancePropertyValues");
if (validationUserResult.isRight()) {
log.debug("Failed to validate user with userId for update service {}. ", modifier.getUserId(), serviceId);
result = Either.right(validationUserResult.right().value());
}
if (result == null) {
currUser = validationUserResult.left().value();
validateComponentExistsRes = validateComponentExists(serviceId, ComponentTypeEnum.SERVICE, null);
if (validateComponentExistsRes.isRight()) {
log.debug("Failed to validate service existing {}. ", serviceId);
result = Either.right(validateComponentExistsRes.right().value());
}
}
if (result == null) {
component = validateComponentExistsRes.left().value();
if (!ComponentValidationUtils.canWorkOnComponent(component, currUser.getUserId())) {
log.info("Restricted operation for user: {}, on service: {}", currUser.getUserId(), component.getCreatorUserId());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
}
if (result == null) {
result = Either.left(new ImmutablePair<>(component, currUser));
}
return result;
}
private Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat> findGroupInstanceOnRelatedComponentInstance(Component component, String componentInstanceId, String groupInstanceId) {
Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat> actionResult = null;
GroupInstance groupInstance = null;
ComponentInstance foundComponentInstance = findRelatedComponentInstance(component, componentInstanceId);
if (foundComponentInstance == null) {
log.debug("Component instance {} not found on service {}. ", componentInstanceId, component.getName());
actionResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstanceId, "resource instance", "service", component.getName()));
} else if (!CollectionUtils.isEmpty(foundComponentInstance.getGroupInstances())) {
groupInstance = foundComponentInstance.getGroupInstances().stream().filter(gi -> gi.getUniqueId().equals(groupInstanceId)).findFirst().orElse(null);
if (groupInstance == null) {
log.debug("Group instance {} not found on component instance {}. ", groupInstanceId, foundComponentInstance.getName());
actionResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_INSTANCE_NOT_FOUND_ON_COMPONENT_INSTANCE, groupInstanceId, foundComponentInstance.getName()));
}
}
if (actionResult == null) {
actionResult = Either.left(new ImmutablePair<>(foundComponentInstance, groupInstance));
}
return actionResult;
}
private ComponentInstance findRelatedComponentInstance(Component component, String componentInstanceId) {
ComponentInstance componentInstance = null;
if (!CollectionUtils.isEmpty(component.getComponentInstances())) {
componentInstance = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(componentInstanceId)).findFirst().orElse(null);
}
return componentInstance;
}
private Either<User, ResponseFormat> validateUserIgnoreAudit(User modifier, String ecompErrorContext) {
Either<User, ResponseFormat> result = validateUser(modifier, ecompErrorContext, null, null, false);
if (result.isLeft()) {
List<Role> roles = new ArrayList<>();
roles.add(Role.ADMIN);
roles.add(Role.DESIGNER);
Either<Boolean, ResponseFormat> validationRoleRes = validateUserRole(result.left().value(), roles);
if (validationRoleRes.isRight()) {
result = Either.right(validationRoleRes.right().value());
}
}
return result;
}
public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String serviceId, List<String> dataParamsToReturn) {
ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
Either<Service, StorageOperationStatus> serviceResultEither = toscaOperationFacade.getToscaElement(serviceId, paramsToRetuen);
if (serviceResultEither.isRight()) {
if(serviceResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
log.debug("Failed to found service with id {} ", serviceId);
Either.right(componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceId));
}
log.debug("failed to get service by id {} with filters {}", serviceId, dataParamsToReturn.toString());
return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(serviceResultEither.right().value()), ""));
}
Service service = serviceResultEither.left().value();
UiComponentDataTransfer dataTransfer = UiComponentDataConverter.getUiDataTransferFromServiceByParams(service, dataParamsToReturn);
return Either.left(dataTransfer);
}
}
|