-
Notifications
You must be signed in to change notification settings - Fork 20
/
BBInputSetup.java
1627 lines (1493 loc) · 75.9 KB
/
BBInputSetup.java
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
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* 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.onap.so.bpmn.servicedecomposition.tasks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.javatuples.Pair;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.DelegateExecutionImpl;
import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.client.aai.AAICommonObjectMapperProvider;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.Relationships;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.exception.ExceptionBuilder;
import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
import org.onap.so.db.catalog.beans.CollectionResource;
import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
import org.onap.so.db.catalog.beans.OrchestrationStatus;
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.logger.MsoLogger;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.ModelType;
import org.onap.so.serviceinstancebeans.Networks;
import org.onap.so.serviceinstancebeans.RelatedInstance;
import org.onap.so.serviceinstancebeans.RelatedInstanceList;
import org.onap.so.serviceinstancebeans.RequestDetails;
import org.onap.so.serviceinstancebeans.RequestParameters;
import org.onap.so.serviceinstancebeans.Resources;
import org.onap.so.serviceinstancebeans.VfModules;
import org.onap.so.serviceinstancebeans.Vnfs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@Component("BBInputSetup")
public class BBInputSetup implements JavaDelegate {
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BBInputSetup.class);
private static final String FLOW_VAR_NAME = "flowToBeCalled";
private static final String LOOKUP_KEY_MAP_VAR_NAME = "lookupKeyMap";
private static final String GBB_INPUT_VAR_NAME = "gBBInput";
private static final String EXECUTE_BB_VAR_NAME = "buildingBlock";
private static final String CLOUD_OWNER = "att-aic";
private static final String VOLUME_GROUP = "VolumeGroup";
private static final String VF_MODULE = "VfModule";
private static final String NETWORK = "Network";
private static final String VNF = "Vnf";
private static final String NETWORK_COLLECTION = "NetworkCollection";
@Autowired
private BBInputSetupUtils bbInputSetupUtils;
@Autowired
private BBInputSetupMapperLayer mapperLayer;
@Autowired
private ExceptionBuilder exceptionUtil;
private ObjectMapper mapper = new ObjectMapper();
public BBInputSetupUtils getBbInputSetupUtils() {
return bbInputSetupUtils;
}
public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
this.bbInputSetupUtils = bbInputSetupUtils;
}
public BBInputSetupMapperLayer getMapperLayer() {
return mapperLayer;
}
public void setMapperLayer(BBInputSetupMapperLayer mapperLayer) {
this.mapperLayer = mapperLayer;
}
@Override
public void execute(DelegateExecution execution) throws Exception {
try {
GeneralBuildingBlock outputBB = null;
ExecuteBuildingBlock executeBB = this.getExecuteBBFromExecution(execution);
String resourceId = executeBB.getResourceId();
String requestAction = executeBB.getRequestAction();
String vnfType = executeBB.getVnfType();
boolean aLaCarte = Boolean.TRUE.equals(executeBB.isaLaCarte());
boolean homing = Boolean.TRUE.equals(executeBB.isHoming());
Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
outputBB = this.getGBB(executeBB, lookupKeyMap, requestAction, aLaCarte, resourceId, vnfType);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
msoLogger.debug("GeneralBB: " + mapper.writeValueAsString(outputBB));
setHomingFlag(outputBB, homing, lookupKeyMap);
execution.setVariable(FLOW_VAR_NAME, executeBB.getBuildingBlock().getBpmnFlowName());
execution.setVariable(GBB_INPUT_VAR_NAME, outputBB);
execution.setVariable(LOOKUP_KEY_MAP_VAR_NAME, lookupKeyMap);
BuildingBlockExecution gBuildingBlockExecution = new DelegateExecutionImpl(execution);
execution.setVariable("gBuildingBlockExecution", gBuildingBlockExecution);
execution.setVariable("RetryCount", 1);
execution.setVariable("handlingCode", "Success");
} catch (Exception e) {
msoLogger.error(e);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage());
}
}
protected void setHomingFlag(GeneralBuildingBlock outputBB, boolean homing, Map<ResourceKey, String> lookupKeyMap) {
if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null && homing && outputBB != null) {
for (GenericVnf vnf : outputBB.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) {
if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
vnf.setCallHoming(homing);
}
}
}
}
protected ExecuteBuildingBlock getExecuteBBFromExecution(DelegateExecution execution) {
return (ExecuteBuildingBlock) execution.getVariable(EXECUTE_BB_VAR_NAME);
}
protected GeneralBuildingBlock getGBB(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap,
String requestAction, boolean aLaCarte, String resourceId, String vnfType) throws Exception {
String requestId = executeBB.getRequestId();
this.populateLookupKeyMapWithIds(executeBB.getWorkflowResourceIds(), lookupKeyMap);
RequestDetails requestDetails = executeBB.getRequestDetails();
if(requestDetails == null) {
requestDetails = bbInputSetupUtils.getRequestDetails(requestId);
}
if (requestDetails.getModelInfo() == null) {
return this.getGBBCM(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId);
}
else {
ModelType modelType = requestDetails.getModelInfo().getModelType();
if (aLaCarte && modelType.equals(ModelType.service)) {
return this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId);
} else if (aLaCarte && !modelType.equals(ModelType.service)) {
return this.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId,
vnfType);
} else {
return this.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType);
}
}
}
protected void populateLookupKeyMapWithIds(WorkflowResourceIds workflowResourceIds,
Map<ResourceKey, String> lookupKeyMap) {
lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, workflowResourceIds.getServiceInstanceId());
lookupKeyMap.put(ResourceKey.NETWORK_ID, workflowResourceIds.getNetworkId());
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, workflowResourceIds.getVnfId());
lookupKeyMap.put(ResourceKey.VF_MODULE_ID, workflowResourceIds.getVfModuleId());
lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, workflowResourceIds.getVolumeGroupId());
lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, workflowResourceIds.getConfigurationId());
}
protected GeneralBuildingBlock getGBBALaCarteNonService(ExecuteBuildingBlock executeBB,
RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction,
String resourceId, String vnfType) throws Exception {
String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
if (serviceInstanceId != null) {
aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
}
Service service = null;
if (aaiServiceInstance != null) {
service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
}
if (aaiServiceInstance != null && service != null) {
ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
this.populateObjectsOnAssignAndCreateFlows(requestDetails, service, bbName, serviceInstance, lookupKeyMap,
resourceId, vnfType);
return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
} else {
msoLogger.debug("Related Service Instance from AAI: " + aaiServiceInstance);
msoLogger.debug("Related Service Instance Model Info from AAI: " + service);
throw new Exception("Could not find relevant information for related Service Instance");
}
}
protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB,
RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction,
String resourceId) throws Exception {
ServiceInstance serviceInstance = new ServiceInstance();
String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
serviceInstance.setServiceInstanceId(serviceInstanceId);
List<GenericVnf> genericVnfs = serviceInstance.getVnfs();
String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf);
genericVnfs.add(genericVnf);
return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, new Customer());
}
protected void populateObjectsOnAssignAndCreateFlows(RequestDetails requestDetails, Service service, String bbName,
ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String vnfType)
throws Exception {
ModelInfo modelInfo = requestDetails.getModelInfo();
String instanceName = requestDetails.getRequestInfo().getInstanceName();
ModelType modelType = modelInfo.getModelType();
RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
org.onap.so.serviceinstancebeans.Platform platform = requestDetails.getPlatform();
org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness = requestDetails.getLineOfBusiness();
if (modelType.equals(ModelType.network)) {
lookupKeyMap.put(ResourceKey.NETWORK_ID, resourceId);
this.populateL3Network(instanceName, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId, null);
} else if (modelType.equals(ModelType.vnf)) {
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, resourceId);
this.populateGenericVnf(modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance,
lookupKeyMap, relatedInstanceList, resourceId, vnfType, null);
} else if (modelType.equals(ModelType.volumeGroup)) {
lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, resourceId);
this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
relatedInstanceList, instanceName, vnfType, null);
} else if (modelType.equals(ModelType.vfModule)) {
lookupKeyMap.put(ResourceKey.VF_MODULE_ID, resourceId);
this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
relatedInstanceList, instanceName, null, requestDetails.getCloudConfiguration());
} else {
return;
}
}
protected void populateConfiguration(ModelInfo modelInfo, Service service, String bbName,
ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String instanceName, ConfigurationResourceKeys configurationResourceKeys) {
Configuration configuration = null;
for (Configuration configurationTemp : serviceInstance.getConfigurations()) {
if (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null
&& configurationTemp.getConfigurationId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID))) {
configuration = configurationTemp;
org.onap.aai.domain.yang.Configuration aaiConfiguration = bbInputSetupUtils.getAAIConfiguration(configuration.getConfigurationId());
if(aaiConfiguration!=null){
modelInfo.setModelCustomizationUuid(aaiConfiguration.getModelCustomizationId());
}
}
}
if (configuration == null && bbName.equalsIgnoreCase(AssignFlows.FABRIC_CONFIGURATION.toString())) {
configuration = this.createConfiguration(lookupKeyMap, instanceName, resourceId);
serviceInstance.getConfigurations().add(configuration);
}
if(configuration != null) {
this.mapCatalogConfiguration(configuration, modelInfo, service, configurationResourceKeys);
}
}
protected Configuration createConfiguration(Map<ResourceKey, String> lookupKeyMap,
String instanceName, String resourceId) {
lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, resourceId);
Configuration configuration = new Configuration();
configuration.setConfigurationId(resourceId);
configuration.setConfigurationName(instanceName);
configuration.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
return configuration;
}
protected void mapCatalogConfiguration(Configuration configuration, ModelInfo modelInfo, Service service, ConfigurationResourceKeys configurationResourceKeys) {
ConfigurationResourceCustomization configurationResourceCustomization = findConfigurationResourceCustomization(modelInfo, service);
VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization =
findVnfVfmoduleCvnfcConfigurationCustomization(configurationResourceKeys.getVfModuleCustomizationUUID(),
configurationResourceKeys.getVnfResourceCustomizationUUID(), configurationResourceKeys.getCvnfcCustomizationUUID(), configurationResourceCustomization);
if (configurationResourceCustomization != null && vnfVfmoduleCvnfcConfigurationCustomization != null) {
configuration.setModelInfoConfiguration(this.mapperLayer.mapCatalogConfigurationToConfiguration(configurationResourceCustomization
, vnfVfmoduleCvnfcConfigurationCustomization));
}
}
protected VnfVfmoduleCvnfcConfigurationCustomization findVnfVfmoduleCvnfcConfigurationCustomization(String vfModuleCustomizationUUID,
String vnfResourceCustomizationUUID, String cvnfcCustomizationUUID, ConfigurationResourceCustomization configurationResourceCustomization) {
for(VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization :
configurationResourceCustomization.getConfigurationResource().getVnfVfmoduleCvnfcConfigurationCustomization()) {
if(vnfVfmoduleCvnfcConfigurationCustomization.getVfModuleCustomization().getModelCustomizationUUID().equalsIgnoreCase(vfModuleCustomizationUUID)
&& vnfVfmoduleCvnfcConfigurationCustomization.getVnfResourceCustomization().getModelCustomizationUUID().equalsIgnoreCase(vnfResourceCustomizationUUID)
&& vnfVfmoduleCvnfcConfigurationCustomization.getCvnfcCustomization().getModelCustomizationUUID().equalsIgnoreCase(cvnfcCustomizationUUID)) {
return vnfVfmoduleCvnfcConfigurationCustomization;
}
}
return null;
}
protected ConfigurationResourceCustomization findConfigurationResourceCustomization(ModelInfo modelInfo, Service service) {
for (ConfigurationResourceCustomization resourceCust : service.getConfigurationCustomizations()) {
if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
return resourceCust;
}
}
return null;
}
protected void populateVfModule(ModelInfo modelInfo, Service service, String bbName,
ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
RelatedInstanceList[] relatedInstanceList, String instanceName, List<Map<String, String>> instanceParams, CloudConfiguration cloudConfiguration) throws Exception {
String vnfModelCustomizationUUID = null;
if (relatedInstanceList != null) {
for (RelatedInstanceList relatedInstList : relatedInstanceList) {
RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
}
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) {
lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, relatedInstance.getInstanceId());
}
}
}
GenericVnf vnf = null;
for (GenericVnf tempVnf : serviceInstance.getVnfs()) {
if (tempVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
vnf = tempVnf;
vnfModelCustomizationUUID = this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId())
.getModelCustomizationId();
ModelInfo vnfModelInfo = new ModelInfo();
vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
this.mapCatalogVnf(tempVnf, vnfModelInfo, service);
if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) == null) {
for(VolumeGroup volumeGroup : tempVnf.getVolumeGroups()) {
String volumeGroupCustId =
this.bbInputSetupUtils.getAAIVolumeGroup(CLOUD_OWNER,
cloudConfiguration.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()).getModelCustomizationId();
if(modelInfo.getModelCustomizationId().equalsIgnoreCase(volumeGroupCustId)) {
lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroup.getVolumeGroupId());
break;
}
}
}
break;
}
}
if (vnf != null) {
VfModule vfModule = null;
for (VfModule vfModuleTemp : vnf.getVfModules()) {
if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null
&& vfModuleTemp.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) {
vfModule = vfModuleTemp;
String vfModuleCustId = bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()).getModelCustomizationId();
modelInfo.setModelCustomizationId(vfModuleCustId);
break;
}
}
if (vfModule == null && bbName.equalsIgnoreCase(AssignFlows.VF_MODULE.toString())) {
vfModule = createVfModule(lookupKeyMap,
resourceId, instanceName, instanceParams);
vnf.getVfModules().add(vfModule);
}
if(vfModule != null) {
mapCatalogVfModule(vfModule, modelInfo, service, vnfModelCustomizationUUID);
}
} else {
msoLogger.debug("Related VNF instance Id not found: " + lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
throw new Exception("Could not find relevant information for related VNF");
}
}
protected void mapCatalogVfModule(VfModule vfModule, ModelInfo modelInfo, Service service,
String vnfModelCustomizationUUID) {
if(modelInfo.getModelCustomizationUuid() != null) {
modelInfo.setModelCustomizationId(modelInfo.getModelCustomizationUuid());
}
VnfResourceCustomization vnfResourceCustomization = null;
for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(vnfModelCustomizationUUID)) {
vnfResourceCustomization = resourceCust;
break;
}
}
if (vnfResourceCustomization != null) {
VfModuleCustomization vfResourceCustomization = vnfResourceCustomization.getVfModuleCustomizations()
.stream() // Convert to steam
.filter(x -> modelInfo.getModelCustomizationId().equalsIgnoreCase(x.getModelCustomizationUUID()))// find
// what
// we
// want
.findAny() // If 'findAny' then return found
.orElse(null);
if (vfResourceCustomization != null) {
vfModule.setModelInfoVfModule(this.mapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization));
}
}
}
protected VfModule createVfModule(Map<ResourceKey, String> lookupKeyMap, String vfModuleId, String instanceName, List<Map<String, String>> instanceParams) {
lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModuleId);
VfModule vfModule = new VfModule();
vfModule.setVfModuleId(vfModuleId);
vfModule.setVfModuleName(instanceName);
vfModule.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
if(instanceParams != null) {
for(Map<String, String> params : instanceParams) {
vfModule.getCloudParams().putAll(params);
}
}
return vfModule;
}
protected void populateVolumeGroup(ModelInfo modelInfo, Service service, String bbName,
ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
RelatedInstanceList[] relatedInstanceList, String instanceName, String vnfType, List<Map<String, String>> instanceParams) throws Exception {
VolumeGroup volumeGroup = null;
GenericVnf vnf = null;
String vnfModelCustomizationUUID = null;
String generatedVnfType = vnfType;
if (generatedVnfType == null || generatedVnfType.isEmpty()) {
generatedVnfType = service.getModelName() + "/" + modelInfo.getModelCustomizationName();
}
if (relatedInstanceList != null) {
for (RelatedInstanceList relatedInstList : relatedInstanceList) {
RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid();
break;
}
}
}
for (GenericVnf tempVnf : serviceInstance.getVnfs()) {
if (tempVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
vnf = tempVnf;
vnfModelCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId())
.getModelCustomizationId();
ModelInfo vnfModelInfo = new ModelInfo();
vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
mapCatalogVnf(tempVnf, vnfModelInfo, service);
break;
}
}
if (vnf != null && vnfModelCustomizationUUID != null) {
for (VolumeGroup volumeGroupTemp : vnf.getVolumeGroups()) {
if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) != null && volumeGroupTemp.getVolumeGroupId()
.equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID))) {
volumeGroup = volumeGroupTemp;
break;
}
}
if (volumeGroup == null && bbName.equalsIgnoreCase(AssignFlows.VOLUME_GROUP.toString())) {
volumeGroup = createVolumeGroup(lookupKeyMap, resourceId, instanceName, generatedVnfType, instanceParams);
vnf.getVolumeGroups().add(volumeGroup);
}
if(volumeGroup != null) {
mapCatalogVolumeGroup(volumeGroup, modelInfo, service, vnfModelCustomizationUUID);
}
} else {
msoLogger.debug("Related VNF instance Id not found: " + lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
throw new Exception("Could not find relevant information for related VNF");
}
}
protected VolumeGroup createVolumeGroup(Map<ResourceKey, String> lookupKeyMap, String volumeGroupId, String instanceName, String vnfType, List<Map<String, String>> instanceParams) {
lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupId);
VolumeGroup volumeGroup = new VolumeGroup();
volumeGroup.setVolumeGroupId(volumeGroupId);
volumeGroup.setVolumeGroupName(instanceName);
volumeGroup.setVnfType(vnfType);
volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
if(instanceParams != null) {
for(Map<String, String> params : instanceParams) {
volumeGroup.getCloudParams().putAll(params);
}
}
return volumeGroup;
}
protected void mapCatalogVolumeGroup(VolumeGroup volumeGroup, ModelInfo modelInfo, Service service,
String vnfModelCustomizationUUID) {
VfModuleCustomization vfResourceCustomization = getVfResourceCustomization(modelInfo, service,
vnfModelCustomizationUUID);
if (vfResourceCustomization != null) {
volumeGroup.setModelInfoVfModule(this.mapperLayer.mapCatalogVfModuleToVfModule(vfResourceCustomization));
}
}
protected VfModuleCustomization getVfResourceCustomization(ModelInfo modelInfo, Service service,
String vnfModelCustomizationUUID) {
VnfResourceCustomization vnfResourceCustomization = null;
for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(vnfModelCustomizationUUID)) {
vnfResourceCustomization = resourceCust;
break;
}
}
if (vnfResourceCustomization != null) {
for (VfModuleCustomization vfResourceCust : vnfResourceCustomization.getVfModuleCustomizations()) {
if (vfResourceCust.getModelCustomizationUUID()
.equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
return vfResourceCust;
}
}
}
return null;
}
protected void populateGenericVnf(ModelInfo modelInfo, String instanceName,
org.onap.so.serviceinstancebeans.Platform platform,
org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, Service service, String bbName,
ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap,
RelatedInstanceList[] relatedInstanceList, String resourceId, String vnfType, List<Map<String, String>> instanceParams) {
GenericVnf vnf = null;
ModelInfo instanceGroupModelInfo = null;
String instanceGroupId = null;
String generatedVnfType = vnfType;
if (generatedVnfType == null || generatedVnfType.isEmpty()) {
generatedVnfType = service.getModelName() + "/" + modelInfo.getModelCustomizationName();
}
if (relatedInstanceList != null) {
for (RelatedInstanceList relatedInstList : relatedInstanceList) {
RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.networkCollection)) {
instanceGroupModelInfo = relatedInstance.getModelInfo();
instanceGroupId = relatedInstance.getInstanceId();
}
}
}
for (GenericVnf vnfTemp : serviceInstance.getVnfs()) {
if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null
&& vnfTemp.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
String vnfModelCustId = bbInputSetupUtils.getAAIGenericVnf(vnfTemp.getVnfId()).getModelCustomizationId();
modelInfo.setModelCustomizationUuid(vnfModelCustId);
vnf = vnfTemp;
break;
}
}
if (vnf == null && bbName.equalsIgnoreCase(AssignFlows.VNF.toString())) {
vnf = createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness,
resourceId, generatedVnfType, instanceParams);
serviceInstance.getVnfs().add(vnf);
}
if(vnf != null) {
mapCatalogVnf(vnf, modelInfo, service);
mapVnfcCollectionInstanceGroup(vnf, modelInfo, service);
if (instanceGroupId != null && instanceGroupModelInfo != null) {
mapNetworkCollectionInstanceGroup(vnf, instanceGroupId);
}
}
}
protected void mapVnfcCollectionInstanceGroup(GenericVnf genericVnf, ModelInfo modelInfo, Service service) {
VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service);
if(vnfResourceCustomization != null) {
List<VnfcInstanceGroupCustomization> vnfcInstanceGroups = vnfResourceCustomization
.getVnfcInstanceGroupCustomizations();
for (VnfcInstanceGroupCustomization vnfcInstanceGroupCust : vnfcInstanceGroups) {
InstanceGroup instanceGroup = this.createInstanceGroup();
instanceGroup.setModelInfoInstanceGroup(this.mapperLayer
.mapCatalogInstanceGroupToInstanceGroup(null, vnfcInstanceGroupCust.getInstanceGroup()));
instanceGroup.getModelInfoInstanceGroup().setFunction(vnfcInstanceGroupCust.getFunction());
instanceGroup.setDescription(vnfcInstanceGroupCust.getDescription());
genericVnf.getInstanceGroups().add(instanceGroup);
}
}
}
protected void mapNetworkCollectionInstanceGroup(GenericVnf genericVnf, String instanceGroupId) {
org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = bbInputSetupUtils
.getAAIInstanceGroup(instanceGroupId);
InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstanceGroup);
instanceGroup.setModelInfoInstanceGroup(this.mapperLayer.mapCatalogInstanceGroupToInstanceGroup(
null, this.bbInputSetupUtils.getCatalogInstanceGroup(aaiInstanceGroup.getModelVersionId())));
genericVnf.getInstanceGroups().add(instanceGroup);
}
protected GenericVnf createGenericVnf(Map<ResourceKey, String> lookupKeyMap, String instanceName,
org.onap.so.serviceinstancebeans.Platform platform,
org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, String vnfId, String vnfType, List<Map<String, String>> instanceParams) {
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId);
GenericVnf genericVnf = new GenericVnf();
genericVnf.setVnfId(vnfId);
genericVnf.setVnfName(instanceName);
genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
genericVnf.setVnfType(vnfType);
if (platform != null) {
genericVnf.setPlatform(this.mapperLayer.mapRequestPlatform(platform));
}
if (lineOfBusiness != null) {
genericVnf.setLineOfBusiness(this.mapperLayer.mapRequestLineOfBusiness(lineOfBusiness));
}
if(instanceParams != null) {
for(Map<String, String> params : instanceParams) {
genericVnf.getCloudParams().putAll(params);
}
}
return genericVnf;
}
protected void mapCatalogVnf(GenericVnf genericVnf, ModelInfo modelInfo, Service service) {
VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service);
if (vnfResourceCustomization != null) {
genericVnf.setModelInfoGenericVnf(this.mapperLayer.mapCatalogVnfToVnf(vnfResourceCustomization));
}
}
protected VnfResourceCustomization getVnfResourceCustomizationFromService(ModelInfo modelInfo, Service service) {
VnfResourceCustomization vnfResourceCustomization = null;
for (VnfResourceCustomization resourceCust : service.getVnfCustomizations()) {
if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
vnfResourceCustomization = resourceCust;
break;
}
}
return vnfResourceCustomization;
}
protected void populateL3Network(String instanceName, ModelInfo modelInfo, Service service, String bbName,
ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, List<Map<String, String>> instanceParams) {
L3Network network = null;
for (L3Network networkTemp : serviceInstance.getNetworks()) {
if (lookupKeyMap.get(ResourceKey.NETWORK_ID) != null
&& networkTemp.getNetworkId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.NETWORK_ID))) {
network = networkTemp;
break;
}
}
if (network == null
&& (bbName.equalsIgnoreCase(AssignFlows.NETWORK_A_LA_CARTE.toString())
|| bbName.equalsIgnoreCase(AssignFlows.NETWORK_MACRO.toString()))) {
network = createNetwork(lookupKeyMap, instanceName, resourceId, instanceParams);
serviceInstance.getNetworks().add(network);
}
if(network != null) {
mapCatalogNetwork(network, modelInfo, service);
}
}
protected L3Network createNetwork(Map<ResourceKey, String> lookupKeyMap, String instanceName,
String networkId, List<Map<String, String>> instanceParams) {
lookupKeyMap.put(ResourceKey.NETWORK_ID, networkId);
L3Network network = new L3Network();
network.setNetworkId(networkId);
network.setNetworkName(instanceName);
network.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
if(instanceParams != null) {
for(Map<String, String> params : instanceParams) {
network.getCloudParams().putAll(params);
}
}
return network;
}
protected void mapCatalogNetwork(L3Network network, ModelInfo modelInfo, Service service) {
NetworkResourceCustomization networkResourceCustomization = null;
for (NetworkResourceCustomization resourceCust : service.getNetworkCustomizations()) {
if (resourceCust.getModelCustomizationUUID().equalsIgnoreCase(modelInfo.getModelCustomizationUuid())) {
networkResourceCustomization = resourceCust;
break;
}
}
if (networkResourceCustomization != null) {
network.setModelInfoNetwork(this.mapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization));
}
}
protected GeneralBuildingBlock getGBBALaCarteService(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
Customer customer = getCustomerAndServiceSubscription(requestDetails, resourceId);
if (customer != null) {
Project project = null;
OwningEntity owningEntity = null;
if (requestDetails.getProject() != null)
project = mapperLayer.mapRequestProject(requestDetails.getProject());
if (requestDetails.getOwningEntity() != null)
owningEntity = mapperLayer.mapRequestOwningEntity(requestDetails.getOwningEntity());
Service service = bbInputSetupUtils
.getCatalogServiceByModelUUID(requestDetails.getModelInfo().getModelVersionId());
if (service == null) {
service = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(
requestDetails.getModelInfo().getModelVersion(),
requestDetails.getModelInfo().getModelInvariantId());
if(service == null) {
throw new Exception("Could not find service for model version Id: "
+ requestDetails.getModelInfo().getModelVersionId() + " and for model invariant Id: "
+ requestDetails.getModelInfo().getModelInvariantId());
}
}
ServiceInstance serviceInstance = this.getALaCarteServiceInstance(service, requestDetails, customer,
project, owningEntity, lookupKeyMap, resourceId, Boolean.TRUE.equals(executeBB.isaLaCarte()),
executeBB.getBuildingBlock().getBpmnFlowName());
return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, customer);
} else {
throw new Exception("Could not find customer");
}
}
protected Customer getCustomerAndServiceSubscription(RequestDetails requestDetails, String resourceId) {
Customer customer;
if (requestDetails.getSubscriberInfo() != null) {
customer = this.getCustomerFromRequest(requestDetails);
} else {
customer = this.getCustomerFromURI(resourceId);
}
if (customer != null) {
ServiceSubscription serviceSubscription = null;
serviceSubscription = getServiceSubscription(requestDetails, customer);
if (serviceSubscription == null) {
serviceSubscription = getServiceSubscriptionFromURI(resourceId, customer);
}
customer.setServiceSubscription(serviceSubscription);
return customer;
} else {
return null;
}
}
protected ServiceSubscription getServiceSubscriptionFromURI(String resourceId, Customer customer) {
Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(resourceId);
String subscriptionServiceType = uriKeys.get("service-type");
org.onap.aai.domain.yang.ServiceSubscription serviceSubscriptionAAI = bbInputSetupUtils
.getAAIServiceSubscription(customer.getGlobalCustomerId(), subscriptionServiceType);
if (serviceSubscriptionAAI != null) {
return mapperLayer.mapAAIServiceSubscription(serviceSubscriptionAAI);
} else {
return null;
}
}
protected Customer getCustomerFromURI(String resourceId) {
Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(resourceId);
String globalCustomerId = uriKeys.get("global-customer-id");
org.onap.aai.domain.yang.Customer customerAAI = this.bbInputSetupUtils.getAAICustomer(globalCustomerId);
if (customerAAI != null) {
return mapperLayer.mapAAICustomer(customerAAI);
} else {
return null;
}
}
protected GeneralBuildingBlock populateGBBWithSIAndAdditionalInfo(RequestDetails requestDetails,
ServiceInstance serviceInstance, ExecuteBuildingBlock executeBB, String requestAction, Customer customer) {
GeneralBuildingBlock outputBB = new GeneralBuildingBlock();
OrchestrationContext orchContext = mapperLayer.mapOrchestrationContext(requestDetails);
RequestContext requestContext = mapperLayer.mapRequestContext(requestDetails);
requestContext.setAction(requestAction);
requestContext.setMsoRequestId(executeBB.getRequestId());
org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils
.getCloudRegion(requestDetails.getCloudConfiguration(), CLOUD_OWNER);
CloudRegion cloudRegion = mapperLayer.mapCloudRegion(requestDetails.getCloudConfiguration(), aaiCloudRegion,
CLOUD_OWNER);
outputBB.setOrchContext(orchContext);
outputBB.setRequestContext(requestContext);
outputBB.setCloudRegion(cloudRegion);
if(customer == null){
Map<String, String> uriKeys = bbInputSetupUtils.getURIKeysFromServiceInstance(serviceInstance.getServiceInstanceId());
String globalCustomerId = uriKeys.get("global-customer-id");
String subscriptionServiceType = uriKeys.get("service-type");
customer = mapCustomer(globalCustomerId, subscriptionServiceType);
}
outputBB.setServiceInstance(serviceInstance);
if (customer.getServiceSubscription() != null) {
customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
}
outputBB.setCustomer(customer);
return outputBB;
}
protected ServiceSubscription getServiceSubscription(RequestDetails requestDetails, Customer customer) {
org.onap.aai.domain.yang.ServiceSubscription aaiServiceSubscription = bbInputSetupUtils
.getAAIServiceSubscription(customer.getGlobalCustomerId(),
requestDetails.getRequestParameters().getSubscriptionServiceType());
if (aaiServiceSubscription != null) {
return mapperLayer.mapAAIServiceSubscription(aaiServiceSubscription);
} else {
return null;
}
}
protected Customer getCustomerFromRequest(RequestDetails requestDetails) {
org.onap.aai.domain.yang.Customer aaiCustomer = bbInputSetupUtils
.getAAICustomer(requestDetails.getSubscriberInfo().getGlobalSubscriberId());
if (aaiCustomer != null) {
return mapperLayer.mapAAICustomer(aaiCustomer);
} else {
return null;
}
}
protected ServiceInstance getALaCarteServiceInstance(Service service, RequestDetails requestDetails,
Customer customer, Project project, OwningEntity owningEntity, Map<ResourceKey, String> lookupKeyMap,
String serviceInstanceId, boolean aLaCarte, String bbName) throws Exception {
ServiceInstance serviceInstance = this.getServiceInstanceHelper(requestDetails, customer, project, owningEntity,
lookupKeyMap, serviceInstanceId, aLaCarte, service, bbName);
org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = this.bbInputSetupUtils
.getAAIServiceInstanceById(serviceInstanceId);
if (serviceInstanceAAI != null
&& !serviceInstanceAAI.getModelVersionId().equalsIgnoreCase(service.getModelUUID())) {
Service tempService = this.bbInputSetupUtils
.getCatalogServiceByModelUUID(serviceInstanceAAI.getModelVersionId());
if (tempService != null) {
serviceInstance
.setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(tempService));
return serviceInstance;
} else {
throw new Exception(
"Could not find model of existing SI. Service Instance in AAI already exists with different model version id: "
+ serviceInstanceAAI.getModelVersionId());
}
}
serviceInstance.setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(service));
return serviceInstance;
}
protected GeneralBuildingBlock getGBBMacro(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId, String vnfType)
throws Exception {
String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
String key = executeBB.getBuildingBlock().getKey();
GeneralBuildingBlock gBB = this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction,
resourceId);
RequestParameters requestParams = requestDetails.getRequestParameters();
Service service = null;
if (gBB != null && gBB.getServiceInstance() != null
&& gBB.getServiceInstance().getModelInfoServiceInstance() != null
&& gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid() != null) {
service = bbInputSetupUtils.getCatalogServiceByModelUUID(
gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid());
} else {
throw new Exception("Could not get service instance for macro request");
}
if (requestParams != null && requestParams.getUserParams() != null) {
for(Map<String, Object> userParams : requestParams.getUserParams()) {
if(userParams.containsKey("service")) {
String input = mapper.writeValueAsString(userParams.get("service"));
return getGBBMacroUserParams(executeBB, requestDetails, lookupKeyMap, vnfType, bbName, key, gBB,
requestParams, service, input);
}
}
}
if (requestAction.equalsIgnoreCase("deactivateInstance")) {
return gBB;
} else if (requestAction.equalsIgnoreCase("createInstance")) {
return getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, bbName, key, gBB, service);
} else if (requestAction.equalsIgnoreCase("deleteInstance")
|| requestAction.equalsIgnoreCase("unassignInstance")
|| requestAction.equalsIgnoreCase("activateInstance")
|| requestAction.equalsIgnoreCase("activateFabricConfiguration")) {
return getGBBMacroExistingService(executeBB, lookupKeyMap, bbName, gBB, service, requestAction,
requestDetails.getCloudConfiguration());
} else {
throw new IllegalArgumentException(
"No user params on requestAction: assignInstance. Please specify user params.");
}
}
protected GeneralBuildingBlock getGBBMacroNoUserParamsCreate(ExecuteBuildingBlock executeBB,
Map<ResourceKey, String> lookupKeyMap, String bbName, String key, GeneralBuildingBlock gBB, Service service)
throws Exception {
ServiceInstance serviceInstance = gBB.getServiceInstance();
if (bbName.contains(NETWORK) && !bbName.contains(NETWORK_COLLECTION)) {
String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
ModelInfo networkModelInfo = new ModelInfo();
if((!Boolean.TRUE.equals(executeBB.getBuildingBlock().getIsVirtualLink()))) {
NetworkResourceCustomization networkCust = getNetworkCustomizationByKey(key, service);
if (networkCust != null) {
networkModelInfo.setModelCustomizationUuid(networkCust.getModelCustomizationUUID());
this.populateL3Network(null, networkModelInfo, service, bbName, serviceInstance, lookupKeyMap,
networkId, null);
} else {
msoLogger.debug("Could not find a network customization with key: " + key);
}
} else {
msoLogger.debug("Orchestrating on Collection Network Resource Customization");
CollectionNetworkResourceCustomization collectionNetworkResourceCust = bbInputSetupUtils.getCatalogCollectionNetworkResourceCustByID(key);
L3Network l3Network = getVirtualLinkL3Network(lookupKeyMap, bbName, key, networkId, collectionNetworkResourceCust, serviceInstance);
NetworkResourceCustomization networkResourceCustomization =
mapperLayer.mapCollectionNetworkResourceCustToNetworkResourceCust(collectionNetworkResourceCust);
if(l3Network != null) {
l3Network.setModelInfoNetwork(mapperLayer.mapCatalogNetworkToNetwork(networkResourceCustomization));
}
}
} else if(bbName.contains("Configuration")) {
String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
ModelInfo configurationModelInfo = new ModelInfo();
configurationModelInfo.setModelCustomizationUuid(key);
this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap, configurationId, null, executeBB.getConfigurationResourceKeys());
}
if (executeBB.getWorkflowResourceIds() != null) {
this.populateNetworkCollectionAndInstanceGroupAssign(service, bbName, serviceInstance,
executeBB.getWorkflowResourceIds().getNetworkCollectionId(), key);
}
return gBB;
}
protected L3Network getVirtualLinkL3Network(Map<ResourceKey, String> lookupKeyMap, String bbName, String key,
String networkId, CollectionNetworkResourceCustomization collectionNetworkResourceCust, ServiceInstance serviceInstance) {
if(collectionNetworkResourceCust != null) {
if((bbName.equalsIgnoreCase(AssignFlows.NETWORK_A_LA_CARTE.toString())
|| bbName.equalsIgnoreCase(AssignFlows.NETWORK_MACRO.toString()))) {
L3Network network = createNetwork(lookupKeyMap, null, networkId, null);
serviceInstance.getNetworks().add(network);
return network;
} else {
for (L3Network network : serviceInstance.getNetworks()) {
if (network.getNetworkId().equalsIgnoreCase(networkId)) {
return network;
}
}
}
}
return null;
}
protected NetworkResourceCustomization getNetworkCustomizationByKey(String key, Service service) {
for (NetworkResourceCustomization networkCust : service.getNetworkCustomizations()) {
if (networkCust.getModelCustomizationUUID().equalsIgnoreCase(key)) {
return networkCust;
}
}
return null;
}
protected GeneralBuildingBlock getGBBMacroExistingService(ExecuteBuildingBlock executeBB,
Map<ResourceKey, String> lookupKeyMap, String bbName, GeneralBuildingBlock gBB, Service service,
String requestAction, CloudConfiguration cloudConfiguration) throws Exception {
ServiceInstance serviceInstance = gBB.getServiceInstance();
if (cloudConfiguration != null && requestAction.equalsIgnoreCase("deleteInstance")) {
org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration,
CLOUD_OWNER);
CloudRegion cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion, CLOUD_OWNER);
gBB.setCloudRegion(cloudRegion);
}
if (bbName.contains(VNF)) {
for (GenericVnf genericVnf : serviceInstance.getVnfs()) {
if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null
&& genericVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
org.onap.aai.domain.yang.GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(genericVnf.getVnfId());
ModelInfo modelInfo = new ModelInfo();
if (vnf != null) {
modelInfo.setModelCustomizationUuid(vnf.getModelCustomizationId());
}
this.mapCatalogVnf(genericVnf, modelInfo, service);
}
}