Merge "Add userParams as inputs"
[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 ObjectMapper objectMapper = new ObjectMapper();
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 = objectMapper.getTypeFactory();
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.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
250             objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
251             return objectMapper.readValue(requestBody, RequestDetails.class);
252         } else {
253             return null;
254         }
255     }
256
257     protected InfraActiveRequests getInfraActiveRequest(String requestId) {
258         if (requestId != null && !requestId.isEmpty()) {
259             return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
260         } else {
261             return null;
262         }
263     }
264
265     protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration) {
266         if (cloudConfiguration != null) {
267             String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
268             String cloudOwner = cloudConfiguration.getCloudOwner();
269             if (cloudRegionId != null && cloudOwner != null && !cloudRegionId.isEmpty() && !cloudOwner.isEmpty()) {
270                 return injectionHelper.getAaiClient()
271                         .get(CloudRegion.class, AAIUriFactory.createResourceUri(
272                                 AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId))
273                                 .depth(Depth.TWO))
274                         .orElse(null);
275
276             } else {
277                 return null;
278             }
279         } else {
280             return null;
281         }
282     }
283
284     public InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
285         return injectionHelper.getAaiClient()
286                 .get(InstanceGroup.class,
287                         AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId)))
288                 .orElse(null);
289     }
290
291     public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
292         return injectionHelper.getAaiClient()
293                 .get(org.onap.aai.domain.yang.Customer.class,
294                         AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId)))
295                 .orElse(null);
296     }
297
298     public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
299
300         if (globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null
301                 || subscriptionServiceType.equals("")) {
302             return null;
303         } else {
304             return injectionHelper
305                     .getAaiClient().get(ServiceSubscription.class, AAIUriFactory.createResourceUri(AAIFluentTypeBuilder
306                             .business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType)))
307                     .orElse(null);
308         }
309
310     }
311
312     public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
313         return injectionHelper.getAaiClient()
314                 .get(ServiceInstance.class, AAIUriFactory
315                         .createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)).depth(Depth.TWO))
316                 .orElse(null);
317     }
318
319     protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
320             String serviceInstanceId) {
321         return injectionHelper.getAaiClient().get(ServiceInstance.class,
322                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustomerId)
323                         .serviceSubscription(serviceType).serviceInstance(serviceInstanceId)).depth(Depth.TWO))
324                 .orElse(null);
325     }
326
327     public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
328             Customer customer) throws Exception {
329         Optional<org.onap.aai.domain.yang.ServiceInstance> aaiServiceInstance = injectionHelper.getAaiClient().getOne(
330                 ServiceInstances.class, org.onap.aai.domain.yang.ServiceInstance.class,
331                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
332                         .serviceSubscription(customer.getServiceSubscription().getServiceType()).serviceInstances())
333                         .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO));
334
335         return aaiServiceInstance.orElse(null);
336     }
337
338     public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
339             String serviceInstanceName) {
340
341         return injectionHelper.getAaiClient().getOne(ServiceInstances.class, ServiceInstance.class,
342                 AAIUriFactory
343                         .createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustomerId)
344                                 .serviceSubscription(serviceType).serviceInstances())
345                         .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO));
346     }
347
348     public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
349         return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
350     }
351
352     public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
353             String modelCustomizationUUID) {
354         return this.catalogDbClient
355                 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
356     }
357
358     public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
359         AAIResourceUri clonedUri = aaiResourceUri.clone();
360         return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
361     }
362
363     public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
364         AAIResourceUri clonedUri = aaiResourceUri.clone();
365         return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
366     }
367
368     public Configuration getAAIConfiguration(String configurationId) {
369         return this.getConcreteAAIResource(Configuration.class,
370                 AAIFluentTypeBuilder.network().configuration(configurationId));
371     }
372
373     public GenericVnf getAAIGenericVnf(String vnfId) {
374         return getConcreteAAIResource(GenericVnf.class, AAIFluentTypeBuilder.network().genericVnf(vnfId));
375     }
376
377     public VpnBinding getAAIVpnBinding(String vpnBindingId) {
378         return getConcreteAAIResource(VpnBinding.class, AAIFluentTypeBuilder.network().vpnBinding(vpnBindingId));
379     }
380
381     public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
382         return getConcreteAAIResource(VolumeGroup.class, AAIFluentTypeBuilder.cloudInfrastructure()
383                 .cloudRegion(cloudOwnerId, cloudRegionId).volumeGroup(volumeGroupId));
384     }
385
386     public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
387         return getConcreteAAIResource(VfModule.class,
388                 AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId));
389     }
390
391     public L3Network getAAIL3Network(String networkId) {
392         return getConcreteAAIResource(L3Network.class, AAIFluentTypeBuilder.network().l3Network(networkId));
393     }
394
395     private <T> T getConcreteAAIResource(Class<T> clazz, AAIFluentSingleType type) {
396         return injectionHelper.getAaiClient().get(clazz, AAIUriFactory.createResourceUri(type).depth(Depth.ONE))
397                 .orElseGet(() -> {
398                     logger.debug("No resource of type: {} matched by ids: {}", type.build().typeName(),
399                             Arrays.toString(type.values()));
400                     return null;
401                 });
402     }
403
404     public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId)
405             throws Exception {
406         AAIPluralResourceUri uri =
407                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId))
408                         .relatedTo(Types.SERVICE_INSTANCES.getFragment());
409         Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
410         ServiceInstance serviceInstance = null;
411         if (!serviceInstances.isPresent()) {
412             logger.debug("No ServiceInstances were found");
413             return Optional.empty();
414         } else {
415             if (serviceInstances.get().getServiceInstance().isEmpty()) {
416                 throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
417             } else if (serviceInstances.get().getServiceInstance().size() > 1) {
418                 String message = String.format("Mulitple service instances were found for instance-group-id: %s.",
419                         instanceGroupId);
420                 throw new MultipleObjectsFoundException(message);
421             } else {
422                 serviceInstance = serviceInstances.get().getServiceInstance().get(0);
423             }
424             return Optional.of(serviceInstance);
425         }
426     }
427
428     public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName)
429             throws MultipleObjectsFoundException {
430         AAIPluralResourceUri uri =
431                 AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
432                         .relatedTo(Types.L3_NETWORKS.getFragment()).queryParam("network-name", networkName);
433         Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
434         L3Network network = null;
435         if (!networks.isPresent()) {
436             logger.debug("No Networks matched by name");
437             return Optional.empty();
438         } else {
439             if (networks.get().getL3Network().size() > 1) {
440                 String message =
441                         String.format("Multiple networks found for service-instance-id: %s and network-name: %s.",
442                                 serviceInstanceId, networkName);
443                 throw new MultipleObjectsFoundException(message);
444             } else {
445                 network = networks.get().getL3Network().get(0);
446             }
447             return Optional.of(network);
448         }
449     }
450
451     public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName) {
452         AAIPluralResourceUri uri =
453                 AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
454                         .relatedTo(Types.GENERIC_VNFS.getFragment()).queryParam("vnf-name", vnfName);
455         return injectionHelper.getAaiClient().getOne(GenericVnfs.class, GenericVnf.class, uri);
456
457     }
458
459     public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName) {
460         AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))
461                 .relatedTo(Types.VOLUME_GROUPS.getFragment()).queryParam("volume-group-name", volumeGroupName);
462         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
463     }
464
465     public Optional<VolumeGroup> getRelatedVolumeGroupByIdFromVnf(String vnfId, String volumeGroupId) {
466         AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))
467                 .relatedTo(Types.VOLUME_GROUPS.getFragment()).queryParam("volume-group-id", volumeGroupId);
468         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
469     }
470
471     public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId,
472             String volumeGroupName) throws Exception {
473         AAIPluralResourceUri uri =
474                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId))
475                         .relatedTo(Types.VOLUME_GROUPS.getFragment()).queryParam("volume-group-name", volumeGroupName);
476         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
477     }
478
479     public Optional<VolumeGroup> getRelatedVolumeGroupFromVfModule(String vnfId, String vfModuleId) throws Exception {
480         AAIPluralResourceUri uri =
481                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId))
482                         .relatedTo(Types.VOLUME_GROUPS.getFragment());
483         return injectionHelper.getAaiClient().getOne(VolumeGroups.class, VolumeGroup.class, uri);
484     }
485
486     public Optional<org.onap.aai.domain.yang.VpnBinding> getAICVpnBindingFromNetwork(
487             org.onap.aai.domain.yang.L3Network aaiLocalNetwork) {
488         AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork);
489         if (networkWrapper.getRelationships().isPresent()
490                 && !networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING).isEmpty()) {
491             return getAAIResourceDepthOne(
492                     networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING).get(0))
493                             .asBean(org.onap.aai.domain.yang.VpnBinding.class);
494         }
495         return Optional.empty();
496     }
497
498     public ServiceInstances getAAIServiceInstancesGloballyByName(String serviceInstanceName) {
499
500         return injectionHelper.getAaiClient()
501                 .get(ServiceInstances.class, AAIUriFactory.createNodesUri(Types.SERVICE_INSTANCES.getFragment())
502                         .queryParam("service-instance-name", serviceInstanceName))
503                 .orElseGet(() -> {
504                     logger.debug("No Service Instance matched by name");
505                     return null;
506                 });
507     }
508
509     public boolean existsAAINetworksGloballyByName(String networkName) {
510
511         AAIPluralResourceUri l3networkUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().l3Networks())
512                 .queryParam("network-name", networkName);
513         AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
514         return aaiRC.exists(l3networkUri);
515     }
516
517     public boolean existsAAIVfModuleGloballyByName(String vfModuleName) {
518         AAIPluralResourceUri vfModuleUri =
519                 AAIUriFactory.createNodesUri(Types.VF_MODULES.getFragment()).queryParam("vf-module-name", vfModuleName);
520         return injectionHelper.getAaiClient().exists(vfModuleUri);
521     }
522
523     public boolean existsAAIConfigurationGloballyByName(String configurationName) {
524         AAIPluralResourceUri configUri =
525                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().configurations())
526                         .queryParam("configuration-name", configurationName);
527         return injectionHelper.getAaiClient().exists(configUri);
528     }
529
530     public boolean existsAAIVolumeGroupGloballyByName(String volumeGroupName) {
531         AAIPluralResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(Types.VOLUME_GROUPS.getFragment())
532                 .queryParam("volume-group-name", volumeGroupName);
533         return injectionHelper.getAaiClient().exists(volumeGroupUri);
534     }
535
536     public GenericVnfs getAAIVnfsGloballyByName(String vnfName) {
537
538         return injectionHelper.getAaiClient()
539                 .get(GenericVnfs.class,
540                         AAIUriFactory.createNodesUri(Types.GENERIC_VNFS.getFragment()).queryParam("vnf-name", vnfName))
541                 .orElseGet(() -> {
542                     logger.debug("No GenericVnfs matched by name");
543                     return null;
544                 });
545     }
546
547     public Optional<Configuration> getRelatedConfigurationByNameFromServiceInstance(String serviceInstanceId,
548             String configurationName) {
549         AAIPluralResourceUri uri = AAIUriFactory
550                 .createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
551                 .relatedTo(Types.CONFIGURATIONS.getFragment()).queryParam("configuration-name", configurationName);
552         return injectionHelper.getAaiClient().getOne(Configurations.class, Configuration.class, uri);
553     }
554 }