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.List;
29 import java.util.Optional;
30 import org.onap.aai.domain.yang.CloudRegion;
31 import org.onap.aai.domain.yang.Configuration;
32 import org.onap.aai.domain.yang.Configurations;
33 import org.onap.aai.domain.yang.GenericVnf;
34 import org.onap.aai.domain.yang.GenericVnfs;
35 import org.onap.aai.domain.yang.InstanceGroup;
36 import org.onap.aai.domain.yang.L3Network;
37 import org.onap.aai.domain.yang.L3Networks;
38 import org.onap.aai.domain.yang.ServiceInstance;
39 import org.onap.aai.domain.yang.ServiceInstances;
40 import org.onap.aai.domain.yang.ServiceSubscription;
41 import org.onap.aai.domain.yang.VfModule;
42 import org.onap.aai.domain.yang.VolumeGroup;
43 import org.onap.aai.domain.yang.VolumeGroups;
44 import org.onap.aai.domain.yang.VpnBinding;
45 import org.onap.so.bpmn.common.InjectionHelper;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
47 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
48 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
49 import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException;
50 import org.onap.so.client.aai.AAIObjectPlurals;
51 import org.onap.so.client.aai.AAIObjectType;
52 import org.onap.so.client.aai.AAIResourcesClient;
53 import org.onap.so.client.aai.entities.AAIResultWrapper;
54 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
55 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
56 import org.onap.so.client.graphinventory.entities.uri.Depth;
57 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
58 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
59 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
60 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
61 import org.onap.so.db.catalog.beans.Service;
62 import org.onap.so.db.catalog.beans.VfModuleCustomization;
63 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
64 import org.onap.so.db.catalog.client.CatalogDbClient;
65 import org.onap.so.db.request.beans.InfraActiveRequests;
66 import org.onap.so.db.request.beans.RequestProcessingData;
67 import org.onap.so.db.request.client.RequestsDbClient;
68 import org.onap.so.serviceinstancebeans.CloudConfiguration;
69 import org.onap.so.serviceinstancebeans.ModelType;
70 import org.onap.so.serviceinstancebeans.RelatedInstance;
71 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
72 import org.onap.so.serviceinstancebeans.RequestDetails;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
75 import org.springframework.beans.factory.annotation.Autowired;
76 import org.springframework.stereotype.Component;
77 import com.fasterxml.jackson.core.JsonProcessingException;
78 import com.fasterxml.jackson.databind.DeserializationFeature;
79 import com.fasterxml.jackson.databind.ObjectMapper;
80 import com.fasterxml.jackson.databind.SerializationFeature;
81 import com.fasterxml.jackson.databind.type.TypeFactory;
83 @Component("BBInputSetupUtils")
84 public class BBInputSetupUtils {
86 private static final Logger logger = LoggerFactory.getLogger(BBInputSetupUtils.class);
87 private ObjectMapper objectMapper = new ObjectMapper();
88 private static final String REQUEST_ERROR = "Could not find request.";
89 private static final String DATA_LOAD_ERROR = "Could not process loading data from database";
90 private static final String DATA_PARSE_ERROR = "Could not parse data";
91 private static final String PROCESSING_DATA_NAME_EXECUTION_FLOWS = "flowExecutionPath";
94 protected CatalogDbClient catalogDbClient;
97 protected RequestsDbClient requestsDbClient;
100 protected InjectionHelper injectionHelper;
102 public RelatedInstance getRelatedInstanceByType(RequestDetails requestDetails, ModelType modelType) {
103 if (requestDetails.getRelatedInstanceList() != null) {
104 for (RelatedInstanceList relatedInstanceList : requestDetails.getRelatedInstanceList()) {
105 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
106 if (relatedInstance != null && relatedInstance.getModelInfo() != null
107 && relatedInstance.getModelInfo().getModelType() != null
108 && relatedInstance.getModelInfo().getModelType().equals(modelType)) {
109 return relatedInstance;
116 public void updateInfraActiveRequestVnfId(InfraActiveRequests request, String vnfId) {
117 if (request != null) {
118 request.setVnfId(vnfId);
119 this.requestsDbClient.updateInfraActiveRequests(request);
121 logger.debug(REQUEST_ERROR);
125 public void updateInfraActiveRequestVfModuleId(InfraActiveRequests request, String vfModuleId) {
126 if (request != null) {
127 request.setVfModuleId(vfModuleId);
128 this.requestsDbClient.updateInfraActiveRequests(request);
130 logger.debug(REQUEST_ERROR);
134 public void updateInfraActiveRequestVolumeGroupId(InfraActiveRequests request, String volumeGroupId) {
135 if (request != null) {
136 request.setVolumeGroupId(volumeGroupId);
137 this.requestsDbClient.updateInfraActiveRequests(request);
139 logger.debug(REQUEST_ERROR);
143 public void updateInfraActiveRequestNetworkId(InfraActiveRequests request, String networkId) {
144 if (request != null) {
145 request.setNetworkId(networkId);
146 this.requestsDbClient.updateInfraActiveRequests(request);
148 logger.debug(REQUEST_ERROR);
152 public void persistFlowExecutionPath(String requestId, List<ExecuteBuildingBlock> flowsToExecute) {
154 if (requestId != null) {
155 List<String> flows = new ArrayList<>();
156 ObjectMapper om = new ObjectMapper();
158 for (ExecuteBuildingBlock ebb : flowsToExecute) {
159 flows.add(om.writeValueAsString(ebb));
161 } catch (JsonProcessingException e) {
162 logger.error(DATA_PARSE_ERROR, e);
165 this.requestsDbClient.persistProcessingData(flows.toString(), requestId);
167 logger.debug(REQUEST_ERROR);
171 public InfraActiveRequests loadInfraActiveRequestById(String requestId) {
173 return this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
176 public InfraActiveRequests loadOriginalInfraActiveRequestById(String requestId) {
177 return this.requestsDbClient.getInfraActiveRequestbyRequestId(
178 this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId).getOriginalRequestId());
181 public List<ExecuteBuildingBlock> loadOriginalFlowExecutionPath(String requestId) {
182 if (requestId != null) {
183 InfraActiveRequests request = loadInfraActiveRequestById(requestId);
184 if (request.getOriginalRequestId() != null) {
185 RequestProcessingData requestProcessingData =
186 this.requestsDbClient.getRequestProcessingDataBySoRequestIdAndName(
187 request.getOriginalRequestId(), PROCESSING_DATA_NAME_EXECUTION_FLOWS);
189 ObjectMapper om = new ObjectMapper();
190 TypeFactory typeFactory = objectMapper.getTypeFactory();
191 return om.readValue(requestProcessingData.getValue(),
192 typeFactory.constructCollectionType(List.class, ExecuteBuildingBlock.class));
193 } catch (Exception e) {
194 logger.error(DATA_LOAD_ERROR, e);
195 throw new RuntimeException("Error Loading Original Request Data", e);
198 throw new RuntimeException("Original Request Id is null for record: " + requestId);
201 throw new RuntimeException("Null Request Id Passed in");
205 public Service getCatalogServiceByModelUUID(String modelUUID) {
206 return catalogDbClient.getServiceByID(modelUUID);
209 public Service getCatalogServiceByModelVersionAndModelInvariantUUID(String modelVersion,
210 String modelInvariantUUID) {
211 return catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
214 public CollectionNetworkResourceCustomization getCatalogCollectionNetworkResourceCustByID(String key) {
215 return catalogDbClient.getCollectionNetworkResourceCustomizationByID(key);
218 public NetworkCollectionResourceCustomization getCatalogNetworkCollectionResourceCustByID(
219 String collectionCustomizationId) {
220 return catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCustomizationId);
223 public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
224 return catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(modelCustomizationUUID);
227 public CvnfcConfigurationCustomization getCvnfcConfigurationCustomization(String serviceModelUUID,
228 String vnfCustomizationUuid, String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
229 return catalogDbClient.getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid,
230 cvnfcCustomizationUuid);
233 public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroups(String modelCustomizationUUID) {
234 return catalogDbClient.getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID);
237 public Map<String, String> getURIKeysFromServiceInstance(String serviceInstanceId) {
238 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
239 return uri.getURIKeys();
242 protected RequestDetails getRequestDetails(String requestId) throws IOException {
243 if (requestId != null && !requestId.isEmpty()) {
244 InfraActiveRequests activeRequest = this.getInfraActiveRequest(requestId);
245 String requestBody = activeRequest.getRequestBody().replaceAll("\\\\", "");
246 objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
247 objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
248 return objectMapper.readValue(requestBody, RequestDetails.class);
254 protected InfraActiveRequests getInfraActiveRequest(String requestId) {
255 if (requestId != null && !requestId.isEmpty()) {
256 return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
262 protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration) {
263 if (cloudConfiguration != null) {
264 String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
265 String cloudOwner = cloudConfiguration.getCloudOwner();
266 if (cloudRegionId != null && cloudOwner != null && !cloudRegionId.isEmpty() && !cloudOwner.isEmpty()) {
267 return injectionHelper.getAaiClient().get(CloudRegion.class, AAIUriFactory
268 .createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwner, cloudRegionId).depth(Depth.TWO))
279 public InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
280 return injectionHelper.getAaiClient().get(InstanceGroup.class,
281 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId)).orElse(null);
284 public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
285 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.Customer.class,
286 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId)).orElse(null);
289 public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
291 if (globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null
292 || subscriptionServiceType.equals("")) {
295 return injectionHelper.getAaiClient().get(ServiceSubscription.class, AAIUriFactory
296 .createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType))
302 public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
303 return injectionHelper.getAaiClient()
304 .get(ServiceInstance.class, AAIUriFactory
305 .createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId).depth(Depth.TWO))
309 protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
310 String serviceInstanceId) {
311 return injectionHelper.getAaiClient().get(ServiceInstance.class, AAIUriFactory
312 .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId)
313 .depth(Depth.TWO)).orElse(null);
316 protected org.onap.aai.domain.yang.ServiceInstances getAAIServiceInstancesByName(String serviceInstanceName,
319 return injectionHelper.getAaiClient()
320 .get(org.onap.aai.domain.yang.ServiceInstances.class,
322 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
323 customer.getServiceSubscription().getServiceType())
324 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
326 logger.debug("No Service Instance matched by name");
331 public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
332 Customer customer) throws Exception {
333 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
334 org.onap.aai.domain.yang.ServiceInstances aaiServiceInstances = null;
335 aaiServiceInstances = getAAIServiceInstancesByName(serviceInstanceName, customer);
337 if (aaiServiceInstances == null) {
339 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
340 throw new Exception("Multiple Service Instances Returned");
342 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
344 return aaiServiceInstance;
347 protected ServiceInstances getAAIServiceInstancesByName(String globalCustomerId, String serviceType,
348 String serviceInstanceName) {
350 return injectionHelper.getAaiClient()
351 .get(ServiceInstances.class,
353 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, globalCustomerId, serviceType)
354 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
356 logger.debug("No Service Instance matched by name");
361 public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
362 String serviceInstanceName) throws MultipleObjectsFoundException {
363 ServiceInstance aaiServiceInstance = null;
364 ServiceInstances aaiServiceInstances = null;
365 aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName);
367 if (aaiServiceInstances == null) {
368 return Optional.empty();
369 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
370 String message = String.format(
371 "Multiple service instances found for customer-id: %s, service-type: %s and service-instance-name: %s.",
372 globalCustomerId, serviceType, serviceInstanceName);
373 throw new MultipleObjectsFoundException(message);
375 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
377 return Optional.of(aaiServiceInstance);
380 public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
381 return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
384 public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
385 String modelCustomizationUUID) {
386 return this.catalogDbClient
387 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
390 public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
391 AAIResourceUri clonedUri = aaiResourceUri.clone();
392 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
395 public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
396 AAIResourceUri clonedUri = aaiResourceUri.clone();
397 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
400 public Configuration getAAIConfiguration(String configurationId) {
401 return this.injectionHelper.getAaiClient()
402 .get(Configuration.class,
403 AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE))
405 logger.debug("No Configuration matched by id");
410 public GenericVnf getAAIGenericVnf(String vnfId) {
412 return this.injectionHelper.getAaiClient()
413 .get(GenericVnf.class,
414 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE))
416 logger.debug("No Generic Vnf matched by id");
421 public VpnBinding getAAIVpnBinding(String vpnBindingId) {
423 return this.injectionHelper.getAaiClient()
424 .get(VpnBinding.class,
425 AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, vpnBindingId).depth(Depth.ONE))
427 logger.debug("No VpnBinding matched by id");
432 public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
433 return this.injectionHelper.getAaiClient()
434 .get(VolumeGroup.class, AAIUriFactory
435 .createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId, volumeGroupId)
438 logger.debug("No Generic Vnf matched by id");
443 public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
444 return this.injectionHelper.getAaiClient()
446 AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE))
448 logger.debug("No Generic Vnf matched by id");
453 public L3Network getAAIL3Network(String networkId) {
455 return this.injectionHelper.getAaiClient()
456 .get(L3Network.class,
457 AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE))
459 logger.debug("No Generic Vnf matched by id");
465 public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId)
467 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId);
468 uri.relatedTo(AAIObjectPlurals.SERVICE_INSTANCE);
469 Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
470 ServiceInstance serviceInstance = null;
471 if (!serviceInstances.isPresent()) {
472 logger.debug("No ServiceInstances were found");
473 return Optional.empty();
475 if (serviceInstances.get().getServiceInstance().isEmpty()) {
476 throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
477 } else if (serviceInstances.get().getServiceInstance().size() > 1) {
478 String message = String.format("Mulitple service instances were found for instance-group-id: %s.",
480 throw new MultipleObjectsFoundException(message);
482 serviceInstance = serviceInstances.get().getServiceInstance().get(0);
484 return Optional.of(serviceInstance);
488 public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName)
489 throws MultipleObjectsFoundException {
490 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
491 uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
492 Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
493 L3Network network = null;
494 if (!networks.isPresent()) {
495 logger.debug("No Networks matched by name");
496 return Optional.empty();
498 if (networks.get().getL3Network().size() > 1) {
500 String.format("Multiple networks found for service-instance-id: %s and network-name: %s.",
501 serviceInstanceId, networkName);
502 throw new MultipleObjectsFoundException(message);
504 network = networks.get().getL3Network().get(0);
506 return Optional.of(network);
510 public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName)
511 throws MultipleObjectsFoundException {
512 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
513 uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
514 Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri);
515 GenericVnf vnf = null;
516 if (!vnfs.isPresent()) {
517 logger.debug("No Vnfs matched by name");
518 return Optional.empty();
520 if (vnfs.get().getGenericVnf().size() > 1) {
521 String message = String.format("Multiple vnfs found for service-instance-id: %s and vnf-name: %s.",
522 serviceInstanceId, vnfName);
523 throw new MultipleObjectsFoundException(message);
525 vnf = vnfs.get().getGenericVnf().get(0);
527 return Optional.of(vnf);
531 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName)
532 throws MultipleObjectsFoundException {
533 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
534 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
535 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
536 VolumeGroup volumeGroup = null;
537 if (!volumeGroups.isPresent()) {
538 logger.debug("No VolumeGroups matched by name");
539 return Optional.empty();
541 if (volumeGroups.get().getVolumeGroup().size() > 1) {
542 String message = String.format("Multiple volume-groups found for vnf-id: %s and volume-group-name: %s.",
543 vnfId, volumeGroupName);
544 throw new MultipleObjectsFoundException(message);
546 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
548 return Optional.of(volumeGroup);
552 public Optional<VolumeGroup> getRelatedVolumeGroupByIdFromVnf(String vnfId, String volumeGroupId) {
553 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
554 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-id", volumeGroupId);
555 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
556 VolumeGroup volumeGroup = null;
557 if (!volumeGroups.isPresent()) {
558 logger.debug("No VolumeGroups matched by id");
559 return Optional.empty();
561 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
562 return Optional.of(volumeGroup);
566 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId,
567 String volumeGroupName) throws MultipleObjectsFoundException {
568 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
569 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
570 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
571 VolumeGroup volumeGroup = null;
572 if (!volumeGroups.isPresent()) {
573 logger.debug("No VolumeGroups matched by name");
574 return Optional.empty();
576 if (volumeGroups.get().getVolumeGroup().size() > 1) {
577 String message = String.format(
578 "Multiple voulme-groups found for vnf-id: %s, vf-module-id: %s and volume-group-name: %s.",
579 vnfId, vfModuleId, volumeGroupName);
580 throw new MultipleObjectsFoundException(message);
582 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
584 return Optional.of(volumeGroup);
588 public Optional<VolumeGroup> getRelatedVolumeGroupFromVfModule(String vnfId, String vfModuleId) throws Exception {
589 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
590 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP);
591 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
592 VolumeGroup volumeGroup = null;
593 if (!volumeGroups.isPresent()) {
594 logger.debug("VfModule does not have a volume group attached");
595 return Optional.empty();
597 if (volumeGroups.get().getVolumeGroup().size() > 1) {
598 throw new Exception("Multiple VolumeGroups Returned");
600 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
602 return Optional.of(volumeGroup);
606 public Optional<org.onap.aai.domain.yang.VpnBinding> getAICVpnBindingFromNetwork(
607 org.onap.aai.domain.yang.L3Network aaiLocalNetwork) {
608 AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork);
609 if (networkWrapper.getRelationships().isPresent()
610 && !networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING).isEmpty()) {
611 return getAAIResourceDepthOne(
612 networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING).get(0))
613 .asBean(org.onap.aai.domain.yang.VpnBinding.class);
615 return Optional.empty();
618 public ServiceInstances getAAIServiceInstancesGloballyByName(String serviceInstanceName) {
620 return injectionHelper.getAaiClient()
621 .get(ServiceInstances.class, AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE)
622 .queryParam("service-instance-name", serviceInstanceName))
624 logger.debug("No Service Instance matched by name");
629 public boolean existsAAINetworksGloballyByName(String networkName) {
631 AAIResourceUri l3networkUri =
632 AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
633 AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
634 return aaiRC.exists(l3networkUri);
637 public boolean existsAAIVfModuleGloballyByName(String vfModuleName) {
638 AAIResourceUri vfModuleUri =
639 AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", vfModuleName);
640 return injectionHelper.getAaiClient().exists(vfModuleUri);
643 public boolean existsAAIConfigurationGloballyByName(String configurationName) {
644 AAIResourceUri configUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION)
645 .queryParam("configuration-name", configurationName);
646 return injectionHelper.getAaiClient().exists(configUri);
649 public boolean existsAAIVolumeGroupGloballyByName(String volumeGroupName) {
650 AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP)
651 .queryParam("volume-group-name", volumeGroupName);
652 return injectionHelper.getAaiClient().exists(volumeGroupUri);
655 public GenericVnfs getAAIVnfsGloballyByName(String vnfName) {
657 return injectionHelper.getAaiClient()
658 .get(GenericVnfs.class,
659 AAIUriFactory.createNodesUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName))
661 logger.debug("No GenericVnfs matched by name");
666 public Optional<Configuration> getRelatedConfigurationByNameFromServiceInstance(String serviceInstanceId,
667 String configurationName) throws MultipleObjectsFoundException {
668 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
669 uri.relatedTo(AAIObjectPlurals.CONFIGURATION).queryParam("configuration-name", configurationName);
670 Optional<Configurations> configurations = injectionHelper.getAaiClient().get(Configurations.class, uri);
671 Configuration configuration = null;
672 if (!configurations.isPresent()) {
673 logger.debug("No Configurations matched by name");
674 return Optional.empty();
676 if (configurations.get().getConfiguration().size() > 1) {
677 String message = String.format(
678 "Multiple configurations found for service-instance-d: %s and configuration-name: %s.",
679 serviceInstanceId, configurationName);
680 throw new MultipleObjectsFoundException(message);
682 configuration = configurations.get().getConfiguration().get(0);
684 return Optional.of(configuration);