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