Remove unnecessary logger error line for not found volume group
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / adapter / vnf / tasks / VnfAdapterCreateTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.adapter.vnf.tasks;
24
25 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
26 import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
33 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
34 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
35 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
36 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
37 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
38 import org.onap.so.client.exception.BBObjectNotFoundException;
39 import org.onap.so.client.exception.ExceptionBuilder;
40 import org.onap.so.client.orchestration.VnfAdapterVfModuleResources;
41 import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.stereotype.Component;
46 import static org.apache.commons.lang3.StringUtils.*;
47
48 @Component
49 public class VnfAdapterCreateTasks {
50     private static final Logger logger = LoggerFactory.getLogger(VnfAdapterCreateTasks.class);
51     public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_";
52     private static final String VNFREST_REQUEST = "VNFREST_Request";
53
54     @Autowired
55     private ExtractPojosForBB extractPojosForBB;
56     @Autowired
57     private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources;
58     @Autowired
59     private VnfAdapterVfModuleResources vnfAdapterVfModuleResources;
60     @Autowired
61     private ExceptionBuilder exceptionUtil;
62
63     /**
64      * This method is used for creating the request for the VolumeGroup.
65      *
66      * @param execution
67      * @return
68      */
69     public void createVolumeGroupRequest(BuildingBlockExecution execution) {
70         try {
71             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
72
73             ServiceInstance serviceInstance =
74                     gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
75
76             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
77             VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
78             VfModule vfModule;
79             String sdncVfModuleQueryResponse = null;
80             try {
81                 vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
82                 if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
83                     sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId());
84                 } else {
85                     throw new Exception("Vf Module " + vfModule.getVfModuleId()
86                             + " exists in gBuildingBlock but does not have a selflink value");
87                 }
88             } catch (BBObjectNotFoundException bbException) {
89                 logger.error("Exception occurred", bbException);
90                 // If there is not a vf module in the general building block (in aLaCarte case),
91                 // we will not retrieve
92                 // the SDNCQueryResponse and proceed as normal without throwing an error
93             }
94
95             CreateVolumeGroupRequest createVolumeGroupRequest = vnfAdapterVolumeGroupResources.createVolumeGroupRequest(
96                     gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance,
97                     genericVnf, volumeGroup, sdncVfModuleQueryResponse);
98             execution.setVariable(VNFREST_REQUEST, createVolumeGroupRequest.toXmlString());
99         } catch (Exception ex) {
100             logger.error("Exception occurred", ex);
101             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
102         }
103     }
104
105
106     /**
107      * This method is used for creating the request for the VfModule.
108      *
109      * @param execution
110      * @return
111      */
112     public void createVfModule(BuildingBlockExecution execution) {
113         try {
114             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
115
116             ServiceInstance serviceInstance =
117                     gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
118             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
119             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
120             VolumeGroup volumeGroup = null;
121             try {
122                 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
123             } catch (BBObjectNotFoundException bbException) {
124                 logger.info("Volume Group not found in GBB. ");
125             }
126             CloudRegion cloudRegion = gBBInput.getCloudRegion();
127             RequestContext requestContext = gBBInput.getRequestContext();
128             OrchestrationContext orchestrationContext = gBBInput.getOrchContext();
129             String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId());
130             String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId());
131
132             CreateVfModuleRequest createVfModuleRequest = vnfAdapterVfModuleResources.createVfModuleRequest(
133                     requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule,
134                     volumeGroup, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
135             execution.setVariable(VNFREST_REQUEST, createVfModuleRequest.toXmlString());
136         } catch (Exception ex) {
137             logger.error("Exception occurred", ex);
138             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
139         }
140     }
141
142 }