2 * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
4 package org.openecomp.mso.bpmn.vcpe.scripts;
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
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.*
23 * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process.
28 * @param - msoRequestId
29 * @param - isDebugLogEnabled
30 * @param - disableRollback - O
31 * @param - rollbackData
34 * @param - rollbackError
35 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
38 public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{
40 String Prefix="DCARBRGRB_"
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
43 public void preProcessRequest (Execution execution) {
45 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
47 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
48 execution.setVariable("prefix", Prefix)
49 String rbType = "DCARBRG_"
52 def rollbackData = execution.getVariable("rollbackData")
53 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
55 if (rollbackData != null) {
56 if (rollbackData.hasType(rbType)) {
58 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
59 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
60 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
63 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
64 if ("true".equals(rollbackAAI))
66 execution.setVariable("rollbackAAI",true)
67 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
70 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
71 if ("true".equals(rollbackSDNC))
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"))
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)
82 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
83 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
84 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
87 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
89 execution.setVariable("skipRollback", true)
93 execution.setVariable("skipRollback", true)
97 execution.setVariable("skipRollback", true)
99 if (execution.getVariable("disableRollback").equals("true" ))
101 execution.setVariable("skipRollback", true)
105 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
107 } catch (Exception ex){
108 msg = "Exception in preProcessRequest " + ex.getMessage()
109 utils.log("DEBUG", msg, isDebugEnabled)
110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
112 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
115 // aaiARPath set during query (existing AR)
116 public void updateAaiAROrchStatus(Execution execution, String status){
117 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
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))
126 ar = arUtils.getARbyLink(execution, aaiARPath, "")
130 msg = "AR not found in AAI at:" + aaiARPath
131 utils.log("DEBUG", msg, isDebugEnabled)
132 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
134 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
135 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
138 public void validateSDNCResp(Execution execution, String response, String method){
140 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
141 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
145 WorkflowException workflowException = execution.getVariable("WorkflowException")
146 utils.logAudit("workflowException: " + workflowException)
148 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
149 utils.logAudit("SDNCResponse: " + response)
151 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
152 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
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)
159 utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
160 throw new BpmnError("MSOWorkflowException")
162 } catch (BpmnError e) {
163 if (e.getErrorCode() == 404)
165 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
166 utils.log("DEBUG", msg, isDebugEnabled)
171 } catch(Exception ex) {
172 msg = "Exception in validateSDNCResp. " + ex.getMessage()
173 utils.log("DEBUG", msg, isDebugEnabled)
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
176 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
179 public void deleteAaiAR(Execution execution){
180 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
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))
188 ar = arUtils.getARbyLink(execution, arLink, "")
190 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
191 } catch (BpmnError 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())
197 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)
200 public void postProcessRequest(Execution execution) {
201 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
202 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
205 execution.setVariable("rollbackData", null)
206 boolean skipRollback = execution.getVariable("skipRollback")
207 if (skipRollback != true)
209 execution.setVariable("rolledBack", true)
210 utils.log("DEBUG","rolledBack", isDebugEnabled)
212 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
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)
224 public void processRollbackException(Execution execution){
225 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
226 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
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)
235 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
237 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
240 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
243 public void processRollbackJavaException(Execution execution){
244 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
245 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
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)
253 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
255 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)