bc34987cecce669e450ea5c95b3161d0c1148f03
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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 package org.openecomp.mso.bpmn.infrastructure.scripts
21
22
23 import static org.apache.commons.lang3.StringUtils.*;
24 import groovy.xml.XmlUtil
25 import groovy.json.*
26
27 import org.openecomp.mso.bpmn.core.json.JsonUtils
28 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.core.RollbackData
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse;
33 import org.openecomp.mso.rest.RESTClient
34 import org.openecomp.mso.rest.RESTConfig
35
36 import java.util.UUID;
37
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.runtime.Execution
40 import org.json.JSONObject;
41 import org.apache.commons.lang3.*
42 import org.apache.commons.codec.binary.Base64;
43 import org.springframework.web.util.UriUtils;
44 /**
45  * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
46  *
47  * Inputs:
48  * @param - msoRequestId
49  * @param - rollbackData with
50  *          globalCustomerId
51  *                      subscriptionServiceType
52  *                      serviceInstanceId
53  *                      disableRollback
54  *                      rollbackAAI
55  *                      rollbackSDNC
56  *                      sdncRollbackRequest
57  * 
58  *
59  * Outputs:
60  * @param - rollbackError
61  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
62  *
63  */
64 public class DoCreateServiceInstanceRollback extends AbstractServiceTaskProcessor{
65
66         String Prefix="DCRESIRB_"
67
68         public void preProcessRequest(Execution execution) {
69                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
70                 execution.setVariable("prefix",Prefix)
71                 String msg = ""
72                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
73                 execution.setVariable("rollbackAAI",false)
74                 execution.setVariable("rollbackSDNC",false)
75
76                 try {
77                         def rollbackData = execution.getVariable("rollbackData")
78                         utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
79
80                         if (rollbackData != null) {
81                                 if (rollbackData.hasType("SERVICEINSTANCE")) {
82
83                                         def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
84                                         execution.setVariable("serviceInstanceId", serviceInstanceId)
85
86                                         def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
87                                         execution.setVariable("subscriptionServiceType", subscriptionServiceType)
88
89                                         def globalSubscriberId  = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
90                                         execution.setVariable("globalSubscriberId", globalSubscriberId)
91
92                                         def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
93                                         if ("true".equals(rollbackAAI))
94                                         {
95                                                 execution.setVariable("rollbackAAI",true)
96                                         }
97
98                                         def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
99                                         if ("true".equals(rollbackSDNC))
100                                         {
101                                                 execution.setVariable("rollbackSDNC", true)
102                                         }
103
104                                         if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
105                                         {
106                                                 execution.setVariable("skipRollback", true)
107                                         }
108
109                                         def sdncRollbackRequest = rollbackData.get("SERVICEINSTANCE", "sdncRollbackRequest")
110                                         execution.setVariable("sdncRollbackRequest", sdncRollbackRequest)
111                                 }
112                                 else {
113                                         execution.setVariable("skipRollback", true)
114                                 }
115                         }
116                         else {
117                                 execution.setVariable("skipRollback", true)
118                         }
119                         if (execution.getVariable("disableRollback").equals("true" ))
120                         {
121                                 execution.setVariable("skipRollback", true)
122                         }
123
124                 } catch (BpmnError e) {
125                         throw e;
126                 } catch (Exception ex){
127                         msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
128                         utils.log("DEBUG", msg, isDebugEnabled)
129                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
130                 }
131                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
132         }
133
134         public void validateSDNCResponse(Execution execution) {
135                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
136                 utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)
137                 String msg = ""
138                 try {
139                         WorkflowException workflowException = execution.getVariable("WorkflowException")
140
141                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
142                         String response = execution.getVariable("sdncAdapterResponse")
143
144                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
145                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
146
147                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
148                                 utils.log("DEBUG", "SDNC Adapter for service-instance delete for rollback successful. response", isDebugEnabled)
149                         }else{
150                                 execution.setVariable("rolledBack", false)
151                                 execution.setVariable("rollbackError", "Error Response from SDNC Adapter for service-instance delete for rollback")
152                                 utils.log("DEBUG","Error Response from SDNC Adapter for service-instance delete for rollback", isDebugEnabled)
153                                 throw new BpmnError("MSOWorkflowException")
154                         }
155                 } catch (BpmnError e) {
156                         throw e;
157                 } catch (Exception ex){
158                         msg = "Exception in Create ServiceInstance Rollback validateSDNCResponse " + ex.getMessage()
159                         utils.log("DEBUG", msg, isDebugEnabled)
160                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
161                 }
162                 utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)
163         }
164
165         public void postProcessRequest(Execution execution) {
166                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
167                 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
168                 String msg = ""
169                 try {
170                         execution.setVariable("rollbackData", null)
171                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
172                         boolean rollbackAAI = execution.getVariable("rollbackAAI")
173                         boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
174                         if (rollbackAAI == true || rollbackSDNC == true)
175                         {
176                                 execution.setVariable("rolledBack", true)
177                         }
178                         if (rollbackAAI == true)
179                         {
180                                 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
181                                 if(succInAAI != true){
182                                         execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
183                                         execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
184                                         utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
185                                 }
186                         }
187                         utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
188
189                 } catch (BpmnError e) {
190                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
191                         utils.log("DEBUG", msg, isDebugEnabled)
192                 } catch (Exception ex) {
193                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
194                         utils.log("DEBUG", msg, isDebugEnabled)
195                 }
196
197         }
198
199         public void processRollbackException(Execution execution){
200                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
201                 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
202                 try{
203                         utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)
204                         execution.setVariable("rollbackData", null)
205                         execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
206                         execution.setVariable("WorkflowException", null)
207
208                 }catch(BpmnError b){
209                         utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
210                 }catch(Exception e){
211                         utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
212                 }
213
214                 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
215         }
216
217         public void processRollbackJavaException(Execution execution){
218                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
219                 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
220                 try{
221                         execution.setVariable("rollbackData", null)
222                         execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
223                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
224
225                 }catch(Exception e){
226                         utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
227                 }
228                 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)
229         }
230
231 }