0e0f5c203564f29d3bc8901ea51ed3b08f493d27
[so.git] /
1 /*
2  * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
3  */
4 package org.openecomp.mso.bpmn.vcpe.scripts;
5
6 import org.openecomp.mso.bpmn.common.scripts.*;
7 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
8 import org.openecomp.mso.bpmn.core.WorkflowException
9 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
10 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
11 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
12 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
13 import org.openecomp.mso.rest.APIResponse
14
15 import java.util.UUID;
16 import org.camunda.bpm.engine.delegate.BpmnError
17 import org.camunda.bpm.engine.runtime.Execution
18 import org.apache.commons.lang3.*
19 import org.springframework.web.util.UriUtils;
20 import static org.apache.commons.lang3.StringUtils.*
21
22 /**
23  * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process.
24  *
25  * @author
26  * 
27  * Inputs:
28  * @param - msoRequestId
29  * @param - isDebugLogEnabled
30  * @param - disableRollback - O 
31  * @param - rollbackData
32  *
33  * Outputs:
34  * @param - rollbackError 
35  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
36  *
37  */
38 public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{
39
40         String Prefix="DCARBRGRB_"
41         ExceptionUtil exceptionUtil = new ExceptionUtil()
42
43         public void preProcessRequest (Execution execution) {
44                 
45                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
46                 String msg = ""
47                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
48                 execution.setVariable("prefix", Prefix)
49                 String rbType = "DCARBRG_"
50                 try {
51                         
52                         def rollbackData = execution.getVariable("rollbackData")
53                         utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
54
55                         if (rollbackData != null) {
56                                 if (rollbackData.hasType(rbType)) {
57                                         
58                                         execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
59                                         execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
60                                         execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
61                                         
62                                         
63                                         def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
64                                         if ("true".equals(rollbackAAI))
65                                         {
66                                                 execution.setVariable("rollbackAAI",true)
67                                                 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
68                                                 
69                                         }
70                                         def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
71                                         if ("true".equals(rollbackSDNC))
72                                         {
73                                                 execution.setVariable("rollbackSDNC", true)
74                                                 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
75                                                 execution.setVariable("deleteSdnc",  rollbackData.get(rbType, "rollbackSDNCcreate"))
76                                                 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
77                                                 
78                                                 utils.log("DEBUG","sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") , isDebugEnabled)
79                                                 utils.log("DEBUG","sdncDelete:\n" + execution.getVariable("deleteSdnc"), isDebugEnabled)
80                                                 utils.log("DEBUG","sdncUnassign:\n" + execution.getVariable("unassignSdnc"), isDebugEnabled)
81                                                 
82                                                 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
83                                                 execution.setVariable("sdncDeleteRequest",  rollbackData.get(rbType, "sdncCreateRollbackReq"))
84                                                 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
85                                         }
86
87                                         if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
88                                         {
89                                                 execution.setVariable("skipRollback", true)
90                                         }
91                                 }
92                                 else {
93                                         execution.setVariable("skipRollback", true)
94                                 }
95                         }
96                         else {
97                                 execution.setVariable("skipRollback", true)
98                         }
99                         if (execution.getVariable("disableRollback").equals("true" ))
100                         {
101                                 execution.setVariable("skipRollback", true)
102                         }
103                         
104                 }catch(BpmnError b){
105                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
106                         throw b
107                 } catch (Exception ex){
108                         msg = "Exception in preProcessRequest " + ex.getMessage()
109                         utils.log("DEBUG", msg, isDebugEnabled)
110                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
111                 }
112                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
113         }
114
115         // aaiARPath set during query (existing AR)
116         public void updateAaiAROrchStatus(Execution execution, String status){
117                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
118                 String msg = null;
119                 utils.log("DEBUG", " *** updateAaiAROrchStatus ***", isDebugEnabled)
120                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
121                 String aaiARPath  = execution.getVariable("aaiARPath")
122                 utils.log("DEBUG", " aaiARPath:" + aaiARPath, isDebugEnabled)
123                 String ar = null; //need this for getting resourceVersion for delete
124                 if (!isBlank(aaiARPath))
125                 {
126                         ar = arUtils.getARbyLink(execution, aaiARPath, "")
127                 }
128                 if (isBlank(ar))
129                 {
130                         msg = "AR not found in AAI at:" + aaiARPath
131                         utils.log("DEBUG", msg, isDebugEnabled)
132                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
133                 }
134                 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
135                 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
136         }
137
138         public void validateSDNCResp(Execution execution, String response, String method){
139
140                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
141                 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
142                 String msg = ""
143
144                 try {
145                         WorkflowException workflowException = execution.getVariable("WorkflowException")
146                         utils.logAudit("workflowException: " + workflowException)
147
148                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
149                         utils.logAudit("SDNCResponse: " + response)
150
151                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
152                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
153
154                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
155                                 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + response, isDebugLogEnabled)
156
157                         }else{
158
159                                 utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
160                                 throw new BpmnError("MSOWorkflowException")
161                         }
162                 } catch (BpmnError e) {
163                         if (e.getErrorCode() == 404)
164                         {
165                                 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
166                                 utils.log("DEBUG", msg, isDebugEnabled)
167                         }
168                         else {
169                                 throw e;
170                         }
171                 } catch(Exception ex) {
172                         msg = "Exception in validateSDNCResp. " + ex.getMessage()
173                         utils.log("DEBUG", msg, isDebugEnabled)
174                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
175                 }
176                 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
177         }
178
179         public void deleteAaiAR(Execution execution){
180                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
181                 try{
182                         utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled)
183                         AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
184                         String ar = null //need to get resource-version 
185                         String arLink = execution.getVariable("aaiARPath")
186                         if (!isBlank(arLink))
187                         {
188                                 ar = arUtils.getARbyLink(execution, arLink, "")
189                         }
190                         arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
191                 } catch (BpmnError e) {
192                         throw e;
193                 }catch(Exception ex){
194                         utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled)
195                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
196                 }
197                 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)
198         }
199         
200         public void postProcessRequest(Execution execution) {
201                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
202                 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
203                 String msg = ""
204                 try {
205                         execution.setVariable("rollbackData", null)
206                         boolean skipRollback = execution.getVariable("skipRollback")
207                         if (skipRollback != true)
208                         {
209                                 execution.setVariable("rolledBack", true)
210                                 utils.log("DEBUG","rolledBack", isDebugEnabled)
211                         }
212                         utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
213
214                 } catch (BpmnError e) {
215                         msg = "Bpmn Exception in  postProcessRequest. "
216                         utils.log("DEBUG", msg, isDebugEnabled)
217                 } catch (Exception ex) {
218                         msg = "Exception in postProcessRequest. " + ex.getMessage()
219                         utils.log("DEBUG", msg, isDebugEnabled)
220                 }
221
222         }
223         
224         public void processRollbackException(Execution execution){
225                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
226                 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
227                 try{
228                         utils.log("DEBUG", "Caught an Exception in DoCreateAllottedResourceRollback", isDebugEnabled)
229                         execution.setVariable("rollbackData", null)
230                         execution.setVariable("rolledBack", false)
231                         execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
232                         execution.setVariable("WorkflowException", null)
233
234                 }catch(BpmnError b){
235                         utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
236                 }catch(Exception e){
237                         utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
238                 }
239
240                 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
241         }
242
243         public void processRollbackJavaException(Execution execution){
244                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
245                 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
246                 try{
247                         execution.setVariable("rollbackData", null)
248                         execution.setVariable("rolledBack", false)
249                         execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
250                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
251
252                 }catch(Exception e){
253                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
254                 }
255                 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)
256         }
257
258 }