2 * ============LICENSE_START=======================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
22 import groovy.xml.XmlUtil
\r
23 import groovy.json.*
\r
26 import java.util.UUID;
\r
28 import org.camunda.bpm.engine.delegate.BpmnError
\r
29 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
30 import org.apache.commons.lang3.*
\r
31 import org.apache.commons.codec.binary.Base64;
\r
32 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
33 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
34 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
35 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
36 import org.openecomp.mso.bpmn.core.RollbackData
\r
37 import org.openecomp.mso.bpmn.core.WorkflowException
\r
38 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
39 import org.openecomp.mso.rest.APIResponse
\r
40 import org.springframework.web.util.UriUtils
\r
43 public class DoCreateVfModuleVolumeRollback extends AbstractServiceTaskProcessor {
\r
44 String Prefix="DCVFMODVOLRBK_"
\r
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
46 JsonUtils jsonUtil = new JsonUtils()
\r
47 VidUtils vidUtils = new VidUtils(this)
\r
49 def className = getClass().getSimpleName()
\r
52 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
\r
55 public InitializeProcessVariables(DelegateExecution execution){
\r
56 /* Initialize all the process variables in this block */
\r
58 execution.setVariable(Prefix + "volumeGroupName", null)
\r
59 execution.setVariable(Prefix + "lcpCloudRegionId", null)
\r
60 execution.setVariable(Prefix + "rollbackVnfARequest", null)
\r
64 // **************************************************
\r
65 // Pre or Prepare Request Section
\r
66 // **************************************************
\r
68 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
\r
71 public void preProcessRequest (DelegateExecution execution) {
\r
72 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
74 InitializeProcessVariables(execution)
\r
75 // rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudSiteId)
\r
76 RollbackData rollbackData = execution.getVariable("rollbackData")
\r
78 // String vnfId = rollbackData.get("DCVFMODULEVOL", "vnfid")
\r
79 // execution.setVariable("DCVFMODVOLRBK_vnfId", vnfId)
\r
80 // String vfModuleId = rollbackData.get("DCVFMODULEVOL", "vfmoduleid")
\r
81 // execution.setVariable("DCVFMODVOLRBK_vfModuleId", vfModuleId)
\r
82 // String source = rollbackData.get("DCVFMODULEVOL", "source")
\r
83 // execution.setVariable("DCVFMODVOLRBK_source", source)
\r
84 // String serviceInstanceId = rollbackData.get("DCVFMODULEVOL", "serviceInstanceId")
\r
85 // execution.setVariable("DCVFMODVOLRBK_serviceInstanceId", serviceInstanceId)
\r
86 // String serviceId = rollbackData.get("DCVFMODULEVOL", "service-id")
\r
87 // execution.setVariable("DCVFMODVOLRBK_serviceId", serviceId)
\r
88 // String vnfType = rollbackData.get("DCVFMODULEVOL", "vnftype")
\r
89 // execution.setVariable("DCVFMODVOLRBK_vnfType", vnfType)
\r
90 // String vnfName = rollbackData.get("DCVFMODULEVOL", "vnfname")
\r
91 // execution.setVariable("DCVFMODVOLRBK_vnfName", vnfName)
\r
92 // String tenantId = rollbackData.get("DCVFMODULEVOL", "tenantid")
\r
93 // execution.setVariable("DCVFMODVOLRBK_tenantId", tenantId)
\r
94 // String vfModuleName = rollbackData.get("DCVFMODULEVOL", "vfmodulename")
\r
95 // execution.setVariable("DCVFMODVOLRBK_vfModuleName", vfModuleName)
\r
96 // String vfModuleModelName = rollbackData.get("DCVFMODULEVOL", "vfmodulemodelname")
\r
97 // execution.setVariable("DCVFMODVOLRBK_vfModuleModelName", vfModuleModelName)
\r
98 // String cloudSiteId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
\r
99 // execution.setVariable("DCVFMODVOLRBK_cloudSiteId", cloudSiteId)
\r
100 // String heatStackId = rollbackData.get("DCVFMODULEVOL", "heatstackid")
\r
101 // execution.setVariable("DCVFMODVOLRBK_heatStackId", heatStackId)
\r
102 // String requestId = rollbackData.get("DCVFMODULEVOL", "msorequestid")
\r
103 // execution.setVariable("DCVFMODVOLRBK_requestId", requestId)
\r
105 String volumeGroupName = rollbackData.get("DCVFMODULEVOL", "volumeGroupName")
\r
106 execution.setVariable("DCVFMODVOLRBK_volumeGroupName", volumeGroupName)
\r
108 String lcpCloudRegionId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
\r
109 execution.setVariable("DCVFMODVOLRBK_lcpCloudRegionId", lcpCloudRegionId)
\r
111 execution.setVariable("DCVFMODVOLRBK_rollbackVnfARequest", rollbackData.get("DCVFMODULEVOL", "rollbackVnfARequest"))
\r
112 execution.setVariable("DCVFMODVOLRBK_backoutOnFailure", rollbackData.get("DCVFMODULEVOL", "backoutOnFailure"))
\r
113 execution.setVariable("DCVFMODVOLRBK_isCreateVnfRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isCreateVnfRollbackNeeded"))
\r
114 execution.setVariable("DCVFMODVOLRBK_isAAIRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isAAIRollbackNeeded"))
\r
119 * Query AAI volume group by name
\r
121 * @param isDebugEnabled
\r
123 public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
\r
125 def volumeGroupName = execution.getVariable('DCVFMODVOLRBK_volumeGroupName')
\r
126 def cloudRegion = execution.getVariable('DCVFMODVOLRBK_lcpCloudRegionId')
\r
128 // This is for stub testing
\r
129 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
\r
130 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
\r
131 volumeGroupName = testVolumeGroupName
\r
134 AaiUtil aaiUtil = new AaiUtil(this)
\r
135 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
136 String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')
\r
138 utils.logAudit('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
\r
140 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
\r
142 String returnCode = response.getStatusCode()
\r
143 String aaiResponseAsString = response.getResponseBodyAsString()
\r
144 //aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
146 utils.logAudit("AAI query volume group by name return code: " + returnCode)
\r
147 utils.logAudit("AAI query volume group by name response: " + aaiResponseAsString)
\r
149 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
151 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
\r
152 execution.setVariable(prefix+'AaiReturnCode', returnCode)
\r
154 if (returnCode=='200') {
\r
155 // @TODO: verify error code
\r
156 // @TODO: create class of literals representing error codes
\r
157 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
\r
158 utils.log("DEBUG", "Volume Group Name $volumeGroupName exists in AAI.", isDebugEnabled)
\r
160 if (returnCode=='404') {
\r
161 utils.log("DEBUG", "Volume Group Name $volumeGroupName does not exist in AAI.", isDebugEnabled)
\r
162 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
\r
164 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
165 throw new BpmnError("MSOWorkflowException")
\r
172 public void callRESTDeleteAAIVolumeGroup(DelegateExecution execution, isDebugEnabled) {
\r
174 callRESTQueryAAIVolGrpName(execution, isDebugEnabled)
\r
176 def queryAaiVolumeGroupResponse = execution.getVariable(prefix+'queryAAIVolGrpNameResponse')
\r
178 def volumeGroupId = utils.getNodeText(queryAaiVolumeGroupResponse, "volume-group-id")
\r
179 def resourceVersion = utils.getNodeText(queryAaiVolumeGroupResponse, "resource-version")
\r
181 def cloudRegion = execution.getVariable("DCVFMODVOLRBK_lcpCloudRegionId")
\r
183 AaiUtil aaiUtil = new AaiUtil(this)
\r
184 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
185 String deleteAAIVolumeGrpIdRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group" + '/' + volumeGroupId + "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
\r
187 utils.logAudit('Delete AAI volume group : ' + deleteAAIVolumeGrpIdRequest)
\r
189 APIResponse response = aaiUtil.executeAAIDeleteCall(execution, deleteAAIVolumeGrpIdRequest)
\r
191 String returnCode = response.getStatusCode()
\r
192 String aaiResponseAsString = response.getResponseBodyAsString()
\r
193 //aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
195 utils.logAudit("AAI delete volume group return code: " + returnCode)
\r
196 utils.logAudit("AAI delete volume group response: " + aaiResponseAsString)
\r
198 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
200 def volumeGroupNameFound = prefix+'volumeGroupNameFound'
\r
201 if (returnCode=='200' || returnCode=='204' ) {
\r
202 utils.log("DEBUG", "Volume group $volumeGroupId deleted.", isDebugEnabled)
\r
204 if (returnCode=='404') {
\r
205 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupId not found for delete in AAI Response code: 404")
\r
207 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
208 throw new BpmnError("MSOWorkflowException")
\r
213 // *******************************
\r
214 // Build Error Section
\r
215 // *******************************
\r
219 public void processJavaException(DelegateExecution execution){
\r
220 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
221 execution.setVariable("prefix",Prefix)
\r
224 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
\r
225 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
226 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
227 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
\r
228 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
230 }catch(Exception e){
\r
231 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
232 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
\r
233 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
\r
235 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)
\r