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.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.logger.MsoLogger;
58 import org.onap.so.serviceinstancebeans.CloudConfiguration;
59 import org.onap.so.serviceinstancebeans.RequestDetails;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.stereotype.Component;
63 import com.fasterxml.jackson.databind.DeserializationFeature;
64 import com.fasterxml.jackson.databind.ObjectMapper;
65 import com.fasterxml.jackson.databind.SerializationFeature;
67 @Component("BBInputSetupUtils")
68 public class BBInputSetupUtils {
70 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BBInputSetupUtils.class);
71 private ObjectMapper objectMapper = new ObjectMapper();
72 private static final String REQUEST_ERROR = "Could not find request.";
75 protected CatalogDbClient catalogDbClient;
78 protected RequestsDbClient requestsDbClient;
81 protected InjectionHelper injectionHelper;
83 public void updateInfraActiveRequestVnfId(InfraActiveRequests request, String vnfId) {
85 request.setVnfId(vnfId);
86 this.requestsDbClient.updateInfraActiveRequests(request);
88 msoLogger.debug(REQUEST_ERROR);
92 public void updateInfraActiveRequestVfModuleId(InfraActiveRequests request, String vfModuleId) {
94 request.setVfModuleId(vfModuleId);
95 this.requestsDbClient.updateInfraActiveRequests(request);
97 msoLogger.debug(REQUEST_ERROR);
101 public void updateInfraActiveRequestVolumeGroupId(InfraActiveRequests request, String volumeGroupId) {
102 if(request != null) {
103 request.setVolumeGroupId(volumeGroupId);
104 this.requestsDbClient.updateInfraActiveRequests(request);
106 msoLogger.debug(REQUEST_ERROR);
110 public void updateInfraActiveRequestNetworkId(InfraActiveRequests request, String networkId) {
111 if(request != null) {
112 request.setNetworkId(networkId);
113 this.requestsDbClient.updateInfraActiveRequests(request);
115 msoLogger.debug(REQUEST_ERROR);
119 public Service getCatalogServiceByModelUUID(String modelUUID) {
120 return catalogDbClient.getServiceByID(modelUUID);
123 public Service getCatalogServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
124 return catalogDbClient.getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID);
127 public CollectionNetworkResourceCustomization getCatalogCollectionNetworkResourceCustByID(String key) {
128 return catalogDbClient.getCollectionNetworkResourceCustomizationByID(key);
131 public NetworkCollectionResourceCustomization getCatalogNetworkCollectionResourceCustByID(
132 String collectionCustomizationId) {
133 return catalogDbClient.getNetworkCollectionResourceCustomizationByID(collectionCustomizationId);
136 public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroups(String modelCustomizationUUID) {
137 return catalogDbClient.getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID);
140 public Map<String, String> getURIKeysFromServiceInstance(String serviceInstanceId) {
141 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
142 return uri.getURIKeys();
145 protected RequestDetails getRequestDetails(String requestId) throws IOException {
146 if (requestId != null && !requestId.isEmpty()) {
147 InfraActiveRequests activeRequest = this.getInfraActiveRequest(requestId);
148 String requestBody = activeRequest.getRequestBody().replaceAll("\\\\", "");
149 objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
150 objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
151 return objectMapper.readValue(requestBody, RequestDetails.class);
157 protected InfraActiveRequests getInfraActiveRequest(String requestId) {
158 if (requestId != null && !requestId.isEmpty()) {
159 return requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
165 protected CloudRegion getCloudRegion(CloudConfiguration cloudConfiguration, String cloudOwner) {
166 if (cloudConfiguration != null) {
167 String cloudRegionId = cloudConfiguration.getLcpCloudRegionId();
168 if (cloudRegionId != null && !cloudRegionId.isEmpty()) {
169 return injectionHelper.getAaiClient().get(CloudRegion.class,
170 AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwner,
171 cloudConfiguration.getLcpCloudRegionId())).orElse(null);
181 protected InstanceGroup getAAIInstanceGroup(String instanceGroupId) {
182 return injectionHelper.getAaiClient().get(InstanceGroup.class,
183 AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId))
187 public org.onap.aai.domain.yang.Customer getAAICustomer(String globalSubscriberId) {
188 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.Customer.class,
189 AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId))
193 public ServiceSubscription getAAIServiceSubscription(String globalSubscriberId, String subscriptionServiceType) {
195 if(globalSubscriberId == null || globalSubscriberId.equals("") || subscriptionServiceType == null || subscriptionServiceType.equals("")) {
198 return injectionHelper.getAaiClient().get(ServiceSubscription.class, AAIUriFactory.createResourceUri(
199 AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType))
205 public ServiceInstance getAAIServiceInstanceById(String serviceInstanceId) {
206 return injectionHelper.getAaiClient().get(ServiceInstance.class,
207 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId).depth(Depth.TWO))
211 protected ServiceInstance getAAIServiceInstanceByIdAndCustomer(String globalCustomerId, String serviceType,
212 String serviceInstanceId) {
213 return injectionHelper.getAaiClient().get(ServiceInstance.class, AAIUriFactory.createResourceUri(
214 AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId).depth(Depth.TWO))
218 protected org.onap.aai.domain.yang.ServiceInstances getAAIServiceInstancesByName(String serviceInstanceName,
221 return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.ServiceInstances.class,
223 .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
224 customer.getServiceSubscription().getServiceType())
225 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
227 msoLogger.debug("No Service Instance matched by name");
232 public org.onap.aai.domain.yang.ServiceInstance getAAIServiceInstanceByName(String serviceInstanceName,
233 Customer customer) throws Exception {
234 org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
235 org.onap.aai.domain.yang.ServiceInstances aaiServiceInstances = null;
236 aaiServiceInstances = getAAIServiceInstancesByName(serviceInstanceName, customer);
238 if (aaiServiceInstances == null) {
240 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
241 throw new Exception("Multiple Service Instances Returned");
243 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
245 return aaiServiceInstance;
248 protected ServiceInstances getAAIServiceInstancesByName(String globalCustomerId, String serviceType,
249 String serviceInstanceName) {
251 return injectionHelper.getAaiClient().get(ServiceInstances.class,
252 AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, globalCustomerId, serviceType)
253 .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO))
255 msoLogger.debug("No Service Instance matched by name");
260 public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
261 String serviceInstanceName) throws Exception {
262 ServiceInstance aaiServiceInstance = null;
263 ServiceInstances aaiServiceInstances = null;
264 aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName);
266 if (aaiServiceInstances == null) {
267 return Optional.empty();
268 } else if (aaiServiceInstances.getServiceInstance().size() > 1) {
269 throw new Exception("Multiple Service Instances Returned");
271 aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
273 return Optional.of(aaiServiceInstance);
276 public org.onap.so.db.catalog.beans.InstanceGroup getCatalogInstanceGroup(String modelUUID) {
277 return this.catalogDbClient.getInstanceGroupByModelUUID(modelUUID);
280 public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomization(
281 String modelCustomizationUUID) {
282 return this.catalogDbClient
283 .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID);
286 public AAIResultWrapper getAAIResourceDepthOne(AAIResourceUri aaiResourceUri) {
287 AAIResourceUri clonedUri = aaiResourceUri.clone();
288 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.ONE));
291 public AAIResultWrapper getAAIResourceDepthTwo(AAIResourceUri aaiResourceUri) {
292 AAIResourceUri clonedUri = aaiResourceUri.clone();
293 return this.injectionHelper.getAaiClient().get(clonedUri.depth(Depth.TWO));
296 public Configuration getAAIConfiguration(String configurationId) {
297 return this.injectionHelper.getAaiClient().get(Configuration.class,
298 AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE))
300 msoLogger.debug("No Configuration matched by id");
305 public GenericVnf getAAIGenericVnf(String vnfId) {
307 return this.injectionHelper.getAaiClient().get(GenericVnf.class,
308 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE))
310 msoLogger.debug("No Generic Vnf matched by id");
315 public VolumeGroup getAAIVolumeGroup(String cloudOwnerId, String cloudRegionId, String volumeGroupId) {
316 return this.injectionHelper.getAaiClient().get(VolumeGroup.class,
317 AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwnerId, cloudRegionId, volumeGroupId).depth(Depth.ONE))
319 msoLogger.debug("No Generic Vnf matched by id");
324 public VfModule getAAIVfModule(String vnfId, String vfModuleId) {
325 return this.injectionHelper.getAaiClient().get(VfModule.class,
326 AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE))
328 msoLogger.debug("No Generic Vnf matched by id");
333 public L3Network getAAIL3Network(String networkId) {
335 return this.injectionHelper.getAaiClient().get(L3Network.class,
336 AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE))
338 msoLogger.debug("No Generic Vnf matched by id");
344 public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName) throws Exception{
345 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
346 uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
347 Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
348 L3Network network = null;
349 if (!networks.isPresent()) {
350 msoLogger.debug("No Networks matched by name");
351 return Optional.empty();
353 if (networks.get().getL3Network().size() > 1) {
354 throw new Exception("Multiple Networks Returned");
356 network = networks.get().getL3Network().get(0);
358 return Optional.of(network);
362 public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName) throws Exception {
363 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
364 uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
365 Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri);
366 GenericVnf vnf = null;
367 if (!vnfs.isPresent()) {
368 msoLogger.debug("No Vnfs matched by name");
369 return Optional.empty();
371 if (vnfs.get().getGenericVnf().size() > 1) {
372 throw new Exception("Multiple Vnfs Returned");
374 vnf = vnfs.get().getGenericVnf().get(0);
376 return Optional.of(vnf);
380 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName) throws Exception{
381 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
382 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
383 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
384 VolumeGroup volumeGroup = null;
385 if (!volumeGroups.isPresent()) {
386 msoLogger.debug("No VolumeGroups matched by name");
387 return Optional.empty();
389 if (volumeGroups.get().getVolumeGroup().size() > 1) {
390 throw new Exception("Multiple VolumeGroups Returned");
392 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
394 return Optional.of(volumeGroup);
398 public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId, String volumeGroupName) throws Exception {
399 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
400 uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
401 Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
402 VolumeGroup volumeGroup = null;
403 if (!volumeGroups.isPresent()) {
404 msoLogger.debug("No VolumeGroups matched by name");
405 return Optional.empty();
407 if (volumeGroups.get().getVolumeGroup().size() > 1) {
408 throw new Exception("Multiple VolumeGroups Returned");
410 volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
412 return Optional.of(volumeGroup);