2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.servicedecomposition.tasks;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
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.so.bpmn.common.InjectionHelper;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
48 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
49 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
50 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException;
51 import org.onap.so.client.aai.AAIObjectPlurals;
52 import org.onap.so.client.aai.AAIObjectType;
53 import org.onap.so.client.aai.AAIResourcesClient;
54 import org.onap.so.client.aai.entities.AAIResultWrapper;
55 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
56 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
57 import org.onap.so.client.graphinventory.entities.uri.Depth;
58 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
59 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
60 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
61 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
62 import org.onap.so.db.catalog.beans.Service;
63 import org.onap.so.db.catalog.beans.VfModuleCustomization;
64 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
65 import org.onap.so.db.catalog.client.CatalogDbClient;
66 import org.onap.so.db.request.beans.InfraActiveRequests;
67 import org.onap.so.db.request.beans.RequestProcessingData;
68 import org.onap.so.db.request.client.RequestsDbClient;
69 import org.onap.so.serviceinstancebeans.CloudConfiguration;
70 import org.onap.so.serviceinstancebeans.ModelType;
71 import org.onap.so.serviceinstancebeans.RelatedInstance;
72 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
73 import org.onap.so.serviceinstancebeans.RequestDetails;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
76 import org.springframework.beans.factory.annotation.Autowired;
77 import org.springframework.stereotype.Component;
78 import com.fasterxml.jackson.core.JsonProcessingException;
79 import com.fasterxml.jackson.databind.DeserializationFeature;
80 import com.fasterxml.jackson.databind.ObjectMapper;
81 import com.fasterxml.jackson.databind.SerializationFeature;
82 import com.fasterxml.jackson.databind.type.TypeFactory;
84 @Component("BBInputSetupUtils")
85 public class BBInputSetupUtils {
87 private static final Logger logger = LoggerFactory.getLogger(BBInputSetupUtils.class);
88 private ObjectMapper objectMapper = new ObjectMapper();
89 private static final String REQUEST_ERROR = "Could not find request.";
90 private static final String DATA_LOAD_ERROR = "Could not process loading data from database";
91 private static final String DATA_PARSE_ERROR = "Could not parse data";
92 private static final String PROCESSING_DATA_NAME_EXECUTION_FLOWS = "flowExecutionPath";
95 protected CatalogDbClient catalogDbClient;
98 protected RequestsDbClient requestsDbClient;
101 protected InjectionHelper injectionHelper;
103 public RelatedInstance getRelatedInstanceByType(RequestDetails requestDetails, ModelType modelType) {
104 if (requestDetails.getRelatedInstanceList() != null) {
105 for (RelatedInstanceList relatedInstanceList : requestDetails.getRelatedInstanceList()) {
106 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
107 if (relatedInstance != null && relatedInstance.getModelInfo() != null
108 && relatedInstance.getModelInfo().getModelType() != null
109 && relatedInstance.getModelInfo().getModelType().equals(modelType)) {
110 return relatedInstance;
117 public void updateInfraActiveRequestVnfId(InfraActiveRequests request, String vnfId) {
118 if (request != null) {
119 request.setVnfId(vnfId);
120 this.requestsDbClient.updateInfraActiveRequests(request);
122 logger.debug(REQUEST_ERROR);
126 public void updateInfraActiveRequestVfModuleId(InfraActiveRequests request, String vfModuleId) {
127 if (request != null) {
128 request.setVfModuleId(vfModuleId);
129 this.requestsDbClient.updateInfraActiveRequests(request);
131 logger.debug(REQUEST_ERROR);
135 public void updateInfraActiveRequestVolumeGroupId(InfraActiveRequests request, String volumeGroupId) {
136 if (request != null) {
137 request.setVolumeGroupId(volumeGroupId);
138 this.requestsDbClient.updateInfraActiveRequests(request);
140 logger.debug(REQUEST_ERROR);
144 public void updateInfraActiveRequestNetworkId(InfraActiveRequests request, String networkId) {
145 if (request != null) {
146 request.setNetworkId(networkId);
147 this.requestsDbClient.updateInfraActiveRequests(request);
149 logger.debug(REQUEST_ERROR);
153 public void persistFlowExecutionPath(String requestId, List<ExecuteBuildingBlock> flowsToExecute) {
155 if (requestId != null) {
156 List<String> flows = new ArrayList<>();
157 ObjectMapper om = new ObjectMapper();
159 for (ExecuteBuildingBlock ebb : flowsToExecute) {
160 flows.add(om.writeValueAsString(ebb));
162 } catch (JsonProcessingException e) {
163 logger.error(DATA_PARSE_ERROR, e);
166 this.requestsDbClient.persistProcessingData(flows.toString(), requestId);
168 logger.debug(REQUEST_ERROR);
172 public InfraActiveRequests loadInfraActiveRequestById(String requestId) {
174 return this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
177 public InfraActiveRequests loadOriginalInfraActiveRequestById(String requestId) {
178 return this.requestsDbClient.getInfraActiveRequestbyRequestId(
179 this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId).getOriginalRequestId());
182 public List<ExecuteBuildingBlock> loadOriginalFlowExecutionPath(String requestId) {
183 if (requestId != null) {
184 InfraActiveRequests request = loadInfraActiveRequestById(requestId);
185 if (request.getOriginalRequestId() != null) {
186 RequestProcessingData requestProcessingData =
187 this.requestsDbClient.getRequestProcessingDataBySoRequestIdAndName(
188 request.getOriginalRequestId(), PROCESSING_DATA_NAME_EXECUTION_FLOWS);
190 ObjectMapper om = new ObjectMapper();
191 TypeFactory typeFactory = objectMapper.getTypeFactory();
192 return om.readValue(requestProcessingData.getValue(),
193 typeFactory.constructCollectionType(List.class, ExecuteBuildingBlock.class));
194 } catch (Exception e) {
195 logger.error(DATA_LOAD_ERROR, e);
196 throw new RuntimeException("Error Loading Original Request Data", e);
199 throw new RuntimeException("Original Request Id is null for record: " + requestId);
202 throw new RuntimeException("Null Request Id Passed in");
206 public Service getCatalogServiceByModelUUID(String modelUUID) {
207 return catalogDbClient.getServiceByID(modelUUID);
210 public Service getCatalogServiceByModelVersionAndModelInvariantUUID(String modelVersion,
211 String modelInvariantUUID) {
212 return catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
215 public CollectionNetworkResourceCustomization getCatalogCollectionNetworkResourceCustByID(String key) {
216 return catalogDbClient.getCollectionNetworkResourceCustomizationByID(key);
219 public NetworkCollectionResourceCustomization getCatalogNetworkCollectionResourceCustByID(
220 String collectionCustomizationId) {
221 return catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCustomizationId);
224 public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
225 return catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(modelCustomizationUUID);
228 public CvnfcConfigurationCustomization getCvnfcConfigurationCustomization(String serviceModelUUID,
229 String vnfCustomizationUuid, String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
230 return catalogDbClient.getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid,
231 cvnfcCustomizationUuid);
234 public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroups(String modelCustomizationUUID) {
235 return catalogDbClient.getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID);
238 public Map<String, String> getURIKeysFromServiceInstance(String serviceInstanceId) {
239 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
240 return uri.getURIKeys();
243 protected RequestDetails getRequestDetails(String requestId) throws IOException {
244 if (requestId != null && !requestId.isEmpty()) {
245 InfraActiveRequests activeRequest = this.getInfraActiveRequest(requestId);
246 String requestBody = activeRequest.getRequestBody().replaceAll("\\\\", "");
247 objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
248 objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
249 return objectMapper.readValue(requestBody, RequestDetails.class);
255 protected InfraActiveRequests getInfraActiveRequest(String requestId) {
256 if (requestId != null && !requestId.isEmpty()) {
257 return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
263 protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration) {
264 if (cloudConfiguration != null) {
265 String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
266 String cloudOwner = cloudConfiguration.getCloudOwner();
267 if (cloudRegionId != null && cloudOwner != null && !cloudRegionId.isEmpty() && !cloudOwner.isEmpty()) {
268 return injectionHelper.getAaiClient().get(CloudRegion.class, AAIUriFactory
269 .createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwner, cloudRegionId).depth(Depth.TWO))
280 public InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
281 return injectionHelper.getAaiClient().get(InstanceGroup.class,
282 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId)).orElse(null);
285 public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
286 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.Customer.class,
287 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId)).orElse(null);
290 public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
292 if (globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null
293 || subscriptionServiceType.equals("")) {
296 return injectionHelper.getAaiClient().get(ServiceSubscription.class, AAIUriFactory
297 .createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType))
303 public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
304 return injectionHelper.getAaiClient()
305 .get(ServiceInstance.class, AAIUriFactory
306 .createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId).depth(Depth.TWO))
310 protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
311 String serviceInstanceId) {
312 return injectionHelper.getAaiClient().get(ServiceInstance.class, AAIUriFactory
313 .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId)
314 .depth(Depth.TWO)).orElse(null);
317 protected org.onap.aai.domain.yang.ServiceInstances getAAIServiceInstancesByName(String serviceInstanceName,
320 return injectionHelper.getAaiClient()
321 .get(org.onap.aai.domain.yang.ServiceInstances.class,
323 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
324 customer.getServiceSubscription().getServiceType())
325 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
327 logger.debug("No Service Instance matched by name");
332 public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
333 Customer customer) throws Exception {
334 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
335 org.onap.aai.domain.yang.ServiceInstances aaiServiceInstances = null;
336 aaiServiceInstances = getAAIServiceInstancesByName(serviceInstanceName, customer);
338 if (aaiServiceInstances == null) {
340 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
341 throw new Exception("Multiple Service Instances Returned");
343 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
345 return aaiServiceInstance;
348 protected ServiceInstances getAAIServiceInstancesByName(String globalCustomerId, String serviceType,
349 String serviceInstanceName) {
351 return injectionHelper.getAaiClient()
352 .get(ServiceInstances.class,
354 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, globalCustomerId, serviceType)
355 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
357 logger.debug("No Service Instance matched by name");
362 public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
363 String serviceInstanceName) throws MultipleObjectsFoundException {
364 ServiceInstance aaiServiceInstance = null;
365 ServiceInstances aaiServiceInstances = null;
366 aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName);
368 if (aaiServiceInstances == null) {
369 return Optional.empty();
370 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
371 String message = String.format(
372 "Multiple service instances found for customer-id: %s, service-type: %s and service-instance-name: %s.",
373 globalCustomerId, serviceType, serviceInstanceName);
374 throw new MultipleObjectsFoundException(message);
376 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
378 return Optional.of(aaiServiceInstance);
381 public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
382 return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
385 public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
386 String modelCustomizationUUID) {
387 return this.catalogDbClient
388 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
391 public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
392 AAIResourceUri clonedUri = aaiResourceUri.clone();
393 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
396 public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
397 AAIResourceUri clonedUri = aaiResourceUri.clone();
398 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
401 public Configuration getAAIConfiguration(String configurationId) {
402 return this.getConcreteAAIResource(Configuration.class, AAIObjectType.CONFIGURATION, configurationId);
405 public GenericVnf getAAIGenericVnf(String vnfId) {
406 return getConcreteAAIResource(GenericVnf.class, AAIObjectType.GENERIC_VNF, vnfId);
409 public VpnBinding getAAIVpnBinding(String vpnBindingId) {
410 return getConcreteAAIResource(VpnBinding.class, AAIObjectType.VPN_BINDING, vpnBindingId);
413 public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
414 return getConcreteAAIResource(VolumeGroup.class, AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId,
418 public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
419 return getConcreteAAIResource(VfModule.class, AAIObjectType.VF_MODULE, vnfId, vfModuleId);
422 public L3Network getAAIL3Network(String networkId) {
423 return getConcreteAAIResource(L3Network.class, AAIObjectType.L3_NETWORK, networkId);
426 private <T> T getConcreteAAIResource(Class<T> clazz, AAIObjectType objectType, Object... ids) {
427 return injectionHelper.getAaiClient()
428 .get(clazz, AAIUriFactory.createResourceUri(objectType, ids).depth(Depth.ONE)).orElseGet(() -> {
429 logger.debug("No resource of type: {} matched by ids: {}", objectType.typeName(),
430 Arrays.toString(ids));
435 public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId)
437 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId);
438 uri.relatedTo(AAIObjectPlurals.SERVICE_INSTANCE);
439 Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
440 ServiceInstance serviceInstance = null;
441 if (!serviceInstances.isPresent()) {
442 logger.debug("No ServiceInstances were found");
443 return Optional.empty();
445 if (serviceInstances.get().getServiceInstance().isEmpty()) {
446 throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
447 } else if (serviceInstances.get().getServiceInstance().size() > 1) {
448 String message = String.format("Mulitple service instances were found for instance-group-id: %s.",
450 throw new MultipleObjectsFoundException(message);
452 serviceInstance = serviceInstances.get().getServiceInstance().get(0);
454 return Optional.of(serviceInstance);
458 public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName)
459 throws MultipleObjectsFoundException {
460 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
461 uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
462 Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
463 L3Network network = null;
464 if (!networks.isPresent()) {
465 logger.debug("No Networks matched by name");
466 return Optional.empty();
468 if (networks.get().getL3Network().size() > 1) {
470 String.format("Multiple networks found for service-instance-id: %s and network-name: %s.",
471 serviceInstanceId, networkName);
472 throw new MultipleObjectsFoundException(message);
474 network = networks.get().getL3Network().get(0);
476 return Optional.of(network);
480 public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName)
481 throws MultipleObjectsFoundException {
482 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
483 uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
484 Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri);
485 GenericVnf vnf = null;
486 if (!vnfs.isPresent()) {
487 logger.debug("No Vnfs matched by name");
488 return Optional.empty();
490 if (vnfs.get().getGenericVnf().size() > 1) {
491 String message = String.format("Multiple vnfs found for service-instance-id: %s and vnf-name: %s.",
492 serviceInstanceId, vnfName);
493 throw new MultipleObjectsFoundException(message);
495 vnf = vnfs.get().getGenericVnf().get(0);
497 return Optional.of(vnf);
501 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName)
502 throws MultipleObjectsFoundException {
503 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
504 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
505 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
506 VolumeGroup volumeGroup = null;
507 if (!volumeGroups.isPresent()) {
508 logger.debug("No VolumeGroups matched by name");
509 return Optional.empty();
511 if (volumeGroups.get().getVolumeGroup().size() > 1) {
512 String message = String.format("Multiple volume-groups found for vnf-id: %s and volume-group-name: %s.",
513 vnfId, volumeGroupName);
514 throw new MultipleObjectsFoundException(message);
516 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
518 return Optional.of(volumeGroup);
522 public Optional<VolumeGroup> getRelatedVolumeGroupByIdFromVnf(String vnfId, String volumeGroupId) {
523 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
524 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-id", volumeGroupId);
525 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
526 VolumeGroup volumeGroup = null;
527 if (!volumeGroups.isPresent()) {
528 logger.debug("No VolumeGroups matched by id");
529 return Optional.empty();
531 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
532 return Optional.of(volumeGroup);
536 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId,
537 String volumeGroupName) throws MultipleObjectsFoundException {
538 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
539 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
540 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
541 VolumeGroup volumeGroup = null;
542 if (!volumeGroups.isPresent()) {
543 logger.debug("No VolumeGroups matched by name");
544 return Optional.empty();
546 if (volumeGroups.get().getVolumeGroup().size() > 1) {
547 String message = String.format(
548 "Multiple voulme-groups found for vnf-id: %s, vf-module-id: %s and volume-group-name: %s.",
549 vnfId, vfModuleId, volumeGroupName);
550 throw new MultipleObjectsFoundException(message);
552 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
554 return Optional.of(volumeGroup);
558 public Optional<VolumeGroup> getRelatedVolumeGroupFromVfModule(String vnfId, String vfModuleId) throws Exception {
559 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
560 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP);
561 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
562 VolumeGroup volumeGroup = null;
563 if (!volumeGroups.isPresent()) {
564 logger.debug("VfModule does not have a volume group attached");
565 return Optional.empty();
567 if (volumeGroups.get().getVolumeGroup().size() > 1) {
568 throw new Exception("Multiple VolumeGroups Returned");
570 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
572 return Optional.of(volumeGroup);
576 public Optional<org.onap.aai.domain.yang.VpnBinding> getAICVpnBindingFromNetwork(
577 org.onap.aai.domain.yang.L3Network aaiLocalNetwork) {
578 AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork);
579 if (networkWrapper.getRelationships().isPresent()
580 && !networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING).isEmpty()) {
581 return getAAIResourceDepthOne(
582 networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING).get(0))
583 .asBean(org.onap.aai.domain.yang.VpnBinding.class);
585 return Optional.empty();
588 public ServiceInstances getAAIServiceInstancesGloballyByName(String serviceInstanceName) {
590 return injectionHelper.getAaiClient()
591 .get(ServiceInstances.class, AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE)
592 .queryParam("service-instance-name", serviceInstanceName))
594 logger.debug("No Service Instance matched by name");
599 public boolean existsAAINetworksGloballyByName(String networkName) {
601 AAIResourceUri l3networkUri =
602 AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
603 AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
604 return aaiRC.exists(l3networkUri);
607 public boolean existsAAIVfModuleGloballyByName(String vfModuleName) {
608 AAIResourceUri vfModuleUri =
609 AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", vfModuleName);
610 return injectionHelper.getAaiClient().exists(vfModuleUri);
613 public boolean existsAAIConfigurationGloballyByName(String configurationName) {
614 AAIResourceUri configUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION)
615 .queryParam("configuration-name", configurationName);
616 return injectionHelper.getAaiClient().exists(configUri);
619 public boolean existsAAIVolumeGroupGloballyByName(String volumeGroupName) {
620 AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP)
621 .queryParam("volume-group-name", volumeGroupName);
622 return injectionHelper.getAaiClient().exists(volumeGroupUri);
625 public GenericVnfs getAAIVnfsGloballyByName(String vnfName) {
627 return injectionHelper.getAaiClient()
628 .get(GenericVnfs.class,
629 AAIUriFactory.createNodesUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName))
631 logger.debug("No GenericVnfs matched by name");
636 public Optional<Configuration> getRelatedConfigurationByNameFromServiceInstance(String serviceInstanceId,
637 String configurationName) throws MultipleObjectsFoundException {
638 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
639 uri.relatedTo(AAIObjectPlurals.CONFIGURATION).queryParam("configuration-name", configurationName);
640 Optional<Configurations> configurations = injectionHelper.getAaiClient().get(Configurations.class, uri);
641 Configuration configuration = null;
642 if (!configurations.isPresent()) {
643 logger.debug("No Configurations matched by name");
644 return Optional.empty();
646 if (configurations.get().getConfiguration().size() > 1) {
647 String message = String.format(
648 "Multiple configurations found for service-instance-d: %s and configuration-name: %s.",
649 serviceInstanceId, configurationName);
650 throw new MultipleObjectsFoundException(message);
652 configuration = configurations.get().getConfiguration().get(0);
654 return Optional.of(configuration);