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
|
/*-
* ============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.db.catalog.client;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.core.UriBuilder;
import org.onap.so.db.catalog.beans.BuildingBlockDetail;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.db.catalog.beans.CloudifyManager;
import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
import org.onap.so.db.catalog.beans.ControllerSelectionReference;
import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
import org.onap.so.db.catalog.beans.CvnfcCustomization;
import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
import org.onap.so.db.catalog.beans.HomingInstance;
import org.onap.so.db.catalog.beans.InstanceGroup;
import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
import org.onap.so.db.catalog.beans.NetworkRecipe;
import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
import org.onap.so.db.catalog.beans.OrchestrationAction;
import org.onap.so.db.catalog.beans.OrchestrationStatus;
import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
import org.onap.so.db.catalog.beans.PnfResource;
import org.onap.so.db.catalog.beans.PnfResourceCustomization;
import org.onap.so.db.catalog.beans.ResourceType;
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.ServiceRecipe;
import org.onap.so.db.catalog.beans.VfModule;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
import org.onap.so.db.catalog.beans.VnfRecipe;
import org.onap.so.db.catalog.beans.VnfResource;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
import org.onap.so.db.catalog.beans.Workflow;
import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
import org.onap.so.logger.LogConstants;
import org.onap.so.logging.jaxrs.filter.SpringClientFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import uk.co.blackpepper.bowman.Client;
import uk.co.blackpepper.bowman.ClientFactory;
import uk.co.blackpepper.bowman.Configuration;
@Component("CatalogDbClient")
public class CatalogDbClient {
private static final Logger logger = LoggerFactory.getLogger(CatalogDbClient.class);
private static final String CLOUD_SITE = "/cloudSite";
private static final String CLOUDIFY_MANAGER = "/cloudifyManager";
private static final String RAINY_DAY_HANDLER_MACRO = "/rainy_day_handler_macro";
private static final String NORTHBOUND_REQUEST_REF_LOOKUP = "/northbound_request_ref_lookup";
private static final String NETWORK_RESOURCE_CUSTOMIZATION = "/networkResourceCustomization";
private static final String COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION =
"/collectionResourceInstanceGroupCustomization";
private static final String VNFC_INSTANCE_GROUP_CUSTOMIZATION = "/vnfcInstanceGroupCustomization";
private static final String ORCHESTRATION_FLOW = "/orchestrationFlow";
private static final String ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE =
"/orchestrationStatusStateTransitionDirective";
private static final String INSTANCE_GROUP = "/instanceGroup";
private static final String COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION = "/collectionNetworkResourceCustomization";
private static final String BUILDING_BLOCK_DETAIL = "/buildingBlockDetail";
private static final String NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION = "/networkCollectionResourceCustomization";
private static final String VNF_RESOURCE_CUSTOMIZATION = "/vnfResourceCustomization";
private static final String SERVICE = "/service";
private static final String EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING = "/externalServiceToInternalService";
private static final String VNF_RESOURCE = "/vnfResource";
private static final String VNF_RECIPE = "/vnfRecipe";
private static final String VFMODULE = "/vfModule";
private static final String VFMODULE_CUSTOMIZATION = "/vfModuleCustomization";
private static final String VNF_COMPONENTS_RECIPE = "/vnfComponentsRecipe";
private static final String SERVICE_RECIPE = "/serviceRecipe";
private static final String NETWORK_RECIPE = "/networkRecipe";
private static final String PNF_RESOURCE = "/pnfResource";
private static final String PNF_RESOURCE_CUSTOMIZATION = "/pnfResourceCustomization";
private static final String WORKFLOW = "/workflow";
private static final String SEARCH = "/search";
private static final String URI_SEPARATOR = "/";
private static final String SERVICE_MODEL_UUID = "serviceModelUUID";
private static final String SERVICE_NAME = "serviceName";
private static final String MODEL_UUID = "modelUUID";
private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
private static final String ACTION = "action";
private static final String MODEL_NAME = "modelName";
private static final String MODEL_VERSION = "modelVersion";
private static final String MODEL_INVARIANT_UUID = "modelInvariantUUID";
private static final String VNF_RESOURCE_MODEL_UUID = "vnfResourceModelUUID";
private static final String NF_ROLE = "nfRole";
private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
private static final String BUILDING_BLOCK_NAME = "buildingBlockName";
private static final String RESOURCE_TYPE = "resourceType";
private static final String ORCHESTRATION_STATUS = "orchestrationStatus";
private static final String TARGET_ACTION = "targetAction";
private static final String REQUEST_SCOPE = "requestScope";
private static final String IS_ALACARTE = "isALaCarte";
private static final String CLOUD_OWNER = "cloudOwner";
private static final String FLOW_NAME = "flowName";
private static final String ERROR_MESSAGE = "errorMessage";
private static final String SERVICE_TYPE = "serviceType";
private static final String VNF_TYPE = "vnfType";
private static final String ERROR_CODE = "errorCode";
private static final String WORK_STEP = "workStep";
private static final String CLLI = "clli";
private static final String CLOUD_VERSION = "cloudVersion";
private static final String HOMING_INSTANCE = "/homingInstance";
private static final String ARTIFACT_UUID = "artifactUUID";
private static final String SOURCE = "source";
private static final String TARGET_ENTITY = "SO:CatalogDB";
private static final String ASTERISK = "*";
private String findExternalToInternalServiceByServiceName = "/findByServiceName";
private String findServiceByModelName = "/findOneByModelName";
private String findServiceRecipeByActionAndServiceModelUUID = "/findByActionAndServiceModelUUID";
private String findServiceByModelUUID = "/findOneByModelUUID";
private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc";
private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction";
private String findFirstByModelVersionAndModelInvariantUUIDURI = "/findFirstByModelVersionAndModelInvariantUUID";
private String findByModelInvariantUUIDURI = "/findByModelInvariantUUIDOrderByModelVersionDesc";
private String findFirstByModelNameAndAction = "/findFirstByModelNameAndAction";
private String findFirstResourceByModelInvariantUUIDAndModelVersion =
"/findFirstResourceByModelInvariantUUIDAndModelVersion";
private String findByModelInstanceNameAndVnfResources = "/findByModelInstanceNameAndVnfResources";
private String findFirstVnfRecipeByNfRoleAndAction = "/findFirstVnfRecipeByNfRoleAndAction";
private String findByModelCustomizationUUIDAndVfModuleModelUUID =
"/findFirstByModelCustomizationUUIDAndVfModuleModelUUIDOrderByCreatedDesc";
private String findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction =
"/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction";
private String findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
"/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction";
private String findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
"/findByModelInvariantUUIDOrderByModelVersionDesc";
private String findFirstVfModuleByModelInvariantUUIDAndModelVersion =
"/findFirstVfModuleByModelInvariantUUIDAndModelVersion";
private String findOneByBuildingBlockName = "/findOneByBuildingBlockName";
private String findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
"/findOneByResourceTypeAndOrchestrationStatusAndTargetAction";
private String findByAction = "/findByAction";
private String findVnfcInstanceGroupCustomizationByModelCustomizationUUID = "/findByModelCustomizationUUID";
private String findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
"/findByModelCustomizationUUID";
private String findOneByActionAndRequestScopeAndIsAlacarte = "/findOneByActionAndRequestScopeAndIsAlacarte";
private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner =
"/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner";
private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
"/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType";
private static final String findRainyDayHandler = "/findRainyDayHandler";
private String findByClliAndCloudVersion = "/findByClliAndCloudVersion";
private String findServiceByServiceInstanceId = "/findServiceByServiceInstanceId";
private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid";
private String findWorkflowByArtifactUUID = "/findByArtifactUUID";
private String findWorkflowByModelUUID = "/findWorkflowByModelUUID";
private String findWorkflowBySource = "/findBySource";
private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
private String serviceURI;
private String vfModuleURI;
private String vnfResourceURI;
private String networkCollectionResourceCustomizationURI;
private String networkResourceCustomizationURI;
private String collectionNetworkResourceCustomizationURI;
private String instanceGroupURI;
private String cloudifyManagerURI;
private String cloudSiteURI;
private String homingInstanceURI;
private String cvnfcResourceCustomizationURI;
private String pnfResourceURI;
private String pnfResourceCustomizationURI;
private String workflowURI;
private final Client<Service> serviceClient;
private final Client<NetworkRecipe> networkRecipeClient;
private final Client<NetworkResourceCustomization> networkResourceCustomizationClient;
private final Client<VnfResource> vnfResourceClient;
private final Client<VnfResourceCustomization> vnfResourceCustomizationClient;
private final Client<VnfRecipe> vnfRecipeClient;
private final Client<VfModuleCustomization> vfModuleCustomizationClient;
private final Client<VfModule> vfModuleClient;
private final Client<VnfComponentsRecipe> vnfComponentsRecipeClient;
private final Client<OrchestrationFlow> orchestrationClient;
private final Client<NorthBoundRequest> northBoundRequestClient;
private final Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
private final Client<BuildingBlockDetail> buildingBlockDetailClient;
private final Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
private final Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
private final Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
private final Client<InstanceGroup> instanceGroupClient;
private final Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
private final Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
private final Client<ServiceRecipe> serviceRecipeClient;
private final Client<ExternalServiceToInternalService> externalServiceToInternalServiceClient;
private final Client<CloudSite> cloudSiteClient;
private final Client<HomingInstance> homingInstanceClient;
private final Client<CloudifyManager> cloudifyManagerClient;
private final Client<ControllerSelectionReference> controllerSelectionReferenceClient;
private final Client<PnfResource> pnfResourceClient;
private final Client<PnfResourceCustomization> pnfResourceCustomizationClient;
private final Client<Workflow> workflowClient;
@Value("${mso.catalog.db.spring.endpoint:#{null}}")
private String endpoint;
@Value("${mso.db.auth:#{null}}")
private String msoAdaptersAuth;
@Autowired
RestTemplate restTemplate;
@PostConstruct
public void init() {
findExternalToInternalServiceByServiceName = endpoint + EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING + SEARCH
+ findExternalToInternalServiceByServiceName;
findServiceByModelName = endpoint + SERVICE + SEARCH + findServiceByModelName;
findServiceRecipeByActionAndServiceModelUUID =
endpoint + SERVICE_RECIPE + SEARCH + findServiceRecipeByActionAndServiceModelUUID;
findServiceByModelUUID = endpoint + SERVICE + SEARCH + findServiceByModelUUID;
findFirstByModelNameURI = endpoint + SERVICE + SEARCH + findFirstByModelNameURI;
findFirstByModelVersionAndModelInvariantUUIDURI =
endpoint + SERVICE + SEARCH + findFirstByModelVersionAndModelInvariantUUIDURI;
findByModelInvariantUUIDURI = endpoint + SERVICE + SEARCH + findByModelInvariantUUIDURI;
findFirstByServiceModelUUIDAndActionURI =
endpoint + SERVICE_RECIPE + SEARCH + findFirstByServiceModelUUIDAndActionURI;
findFirstByModelNameAndAction = endpoint + NETWORK_RECIPE + SEARCH + findFirstByModelNameAndAction;
findFirstResourceByModelInvariantUUIDAndModelVersion =
endpoint + VNF_RESOURCE + SEARCH + findFirstResourceByModelInvariantUUIDAndModelVersion;
findByModelInstanceNameAndVnfResources =
endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findByModelInstanceNameAndVnfResources;
findFirstVnfRecipeByNfRoleAndAction = endpoint + VNF_RECIPE + SEARCH + findFirstVnfRecipeByNfRoleAndAction;
findByModelCustomizationUUIDAndVfModuleModelUUID =
endpoint + VFMODULE_CUSTOMIZATION + SEARCH + findByModelCustomizationUUIDAndVfModuleModelUUID;
findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction = endpoint + VNF_COMPONENTS_RECIPE
+ SEARCH + findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction;
findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
endpoint + VNF_COMPONENTS_RECIPE + SEARCH + findFirstVnfComponentsRecipeByVnfComponentTypeAndAction;
findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
endpoint + VFMODULE + SEARCH + findVfModuleByModelInvariantUUIDOrderByModelVersionDesc;
findFirstVfModuleByModelInvariantUUIDAndModelVersion =
endpoint + VFMODULE + SEARCH + findFirstVfModuleByModelInvariantUUIDAndModelVersion;
findOneByBuildingBlockName = endpoint + BUILDING_BLOCK_DETAIL + SEARCH + findOneByBuildingBlockName;
findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
endpoint + ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE + SEARCH
+ findOneByResourceTypeAndOrchestrationStatusAndTargetAction;
findByAction = endpoint + ORCHESTRATION_FLOW + SEARCH + findByAction;
findVnfcInstanceGroupCustomizationByModelCustomizationUUID = endpoint + VNFC_INSTANCE_GROUP_CUSTOMIZATION
+ SEARCH + findVnfcInstanceGroupCustomizationByModelCustomizationUUID;
findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
endpoint + COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION + SEARCH
+ findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID;
findOneByActionAndRequestScopeAndIsAlacarte =
endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH + findOneByActionAndRequestScopeAndIsAlacarte;
findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner = endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
+ findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner;
findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
+ findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType;
findByClliAndCloudVersion = endpoint + CLOUD_SITE + SEARCH + findByClliAndCloudVersion;
findPnfResourceCustomizationByModelUuid =
endpoint + PNF_RESOURCE_CUSTOMIZATION + SEARCH + findPnfResourceCustomizationByModelUuid;
findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID;
findWorkflowByModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByModelUUID;
findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
findVnfResourceCustomizationByModelUuid =
endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findVnfResourceCustomizationByModelUuid;
serviceURI = endpoint + SERVICE + URI_SEPARATOR;
vfModuleURI = endpoint + VFMODULE + URI_SEPARATOR;
vnfResourceURI = endpoint + VNF_RESOURCE + URI_SEPARATOR;
networkCollectionResourceCustomizationURI =
endpoint + NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
networkResourceCustomizationURI = endpoint + NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
collectionNetworkResourceCustomizationURI =
endpoint + COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
instanceGroupURI = endpoint + INSTANCE_GROUP + URI_SEPARATOR;
cloudifyManagerURI = endpoint + CLOUDIFY_MANAGER + URI_SEPARATOR;
cloudSiteURI = endpoint + CLOUD_SITE + URI_SEPARATOR;
homingInstanceURI = endpoint + HOMING_INSTANCE + URI_SEPARATOR;
pnfResourceURI = endpoint + PNF_RESOURCE + URI_SEPARATOR;
pnfResourceCustomizationURI = endpoint + PNF_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
workflowURI = endpoint + WORKFLOW + URI_SEPARATOR;
}
public CatalogDbClient() {
ClientHttpRequestFactory factory =
new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
ClientFactory clientFactory =
Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
restTemplate.getInterceptors().add((new SpringClientFilter()));
restTemplate.getInterceptors().add((request, body, execution) -> {
request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
request.getHeaders().add(LogConstants.TARGET_ENTITY_HEADER, TARGET_ENTITY);
return execution.execute(request, body);
});
}).build().buildClientFactory();
serviceClient = clientFactory.create(Service.class);
networkRecipeClient = clientFactory.create(NetworkRecipe.class);
networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
vnfResourceClient = clientFactory.create(VnfResource.class);
vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
vnfRecipeClient = clientFactory.create(VnfRecipe.class);
orchestrationClient = clientFactory.create(OrchestrationFlow.class);
vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
vfModuleClient = clientFactory.create(VfModule.class);
vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
orchestrationStatusStateTransitionDirectiveClient =
clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
collectionResourceInstanceGroupCustomizationClient =
clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
instanceGroupClient = clientFactory.create(InstanceGroup.class);
networkCollectionResourceCustomizationClient =
clientFactory.create(NetworkCollectionResourceCustomization.class);
collectionNetworkResourceCustomizationClient =
clientFactory.create(CollectionNetworkResourceCustomization.class);
cloudSiteClient = clientFactory.create(CloudSite.class);
homingInstanceClient = clientFactory.create(HomingInstance.class);
cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
pnfResourceClient = clientFactory.create(PnfResource.class);
pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
workflowClient = clientFactory.create(Workflow.class);
}
public CatalogDbClient(String baseUri, String auth) {
ClientHttpRequestFactory factory =
new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
ClientFactory clientFactory = Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory)
.setRestTemplateConfigurer(restTemplate -> {
restTemplate.getInterceptors().add((new SpringClientFilter()));
restTemplate.getInterceptors().add((request, body, execution) -> {
request.getHeaders().add(HttpHeaders.AUTHORIZATION, auth);
request.getHeaders().add(LogConstants.TARGET_ENTITY_HEADER, TARGET_ENTITY);
return execution.execute(request, body);
});
}).build().buildClientFactory();
serviceClient = clientFactory.create(Service.class);
networkRecipeClient = clientFactory.create(NetworkRecipe.class);
networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
vnfResourceClient = clientFactory.create(VnfResource.class);
vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
vnfRecipeClient = clientFactory.create(VnfRecipe.class);
orchestrationClient = clientFactory.create(OrchestrationFlow.class);
vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
vfModuleClient = clientFactory.create(VfModule.class);
vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
orchestrationStatusStateTransitionDirectiveClient =
clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
collectionResourceInstanceGroupCustomizationClient =
clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
instanceGroupClient = clientFactory.create(InstanceGroup.class);
networkCollectionResourceCustomizationClient =
clientFactory.create(NetworkCollectionResourceCustomization.class);
collectionNetworkResourceCustomizationClient =
clientFactory.create(CollectionNetworkResourceCustomization.class);
cloudSiteClient = clientFactory.create(CloudSite.class);
homingInstanceClient = clientFactory.create(HomingInstance.class);
cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
pnfResourceClient = clientFactory.create(PnfResource.class);
pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
workflowClient = clientFactory.create(Workflow.class);
}
public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(
String modelCustomizationUUID) {
NetworkCollectionResourceCustomization networkCollectionResourceCustomization =
this.getSingleResource(networkCollectionResourceCustomizationClient,
getUri(networkCollectionResourceCustomizationURI + modelCustomizationUUID));
if (networkCollectionResourceCustomization != null) {
networkCollectionResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
}
return networkCollectionResourceCustomization;
}
public Service getServiceByID(String modelUUID) {
Service service = getSingleResource(serviceClient, getUri(serviceURI + modelUUID));
if (service != null) {
service.setModelUUID(modelUUID);
}
return service;
}
public VfModule getVfModuleByModelUUID(String modelUUID) {
VfModule vfModule = getSingleResource(vfModuleClient, getUri(vfModuleURI + modelUUID));
if (vfModule != null) {
vfModule.setModelUUID(modelUUID);
}
return vfModule;
}
public VnfResource getVnfResourceByModelUUID(String modelUUID) {
VnfResource vnfResource = this.getSingleResource(vnfResourceClient, getUri(vnfResourceURI + modelUUID));
if (vnfResource != null) {
vnfResource.setModelUUID(modelUUID);
}
return vnfResource;
}
// A VNFResource customization UUID is the same object across services, so we can return anyone from the list
// In the future the client should query starting at a service model uuid
public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
List<VnfResourceCustomization> vnfResourceCustomization = this.getMultipleResources(
vnfResourceCustomizationClient, getUri(endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH
+ "/findByModelCustomizationUUID" + "?MODEL_CUSTOMIZATION_UUID=" + modelCustomizationUUID));
if (vnfResourceCustomization != null && !vnfResourceCustomization.isEmpty()) {
return vnfResourceCustomization.get(0);
} else {
return null;
}
}
public List<VnfResourceCustomization> getVnfResourceCustomizationByModelUuid(String modelUuid) {
return this.getMultipleResources(vnfResourceCustomizationClient,
getUri(UriBuilder.fromUri(findVnfResourceCustomizationByModelUuid)
.queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
}
public PnfResource getPnfResourceByModelUUID(String modelUUID) {
PnfResource PnfResource = this.getSingleResource(pnfResourceClient, getUri(pnfResourceURI + modelUUID));
if (PnfResource != null) {
PnfResource.setModelUUID(modelUUID);
}
return PnfResource;
}
public PnfResourceCustomization getPnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
PnfResourceCustomization pnfResourceCustomization = getSingleResource(pnfResourceCustomizationClient,
getUri(pnfResourceCustomizationURI + modelCustomizationUUID));
if (pnfResourceCustomization != null) {
pnfResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
}
return pnfResourceCustomization;
}
public List<PnfResourceCustomization> getPnfResourceCustomizationByModelUuid(String modelUuid) {
return this.getMultipleResources(pnfResourceCustomizationClient,
getUri(UriBuilder.fromUri(findPnfResourceCustomizationByModelUuid)
.queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
}
public CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomizationByID(
String modelCustomizationUUID) {
CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
this.getSingleResource(collectionNetworkResourceCustomizationClient,
getUri(UriBuilder.fromUri(collectionNetworkResourceCustomizationURI + modelCustomizationUUID)
.build().toString()));
if (collectionNetworkResourceCustomization != null) {
collectionNetworkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
}
return collectionNetworkResourceCustomization;
}
public InstanceGroup getInstanceGroupByModelUUID(String modelUUID) {
InstanceGroup instanceGroup = this.getSingleResource(instanceGroupClient, getUri(instanceGroupURI + modelUUID));
if (instanceGroup != null) {
instanceGroup.setModelUUID(modelUUID);
}
return instanceGroup;
}
public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
return this.getSingleResource(vfModuleCustomizationClient,
getUri(endpoint + VFMODULE_CUSTOMIZATION + SEARCH
+ "/findFirstByModelCustomizationUUIDOrderByCreatedDesc" + "?MODEL_CUSTOMIZATION_UUID="
+ modelCustomizationUUID));
}
public NetworkResourceCustomization getNetworkResourceCustomizationByModelCustomizationUUID(
String modelCustomizationUUID) {
NetworkResourceCustomization networkResourceCustomization = this.getSingleResource(
networkResourceCustomizationClient, getUri(networkResourceCustomizationURI + modelCustomizationUUID));
if (networkResourceCustomization != null) {
networkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
}
return networkResourceCustomization;
}
public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) {
BuildingBlockDetail buildingBlockDetail =
getSingleResource(buildingBlockDetailClient, getUri(UriBuilder.fromUri(findOneByBuildingBlockName)
.queryParam(BUILDING_BLOCK_NAME, buildingBlockName).build().toString()));
if (buildingBlockDetail != null) {
buildingBlockDetail.setBuildingBlockName(buildingBlockName);
}
return buildingBlockDetail;
}
public OrchestrationStatusStateTransitionDirective getOrchestrationStatusStateTransitionDirective(
ResourceType resourceType, OrchestrationStatus orchestrationStatus, OrchestrationAction targetAction) {
return getSingleResource(orchestrationStatusStateTransitionDirectiveClient,
UriBuilder.fromUri(findOneByResourceTypeAndOrchestrationStatusAndTargetAction)
.queryParam(RESOURCE_TYPE, resourceType.name())
.queryParam(ORCHESTRATION_STATUS, orchestrationStatus.name())
.queryParam(TARGET_ACTION, targetAction.name()).build());
}
public List<OrchestrationFlow> getOrchestrationFlowByAction(String action) {
return this.getMultipleResources(orchestrationClient,
UriBuilder.fromUri(findByAction).queryParam(ACTION, action).build());
}
public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroupsByVnfResourceCust(String modelCustomizationUUID) {
return this.getMultipleResources(vnfcInstanceGroupCustomizationClient,
UriBuilder.fromUri(findVnfcInstanceGroupCustomizationByModelCustomizationUUID)
.queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
}
public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomizationByModelCustUUID(
String modelCustomizationUUID) {
return this.getMultipleResources(collectionResourceInstanceGroupCustomizationClient,
UriBuilder.fromUri(findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID)
.queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
}
public VfModuleCustomization getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
String modelCustomizationUUID, String vfModuleModelUUID) {
return this.getSingleResource(vfModuleCustomizationClient,
getUri(UriBuilder.fromUri(findByModelCustomizationUUIDAndVfModuleModelUUID)
.queryParam("MODEL_CUSTOMIZATION_UUID", modelCustomizationUUID)
.queryParam("MODEL_UUID", vfModuleModelUUID).build().toString()));
}
public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(String requestAction,
String resourceName, boolean aLaCarte) {
return this.getSingleResource(northBoundRequestClient,
UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarte).queryParam(ACTION, requestAction)
.queryParam(REQUEST_SCOPE, resourceName).queryParam(IS_ALACARTE, aLaCarte).build());
}
public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(String requestAction,
String resourceName, boolean aLaCarte, String cloudOwner) {
return this.getSingleResource(northBoundRequestClient,
getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
.queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
.queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
.queryParam(SERVICE_TYPE, ASTERISK).build().toString()));
}
public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType(
String requestAction, String resourceName, boolean aLaCarte, String cloudOwner, String serviceType) {
return this.getSingleResource(northBoundRequestClient,
getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
.queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
.queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
.queryParam(SERVICE_TYPE, serviceType).build().toString()));
}
public RainyDayHandlerStatus getRainyDayHandlerStatus(String flowName, String serviceType, String vnfType,
String errorCode, String workStep, String errorMessage) {
logger.debug(
"Get Rainy Day Status - Flow Name {}, Service Type: {} , vnfType {} , errorCode {}, workStep {}, errorMessage {}",
flowName, serviceType, vnfType, errorCode, workStep, errorMessage);
return this.getSingleResource(rainyDayHandlerStatusClient,
UriComponentsBuilder.fromUriString(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler)
.queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType)
.queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep)
.queryParam(ERROR_MESSAGE, errorMessage).build().encode().toUri());
}
public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action) {
return this.getSingleResource(serviceRecipeClient,
getUri(UriBuilder.fromUri(findFirstByServiceModelUUIDAndActionURI)
.queryParam(SERVICE_MODEL_UUID, modelUUID).queryParam(ACTION, action).build().toString()));
}
public NetworkRecipe getFirstNetworkRecipeByModelNameAndAction(String modelName, String action) {
return this.getSingleResource(networkRecipeClient, UriBuilder.fromUri(findFirstByModelNameAndAction)
.queryParam(MODEL_NAME, modelName).queryParam(ACTION, action).build());
}
public ControllerSelectionReference getControllerSelectionReferenceByVnfTypeAndActionCategory(String vnfType,
String actionCategory) {
return this.getSingleResource(controllerSelectionReferenceClient, UriBuilder.fromUri(endpoint
+ "/controllerSelectionReference/search/findControllerSelectionReferenceByVnfTypeAndActionCategory")
.queryParam("VNF_TYPE", vnfType).queryParam("ACTION_CATEGORY", actionCategory).build());
}
public Service getFirstByModelNameOrderByModelVersionDesc(String modelName) {
return this.getSingleResource(serviceClient,
UriBuilder.fromUri(findFirstByModelNameURI).queryParam(MODEL_NAME, modelName).build());
}
public ExternalServiceToInternalService findExternalToInternalServiceByServiceName(String serviceName) {
return this.getSingleResource(externalServiceToInternalServiceClient,
getUri(UriBuilder.fromUri(findExternalToInternalServiceByServiceName)
.queryParam(SERVICE_NAME, serviceName).build().toString()));
}
public ServiceRecipe findServiceRecipeByActionAndServiceModelUUID(String action, String modelUUID) {
return this.getSingleResource(serviceRecipeClient,
getUri(UriBuilder.fromUri(findServiceRecipeByActionAndServiceModelUUID).queryParam(ACTION, action)
.queryParam(SERVICE_MODEL_UUID, modelUUID).build().toString()));
}
public Service getServiceByModelName(String modelName) {
return this.getSingleResource(serviceClient, getUri(
UriBuilder.fromUri(findServiceByModelName).queryParam(MODEL_NAME, modelName).build().toString()));
}
public Service getServiceByModelUUID(String modelModelUUID) {
return this.getSingleResource(serviceClient, getUri(
UriBuilder.fromUri(findServiceByModelUUID).queryParam(MODEL_UUID, modelModelUUID).build().toString()));
}
public VnfResource getFirstVnfResourceByModelInvariantUUIDAndModelVersion(String modelInvariantUUID,
String modelVersion) {
return this.getSingleResource(vnfResourceClient,
getUri(UriBuilder.fromUri(findFirstResourceByModelInvariantUUIDAndModelVersion)
.queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
.build().toString()));
}
public VnfResourceCustomization getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources(
String modelInstanceName, VnfResource vnfResource) {
return this.getSingleResource(vnfResourceCustomizationClient,
getUri(UriBuilder.fromUri(findByModelInstanceNameAndVnfResources)
.queryParam("MODEL_INSTANCE_NAME", modelInstanceName)
.queryParam("VNF_RESOURCE_MODEL_UUID", vnfResource.getModelUUID()).build().toString()));
}
public VnfRecipe getFirstVnfRecipeByNfRoleAndAction(String nfRole, String action) {
return this.getSingleResource(vnfRecipeClient, getUri(UriBuilder.fromUri(findFirstVnfRecipeByNfRoleAndAction)
.queryParam(NF_ROLE, nfRole).queryParam(ACTION, action).build().toString()));
}
public VnfComponentsRecipe getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
String vfModuleModelUUID, String modelType, String action) {
return this.getSingleResource(vnfComponentsRecipeClient,
getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction)
.queryParam(VF_MODULE_MODEL_UUID, vfModuleModelUUID).queryParam(VNF_COMPONENT_TYPE, modelType)
.queryParam(ACTION, action).build().toString()));
}
public VnfComponentsRecipe getFirstVnfComponentsRecipeByVnfComponentTypeAndAction(String modelType, String action) {
return this.getSingleResource(vnfComponentsRecipeClient,
getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVnfComponentTypeAndAction)
.queryParam(VNF_COMPONENT_TYPE, modelType).queryParam(ACTION, action).build().toString()));
}
protected URI getUri(String template) {
return URI.create(template);
}
public CloudifyManager getCloudifyManager(String id) {
return this.getSingleResource(cloudifyManagerClient, getUri(cloudifyManagerURI + id));
}
public CloudSite getCloudSite(String id) {
return this.getSingleResource(cloudSiteClient, getUri(cloudSiteURI + id));
}
public CloudSite getCloudSite(String id, String uri) {
return this.getSingleResource(cloudSiteClient, getUri(uri + id));
}
public void postCloudSite(CloudSite cloudSite) {
this.postSingleResource(cloudSiteClient, cloudSite);
}
public CloudSite getCloudSiteByClliAndAicVersion(String clli, String cloudVersion) {
return this.getSingleResource(cloudSiteClient, getUri(UriBuilder.fromUri(findByClliAndCloudVersion)
.queryParam(CLLI, clli).queryParam(CLOUD_VERSION, cloudVersion).build().toString()));
}
public HomingInstance getHomingInstance(String serviceInstanceId) {
return this.getSingleResource(homingInstanceClient, getUri(homingInstanceURI + serviceInstanceId));
}
public HomingInstance getHomingInstance(String serviceInstanceId, String uri) {
return this.getSingleResource(homingInstanceClient, getUri(uri + serviceInstanceId));
}
public void postHomingInstance(HomingInstance homingInstance) {
this.postSingleResource(homingInstanceClient, homingInstance);
}
public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
return this.getSingleResource(serviceClient,
getUri(UriBuilder.fromUri(findFirstByModelVersionAndModelInvariantUUIDURI)
.queryParam(MODEL_VERSION, modelVersion).queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID)
.build().toString()));
}
public VfModule getVfModuleByModelInvariantUUIDAndModelVersion(String modelInvariantUUID, String modelVersion) {
return this.getSingleResource(vfModuleClient,
getUri(UriBuilder.fromUri(findFirstVfModuleByModelInvariantUUIDAndModelVersion)
.queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
.build().toString()));
}
public List<Service> getServiceByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
return this.getMultipleResources(serviceClient, getUri(UriBuilder.fromUri(findByModelInvariantUUIDURI)
.queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
}
public List<VfModule> getVfModuleByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
return this.getMultipleResources(vfModuleClient,
getUri(UriBuilder.fromUri(findVfModuleByModelInvariantUUIDOrderByModelVersionDesc)
.queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
}
private <T> T getSingleResource(Client<T> client, URI uri) {
return client.get(uri);
}
private <T> List<T> getMultipleResources(Client<T> client, URI uri) {
Iterable<T> iterator = client.getAll(uri);
List<T> list = new ArrayList<>();
Iterator<T> it = iterator.iterator();
it.forEachRemaining(list::add);
return list;
}
private <T> URI postSingleResource(Client<T> client, T type) {
return client.post(type);
}
public List<CvnfcCustomization> getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUUID,
String vfModuleCustomizationUUID) {
Service service = this.getServiceByID(serviceModelUUID);
VnfResourceCustomization vnfResourceCust =
findVnfResourceCustomizationInList(vnfCustomizationUUID, service.getVnfCustomizations());
VfModuleCustomization vfModuleCust =
findVfModuleCustomizationInList(vfModuleCustomizationUUID, vnfResourceCust.getVfModuleCustomizations());
return vfModuleCust.getCvnfcCustomization().stream().collect(Collectors.toList());
}
public VnfResourceCustomization findVnfResourceCustomizationInList(String vnfCustomizationUUID,
List<VnfResourceCustomization> vnfResourceCusts) {
if (vnfCustomizationUUID == null) {
throw new EntityNotFoundException(
"a NULL UUID was provided in query to search for VnfResourceCustomization");
}
List<VnfResourceCustomization> filtered =
vnfResourceCusts.stream().filter(v -> v.getModelCustomizationUUID() != null)
.filter(vnfCustRes -> vnfCustomizationUUID.equals(vnfCustRes.getModelCustomizationUUID()))
.collect(Collectors.toList());
if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
return filtered.get(0);
} else
throw new EntityNotFoundException(
"Unable to find VnfResourceCustomization ModelCustomizationUUID:" + vnfCustomizationUUID);
}
protected VfModuleCustomization findVfModuleCustomizationInList(String vfModuleCustomizationUUID,
List<VfModuleCustomization> vfModuleList) {
if (vfModuleCustomizationUUID == null) {
throw new EntityNotFoundException("a NULL UUID was provided in query to search for VfModuleCustomization");
}
List<VfModuleCustomization> filtered = vfModuleList.stream().filter(v -> v.getModelCustomizationUUID() != null)
.filter(vfModuleCust -> vfModuleCustomizationUUID.equals(vfModuleCust.getModelCustomizationUUID()))
.collect(Collectors.toList());
if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
return filtered.get(0);
} else
throw new EntityNotFoundException(
"Unable to find VfModuleCustomization ModelCustomizationUUID:" + vfModuleCustomizationUUID);
}
protected CvnfcCustomization findCvnfcCustomizationInAList(String cvnfcCustomizationUuid,
List<CvnfcCustomization> cvnfcCustomList) {
if (cvnfcCustomizationUuid == null) {
throw new EntityNotFoundException(
"a NULL UUID was provided in query to search for CvnfcCustomization" + cvnfcCustomizationUuid);
}
List<CvnfcCustomization> filtered = cvnfcCustomList.stream().filter(c -> c.getModelCustomizationUUID() != null)
.filter(cvnfc -> cvnfcCustomizationUuid.equals(cvnfc.getModelCustomizationUUID()))
.collect(Collectors.toList());
if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
logger.debug("Found CvnfcCustomization: {}", filtered.get(0));
return filtered.get(0);
} else
throw new EntityNotFoundException(
"Unable to find CvnfcCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
}
public CvnfcConfigurationCustomization getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUuid,
String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
List<CvnfcCustomization> cvnfcCustomization =
getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid);
CvnfcCustomization cvnfc = findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcCustomization);
List<CvnfcConfigurationCustomization> fabricConfigs = cvnfc
.getCvnfcConfigurationCustomization().stream().filter(cvnfcCustom -> cvnfcCustom
.getConfigurationResource().getToscaNodeType().contains("FabricConfiguration"))
.collect(Collectors.toList());
if (fabricConfigs != null && !fabricConfigs.isEmpty() && fabricConfigs.size() == 1) {
logger.debug("Found Fabric Configuration: {}", fabricConfigs.get(0));
return fabricConfigs.get(0);
} else
throw new EntityNotFoundException(
"Unable to find CvnfcConfigurationCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
}
public Workflow findWorkflowByArtifactUUID(String artifactUUID) {
return this.getSingleResource(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByArtifactUUID)
.queryParam(ARTIFACT_UUID, artifactUUID).build().toString()));
}
public List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID) {
return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByModelUUID)
.queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString()));
}
public List<Workflow> findWorkflowBySource(String source) {
return this.getMultipleResources(workflowClient,
getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString()));
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
}
|