Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCQueryTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
22
23 import org.onap.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
26 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
27 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
28 import org.onap.so.client.exception.BBObjectNotFoundException;
29 import org.onap.so.client.exception.BadResponseException;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.onap.so.client.orchestration.SDNCVnfResources;
32 import org.onap.so.client.orchestration.SDNCVfModuleResources;
33 import org.onap.so.logger.MsoLogger;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
36
37 @Component
38 public class SDNCQueryTasks {
39         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCQueryTasks.class);        
40         @Autowired
41         private SDNCVnfResources sdncVnfResources;
42         @Autowired
43         private SDNCVfModuleResources sdncVfModuleResources;
44         @Autowired
45         private ExceptionBuilder exceptionUtil;
46         @Autowired
47         private ExtractPojosForBB extractPojosForBB;
48         
49         public void queryVnf(BuildingBlockExecution execution) throws Exception {               
50                 GenericVnf genericVnf =  extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
51                                 
52                 try {
53                         String response = sdncVnfResources.queryVnf(genericVnf);                
54                         execution.setVariable("SDNCQueryResponse_" + genericVnf.getVnfId(), response);                  
55                 } catch (Exception ex) {                        
56                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
57                 }
58         }
59
60         
61         public void queryVfModule(BuildingBlockExecution execution) throws Exception {          
62                 VfModule vfModule =  extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));               
63                 
64                 try {
65                         if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {       
66                                 String response = sdncVfModuleResources.queryVfModule(vfModule);                
67                         execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);                       
68                         }
69                         else {
70                                 throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
71                         }
72                 } catch (Exception ex) {                        
73                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
74                 }
75         }
76         
77         public void queryVfModuleForVolumeGroup(BuildingBlockExecution execution) {
78                 try {
79                         VfModule vfModule =  extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
80                         if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
81                                 String response = sdncVfModuleResources.queryVfModule(vfModule);
82                                 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response);
83                         }
84                         else {
85                                 throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
86                         }
87                 } catch(BBObjectNotFoundException bbException) {
88                         // If there is not a vf module in the general building block, we will not call SDNC and proceed as normal without throwing an error
89                         // If we see a bb object not found exception for something that is not a vf module id, then we should throw the error as normal
90                         if(!ResourceKey.VF_MODULE_ID.equals(bbException.getResourceKey())) {
91                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException);
92                         }
93                 } catch(Exception ex) {
94                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
95                 }
96         }
97 }