VoLTE groovy draft files
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateE2EServiceInstanceRollback.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts\r
21 \r
22 \r
23 import static org.apache.commons.lang3.StringUtils.*;\r
24 import groovy.xml.XmlUtil\r
25 import groovy.json.*\r
26 \r
27 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
28 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils\r
30 import org.openecomp.mso.bpmn.core.RollbackData\r
31 import org.openecomp.mso.bpmn.core.WorkflowException\r
32 import org.openecomp.mso.rest.APIResponse;\r
33 import org.openecomp.mso.rest.RESTClient\r
34 import org.openecomp.mso.rest.RESTConfig\r
35 \r
36 import java.util.UUID;\r
37 \r
38 import org.camunda.bpm.engine.delegate.BpmnError\r
39 import org.camunda.bpm.engine.runtime.Execution\r
40 import org.json.JSONObject;\r
41 import org.apache.commons.lang3.*\r
42 import org.apache.commons.codec.binary.Base64;\r
43 import org.springframework.web.util.UriUtils;\r
44 /**\r
45  * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.\r
46  *\r
47  * Inputs:\r
48  * @param - msoRequestId\r
49  * @param - rollbackData with\r
50  *          globalCustomerId\r
51  *                      subscriptionServiceType\r
52  *                      serviceInstanceId\r
53  *                      disableRollback\r
54  *                      rollbackAAI\r
55  *                      rollbackSDNC\r
56  *                      sdncRollbackRequest\r
57  * \r
58  *\r
59  * Outputs:\r
60  * @param - rollbackError\r
61  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)\r
62  *\r
63  */\r
64 public class DoCreateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{\r
65 \r
66         String Prefix="DCRESIRB_"\r
67 \r
68         public void preProcessRequest(Execution execution) {\r
69                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
70                 execution.setVariable("prefix",Prefix)\r
71                 String msg = ""\r
72                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)\r
73                 execution.setVariable("rollbackAAI",false)\r
74                 execution.setVariable("rollbackSDNC",false)\r
75 \r
76                 try {\r
77                         def rollbackData = execution.getVariable("rollbackData")\r
78                         utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)\r
79 \r
80                         if (rollbackData != null) {\r
81                                 if (rollbackData.hasType("SERVICEINSTANCE")) {\r
82 \r
83                                         def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")\r
84                                         execution.setVariable("serviceInstanceId", serviceInstanceId)\r
85 \r
86                                         def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")\r
87                                         execution.setVariable("subscriptionServiceType", subscriptionServiceType)\r
88 \r
89                                         def globalSubscriberId  = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")\r
90                                         execution.setVariable("globalSubscriberId", globalSubscriberId)\r
91 \r
92                                         def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")\r
93                                         if ("true".equals(rollbackAAI))\r
94                                         {\r
95                                                 execution.setVariable("rollbackAAI",true)\r
96                                         }\r
97 \r
98                                         def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")\r
99                                         if ("true".equals(rollbackSDNC))\r
100                                         {\r
101                                                 execution.setVariable("rollbackSDNC", true)\r
102                                         }\r
103 \r
104                                         if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)\r
105                                         {\r
106                                                 execution.setVariable("skipRollback", true)\r
107                                         }\r
108 \r
109                                         def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")\r
110                                         execution.setVariable("sdncDelete", sdncDelete)\r
111                                         def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")\r
112                                         execution.setVariable("sdncDeactivate", sdncDeactivate)\r
113                                         utils.log("DEBUG","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)\r
114                                         utils.log("DEBUG","sdncDelete:\n" + sdncDelete, isDebugEnabled)\r
115                                 }\r
116                                 else {\r
117                                         execution.setVariable("skipRollback", true)\r
118                                 }\r
119                         }\r
120                         else {\r
121                                 execution.setVariable("skipRollback", true)\r
122                         }\r
123                         if (execution.getVariable("disableRollback").equals("true" ))\r
124                         {\r
125                                 execution.setVariable("skipRollback", true)\r
126                         }\r
127 \r
128                 } catch (BpmnError e) {\r
129                         throw e;\r
130                 } catch (Exception ex){\r
131                         msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()\r
132                         utils.log("DEBUG", msg, isDebugEnabled)\r
133                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
134                 }\r
135                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
136         }\r
137 \r
138         public void validateSDNCResponse(Execution execution, String response, String method) {\r
139                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
140                 utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)\r
141                 String msg = ""\r
142                 try {\r
143                         WorkflowException workflowException = execution.getVariable("WorkflowException")\r
144                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")\r
145                         utils.log("DEBUG", "SDNCResponse: " + response, isDebugEnabled)\r
146                         utils.log("DEBUG", "workflowException: " + workflowException, isDebugEnabled)\r
147                         \r
148                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
149                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)\r
150 \r
151                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){\r
152                                 msg = "SDNC Adapter service-instance rollback successful for " + method\r
153                                 utils.log("DEBUG", msg, isDebugEnabled)\r
154                         }else{\r
155                                 execution.setVariable("rolledBack", false)\r
156                                 msg =  "Error Response from SDNC Adapter service-instance rollback for " + method\r
157                                 execution.setVariable("rollbackError", msg)\r
158                                 utils.log("DEBUG", msg, isDebugEnabled)\r
159                                 throw new BpmnError("MSOWorkflowException")\r
160                         }\r
161                 } catch (BpmnError e) {\r
162                         throw e;\r
163                 } catch (Exception ex){\r
164                         msg = "Exception in Create ServiceInstance rollback for "  + method  + " Exception:" + ex.getMessage()\r
165                         utils.log("DEBUG", msg, isDebugEnabled)\r
166                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
167                 }\r
168                 utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)\r
169         }\r
170 \r
171         public void postProcessRequest(Execution execution) {\r
172                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
173                 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)\r
174                 String msg = ""\r
175                 try {\r
176                         execution.setVariable("rollbackData", null)\r
177                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
178                         boolean rollbackAAI = execution.getVariable("rollbackAAI")\r
179                         boolean rollbackSDNC = execution.getVariable("rollbackSDNC")\r
180                         if (rollbackAAI == true || rollbackSDNC == true)\r
181                         {\r
182                                 execution.setVariable("rolledBack", true)\r
183                         }\r
184                         if (rollbackAAI == true)\r
185                         {\r
186                                 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")\r
187                                 if(succInAAI != true){\r
188                                         execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful\r
189                                         execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")\r
190                                         utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)\r
191                                 }\r
192                         }\r
193                         utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)\r
194 \r
195                 } catch (BpmnError e) {\r
196                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()\r
197                         utils.log("DEBUG", msg, isDebugEnabled)\r
198                 } catch (Exception ex) {\r
199                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()\r
200                         utils.log("DEBUG", msg, isDebugEnabled)\r
201                 }\r
202 \r
203         }\r
204 \r
205         public void processRollbackException(Execution execution){\r
206                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
207                 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)\r
208                 try{\r
209                         utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)\r
210                         execution.setVariable("rollbackData", null)\r
211                         execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")\r
212                         execution.setVariable("WorkflowException", null)\r
213 \r
214                 }catch(BpmnError b){\r
215                         utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)\r
216                 }catch(Exception e){\r
217                         utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)\r
218                 }\r
219 \r
220                 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)\r
221         }\r
222 \r
223         public void processRollbackJavaException(Execution execution){\r
224                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
225                 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)\r
226                 try{\r
227                         execution.setVariable("rollbackData", null)\r
228                         execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")\r
229                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)\r
230 \r
231                 }catch(Exception e){\r
232                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)\r
233                 }\r
234                 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)\r
235         }\r
236 \r
237 }\r