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 static org.apache.commons.lang3.StringUtils.*;
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.logger.MessageEnum
35 import org.onap.so.logger.MsoLogger
38 * This class supports the macro VID Flow
39 * with the rollback of a creation of a generic vnf and related VF modules.
41 class DoCreateVnfAndModulesRollback extends AbstractServiceTaskProcessor {
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVnfAndModulesRollback.class);
44 String Prefix="DCVAMR_"
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 JsonUtils jsonUtil = new JsonUtils()
50 * This method gets and validates the incoming
56 public void preProcessRequest(DelegateExecution execution) {
58 execution.setVariable("prefix",Prefix)
59 msoLogger.debug("STARTED DoCreateVnfAndModulesRollback PreProcessRequest Process")
62 // Get Rollback Variables
64 def rollbackData = execution.getVariable("rollbackData")
65 msoLogger.debug("Incoming RollbackData is: " + rollbackData.toString())
66 execution.setVariable("rolledBack", null)
67 execution.setVariable("rollbackError", null)
69 if (execution.getVariable("disableRollback").equals("true" ))
71 execution.setVariable("skipRollback", true)
74 String vnfId = rollbackData.get("VNF", "vnfId")
75 msoLogger.debug("Rollback vnfId is: " + vnfId)
76 execution.setVariable("DCVAMR_vnfId", vnfId)
78 execution.setVariable("mso-request-id", execution.getVariable("msoRequestId"))
80 execution.setVariable("DCVAMR_rollbackSDNCAssign", rollbackData.get("VNF", "rollbackSDNCAssign"))
81 execution.setVariable("DCVAMR_rollbackSDNCActivate", rollbackData.get("VNF", "rollbackSDNCActivate"))
82 execution.setVariable("DCVAMR_rollbackVnfCreate", rollbackData.get("VNF", "rollbackVnfCreate"))
84 String sdncCallbackUrl = rollbackData.get("VNF", "sdncCallbackUrl")
85 msoLogger.debug("Rollback sdncCallbackUrl is: " + sdncCallbackUrl)
86 execution.setVariable("DCVAMR_sdncCallbackUrl", sdncCallbackUrl)
88 String tenantId= rollbackData.get("VNF", "tenantId")
89 msoLogger.debug("Rollback tenantId is: " + tenantId)
90 execution.setVariable("DCVAMR_tenantId", tenantId)
92 String source= rollbackData.get("VNF", "source")
93 msoLogger.debug("Rollback source is: " + source)
94 execution.setVariable("DCVAMR_source", source)
96 String serviceInstanceId = rollbackData.get("VNF", "serviceInstanceId")
97 msoLogger.debug("Rollback serviceInstanceId is: " + serviceInstanceId)
98 execution.setVariable("DCVAMR_serviceInstanceId", serviceInstanceId)
100 String cloudSiteId = rollbackData.get("VNF", "cloudSiteId")
101 msoLogger.debug("Rollback cloudSiteId is: " + cloudSiteId)
102 execution.setVariable("DCVAMR_cloudSiteId", cloudSiteId)
104 def numOfAddOnModulesString = rollbackData.get("VNFANDMODULES", "numOfCreatedAddOnModules")
105 int numOfAddOnModules = 0
106 if (numOfAddOnModulesString != null) {
107 numOfAddOnModules = Integer.parseInt(numOfAddOnModulesString)
109 execution.setVariable("DCVAMR_numOfAddOnModules", numOfAddOnModules)
111 def baseVfModuleRollbackMap = rollbackData.get("VFMODULE_BASE")
112 if (baseVfModuleRollbackMap == null) {
113 // there are no VF Modules to delete
114 execution.setVariable("DCVAMR_numOfModulesToDelete", 0)
117 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfAddOnModules + 1)
120 // Set aLaCarte to false
121 execution.setVariable("DCVAMR_aLaCarte", false)
124 msoLogger.debug("Rethrowing MSOWorkflowException")
127 msoLogger.debug(" Error Occured in DoCreateVnfAndModulesRollback PreProcessRequest method!" + e.getMessage())
128 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnfAndModulesRollback PreProcessRequest")
131 msoLogger.trace("COMPLETED DoCreateVnfAndModulesRollback PreProcessRequest Process")
136 public void preProcessCreateVfModuleRollback(DelegateExecution execution){
138 execution.setVariable("prefix", Prefix)
139 msoLogger.trace("STARTED preProcessCreateVfModuleRollback")
143 def rollbackData = execution.getVariable("rollbackData")
145 def vfModuleRollbackData = new RollbackData()
147 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
148 msoLogger.debug("numOfModulesToDelete: " + numOfModulesToDelete)
151 if (numOfModulesToDelete > 1) {
152 int addOnModuleIndex = numOfModulesToDelete - 1
153 moduleMap = rollbackData.get("VFMODULE_ADDON_" + addOnModuleIndex)
154 msoLogger.debug("Removing ADDON VF module # " + addOnModuleIndex)
157 moduleMap = rollbackData.get("VFMODULE_BASE")
158 msoLogger.debug("Removing BASE VF module")
160 moduleMap.each{ k, v -> vfModuleRollbackData.put("VFMODULE", "${k}","${v}") }
161 execution.setVariable("DCVAMR_RollbackData", vfModuleRollbackData)
164 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessCreateVfModuleRollback ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
165 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessCreateVfModuleRollback Method:\n" + e.getMessage())
167 msoLogger.trace("COMPLETED preProcessCreateVfModuleRollback")
171 public void postProcessCreateVfModuleRollback(DelegateExecution execution){
173 execution.setVariable("prefix", Prefix)
174 msoLogger.trace("STARTED postProcessCreateVfModuleRollback")
175 def rolledBack = false
178 rolledBack = execution.getVariable("DCVM_rolledBack")
179 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
180 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfModulesToDelete - 1)
182 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing postProcessCreateVfModuleRollback ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
183 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during postProcessCreateVfModuleRollback Method:\n" + e.getMessage())
185 if (rolledBack == false) {
186 msoLogger.debug("Failure on DoCreateVfModuleRollback")
187 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Unsuccessful rollback of DoCreateVfModule ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError);
188 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during rollback of DoCreateVfModule")
190 msoLogger.trace("COMPLETED postProcessCreateVfModuleRollback")
194 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
196 execution.setVariable("prefix", Prefix)
197 msoLogger.trace("STARTED preProcessSDNCDeactivateRequest")
198 def vnfId = execution.getVariable("vnfId")
199 def serviceInstanceId = execution.getVariable("serviceInstanceId")
204 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
206 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
207 execution.setVariable(Prefix + "deactivateSDNCRequest", deactivateSDNCRequest)
208 msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
211 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCDeactivateRequest ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
212 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
214 msoLogger.trace("COMPLETED preProcessSDNCDeactivateRequest")
217 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
218 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
219 'execution=' + execution.getId() +
221 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
222 msoLogger.trace('Entered ' + method)
223 execution.setVariable("prefix", Prefix)
224 msoLogger.trace("STARTED preProcessSDNCUnassignRequest Process")
226 String vnfId = execution.getVariable("vnfId")
227 String serviceInstanceId = execution.getVariable("serviceInstanceId")
229 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
231 execution.setVariable(Prefix + "unassignSDNCRequest", unassignSDNCRequest)
232 msoLogger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
235 msoLogger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
236 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
238 msoLogger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
241 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
243 String uuid = execution.getVariable('testReqId') // for junits
245 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
247 def callbackURL = execution.getVariable(Prefix + "sdncCallbackUrl")
248 def requestId = execution.getVariable("msoRequestId")
249 def tenantId = execution.getVariable(Prefix + "tenantId")
250 def source = execution.getVariable(Prefix + "source")
251 def vnfId = execution.getVariable(Prefix + "vnfId")
252 def serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
253 def cloudSiteId = execution.getVariable(Prefix + "cloudSiteId")
256 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
257 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
258 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
259 <sdncadapter:RequestHeader>
260 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
261 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
262 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
263 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
264 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
265 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
266 </sdncadapter:RequestHeader>
267 <sdncadapterworkflow:SDNCRequestData>
268 <request-information>
269 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
270 <request-action>DeleteVnfInstance</request-action>
271 <source>${MsoUtils.xmlEscape(source)}</source>
275 </request-information>
276 <service-information>
278 <subscription-service-type/>
279 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
280 <global-customer-id/>
281 </service-information>
283 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
288 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
289 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
291 </sdncadapterworkflow:SDNCRequestData>
292 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
294 msoLogger.debug("sdncRequest: " + sdncRequest)
298 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
300 execution.setVariable("prefix",Prefix)
301 msoLogger.debug("STARTED ValidateSDNCResponse Process")
303 WorkflowException workflowException = execution.getVariable("WorkflowException")
304 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
306 msoLogger.debug("workflowException: " + workflowException)
308 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
309 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
311 String sdncResponse = response
312 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
313 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
315 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
316 throw new BpmnError("MSOWorkflowException")
318 msoLogger.debug("COMPLETED ValidateSDNCResponse Process")
321 public void setSuccessfulRollbackStatus (DelegateExecution execution){
323 execution.setVariable("prefix", Prefix)
324 msoLogger.trace("STARTED setSuccessfulRollbackStatus")
327 // Set rolledBack to true, rollbackError to null
328 execution.setVariable("rolledBack", true)
329 execution.setVariable("rollbackError", null)
332 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing setSuccessfulRollbackStatus ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
333 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
335 msoLogger.trace("COMPLETED setSuccessfulRollbackStatus")
338 public void setFailedRollbackStatus (DelegateExecution execution){
340 execution.setVariable("prefix", Prefix)
341 msoLogger.trace("STARTED setFailedRollbackStatus")
344 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
345 execution.setVariable("rolledBack", false)
346 def rollbackError = execution.getVariable("rollbackError")
347 if (rollbackError == null) {
348 execution.setVariable("rollbackError", 'Caught exception in DoCreateVnfAndModulesRollback')
350 execution.setVariable("rollbackData", null)
353 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing setFailedRollbackStatus. ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
354 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
356 msoLogger.trace("COMPLETED setFailedRollbackStatus")