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.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.client.aai.entities.uri.AAIUriFactory
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.AAIObjectPlurals
45 import org.onap.so.constants.Defaults
46 import org.onap.so.rest.APIResponse
47 import org.springframework.web.util.UriUtils
48 import org.onap.so.logger.MsoLogger
49 import org.onap.so.logger.MessageEnum
52 public class DoCreateVfModuleVolumeRollback extends AbstractServiceTaskProcessor {
53 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleVolumeRollback.class);
55 String Prefix="DCVFMODVOLRBK_"
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
57 JsonUtils jsonUtil = new JsonUtils()
58 VidUtils vidUtils = new VidUtils(this)
60 def className = getClass().getSimpleName()
63 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
66 public InitializeProcessVariables(DelegateExecution execution){
67 /* Initialize all the process variables in this block */
69 execution.setVariable(Prefix + "volumeGroupName", null)
70 execution.setVariable(Prefix + "lcpCloudRegionId", null)
71 execution.setVariable(Prefix + "rollbackVnfARequest", null)
75 // **************************************************
76 // Pre or Prepare Request Section
77 // **************************************************
79 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
82 public void preProcessRequest (DelegateExecution execution) {
83 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
85 InitializeProcessVariables(execution)
86 // rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudSiteId)
87 RollbackData rollbackData = execution.getVariable("rollbackData")
89 // String vnfId = rollbackData.get("DCVFMODULEVOL", "vnfid")
90 // execution.setVariable("DCVFMODVOLRBK_vnfId", vnfId)
91 // String vfModuleId = rollbackData.get("DCVFMODULEVOL", "vfmoduleid")
92 // execution.setVariable("DCVFMODVOLRBK_vfModuleId", vfModuleId)
93 // String source = rollbackData.get("DCVFMODULEVOL", "source")
94 // execution.setVariable("DCVFMODVOLRBK_source", source)
95 // String serviceInstanceId = rollbackData.get("DCVFMODULEVOL", "serviceInstanceId")
96 // execution.setVariable("DCVFMODVOLRBK_serviceInstanceId", serviceInstanceId)
97 // String serviceId = rollbackData.get("DCVFMODULEVOL", "service-id")
98 // execution.setVariable("DCVFMODVOLRBK_serviceId", serviceId)
99 // String vnfType = rollbackData.get("DCVFMODULEVOL", "vnftype")
100 // execution.setVariable("DCVFMODVOLRBK_vnfType", vnfType)
101 // String vnfName = rollbackData.get("DCVFMODULEVOL", "vnfname")
102 // execution.setVariable("DCVFMODVOLRBK_vnfName", vnfName)
103 // String tenantId = rollbackData.get("DCVFMODULEVOL", "tenantid")
104 // execution.setVariable("DCVFMODVOLRBK_tenantId", tenantId)
105 // String vfModuleName = rollbackData.get("DCVFMODULEVOL", "vfmodulename")
106 // execution.setVariable("DCVFMODVOLRBK_vfModuleName", vfModuleName)
107 // String vfModuleModelName = rollbackData.get("DCVFMODULEVOL", "vfmodulemodelname")
108 // execution.setVariable("DCVFMODVOLRBK_vfModuleModelName", vfModuleModelName)
109 // String cloudSiteId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
110 // execution.setVariable("DCVFMODVOLRBK_cloudSiteId", cloudSiteId)
111 // String heatStackId = rollbackData.get("DCVFMODULEVOL", "heatstackid")
112 // execution.setVariable("DCVFMODVOLRBK_heatStackId", heatStackId)
113 // String requestId = rollbackData.get("DCVFMODULEVOL", "msorequestid")
114 // execution.setVariable("DCVFMODVOLRBK_requestId", requestId)
116 String volumeGroupName = rollbackData.get("DCVFMODULEVOL", "volumeGroupName")
117 execution.setVariable("DCVFMODVOLRBK_volumeGroupName", volumeGroupName)
119 String lcpCloudRegionId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
120 execution.setVariable("DCVFMODVOLRBK_lcpCloudRegionId", lcpCloudRegionId)
122 execution.setVariable("DCVFMODVOLRBK_rollbackVnfARequest", rollbackData.get("DCVFMODULEVOL", "rollbackVnfARequest"))
123 execution.setVariable("DCVFMODVOLRBK_backoutOnFailure", rollbackData.get("DCVFMODULEVOL", "backoutOnFailure"))
124 execution.setVariable("DCVFMODVOLRBK_isCreateVnfRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isCreateVnfRollbackNeeded"))
125 execution.setVariable("DCVFMODVOLRBK_isAAIRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isAAIRollbackNeeded"))
130 * Query AAI volume group by name
132 * @param isDebugEnabled
134 public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
136 def volumeGroupName = execution.getVariable('DCVFMODVOLRBK_volumeGroupName')
137 def cloudRegion = execution.getVariable('DCVFMODVOLRBK_lcpCloudRegionId')
139 // This is for stub testing
140 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
141 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
142 volumeGroupName = testVolumeGroupName
145 AaiUtil aaiUtil = new AaiUtil(this)
147 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion).queryParam("volume-group-name", volumeGroupName)
148 def queryAAIVolumeNameRequest = aaiUtil.createAaiUri(uri)
150 msoLogger.debug('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
152 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
154 String returnCode = response.getStatusCode()
155 String aaiResponseAsString = response.getResponseBodyAsString()
157 msoLogger.debug("AAI query volume group by name return code: " + returnCode)
158 msoLogger.debug("AAI query volume group by name response: " + aaiResponseAsString)
160 ExceptionUtil exceptionUtil = new ExceptionUtil()
162 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
163 execution.setVariable(prefix+'AaiReturnCode', returnCode)
165 if (returnCode=='200') {
166 // @TODO: verify error code
167 // @TODO: create class of literals representing error codes
168 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
169 msoLogger.debug("Volume Group Name $volumeGroupName exists in AAI.")
171 if (returnCode=='404') {
172 msoLogger.debug("Volume Group Name $volumeGroupName does not exist in AAI.")
173 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
175 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
176 throw new BpmnError("MSOWorkflowException")
183 public void callRESTDeleteAAIVolumeGroup(DelegateExecution execution, isDebugEnabled) {
185 callRESTQueryAAIVolGrpName(execution, isDebugEnabled)
187 def queryAaiVolumeGroupResponse = execution.getVariable(prefix+'queryAAIVolGrpNameResponse')
189 def volumeGroupId = utils.getNodeText(queryAaiVolumeGroupResponse, "volume-group-id")
190 def resourceVersion = utils.getNodeText(queryAaiVolumeGroupResponse, "resource-version")
192 def cloudRegion = execution.getVariable("DCVFMODVOLRBK_lcpCloudRegionId")
194 AaiUtil aaiUtil = new AaiUtil(this)
196 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion, volumeGroupId).resourceVersion(resourceVersion)
197 def deleteAAIVolumeGrpIdRequest = aaiUtil.createAaiUri(uri)
199 msoLogger.debug('Delete AAI volume group : ' + deleteAAIVolumeGrpIdRequest)
201 APIResponse response = aaiUtil.executeAAIDeleteCall(execution, deleteAAIVolumeGrpIdRequest)
203 String returnCode = response.getStatusCode()
204 String aaiResponseAsString = response.getResponseBodyAsString()
206 msoLogger.debug("AAI delete volume group return code: " + returnCode)
207 msoLogger.debug("AAI delete volume group response: " + aaiResponseAsString)
209 ExceptionUtil exceptionUtil = new ExceptionUtil()
211 def volumeGroupNameFound = prefix+'volumeGroupNameFound'
212 if (returnCode=='200' || returnCode=='204' ) {
213 msoLogger.debug("Volume group $volumeGroupId deleted.")
215 if (returnCode=='404') {
216 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupId not found for delete in AAI Response code: 404")
218 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
219 throw new BpmnError("MSOWorkflowException")
224 // *******************************
225 // Build Error Section
226 // *******************************
230 public void processJavaException(DelegateExecution execution){
231 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
232 execution.setVariable("prefix",Prefix)
235 msoLogger.debug("Caught a Java Exception in " + Prefix)
236 msoLogger.debug("Started processJavaException Method")
237 msoLogger.debug("Variables List: " + execution.getVariables())
238 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
239 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
242 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
243 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
244 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
246 msoLogger.debug("Completed processJavaException Method in " + Prefix)