Add or Delete a PNF to an Active Service
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / bpmn / servicedecomposition / tasks / BBInputSetupUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.servicedecomposition.tasks;
24
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Optional;
31 import org.onap.aai.domain.yang.CloudRegion;
32 import org.onap.aai.domain.yang.Configuration;
33 import org.onap.aai.domain.yang.Configurations;
34 import org.onap.aai.domain.yang.GenericVnf;
35 import org.onap.aai.domain.yang.GenericVnfs;
36 import org.onap.aai.domain.yang.InstanceGroup;
37 import org.onap.aai.domain.yang.L3Network;
38 import org.onap.aai.domain.yang.L3Networks;
39 import org.onap.aai.domain.yang.Pnf;
40 import org.onap.aai.domain.yang.ServiceInstance;
41 import org.onap.aai.domain.yang.ServiceInstances;
42 import org.onap.aai.domain.yang.ServiceSubscription;
43 import org.onap.aai.domain.yang.VfModule;
44 import org.onap.aai.domain.yang.VolumeGroup;
45 import org.onap.aai.domain.yang.VolumeGroups;
46 import org.onap.aai.domain.yang.VpnBinding;
47 import org.onap.aaiclient.client.aai.AAIResourcesClient;
48 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
49 import org.onap.aaiclient.client.aai.entities.uri.AAIFluentSingleType;
50 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri;
51 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
52 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
53 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
54 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
55 import org.onap.aaiclient.client.graphinventory.entities.uri.Depth;
56 import org.onap.so.bpmn.common.InjectionHelper;
57 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
58 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
59 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
60 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException;
61 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
62 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
63 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
64 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
65 import org.onap.so.db.catalog.beans.Service;
66 import org.onap.so.db.catalog.beans.VfModuleCustomization;
67 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
68 import org.onap.so.db.catalog.client.CatalogDbClient;
69 import org.onap.so.db.request.beans.InfraActiveRequests;
70 import org.onap.so.db.request.beans.RequestProcessingData;
71 import org.onap.so.db.request.client.RequestsDbClient;
72 import org.onap.so.serviceinstancebeans.CloudConfiguration;
73 import org.onap.so.serviceinstancebeans.ModelType;
74 import org.onap.so.serviceinstancebeans.RelatedInstance;
75 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
76 import org.onap.so.serviceinstancebeans.RequestDetails;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
79 import org.springframework.beans.factory.annotation.Autowired;
80 import org.springframework.stereotype.Component;
81 import com.fasterxml.jackson.core.JsonProcessingException;
82 import com.fasterxml.jackson.databind.DeserializationFeature;
83 import com.fasterxml.jackson.databind.ObjectMapper;
84 import com.fasterxml.jackson.databind.SerializationFeature;
85 import com.fasterxml.jackson.databind.type.TypeFactory;
86
87 @Component("BBInputSetupUtils")
88 public class BBInputSetupUtils {
89
90     private static final Logger logger = LoggerFactory.getLogger(BBInputSetupUtils.class);
91     private static final String REQUEST_ERROR = "Could not find request.";
92     private static final String DATA_LOAD_ERROR = "Could not process loading data from database";
93     private static final String DATA_PARSE_ERROR = "Could not parse data";
94     private static final String PROCESSING_DATA_NAME_EXECUTION_FLOWS = "flowExecutionPath";
95
96     @Autowired
97     protected CatalogDbClient catalogDbClient;
98
99     @Autowired
100     protected RequestsDbClient requestsDbClient;
101
102     @Autowired
103     protected InjectionHelper injectionHelper;
104
105     public RelatedInstance getRelatedInstanceByType(RequestDetails requestDetails, ModelType modelType) {
106         if (requestDetails.getRelatedInstanceList() != null) {
107             for (RelatedInstanceList relatedInstanceList : requestDetails.getRelatedInstanceList()) {
108                 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
109                 if (relatedInstance != null && relatedInstance.getModelInfo() != null
110                         && relatedInstance.getModelInfo().getModelType() != null
111                         && relatedInstance.getModelInfo().getModelType().equals(modelType)) {
112                     return relatedInstance;
113                 }
114             }
115         }
116         return null;
117     }
118
119     public void updateInfraActiveRequestVnfId(InfraActiveRequests request, String vnfId) {
120         if (request != null) {
121             request.setVnfId(vnfId);
122             this.requestsDbClient.updateInfraActiveRequests(request);
123         } else {
124             logger.debug(REQUEST_ERROR);
125         }
126     }
127
128     public void updateInfraActiveRequestVfModuleId(InfraActiveRequests request, String vfModuleId) {
129         if (request != null) {
130             request.setVfModuleId(vfModuleId);
131             this.requestsDbClient.updateInfraActiveRequests(request);
132         } else {
133             logger.debug(REQUEST_ERROR);
134         }
135     }
136
137     public void updateInfraActiveRequestVolumeGroupId(InfraActiveRequests request, String volumeGroupId) {
138         if (request != null) {
139             request.setVolumeGroupId(volumeGroupId);
140             this.requestsDbClient.updateInfraActiveRequests(request);
141         } else {
142             logger.debug(REQUEST_ERROR);
143         }
144     }
145
146     public void updateInfraActiveRequestNetworkId(InfraActiveRequests request, String networkId) {
147         if (request != null) {
148             request.setNetworkId(networkId);
149             this.requestsDbClient.updateInfraActiveRequests(request);
150         } else {
151             logger.debug(REQUEST_ERROR);
152         }
153     }
154
155     public void persistFlowExecutionPath(String requestId, List<ExecuteBuildingBlock> flowsToExecute) {
156
157         if (requestId != null) {
158             List<String> flows = new ArrayList<>();
159             ObjectMapper om = new ObjectMapper();
160             try {
161                 for (ExecuteBuildingBlock ebb : flowsToExecute) {
162                     flows.add(om.writeValueAsString(ebb));
163                 }
164             } catch (JsonProcessingException e) {
165                 logger.error(DATA_PARSE_ERROR, e);
166             }
167
168             this.requestsDbClient.persistProcessingData(flows.toString(), requestId);
169         } else {
170             logger.debug(REQUEST_ERROR);
171         }
172     }
173
174     public InfraActiveRequests loadInfraActiveRequestById(String requestId) {
175
176         return this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
177     }
178
179     public InfraActiveRequests loadOriginalInfraActiveRequestById(String requestId) {
180         return this.requestsDbClient.getInfraActiveRequestbyRequestId(
181                 this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId).getOriginalRequestId());
182     }
183
184     public List<ExecuteBuildingBlock> loadOriginalFlowExecutionPath(String requestId) {
185         if (requestId != null) {
186             InfraActiveRequests request = loadInfraActiveRequestById(requestId);
187             if (request.getOriginalRequestId() != null) {
188                 RequestProcessingData requestProcessingData =
189                         this.requestsDbClient.getRequestProcessingDataBySoRequestIdAndName(
190                                 request.getOriginalRequestId(), PROCESSING_DATA_NAME_EXECUTION_FLOWS);
191                 try {
192                     ObjectMapper om = new ObjectMapper();
193                     TypeFactory typeFactory = om.getTypeFactory();
194                     om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
195                     return om.readValue(requestProcessingData.getValue(),
196                             typeFactory.constructCollectionType(List.class, ExecuteBuildingBlock.class));
197                 } catch (Exception e) {
198                     logger.error(DATA_LOAD_ERROR, e);
199                     throw new RuntimeException("Error Loading Original Request Data", e);
200                 }
201             } else {
202                 throw new RuntimeException("Original Request Id is null for record: " + requestId);
203             }
204         } else {
205             throw new RuntimeException("Null Request Id Passed in");
206         }
207     }
208
209     public Service getCatalogServiceByModelUUID(String modelUUID) {
210         return catalogDbClient.getServiceByID(modelUUID);
211     }
212
213     public Service getCatalogServiceByModelVersionAndModelInvariantUUID(String modelVersion,
214             String modelInvariantUUID) {
215         return catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
216     }
217
218     public CollectionNetworkResourceCustomization getCatalogCollectionNetworkResourceCustByID(String key) {
219         return catalogDbClient.getCollectionNetworkResourceCustomizationByID(key);
220     }
221
222     public NetworkCollectionResourceCustomization getCatalogNetworkCollectionResourceCustByID(
223             String collectionCustomizationId) {
224         return catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCustomizationId);
225     }
226
227     public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
228         return catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(modelCustomizationUUID);
229     }
230
231     public CvnfcConfigurationCustomization getCvnfcConfigurationCustomization(String serviceModelUUID,
232             String vnfCustomizationUuid, String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
233         return catalogDbClient.getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid,
234                 cvnfcCustomizationUuid);
235     }
236
237     public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroups(String modelCustomizationUUID) {
238         return catalogDbClient.getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID);
239     }
240
241     public Map<String, String> getURIKeysFromServiceInstance(String serviceInstanceId) {
242         AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId));
243         return uri.getURIKeys();
244     }
245
246     protected RequestDetails getRequestDetails(String requestId) throws IOException {
247         if (requestId != null && !requestId.isEmpty()) {
248             InfraActiveRequests activeRequest = this.getInfraActiveRequest(requestId);
249             String requestBody = activeRequest.getRequestBody().replaceAll("\\\\", "");
250             ObjectMapper objectMapper = new ObjectMapper();
251             objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
252             objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
253             objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
254             return objectMapper.readValue(requestBody, RequestDetails.class);
255         } else {
256             return null;
257         }
258     }
259
260     protected InfraActiveRequests getInfraActiveRequest(String requestId) {
261         if (requestId != null && !requestId.isEmpty()) {
262             return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
263         } else {
264             return null;
265         }
266     }
267
268     protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration) {
269         if (cloudConfiguration != null) {
270             String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
271             String cloudOwner = cloudConfiguration.getCloudOwner();
272             if (cloudRegionId != null && cloudOwner != null && !cloudRegionId.isEmpty() && !cloudOwner.isEmpty()) {
273                 return injectionHelper.getAaiClient().get(CloudRegion.class,
274                         AAIUriFactory.createResourceUri(
275                                 AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId))
276                                 .depth(Depth.ONE).nodesOnly(true))
277                         .orElse(null);
278
279             } else {
280                 return null;
281             }
282         } else {
283             return null;
284         }
285     }
286
287     public InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
288         return injectionHelper.getAaiClient()
289                 .get(InstanceGroup.class,
290                         AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId)))
291                 .orElse(null);
292     }
293
294     public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
295         return injectionHelper.getAaiClient()
296                 .get(org.onap.aai.domain.yang.Customer.class,
297                         AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId)))
298                 .orElse(null);
299     }
300
301     public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
302
303         if (globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null
304                 || subscriptionServiceType.equals("")) {
305             return null;
306         } else {
307             return injectionHelper
308                     .getAaiClient().get(ServiceSubscription.class, AAIUriFactory.createResourceUri(AAIFluentTypeBuilder
309                             .business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType)))
310                     .orElse(null);
311         }
312
313     }
314
315     public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
316         return injectionHelper.getAaiClient()
317                 .get(ServiceInstance.class, AAIUriFactory
318                         .createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)).depth(Depth.TWO))
319                 .orElse(null);
320     }
321
322     protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
323             String serviceInstanceId) {
324         return injectionHelper.getAaiClient().get(ServiceInstance.class,
325                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustomerId)
326                         .serviceSubscription(serviceType).serviceInstance(serviceInstanceId)).depth(Depth.TWO))
327                 .orElse(null);
328     }
329
330     public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
331             Customer customer) throws Exception {
332         Optional<org.onap.aai.domain.yang.ServiceInstance> aaiServiceInstance = injectionHelper.getAaiClient().getOne(
333                 ServiceInstances.class, org.onap.aai.domain.yang.ServiceInstance.class,
334                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
335                         .serviceSubscription(customer.getServiceSubscription().getServiceType()).serviceInstances())
336                         .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO));
337
338         return aaiServiceInstance.orElse(null);
339     }
340
341     public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
342             String serviceInstanceName) {
343
344         return injectionHelper.getAaiClient().getOne(ServiceInstances.class, ServiceInstance.class,
345                 AAIUriFactory
346                         .createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustomerId)
347                                 .serviceSubscription(serviceType).serviceInstances())
348                         .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO));
349     }
350
351     public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
352         return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
353     }
354
355     public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
356             String modelCustomizationUUID) {
357         return this.catalogDbClient
358                 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
359     }
360
361     public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
362         AAIResourceUri clonedUri = aaiResourceUri.clone();
363         return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
364     }
365
366     public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
367         AAIResourceUri clonedUri = aaiResourceUri.clone();
368         return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
369     }
370
371     public Configuration getAAIConfiguration(String configurationId) {
372         return this.getConcreteAAIResource(Configuration.class,
373                 AAIFluentTypeBuilder.network().configuration(configurationId));
374     }
375
376     public GenericVnf getAAIGenericVnf(String vnfId) {
377         return getConcreteAAIResource(GenericVnf.class, AAIFluentTypeBuilder.network().genericVnf(vnfId));
378     }
379
380
381     public Pnf getAAIPnf(String pnfId) {
382         return getConcreteAAIResource(Pnf.class, AAIFluentTypeBuilder.network().pnf(pnfId));
383     }
384
385     public VpnBinding getAAIVpnBinding(String vpnBindingId) {
386         return getConcreteAAIResource(VpnBinding.class, AAIFluentTypeBuilder.network().vpnBinding(vpnBindingId));
387     }
388
389     public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
390         return getConcreteAAIResource(VolumeGroup.class, AAIFluentTypeBuilder.cloudInfrastructure()
391                 .cloudRegion(cloudOwnerId, cloudRegionId).volumeGroup(volumeGroupId));
392     }
393
394     public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
395         return getConcreteAAIResource(VfModule.class,
396                 AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId));
397     }
398
399     public L3Network getAAIL3Network(String networkId) {
400         return getConcreteAAIResource(L3Network.class, AAIFluentTypeBuilder.network().l3Network(networkId));
401     }
402
403     private <T> T getConcreteAAIResource(Class<T> clazz, AAIFluentSingleType type) {
404         return injectionHelper.getAaiClient().get(clazz, AAIUriFactory.createResourceUri(type).depth(Depth.ONE))
405                 .orElseGet(() -> {
406                     logger.debug("No resource of type: {} matched by ids: {}", type.build().typeName(),
407                             Arrays.toString(type.values()));
408                     return null;
409                 });
410     }
411
412     public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId)
413             throws Exception {
414         AAIPluralResourceUri uri =
415                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId))
416                         .relatedTo(Types.SERVICE_INSTANCES.getFragment());
417         Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
418         ServiceInstance serviceInstance = null;
419         if (!serviceInstances.isPresent()) {
420             logger.debug("No ServiceInstances were found");
421             return Optional.empty();
422         } else {
423             if (serviceInstances.get().getServiceInstance().isEmpty()) {
424                 throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
425             } else if (serviceInstances.get().getServiceInstance().size() > 1) {
426                 String message = String.format("Mulitple service instances were found for instance-group-id: %s.",
427                         instanceGroupId);
428                 throw new MultipleObjectsFoundException(message);
429             } else {
430                 serviceInstance = serviceInstances.get().getServiceInstance().get(0);
431             }
432             return Optional.of(serviceInstance);
433         }
434     }
435
436     public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName)
437             throws MultipleObjectsFoundException {
438         AAIPluralResourceUri uri =
439                 AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
440                         .relatedTo(Types.L3_NETWORKS.getFragment()).queryParam("network-name", networkName);
441         Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
442         L3Network network = null;
443         if (!networks.isPresent()) {
444             logger.debug("No Networks matched by name");
445             return Optional.empty();
446         } else {
447             if (networks.get().getL3Network().size() > 1) {
448                 String message =
449                         String.format("Multiple networks found for service-instance-id: %s and network-name: %s.",
450                                 serviceInstanceId, networkName);
451                 throw new MultipleObjectsFoundException(message);
452             } else {
453                 network = networks.get().getL3Network().get(0);
454             }
455             return Optional.of(network);
456         }
457     }
458
459     public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName) {
460         AAIPluralResourceUri uri =
461                 AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
462                         .relatedTo(Types.GENERIC_VNFS.getFragment()).queryParam("vnf-name", vnfName);
463         return injectionHelper.getAaiClient().getOne(GenericVnfs.class, GenericVnf.class, uri);
464
465     }
466
467     public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName) {
468         AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))
469                 .relatedTo(Types.VOLUME_GROUPS.getFragment()).queryParam("volume-group-name", volumeGroupName);
470         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
471     }
472
473     public Optional<VolumeGroup> getRelatedVolumeGroupByIdFromVnf(String vnfId, String volumeGroupId) {
474         AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))
475                 .relatedTo(Types.VOLUME_GROUPS.getFragment()).queryParam("volume-group-id", volumeGroupId);
476         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
477     }
478
479     public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId,
480             String volumeGroupName) throws Exception {
481         AAIPluralResourceUri uri =
482                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId))
483                         .relatedTo(Types.VOLUME_GROUPS.getFragment()).queryParam("volume-group-name", volumeGroupName);
484         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
485     }
486
487     public Optional<VolumeGroup> getRelatedVolumeGroupFromVfModule(String vnfId, String vfModuleId) throws Exception {
488         AAIPluralResourceUri uri =
489                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId))
490                         .relatedTo(Types.VOLUME_GROUPS.getFragment());
491         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
492     }
493
494     public Optional<org.onap.aai.domain.yang.VpnBinding> getAICVpnBindingFromNetwork(
495             org.onap.aai.domain.yang.L3Network aaiLocalNetwork) {
496         AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork);
497         if (networkWrapper.getRelationships().isPresent()
498                 && !networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING).isEmpty()) {
499             return getAAIResourceDepthOne(
500                     networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING).get(0))
501                             .asBean(org.onap.aai.domain.yang.VpnBinding.class);
502         }
503         return Optional.empty();
504     }
505
506     public ServiceInstances getAAIServiceInstancesGloballyByName(String serviceInstanceName) {
507
508         return injectionHelper.getAaiClient()
509                 .get(ServiceInstances.class, AAIUriFactory.createNodesUri(Types.SERVICE_INSTANCES.getFragment())
510                         .queryParam("service-instance-name", serviceInstanceName))
511                 .orElseGet(() -> {
512                     logger.debug("No Service Instance matched by name");
513                     return null;
514                 });
515     }
516
517     public boolean existsAAINetworksGloballyByName(String networkName) {
518
519         AAIPluralResourceUri l3networkUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().l3Networks())
520                 .queryParam("network-name", networkName);
521         AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
522         return aaiRC.exists(l3networkUri);
523     }
524
525     public boolean existsAAIVfModuleGloballyByName(String vfModuleName) {
526         AAIPluralResourceUri vfModuleUri =
527                 AAIUriFactory.createNodesUri(Types.VF_MODULES.getFragment()).queryParam("vf-module-name", vfModuleName);
528         return injectionHelper.getAaiClient().exists(vfModuleUri);
529     }
530
531     public boolean existsAAIConfigurationGloballyByName(String configurationName) {
532         AAIPluralResourceUri configUri =
533                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().configurations())
534                         .queryParam("configuration-name", configurationName);
535         return injectionHelper.getAaiClient().exists(configUri);
536     }
537
538     public boolean existsAAIVolumeGroupGloballyByName(String volumeGroupName) {
539         AAIPluralResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(Types.VOLUME_GROUPS.getFragment())
540                 .queryParam("volume-group-name", volumeGroupName);
541         return injectionHelper.getAaiClient().exists(volumeGroupUri);
542     }
543
544     public GenericVnfs getAAIVnfsGloballyByName(String vnfName) {
545
546         return injectionHelper.getAaiClient()
547                 .get(GenericVnfs.class,
548                         AAIUriFactory.createNodesUri(Types.GENERIC_VNFS.getFragment()).queryParam("vnf-name", vnfName))
549                 .orElseGet(() -> {
550                     logger.debug("No GenericVnfs matched by name");
551                     return null;
552                 });
553     }
554
555     public Optional<Configuration> getRelatedConfigurationByNameFromServiceInstance(String serviceInstanceId,
556             String configurationName) {
557         AAIPluralResourceUri uri = AAIUriFactory
558                 .createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
559                 .relatedTo(Types.CONFIGURATIONS.getFragment()).queryParam("configuration-name", configurationName);
560         return injectionHelper.getAaiClient().getOne(Configurations.class, Configuration.class, uri);
561     }
562 }