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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts;
23 import groovy.xml.XmlUtil
28 import java.util.UUID;
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.delegate.DelegateExecution
32 import org.apache.commons.lang3.*
33 import org.apache.commons.codec.binary.Base64;
34 import org.onap.so.bpmn.common.scripts.AaiUtil
35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.VidUtils
38 import org.onap.so.bpmn.core.RollbackData
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.core.json.JsonUtils
41 import org.onap.so.rest.APIResponse
42 import org.springframework.web.util.UriUtils
43 import org.onap.so.logger.MsoLogger
44 import org.onap.so.logger.MessageEnum
47 public class DoCreateVfModuleVolumeRollback extends AbstractServiceTaskProcessor {
48 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleVolumeRollback.class);
50 String Prefix="DCVFMODVOLRBK_"
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
53 VidUtils vidUtils = new VidUtils(this)
55 def className = getClass().getSimpleName()
58 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
61 public InitializeProcessVariables(DelegateExecution execution){
62 /* Initialize all the process variables in this block */
64 execution.setVariable(Prefix + "volumeGroupName", null)
65 execution.setVariable(Prefix + "lcpCloudRegionId", null)
66 execution.setVariable(Prefix + "rollbackVnfARequest", null)
70 // **************************************************
71 // Pre or Prepare Request Section
72 // **************************************************
74 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
77 public void preProcessRequest (DelegateExecution execution) {
78 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
80 InitializeProcessVariables(execution)
81 // rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudSiteId)
82 RollbackData rollbackData = execution.getVariable("rollbackData")
84 // String vnfId = rollbackData.get("DCVFMODULEVOL", "vnfid")
85 // execution.setVariable("DCVFMODVOLRBK_vnfId", vnfId)
86 // String vfModuleId = rollbackData.get("DCVFMODULEVOL", "vfmoduleid")
87 // execution.setVariable("DCVFMODVOLRBK_vfModuleId", vfModuleId)
88 // String source = rollbackData.get("DCVFMODULEVOL", "source")
89 // execution.setVariable("DCVFMODVOLRBK_source", source)
90 // String serviceInstanceId = rollbackData.get("DCVFMODULEVOL", "serviceInstanceId")
91 // execution.setVariable("DCVFMODVOLRBK_serviceInstanceId", serviceInstanceId)
92 // String serviceId = rollbackData.get("DCVFMODULEVOL", "service-id")
93 // execution.setVariable("DCVFMODVOLRBK_serviceId", serviceId)
94 // String vnfType = rollbackData.get("DCVFMODULEVOL", "vnftype")
95 // execution.setVariable("DCVFMODVOLRBK_vnfType", vnfType)
96 // String vnfName = rollbackData.get("DCVFMODULEVOL", "vnfname")
97 // execution.setVariable("DCVFMODVOLRBK_vnfName", vnfName)
98 // String tenantId = rollbackData.get("DCVFMODULEVOL", "tenantid")
99 // execution.setVariable("DCVFMODVOLRBK_tenantId", tenantId)
100 // String vfModuleName = rollbackData.get("DCVFMODULEVOL", "vfmodulename")
101 // execution.setVariable("DCVFMODVOLRBK_vfModuleName", vfModuleName)
102 // String vfModuleModelName = rollbackData.get("DCVFMODULEVOL", "vfmodulemodelname")
103 // execution.setVariable("DCVFMODVOLRBK_vfModuleModelName", vfModuleModelName)
104 // String cloudSiteId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
105 // execution.setVariable("DCVFMODVOLRBK_cloudSiteId", cloudSiteId)
106 // String heatStackId = rollbackData.get("DCVFMODULEVOL", "heatstackid")
107 // execution.setVariable("DCVFMODVOLRBK_heatStackId", heatStackId)
108 // String requestId = rollbackData.get("DCVFMODULEVOL", "msorequestid")
109 // execution.setVariable("DCVFMODVOLRBK_requestId", requestId)
111 String volumeGroupName = rollbackData.get("DCVFMODULEVOL", "volumeGroupName")
112 execution.setVariable("DCVFMODVOLRBK_volumeGroupName", volumeGroupName)
114 String lcpCloudRegionId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
115 execution.setVariable("DCVFMODVOLRBK_lcpCloudRegionId", lcpCloudRegionId)
117 execution.setVariable("DCVFMODVOLRBK_rollbackVnfARequest", rollbackData.get("DCVFMODULEVOL", "rollbackVnfARequest"))
118 execution.setVariable("DCVFMODVOLRBK_backoutOnFailure", rollbackData.get("DCVFMODULEVOL", "backoutOnFailure"))
119 execution.setVariable("DCVFMODVOLRBK_isCreateVnfRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isCreateVnfRollbackNeeded"))
120 execution.setVariable("DCVFMODVOLRBK_isAAIRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isAAIRollbackNeeded"))
125 * Query AAI volume group by name
127 * @param isDebugEnabled
129 public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
131 def volumeGroupName = execution.getVariable('DCVFMODVOLRBK_volumeGroupName')
132 def cloudRegion = execution.getVariable('DCVFMODVOLRBK_lcpCloudRegionId')
134 // This is for stub testing
135 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
136 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
137 volumeGroupName = testVolumeGroupName
140 AaiUtil aaiUtil = new AaiUtil(this)
141 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
142 String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')
144 msoLogger.debug('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
146 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
148 String returnCode = response.getStatusCode()
149 String aaiResponseAsString = response.getResponseBodyAsString()
151 msoLogger.debug("AAI query volume group by name return code: " + returnCode)
152 msoLogger.debug("AAI query volume group by name response: " + aaiResponseAsString)
154 ExceptionUtil exceptionUtil = new ExceptionUtil()
156 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
157 execution.setVariable(prefix+'AaiReturnCode', returnCode)
159 if (returnCode=='200') {
160 // @TODO: verify error code
161 // @TODO: create class of literals representing error codes
162 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
163 msoLogger.debug("Volume Group Name $volumeGroupName exists in AAI.")
165 if (returnCode=='404') {
166 msoLogger.debug("Volume Group Name $volumeGroupName does not exist in AAI.")
167 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
169 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
170 throw new BpmnError("MSOWorkflowException")
177 public void callRESTDeleteAAIVolumeGroup(DelegateExecution execution, isDebugEnabled) {
179 callRESTQueryAAIVolGrpName(execution, isDebugEnabled)
181 def queryAaiVolumeGroupResponse = execution.getVariable(prefix+'queryAAIVolGrpNameResponse')
183 def volumeGroupId = utils.getNodeText(queryAaiVolumeGroupResponse, "volume-group-id")
184 def resourceVersion = utils.getNodeText(queryAaiVolumeGroupResponse, "resource-version")
186 def cloudRegion = execution.getVariable("DCVFMODVOLRBK_lcpCloudRegionId")
188 AaiUtil aaiUtil = new AaiUtil(this)
189 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
190 String deleteAAIVolumeGrpIdRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group" + '/' + volumeGroupId + "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
192 msoLogger.debug('Delete AAI volume group : ' + deleteAAIVolumeGrpIdRequest)
194 APIResponse response = aaiUtil.executeAAIDeleteCall(execution, deleteAAIVolumeGrpIdRequest)
196 String returnCode = response.getStatusCode()
197 String aaiResponseAsString = response.getResponseBodyAsString()
199 msoLogger.debug("AAI delete volume group return code: " + returnCode)
200 msoLogger.debug("AAI delete volume group response: " + aaiResponseAsString)
202 ExceptionUtil exceptionUtil = new ExceptionUtil()
204 def volumeGroupNameFound = prefix+'volumeGroupNameFound'
205 if (returnCode=='200' || returnCode=='204' ) {
206 msoLogger.debug("Volume group $volumeGroupId deleted.")
208 if (returnCode=='404') {
209 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupId not found for delete in AAI Response code: 404")
211 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
212 throw new BpmnError("MSOWorkflowException")
217 // *******************************
218 // Build Error Section
219 // *******************************
223 public void processJavaException(DelegateExecution execution){
224 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
225 execution.setVariable("prefix",Prefix)
228 msoLogger.debug("Caught a Java Exception in " + Prefix)
229 msoLogger.debug("Started processJavaException Method")
230 msoLogger.debug("Variables List: " + execution.getVariables())
231 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
232 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
235 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
236 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
237 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
239 msoLogger.debug("Completed processJavaException Method in " + Prefix)