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 javax.ws.rs.NotFoundException
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.VolumeGroups
29 import org.onap.aaiclient.client.aai.AAIObjectType
30 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
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.json.JsonUtils
40 import org.onap.so.constants.Defaults
41 import org.slf4j.Logger
42 import org.slf4j.LoggerFactory
44 public class DoCreateVfModuleVolumeRollback extends AbstractServiceTaskProcessor {
45 private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleVolumeRollback.class);
47 String Prefix="DCVFMODVOLRBK_"
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
50 VidUtils vidUtils = new VidUtils(this)
52 def className = getClass().getSimpleName()
55 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
58 public InitializeProcessVariables(DelegateExecution execution){
59 /* Initialize all the process variables in this block */
61 execution.setVariable(Prefix + "volumeGroupName", null)
62 execution.setVariable(Prefix + "lcpCloudRegionId", null)
63 execution.setVariable(Prefix + "rollbackVnfARequest", null)
67 // **************************************************
68 // Pre or Prepare Request Section
69 // **************************************************
71 * This method is executed during the preProcessRequest task of the <class>DoCreateVfModuleVolumeRollback.bpmn</class> process.
74 public void preProcessRequest (DelegateExecution execution) {
75 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
77 InitializeProcessVariables(execution)
78 // rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudSiteId)
79 RollbackData rollbackData = execution.getVariable("rollbackData")
81 // String vnfId = rollbackData.get("DCVFMODULEVOL", "vnfid")
82 // execution.setVariable("DCVFMODVOLRBK_vnfId", vnfId)
83 // String vfModuleId = rollbackData.get("DCVFMODULEVOL", "vfmoduleid")
84 // execution.setVariable("DCVFMODVOLRBK_vfModuleId", vfModuleId)
85 // String source = rollbackData.get("DCVFMODULEVOL", "source")
86 // execution.setVariable("DCVFMODVOLRBK_source", source)
87 // String serviceInstanceId = rollbackData.get("DCVFMODULEVOL", "serviceInstanceId")
88 // execution.setVariable("DCVFMODVOLRBK_serviceInstanceId", serviceInstanceId)
89 // String serviceId = rollbackData.get("DCVFMODULEVOL", "service-id")
90 // execution.setVariable("DCVFMODVOLRBK_serviceId", serviceId)
91 // String vnfType = rollbackData.get("DCVFMODULEVOL", "vnftype")
92 // execution.setVariable("DCVFMODVOLRBK_vnfType", vnfType)
93 // String vnfName = rollbackData.get("DCVFMODULEVOL", "vnfname")
94 // execution.setVariable("DCVFMODVOLRBK_vnfName", vnfName)
95 // String tenantId = rollbackData.get("DCVFMODULEVOL", "tenantid")
96 // execution.setVariable("DCVFMODVOLRBK_tenantId", tenantId)
97 // String vfModuleName = rollbackData.get("DCVFMODULEVOL", "vfmodulename")
98 // execution.setVariable("DCVFMODVOLRBK_vfModuleName", vfModuleName)
99 // String vfModuleModelName = rollbackData.get("DCVFMODULEVOL", "vfmodulemodelname")
100 // execution.setVariable("DCVFMODVOLRBK_vfModuleModelName", vfModuleModelName)
101 // String cloudSiteId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
102 // execution.setVariable("DCVFMODVOLRBK_cloudSiteId", cloudSiteId)
103 // String heatStackId = rollbackData.get("DCVFMODULEVOL", "heatstackid")
104 // execution.setVariable("DCVFMODVOLRBK_heatStackId", heatStackId)
105 // String requestId = rollbackData.get("DCVFMODULEVOL", "msorequestid")
106 // execution.setVariable("DCVFMODVOLRBK_requestId", requestId)
108 String volumeGroupName = rollbackData.get("DCVFMODULEVOL", "volumeGroupName")
109 execution.setVariable("DCVFMODVOLRBK_volumeGroupName", volumeGroupName)
111 String lcpCloudRegionId = rollbackData.get("DCVFMODULEVOL", "aiccloudregion")
112 execution.setVariable("DCVFMODVOLRBK_lcpCloudRegionId", lcpCloudRegionId)
114 execution.setVariable("DCVFMODVOLRBK_rollbackVnfARequest", rollbackData.get("DCVFMODULEVOL", "rollbackVnfARequest"))
115 execution.setVariable("DCVFMODVOLRBK_backoutOnFailure", rollbackData.get("DCVFMODULEVOL", "backoutOnFailure"))
116 execution.setVariable("DCVFMODVOLRBK_isCreateVnfRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isCreateVnfRollbackNeeded"))
117 execution.setVariable("DCVFMODVOLRBK_isAAIRollbackNeeded", rollbackData.get("DCVFMODULEVOL", "isAAIRollbackNeeded"))
122 * Query AAI volume group by name
127 private String callRESTQueryAAIVolGrpName(DelegateExecution execution, String cloudRegion) {
129 def volumeGroupName = execution.getVariable('DCVFMODVOLRBK_volumeGroupName')
131 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
132 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
133 volumeGroupName = testVolumeGroupName
136 AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), cloudRegion).volumeGroups()).queryParam("volume-group-name", volumeGroupName)
138 Optional<VolumeGroups> volumeGroups = getAAIClient().get(VolumeGroups.class, uri)
139 if (volumeGroups.isPresent()) {
140 return volumeGroups.get().getVolumeGroup().get(0).getVolumeGroupId()
142 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
144 } catch (Exception e) {
145 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, e.getMessage())
152 public void callRESTDeleteAAIVolumeGroup(DelegateExecution execution, isDebugEnabled) {
154 String cloudRegion = execution.getVariable("DCVFMODVOLRBK_lcpCloudRegionId")
155 String volumeGroupId = callRESTQueryAAIVolGrpName(execution, cloudRegion)
157 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), cloudRegion).volumeGroup(volumeGroupId))
159 getAAIClient().delete(uri)
160 }catch(NotFoundException ignored){
161 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupId not found for delete in AAI Response code: 404")
163 exceptionUtil.buildAndThrowWorkflowException(execution, 2500,e.getMessage())
167 // *******************************
168 // Build Error Section
169 // *******************************
173 public void processJavaException(DelegateExecution execution){
174 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
175 execution.setVariable("prefix",Prefix)
178 logger.debug("Caught a Java Exception in " + Prefix)
179 logger.debug("Started processJavaException Method")
180 logger.debug("Variables List: " + execution.getVariables())
181 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
182 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
185 logger.debug("Caught Exception during processJavaException Method: " + e)
186 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
187 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
189 logger.debug("Completed processJavaException Method in " + Prefix)