2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.VolumeGroups
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.VidUtils
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.json.JsonUtils
33 import org.onap.so.client.aai.AAIObjectPlurals
34 import org.onap.so.client.aai.AAIObjectType
35 import org.onap.so.client.aai.entities.uri.AAIResourceUri
36 import org.onap.so.client.aai.entities.uri.AAIUriFactory
37 import org.onap.so.constants.Defaults
38 import org.slf4j.Logger
39 import org.slf4j.LoggerFactory
41 import javax.ws.rs.NotFoundException
43 public class DoCreateVfModuleVolumeRollback extends AbstractServiceTaskProcessor {
44 private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleVolumeRollback.class);
46 String Prefix="DCVFMODVOLRBK_"
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 JsonUtils jsonUtil = new JsonUtils()
49 VidUtils vidUtils = new VidUtils(this)
51 def className = getClass().getSimpleName()
54 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
57 public InitializeProcessVariables(DelegateExecution execution){
58 /* Initialize all the process variables in this block */
60 execution.setVariable(Prefix + "volumeGroupName", null)
61 execution.setVariable(Prefix + "lcpCloudRegionId", null)
62 execution.setVariable(Prefix + "rollbackVnfARequest", null)
66 // **************************************************
67 // Pre or Prepare Request Section
68 // **************************************************
70 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
73 public void preProcessRequest (DelegateExecution execution) {
74 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
76 InitializeProcessVariables(execution)
77 // rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudSiteId)
78 RollbackData rollbackData = execution.getVariable("rollbackData")
80 // String vnfId = rollbackData.get("DCVFMODULEVOL", "vnfid")
81 // execution.setVariable("DCVFMODVOLRBK_vnfId", vnfId)
82 // String vfModuleId = rollbackData.get("DCVFMODULEVOL", "vfmoduleid")
83 // execution.setVariable("DCVFMODVOLRBK_vfModuleId", vfModuleId)
84 // String source = rollbackData.get("DCVFMODULEVOL", "source")
85 // execution.setVariable("DCVFMODVOLRBK_source", source)
86 // String serviceInstanceId = rollbackData.get("DCVFMODULEVOL", "serviceInstanceId")
87 // execution.setVariable("DCVFMODVOLRBK_serviceInstanceId", serviceInstanceId)
88 // String serviceId = rollbackData.get("DCVFMODULEVOL", "service-id")
89 // execution.setVariable("DCVFMODVOLRBK_serviceId", serviceId)
90 // String vnfType = rollbackData.get("DCVFMODULEVOL", "vnftype")
91 // execution.setVariable("DCVFMODVOLRBK_vnfType", vnfType)
92 // String vnfName = rollbackData.get("DCVFMODULEVOL", "vnfname")
93 // execution.setVariable("DCVFMODVOLRBK_vnfName", vnfName)
94 // String tenantId = rollbackData.get("DCVFMODULEVOL", "tenantid")
95 // execution.setVariable("DCVFMODVOLRBK_tenantId", tenantId)
96 // String vfModuleName = rollbackData.get("DCVFMODULEVOL", "vfmodulename")
97 // execution.setVariable("DCVFMODVOLRBK_vfModuleName", vfModuleName)
98 // String vfModuleModelName = rollbackData.get("DCVFMODULEVOL", "vfmodulemodelname")
99 // execution.setVariable("DCVFMODVOLRBK_vfModuleModelName", vfModuleModelName)
100 // String cloudSiteId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
101 // execution.setVariable("DCVFMODVOLRBK_cloudSiteId", cloudSiteId)
102 // String heatStackId = rollbackData.get("DCVFMODULEVOL", "heatstackid")
103 // execution.setVariable("DCVFMODVOLRBK_heatStackId", heatStackId)
104 // String requestId = rollbackData.get("DCVFMODULEVOL", "msorequestid")
105 // execution.setVariable("DCVFMODVOLRBK_requestId", requestId)
107 String volumeGroupName = rollbackData.get("DCVFMODULEVOL", "volumeGroupName")
108 execution.setVariable("DCVFMODVOLRBK_volumeGroupName", volumeGroupName)
110 String lcpCloudRegionId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
111 execution.setVariable("DCVFMODVOLRBK_lcpCloudRegionId", lcpCloudRegionId)
113 execution.setVariable("DCVFMODVOLRBK_rollbackVnfARequest", rollbackData.get("DCVFMODULEVOL", "rollbackVnfARequest"))
114 execution.setVariable("DCVFMODVOLRBK_backoutOnFailure", rollbackData.get("DCVFMODULEVOL", "backoutOnFailure"))
115 execution.setVariable("DCVFMODVOLRBK_isCreateVnfRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isCreateVnfRollbackNeeded"))
116 execution.setVariable("DCVFMODVOLRBK_isAAIRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isAAIRollbackNeeded"))
121 * Query AAI volume group by name
126 private String callRESTQueryAAIVolGrpName(DelegateExecution execution, String cloudRegion) {
128 def volumeGroupName = execution.getVariable('DCVFMODVOLRBK_volumeGroupName')
130 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
131 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
132 volumeGroupName = testVolumeGroupName
135 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion).queryParam("volume-group-name", volumeGroupName)
137 Optional<VolumeGroups> volumeGroups = getAAIClient().get(VolumeGroups.class, uri)
138 if (volumeGroups.isPresent()) {
139 return volumeGroups.get().getVolumeGroup().get(0).getVolumeGroupId()
141 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
143 } catch (Exception e) {
144 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, e.getMessage())
151 public void callRESTDeleteAAIVolumeGroup(DelegateExecution execution, isDebugEnabled) {
153 String cloudRegion = execution.getVariable("DCVFMODVOLRBK_lcpCloudRegionId")
154 String volumeGroupId = callRESTQueryAAIVolGrpName(execution, cloudRegion)
156 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion, volumeGroupId)
158 getAAIClient().delete(uri)
159 }catch(NotFoundException ignored){
160 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupId not found for delete in AAI Response code: 404")
162 exceptionUtil.buildAndThrowWorkflowException(execution, 2500,e.getMessage())
166 // *******************************
167 // Build Error Section
168 // *******************************
172 public void processJavaException(DelegateExecution execution){
173 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
174 execution.setVariable("prefix",Prefix)
177 logger.debug("Caught a Java Exception in " + Prefix)
178 logger.debug("Started processJavaException Method")
179 logger.debug("Variables List: " + execution.getVariables())
180 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
181 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
184 logger.debug("Caught Exception during processJavaException Method: " + e)
185 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
186 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
188 logger.debug("Completed processJavaException Method in " + Prefix)