2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.servicedecomposition.tasks;
23 import java.io.IOException;
24 import java.util.List;
26 import java.util.Optional;
28 import org.onap.aai.domain.yang.CloudRegion;
29 import org.onap.aai.domain.yang.Configuration;
30 import org.onap.aai.domain.yang.GenericVnf;
31 import org.onap.aai.domain.yang.GenericVnfs;
32 import org.onap.aai.domain.yang.InstanceGroup;
33 import org.onap.aai.domain.yang.L3Network;
34 import org.onap.aai.domain.yang.L3Networks;
35 import org.onap.aai.domain.yang.ServiceInstance;
36 import org.onap.aai.domain.yang.ServiceInstances;
37 import org.onap.aai.domain.yang.ServiceSubscription;
38 import org.onap.aai.domain.yang.VfModule;
39 import org.onap.aai.domain.yang.VolumeGroup;
40 import org.onap.aai.domain.yang.VolumeGroups;
41 import org.onap.so.bpmn.common.InjectionHelper;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
43 import org.onap.so.client.aai.AAIObjectPlurals;
44 import org.onap.so.client.aai.AAIObjectType;
45 import org.onap.so.client.aai.entities.AAIResultWrapper;
46 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
47 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
48 import org.onap.so.client.db.request.RequestsDbClient;
49 import org.onap.so.client.graphinventory.entities.uri.Depth;
50 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
51 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
52 import org.onap.so.db.catalog.beans.Service;
53 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
54 import org.onap.so.db.catalog.client.CatalogDbClient;
55 import org.onap.so.db.request.beans.InfraActiveRequests;
56 import org.onap.so.logger.MsoLogger;
57 import org.onap.so.serviceinstancebeans.CloudConfiguration;
58 import org.onap.so.serviceinstancebeans.RequestDetails;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.stereotype.Component;
62 import com.fasterxml.jackson.databind.DeserializationFeature;
63 import com.fasterxml.jackson.databind.ObjectMapper;
64 import com.fasterxml.jackson.databind.SerializationFeature;
66 @Component("BBInputSetupUtils")
67 public class BBInputSetupUtils {
69 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BBInputSetupUtils.class);
70 private ObjectMapper objectMapper = new ObjectMapper();
71 private static final String REQUEST_ERROR = "Could not find request.";
74 protected CatalogDbClient catalogDbClient;
77 protected RequestsDbClient requestsDbClient;
80 protected InjectionHelper injectionHelper;
82 public void updateInfraActiveRequestVnfId(InfraActiveRequests request, String vnfId) {
84 request.setVnfId(vnfId);
85 this.requestsDbClient.updateInfraActiveRequests(request);
87 msoLogger.debug(REQUEST_ERROR);
91 public void updateInfraActiveRequestVfModuleId(InfraActiveRequests request, String vfModuleId) {
93 request.setVfModuleId(vfModuleId);
94 this.requestsDbClient.updateInfraActiveRequests(request);
96 msoLogger.debug(REQUEST_ERROR);
100 public void updateInfraActiveRequestVolumeGroupId(InfraActiveRequests request, String volumeGroupId) {
101 if(request != null) {
102 request.setVolumeGroupId(volumeGroupId);
103 this.requestsDbClient.updateInfraActiveRequests(request);
105 msoLogger.debug(REQUEST_ERROR);
109 public void updateInfraActiveRequestNetworkId(InfraActiveRequests request, String networkId) {
110 if(request != null) {
111 request.setNetworkId(networkId);
112 this.requestsDbClient.updateInfraActiveRequests(request);
114 msoLogger.debug(REQUEST_ERROR);
118 public Service getCatalogServiceByModelUUID(String modelUUID) {
119 return catalogDbClient.getServiceByID(modelUUID);
122 public Service getCatalogServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
123 return catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
126 public CollectionNetworkResourceCustomization getCatalogCollectionNetworkResourceCustByID(String key) {
127 return catalogDbClient.getCollectionNetworkResourceCustomizationByID(key);
130 public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroups(String modelCustomizationUUID) {
131 return catalogDbClient.getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID);
134 public Map<String, String> getURIKeysFromServiceInstance(String serviceInstanceId) {
135 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
136 return uri.getURIKeys();
139 protected RequestDetails getRequestDetails(String requestId) throws IOException {
140 if (requestId != null && !requestId.isEmpty()) {
141 InfraActiveRequests activeRequest = this.getInfraActiveRequest(requestId);
142 String requestBody = activeRequest.getRequestBody().replaceAll("\\\\", "");
143 objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
144 objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
145 return objectMapper.readValue(requestBody, RequestDetails.class);
151 protected InfraActiveRequests getInfraActiveRequest(String requestId) {
152 if (requestId != null && !requestId.isEmpty()) {
153 return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
159 protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration, String cloudOwner) {
160 if (cloudConfiguration != null) {
161 String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
162 if (cloudRegionId != null && !cloudRegionId.isEmpty()) {
163 return injectionHelper.getAaiClient().get(CloudRegion.class,
164 AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwner,
165 cloudConfiguration.getLcpCloudRegionId())).orElse(null);
175 protected InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
176 return injectionHelper.getAaiClient().get(InstanceGroup.class,
177 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId))
181 public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
182 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.Customer.class,
183 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId))
187 public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
189 if(globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null || subscriptionServiceType.equals("")) {
192 return injectionHelper.getAaiClient().get(ServiceSubscription.class, AAIUriFactory.createResourceUri(
193 AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType))
199 public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
200 return injectionHelper.getAaiClient().get(ServiceInstance.class,
201 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId).depth(Depth.TWO))
205 protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
206 String serviceInstanceId) {
207 return injectionHelper.getAaiClient().get(ServiceInstance.class, AAIUriFactory.createResourceUri(
208 AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId).depth(Depth.TWO))
212 protected org.onap.aai.domain.yang.ServiceInstances getAAIServiceInstancesByName(String serviceInstanceName,
215 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.ServiceInstances.class,
217 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
218 customer.getServiceSubscription().getServiceType())
219 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
221 msoLogger.debug("No Service Instance matched by name");
226 public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
227 Customer customer) throws Exception {
228 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
229 org.onap.aai.domain.yang.ServiceInstances aaiServiceInstances = null;
230 aaiServiceInstances = getAAIServiceInstancesByName(serviceInstanceName, customer);
232 if (aaiServiceInstances == null) {
234 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
235 throw new Exception("Multiple Service Instances Returned");
237 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
239 return aaiServiceInstance;
242 protected ServiceInstances getAAIServiceInstancesByName(String globalCustomerId, String serviceType,
243 String serviceInstanceName) {
245 return injectionHelper.getAaiClient().get(ServiceInstances.class,
246 AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, globalCustomerId, serviceType)
247 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
249 msoLogger.debug("No Service Instance matched by name");
254 public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
255 String serviceInstanceName) throws Exception {
256 ServiceInstance aaiServiceInstance = null;
257 ServiceInstances aaiServiceInstances = null;
258 aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName);
260 if (aaiServiceInstances == null) {
261 return Optional.empty();
262 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
263 throw new Exception("Multiple Service Instances Returned");
265 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
267 return Optional.of(aaiServiceInstance);
270 public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
271 return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
274 public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
275 String modelCustomizationUUID) {
276 return this.catalogDbClient
277 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
280 public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
281 AAIResourceUri clonedUri = aaiResourceUri.clone();
282 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
285 public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
286 AAIResourceUri clonedUri = aaiResourceUri.clone();
287 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
290 public Configuration getAAIConfiguration(String configurationId) {
291 return this.injectionHelper.getAaiClient().get(Configuration.class,
292 AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE))
294 msoLogger.debug("No Configuration matched by id");
299 public GenericVnf getAAIGenericVnf(String vnfId) {
301 return this.injectionHelper.getAaiClient().get(GenericVnf.class,
302 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE))
304 msoLogger.debug("No Generic Vnf matched by id");
309 public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
310 return this.injectionHelper.getAaiClient().get(VolumeGroup.class,
311 AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId, volumeGroupId).depth(Depth.ONE))
313 msoLogger.debug("No Generic Vnf matched by id");
318 public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
319 return this.injectionHelper.getAaiClient().get(VfModule.class,
320 AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE))
322 msoLogger.debug("No Generic Vnf matched by id");
327 public L3Network getAAIL3Network(String networkId) {
329 return this.injectionHelper.getAaiClient().get(L3Network.class,
330 AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE))
332 msoLogger.debug("No Generic Vnf matched by id");
338 public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName) throws Exception{
339 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
340 uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
341 Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
342 L3Network network = null;
343 if (!networks.isPresent()) {
344 msoLogger.debug("No Networks matched by name");
345 return Optional.empty();
347 if (networks.get().getL3Network().size() > 1) {
348 throw new Exception("Multiple Networks Returned");
350 network = networks.get().getL3Network().get(0);
352 return Optional.of(network);
356 public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName) throws Exception {
357 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
358 uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
359 Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri);
360 GenericVnf vnf = null;
361 if (!vnfs.isPresent()) {
362 msoLogger.debug("No Vnfs matched by name");
363 return Optional.empty();
365 if (vnfs.get().getGenericVnf().size() > 1) {
366 throw new Exception("Multiple Vnfs Returned");
368 vnf = vnfs.get().getGenericVnf().get(0);
370 return Optional.of(vnf);
374 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName) throws Exception{
375 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
376 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
377 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
378 VolumeGroup volumeGroup = null;
379 if (!volumeGroups.isPresent()) {
380 msoLogger.debug("No VolumeGroups matched by name");
381 return Optional.empty();
383 if (volumeGroups.get().getVolumeGroup().size() > 1) {
384 throw new Exception("Multiple VolumeGroups Returned");
386 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
388 return Optional.of(volumeGroup);
392 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vfModuleId, String volumeGroupName) throws Exception {
393 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vfModuleId);
394 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
395 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
396 VolumeGroup volumeGroup = null;
397 if (!volumeGroups.isPresent()) {
398 msoLogger.debug("No VolumeGroups matched by name");
399 return Optional.empty();
401 if (volumeGroups.get().getVolumeGroup().size() > 1) {
402 throw new Exception("Multiple VolumeGroups Returned");
404 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
406 return Optional.of(volumeGroup);