2 * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
\r
4 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
6 import groovy.xml.XmlUtil
\r
10 import java.util.UUID;
\r
12 import org.camunda.bpm.engine.delegate.BpmnError
\r
13 import org.camunda.bpm.engine.runtime.Execution
\r
14 import org.apache.commons.lang3.*
\r
15 import org.apache.commons.codec.binary.Base64;
\r
16 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
17 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
18 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
19 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
20 import org.openecomp.mso.bpmn.core.RollbackData
\r
21 import org.openecomp.mso.bpmn.core.WorkflowException
\r
22 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
23 import org.openecomp.mso.rest.APIResponse
\r
24 import org.springframework.web.util.UriUtils
\r
27 public class DoCreateVfModuleVolumeRollback extends AbstractServiceTaskProcessor {
\r
28 String Prefix="DCVFMODVOLRBK_"
\r
29 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
30 JsonUtils jsonUtil = new JsonUtils()
\r
31 VidUtils vidUtils = new VidUtils(this)
\r
33 def className = getClass().getSimpleName()
\r
36 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
\r
39 public InitializeProcessVariables(Execution execution){
\r
40 /* Initialize all the process variables in this block */
\r
42 execution.setVariable(Prefix + "volumeGroupName", null)
\r
43 execution.setVariable(Prefix + "lcpCloudRegionId", null)
\r
44 execution.setVariable(Prefix + "rollbackVnfARequest", null)
\r
48 // **************************************************
\r
49 // Pre or Prepare Request Section
\r
50 // **************************************************
\r
52 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
\r
55 public void preProcessRequest (Execution execution) {
\r
56 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
58 InitializeProcessVariables(execution)
\r
59 // rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudSiteId)
\r
60 RollbackData rollbackData = execution.getVariable("rollbackData")
\r
62 // String vnfId = rollbackData.get("DCVFMODULEVOL", "vnfid")
\r
63 // execution.setVariable("DCVFMODVOLRBK_vnfId", vnfId)
\r
64 // String vfModuleId = rollbackData.get("DCVFMODULEVOL", "vfmoduleid")
\r
65 // execution.setVariable("DCVFMODVOLRBK_vfModuleId", vfModuleId)
\r
66 // String source = rollbackData.get("DCVFMODULEVOL", "source")
\r
67 // execution.setVariable("DCVFMODVOLRBK_source", source)
\r
68 // String serviceInstanceId = rollbackData.get("DCVFMODULEVOL", "serviceInstanceId")
\r
69 // execution.setVariable("DCVFMODVOLRBK_serviceInstanceId", serviceInstanceId)
\r
70 // String serviceId = rollbackData.get("DCVFMODULEVOL", "service-id")
\r
71 // execution.setVariable("DCVFMODVOLRBK_serviceId", serviceId)
\r
72 // String vnfType = rollbackData.get("DCVFMODULEVOL", "vnftype")
\r
73 // execution.setVariable("DCVFMODVOLRBK_vnfType", vnfType)
\r
74 // String vnfName = rollbackData.get("DCVFMODULEVOL", "vnfname")
\r
75 // execution.setVariable("DCVFMODVOLRBK_vnfName", vnfName)
\r
76 // String tenantId = rollbackData.get("DCVFMODULEVOL", "tenantid")
\r
77 // execution.setVariable("DCVFMODVOLRBK_tenantId", tenantId)
\r
78 // String vfModuleName = rollbackData.get("DCVFMODULEVOL", "vfmodulename")
\r
79 // execution.setVariable("DCVFMODVOLRBK_vfModuleName", vfModuleName)
\r
80 // String vfModuleModelName = rollbackData.get("DCVFMODULEVOL", "vfmodulemodelname")
\r
81 // execution.setVariable("DCVFMODVOLRBK_vfModuleModelName", vfModuleModelName)
\r
82 // String cloudSiteId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
\r
83 // execution.setVariable("DCVFMODVOLRBK_cloudSiteId", cloudSiteId)
\r
84 // String heatStackId = rollbackData.get("DCVFMODULEVOL", "heatstackid")
\r
85 // execution.setVariable("DCVFMODVOLRBK_heatStackId", heatStackId)
\r
86 // String requestId = rollbackData.get("DCVFMODULEVOL", "msorequestid")
\r
87 // execution.setVariable("DCVFMODVOLRBK_requestId", requestId)
\r
89 String volumeGroupName = rollbackData.get("DCVFMODULEVOL", "volumeGroupName")
\r
90 execution.setVariable("DCVFMODVOLRBK_volumeGroupName", volumeGroupName)
\r
92 String lcpCloudRegionId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
\r
93 execution.setVariable("DCVFMODVOLRBK_lcpCloudRegionId", lcpCloudRegionId)
\r
95 execution.setVariable("DCVFMODVOLRBK_rollbackVnfARequest", rollbackData.get("DCVFMODULEVOL", "rollbackVnfARequest"))
\r
96 execution.setVariable("DCVFMODVOLRBK_backoutOnFailure", rollbackData.get("DCVFMODULEVOL", "backoutOnFailure"))
\r
97 execution.setVariable("DCVFMODVOLRBK_isCreateVnfRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isCreateVnfRollbackNeeded"))
\r
98 execution.setVariable("DCVFMODVOLRBK_isAAIRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isAAIRollbackNeeded"))
\r
103 * Query AAI volume group by name
\r
105 * @param isDebugEnabled
\r
107 public void callRESTQueryAAIVolGrpName(Execution execution, isDebugEnabled) {
\r
109 def volumeGroupName = execution.getVariable('DCVFMODVOLRBK_volumeGroupName')
\r
110 def cloudRegion = execution.getVariable('DCVFMODVOLRBK_lcpCloudRegionId')
\r
112 // This is for stub testing
\r
113 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
\r
114 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
\r
115 volumeGroupName = testVolumeGroupName
\r
118 AaiUtil aaiUtil = new AaiUtil(this)
\r
119 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
120 String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')
\r
122 utils.logAudit('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
\r
124 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
\r
126 String returnCode = response.getStatusCode()
\r
127 String aaiResponseAsString = response.getResponseBodyAsString()
\r
128 //aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
130 utils.logAudit("AAI query volume group by name return code: " + returnCode)
\r
131 utils.logAudit("AAI query volume group by name response: " + aaiResponseAsString)
\r
133 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
135 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
\r
136 execution.setVariable(prefix+'AaiReturnCode', returnCode)
\r
138 if (returnCode=='200') {
\r
139 // @TODO: verify error code
\r
140 // @TODO: create class of literals representing error codes
\r
141 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
\r
142 utils.log("DEBUG", "Volume Group Name $volumeGroupName exists in AAI.", isDebugEnabled)
\r
144 if (returnCode=='404') {
\r
145 utils.log("DEBUG", "Volume Group Name $volumeGroupName does not exist in AAI.", isDebugEnabled)
\r
146 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
\r
148 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
149 throw new BpmnError("MSOWorkflowException")
\r
156 public void callRESTDeleteAAIVolumeGroup(Execution execution, isDebugEnabled) {
\r
158 callRESTQueryAAIVolGrpName(execution, isDebugEnabled)
\r
160 def queryAaiVolumeGroupResponse = execution.getVariable(prefix+'queryAAIVolGrpNameResponse')
\r
162 def volumeGroupId = utils.getNodeText(queryAaiVolumeGroupResponse, "volume-group-id")
\r
163 def resourceVersion = utils.getNodeText(queryAaiVolumeGroupResponse, "resource-version")
\r
165 def cloudRegion = execution.getVariable("DCVFMODVOLRBK_lcpCloudRegionId")
\r
167 AaiUtil aaiUtil = new AaiUtil(this)
\r
168 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
169 String deleteAAIVolumeGrpIdRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group" + '/' + volumeGroupId + "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
\r
171 utils.logAudit('Delete AAI volume group : ' + deleteAAIVolumeGrpIdRequest)
\r
173 APIResponse response = aaiUtil.executeAAIDeleteCall(execution, deleteAAIVolumeGrpIdRequest)
\r
175 String returnCode = response.getStatusCode()
\r
176 String aaiResponseAsString = response.getResponseBodyAsString()
\r
177 //aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
179 utils.logAudit("AAI delete volume group return code: " + returnCode)
\r
180 utils.logAudit("AAI delete volume group response: " + aaiResponseAsString)
\r
182 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
184 def volumeGroupNameFound = prefix+'volumeGroupNameFound'
\r
185 if (returnCode=='200' || returnCode=='204' ) {
\r
186 utils.log("DEBUG", "Volume group $volumeGroupId deleted.", isDebugEnabled)
\r
188 if (returnCode=='404') {
\r
189 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupId not found for delete in AAI Response code: 404")
\r
191 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
192 throw new BpmnError("MSOWorkflowException")
\r
197 // *******************************
\r
198 // Build Error Section
\r
199 // *******************************
\r
203 public void processJavaException(Execution execution){
\r
204 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
205 execution.setVariable("prefix",Prefix)
\r
208 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
\r
209 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
210 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
211 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
\r
212 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
214 }catch(Exception e){
\r
215 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
216 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
\r
217 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
\r
219 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)
\r