2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.mso.bpmn.vcpe.scripts;
22 import org.openecomp.mso.bpmn.common.scripts.*;
23 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
24 import org.openecomp.mso.bpmn.core.WorkflowException
25 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
26 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
27 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
28 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
29 import org.openecomp.mso.rest.APIResponse
31 import java.util.UUID;
32 import org.camunda.bpm.engine.delegate.BpmnError
33 import org.camunda.bpm.engine.runtime.Execution
34 import org.apache.commons.lang3.*
35 import org.springframework.web.util.UriUtils;
36 import static org.apache.commons.lang3.StringUtils.*
39 * This groovy class supports the <class>CreateAllottedResourceTXCRollback.bpmn</class> process.
44 * @param - msoRequestId
45 * @param - isDebugLogEnabled
46 * @param - disableRollback - O
47 * @param - rollbackData
50 * @param - rollbackError
51 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
54 public class DoCreateAllottedResourceTXCRollback extends AbstractServiceTaskProcessor{
56 private static final String DebugFlag = "isDebugLogEnabled"
58 String Prefix="DCARTXCRB_"
59 ExceptionUtil exceptionUtil = new ExceptionUtil()
61 public void preProcessRequest (Execution execution) {
63 def isDebugEnabled = execution.getVariable(DebugFlag)
65 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
66 execution.setVariable("prefix", Prefix)
67 String rbType = "DCARTXC_"
70 def rollbackData = execution.getVariable("rollbackData")
71 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
73 if (rollbackData != null) {
74 if (rollbackData.hasType(rbType)) {
76 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
77 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
78 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
81 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
82 if ("true".equals(rollbackAAI))
84 execution.setVariable("rollbackAAI",true)
85 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
88 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
89 if ("true".equals(rollbackSDNC))
91 execution.setVariable("rollbackSDNC", true)
92 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
93 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
94 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
96 utils.log("DEBUG","sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") , isDebugEnabled)
97 utils.log("DEBUG","sdncDelete:\n" + execution.getVariable("deleteSdnc"), isDebugEnabled)
98 utils.log("DEBUG","sdncUnassign:\n" + execution.getVariable("unassignSdnc"), isDebugEnabled)
100 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
101 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
102 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
105 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
107 execution.setVariable("skipRollback", true)
111 execution.setVariable("skipRollback", true)
115 execution.setVariable("skipRollback", true)
117 if (execution.getVariable("disableRollback").equals("true" ))
119 execution.setVariable("skipRollback", true)
123 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
125 } catch (Exception ex){
126 msg = "Exception in preProcessRequest " + ex.getMessage()
127 utils.log("DEBUG", msg, isDebugEnabled)
128 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
130 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
133 // aaiARPath set during query (existing AR)
134 public void updateAaiAROrchStatus(Execution execution, String status){
135 def isDebugEnabled = execution.getVariable(DebugFlag)
137 utils.log("DEBUG", " *** updateAaiAROrchStatus ***", isDebugEnabled)
138 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
139 String aaiARPath = execution.getVariable("aaiARPath")
140 utils.log("DEBUG", " aaiARPath:" + aaiARPath, isDebugEnabled)
141 String ar = null; //need this for getting resourceVersion for delete
142 if (!isBlank(aaiARPath))
144 ar = arUtils.getARbyLink(execution, aaiARPath, "")
148 msg = "AR not found in AAI at:" + aaiARPath
149 utils.log("DEBUG", msg, isDebugEnabled)
150 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
152 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
153 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
156 public void validateSDNCResp(Execution execution, String response, String method){
158 def isDebugLogEnabled=execution.getVariable(DebugFlag)
159 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
163 WorkflowException workflowException = execution.getVariable("WorkflowException")
164 utils.logAudit("workflowException: " + workflowException)
166 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
167 utils.logAudit("SDNCResponse: " + response)
169 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
170 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
172 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
173 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled)
177 utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
178 throw new BpmnError("MSOWorkflowException")
180 } catch (BpmnError e) {
181 if ("404".contentEquals(e.getErrorCode()))
183 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
184 utils.log("DEBUG", msg, isDebugLogEnabled)
189 } catch(Exception ex) {
190 msg = "Exception in validateSDNCResp. " + ex.getMessage()
191 utils.log("DEBUG", msg, isDebugLogEnabled)
192 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
194 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
197 public void deleteAaiAR(Execution execution){
198 def isDebugLogEnabled = execution.getVariable(DebugFlag)
200 utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled)
201 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
202 String ar = null //need to get resource-version
203 String arLink = execution.getVariable("aaiARPath")
204 if (!isBlank(arLink))
206 ar = arUtils.getARbyLink(execution, arLink, "")
208 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
209 } catch (BpmnError e) {
211 }catch(Exception ex){
212 utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled)
213 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
215 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)
218 public void postProcessRequest(Execution execution) {
219 def isDebugEnabled=execution.getVariable(DebugFlag)
220 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
223 execution.setVariable("rollbackData", null)
224 boolean skipRollback = execution.getVariable("skipRollback")
225 if (skipRollback != true)
227 execution.setVariable("rolledBack", true)
228 utils.log("DEBUG","rolledBack", isDebugEnabled)
230 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
232 } catch (BpmnError e) {
233 msg = "Bpmn Exception in postProcessRequest. "
234 utils.log("DEBUG", msg, isDebugEnabled)
235 } catch (Exception ex) {
236 msg = "Exception in postProcessRequest. " + ex.getMessage()
237 utils.log("DEBUG", msg, isDebugEnabled)
242 public void processRollbackException(Execution execution){
243 def isDebugEnabled=execution.getVariable(DebugFlag)
244 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
246 utils.log("DEBUG", "Caught an Exception in DoCreateAllottedResourceRollback", isDebugEnabled)
247 execution.setVariable("rollbackData", null)
248 execution.setVariable("rolledBack", false)
249 execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
250 execution.setVariable("WorkflowException", null)
253 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
255 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
258 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
261 public void processRollbackJavaException(Execution execution){
262 def isDebugEnabled=execution.getVariable(DebugFlag)
263 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
265 execution.setVariable("rollbackData", null)
266 execution.setVariable("rolledBack", false)
267 execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
268 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
271 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
273 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)