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;
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.NetworkCollectionResourceCustomization;
53 import org.onap.so.db.catalog.beans.Service;
54 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
55 import org.onap.so.db.catalog.client.CatalogDbClient;
56 import org.onap.so.db.request.beans.InfraActiveRequests;
57 import org.onap.so.db.request.client.RequestsDbClient;
58 import org.onap.so.logger.MsoLogger;
59 import org.onap.so.serviceinstancebeans.CloudConfiguration;
60 import org.onap.so.serviceinstancebeans.RequestDetails;
61 import org.springframework.beans.factory.annotation.Autowired;
62 import org.springframework.stereotype.Component;
64 import com.fasterxml.jackson.databind.DeserializationFeature;
65 import com.fasterxml.jackson.databind.ObjectMapper;
66 import com.fasterxml.jackson.databind.SerializationFeature;
68 @Component("BBInputSetupUtils")
69 public class BBInputSetupUtils {
71 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BBInputSetupUtils.class);
72 private ObjectMapper objectMapper = new ObjectMapper();
73 private static final String REQUEST_ERROR = "Could not find request.";
76 protected CatalogDbClient catalogDbClient;
79 protected RequestsDbClient requestsDbClient;
82 protected InjectionHelper injectionHelper;
84 public void updateInfraActiveRequestVnfId(InfraActiveRequests request, String vnfId) {
86 request.setVnfId(vnfId);
87 this.requestsDbClient.updateInfraActiveRequests(request);
89 msoLogger.debug(REQUEST_ERROR);
93 public void updateInfraActiveRequestVfModuleId(InfraActiveRequests request, String vfModuleId) {
95 request.setVfModuleId(vfModuleId);
96 this.requestsDbClient.updateInfraActiveRequests(request);
98 msoLogger.debug(REQUEST_ERROR);
102 public void updateInfraActiveRequestVolumeGroupId(InfraActiveRequests request, String volumeGroupId) {
103 if(request != null) {
104 request.setVolumeGroupId(volumeGroupId);
105 this.requestsDbClient.updateInfraActiveRequests(request);
107 msoLogger.debug(REQUEST_ERROR);
111 public void updateInfraActiveRequestNetworkId(InfraActiveRequests request, String networkId) {
112 if(request != null) {
113 request.setNetworkId(networkId);
114 this.requestsDbClient.updateInfraActiveRequests(request);
116 msoLogger.debug(REQUEST_ERROR);
120 public Service getCatalogServiceByModelUUID(String modelUUID) {
121 return catalogDbClient.getServiceByID(modelUUID);
124 public Service getCatalogServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
125 return catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
128 public CollectionNetworkResourceCustomization getCatalogCollectionNetworkResourceCustByID(String key) {
129 return catalogDbClient.getCollectionNetworkResourceCustomizationByID(key);
132 public NetworkCollectionResourceCustomization getCatalogNetworkCollectionResourceCustByID(
133 String collectionCustomizationId) {
134 return catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCustomizationId);
137 public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroups(String modelCustomizationUUID) {
138 return catalogDbClient.getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID);
141 public Map<String, String> getURIKeysFromServiceInstance(String serviceInstanceId) {
142 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
143 return uri.getURIKeys();
146 protected RequestDetails getRequestDetails(String requestId) throws IOException {
147 if (requestId != null && !requestId.isEmpty()) {
148 InfraActiveRequests activeRequest = this.getInfraActiveRequest(requestId);
149 String requestBody = activeRequest.getRequestBody().replaceAll("\\\\", "");
150 objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
151 objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
152 return objectMapper.readValue(requestBody, RequestDetails.class);
158 protected InfraActiveRequests getInfraActiveRequest(String requestId) {
159 if (requestId != null && !requestId.isEmpty()) {
160 return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
166 protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration) {
167 if (cloudConfiguration != null) {
168 String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
169 String cloudOwner = cloudConfiguration.getCloudOwner();
170 if (cloudRegionId != null && cloudOwner != null && !cloudRegionId.isEmpty() && !cloudOwner.isEmpty()) {
171 return injectionHelper.getAaiClient().get(CloudRegion.class,
172 AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwner,
173 cloudRegionId)).orElse(null);
183 protected InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
184 return injectionHelper.getAaiClient().get(InstanceGroup.class,
185 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId))
189 public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
190 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.Customer.class,
191 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId))
195 public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
197 if(globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null || subscriptionServiceType.equals("")) {
200 return injectionHelper.getAaiClient().get(ServiceSubscription.class, AAIUriFactory.createResourceUri(
201 AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType))
207 public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
208 return injectionHelper.getAaiClient().get(ServiceInstance.class,
209 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId).depth(Depth.TWO))
213 protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
214 String serviceInstanceId) {
215 return injectionHelper.getAaiClient().get(ServiceInstance.class, AAIUriFactory.createResourceUri(
216 AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId).depth(Depth.TWO))
220 protected org.onap.aai.domain.yang.ServiceInstances getAAIServiceInstancesByName(String serviceInstanceName,
223 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.ServiceInstances.class,
225 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
226 customer.getServiceSubscription().getServiceType())
227 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
229 msoLogger.debug("No Service Instance matched by name");
234 public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
235 Customer customer) throws Exception {
236 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
237 org.onap.aai.domain.yang.ServiceInstances aaiServiceInstances = null;
238 aaiServiceInstances = getAAIServiceInstancesByName(serviceInstanceName, customer);
240 if (aaiServiceInstances == null) {
242 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
243 throw new Exception("Multiple Service Instances Returned");
245 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
247 return aaiServiceInstance;
250 protected ServiceInstances getAAIServiceInstancesByName(String globalCustomerId, String serviceType,
251 String serviceInstanceName) {
253 return injectionHelper.getAaiClient().get(ServiceInstances.class,
254 AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, globalCustomerId, serviceType)
255 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
257 msoLogger.debug("No Service Instance matched by name");
262 public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
263 String serviceInstanceName) throws Exception {
264 ServiceInstance aaiServiceInstance = null;
265 ServiceInstances aaiServiceInstances = null;
266 aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName);
268 if (aaiServiceInstances == null) {
269 return Optional.empty();
270 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
271 throw new Exception("Multiple Service Instances Returned");
273 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
275 return Optional.of(aaiServiceInstance);
278 public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
279 return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
282 public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
283 String modelCustomizationUUID) {
284 return this.catalogDbClient
285 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
288 public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
289 AAIResourceUri clonedUri = aaiResourceUri.clone();
290 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
293 public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
294 AAIResourceUri clonedUri = aaiResourceUri.clone();
295 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
298 public Configuration getAAIConfiguration(String configurationId) {
299 return this.injectionHelper.getAaiClient().get(Configuration.class,
300 AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE))
302 msoLogger.debug("No Configuration matched by id");
307 public GenericVnf getAAIGenericVnf(String vnfId) {
309 return this.injectionHelper.getAaiClient().get(GenericVnf.class,
310 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE))
312 msoLogger.debug("No Generic Vnf matched by id");
317 public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
318 return this.injectionHelper.getAaiClient().get(VolumeGroup.class,
319 AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId, volumeGroupId).depth(Depth.ONE))
321 msoLogger.debug("No Generic Vnf matched by id");
326 public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
327 return this.injectionHelper.getAaiClient().get(VfModule.class,
328 AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE))
330 msoLogger.debug("No Generic Vnf matched by id");
335 public L3Network getAAIL3Network(String networkId) {
337 return this.injectionHelper.getAaiClient().get(L3Network.class,
338 AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE))
340 msoLogger.debug("No Generic Vnf matched by id");
346 public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName) throws Exception{
347 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
348 uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
349 Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
350 L3Network network = null;
351 if (!networks.isPresent()) {
352 msoLogger.debug("No Networks matched by name");
353 return Optional.empty();
355 if (networks.get().getL3Network().size() > 1) {
356 throw new Exception("Multiple Networks Returned");
358 network = networks.get().getL3Network().get(0);
360 return Optional.of(network);
364 public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName) throws Exception {
365 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
366 uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
367 Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri);
368 GenericVnf vnf = null;
369 if (!vnfs.isPresent()) {
370 msoLogger.debug("No Vnfs matched by name");
371 return Optional.empty();
373 if (vnfs.get().getGenericVnf().size() > 1) {
374 throw new Exception("Multiple Vnfs Returned");
376 vnf = vnfs.get().getGenericVnf().get(0);
378 return Optional.of(vnf);
382 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName) throws Exception{
383 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
384 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
385 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
386 VolumeGroup volumeGroup = null;
387 if (!volumeGroups.isPresent()) {
388 msoLogger.debug("No VolumeGroups matched by name");
389 return Optional.empty();
391 if (volumeGroups.get().getVolumeGroup().size() > 1) {
392 throw new Exception("Multiple VolumeGroups Returned");
394 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
396 return Optional.of(volumeGroup);
400 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId, String volumeGroupName) throws Exception {
401 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
402 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
403 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
404 VolumeGroup volumeGroup = null;
405 if (!volumeGroups.isPresent()) {
406 msoLogger.debug("No VolumeGroups matched by name");
407 return Optional.empty();
409 if (volumeGroups.get().getVolumeGroup().size() > 1) {
410 throw new Exception("Multiple VolumeGroups Returned");
412 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
414 return Optional.of(volumeGroup);