1e6541e226a87eae758c1f9b2ba60ffc3ce17261
[so.git] /
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - MSO\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 DoCreateServiceInstanceRollback 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 sdncRollbackRequest = rollbackData.get("SERVICEINSTANCE", "sdncRollbackRequest")\r
110                                         execution.setVariable("sdncRollbackRequest", sdncRollbackRequest)\r
111                                 }\r
112                                 else {\r
113                                         execution.setVariable("skipRollback", true)\r
114                                 }\r
115                         }\r
116                         else {\r
117                                 execution.setVariable("skipRollback", true)\r
118                         }\r
119                         if (execution.getVariable("disableRollback").equals("true" ))\r
120                         {\r
121                                 execution.setVariable("skipRollback", true)\r
122                         }\r
123 \r
124                 } catch (BpmnError e) {\r
125                         throw e;\r
126                 } catch (Exception ex){\r
127                         msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()\r
128                         utils.log("DEBUG", msg, isDebugEnabled)\r
129                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
130                 }\r
131                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
132         }\r
133 \r
134         public void validateSDNCResponse(Execution execution) {\r
135                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
136                 utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)\r
137                 String msg = ""\r
138                 try {\r
139                         WorkflowException workflowException = execution.getVariable("WorkflowException")\r
140 \r
141                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")\r
142                         String response = execution.getVariable("sdncAdapterResponse")\r
143 \r
144                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
145                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)\r
146 \r
147                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){\r
148                                 utils.log("DEBUG", "SDNC Adapter for service-instance delete for rollback successful. response", isDebugEnabled)\r
149                         }else{\r
150                                 execution.setVariable("rolledBack", false)\r
151                                 execution.setVariable("rollbackError", "Error Response from SDNC Adapter for service-instance delete for rollback")\r
152                                 utils.log("DEBUG","Error Response from SDNC Adapter for service-instance delete for rollback", isDebugEnabled)\r
153                                 throw new BpmnError("MSOWorkflowException")\r
154                         }\r
155                 } catch (BpmnError e) {\r
156                         throw e;\r
157                 } catch (Exception ex){\r
158                         msg = "Exception in Create ServiceInstance Rollback validateSDNCResponse " + ex.getMessage()\r
159                         utils.log("DEBUG", msg, isDebugEnabled)\r
160                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
161                 }\r
162                 utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)\r
163         }\r
164 \r
165         public void postProcessRequest(Execution execution) {\r
166                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
167                 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)\r
168                 String msg = ""\r
169                 try {\r
170                         execution.setVariable("rollbackData", null)\r
171                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
172                         boolean rollbackAAI = execution.getVariable("rollbackAAI")\r
173                         boolean rollbackSDNC = execution.getVariable("rollbackSDNC")\r
174                         if (rollbackAAI == true || rollbackSDNC == true)\r
175                         {\r
176                                 execution.setVariable("rolledBack", true)\r
177                         }\r
178                         if (rollbackAAI == true)\r
179                         {\r
180                                 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")\r
181                                 if(succInAAI != true){\r
182                                         execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful\r
183                                         execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")\r
184                                         utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)\r
185                                 }\r
186                         }\r
187                         utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)\r
188 \r
189                 } catch (BpmnError e) {\r
190                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()\r
191                         utils.log("DEBUG", msg, isDebugEnabled)\r
192                 } catch (Exception ex) {\r
193                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()\r
194                         utils.log("DEBUG", msg, isDebugEnabled)\r
195                 }\r
196 \r
197         }\r
198 \r
199         public void processRollbackException(Execution execution){\r
200                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
201                 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)\r
202                 try{\r
203                         utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)\r
204                         execution.setVariable("rollbackData", null)\r
205                         execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")\r
206                         execution.setVariable("WorkflowException", null)\r
207 \r
208                 }catch(BpmnError b){\r
209                         utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)\r
210                 }catch(Exception e){\r
211                         utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)\r
212                 }\r
213 \r
214                 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)\r
215         }\r
216 \r
217         public void processRollbackJavaException(Execution execution){\r
218                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
219                 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)\r
220                 try{\r
221                         execution.setVariable("rollbackData", null)\r
222                         execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")\r
223                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)\r
224 \r
225                 }catch(Exception e){\r
226                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)\r
227                 }\r
228                 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)\r
229         }\r
230 \r
231 }\r