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
25 import org.onap.so.logger.LoggingAnchor
26 import org.onap.logging.filter.base.ErrorCode
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.RollbackData
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.logger.MessageEnum
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
41 * This class supports the macro VID Flow
42 * with the rollback of a creation of a generic vnf and related VF modules.
44 class DoCreateVnfAndModulesRollback extends AbstractServiceTaskProcessor {
46 private static final Logger logger = LoggerFactory.getLogger( DoCreateVnfAndModulesRollback.class);
47 String Prefix="DCVAMR_"
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
53 * This method gets and validates the incoming
59 public void preProcessRequest(DelegateExecution execution) {
61 execution.setVariable("prefix",Prefix)
62 logger.debug("STARTED DoCreateVnfAndModulesRollback PreProcessRequest Process")
65 // Get Rollback Variables
67 def rollbackData = execution.getVariable("rollbackData")
68 logger.debug("Incoming RollbackData is: " + rollbackData.toString())
69 execution.setVariable("rolledBack", null)
70 execution.setVariable("rollbackError", null)
72 if (execution.getVariable("disableRollback").equals("true" ))
74 execution.setVariable("skipRollback", true)
77 String vnfId = rollbackData.get("VNF", "vnfId")
78 logger.debug("Rollback vnfId is: " + vnfId)
79 execution.setVariable("DCVAMR_vnfId", vnfId)
81 execution.setVariable("mso-request-id", execution.getVariable("msoRequestId"))
83 execution.setVariable("DCVAMR_rollbackSDNCAssign", rollbackData.get("VNF", "rollbackSDNCAssign"))
84 execution.setVariable("DCVAMR_rollbackSDNCActivate", rollbackData.get("VNF", "rollbackSDNCActivate"))
85 execution.setVariable("DCVAMR_rollbackVnfCreate", rollbackData.get("VNF", "rollbackVnfCreate"))
87 String sdncCallbackUrl = rollbackData.get("VNF", "sdncCallbackUrl")
88 logger.debug("Rollback sdncCallbackUrl is: " + sdncCallbackUrl)
89 execution.setVariable("DCVAMR_sdncCallbackUrl", sdncCallbackUrl)
91 String tenantId= rollbackData.get("VNF", "tenantId")
92 logger.debug("Rollback tenantId is: " + tenantId)
93 execution.setVariable("DCVAMR_tenantId", tenantId)
95 String source= rollbackData.get("VNF", "source")
96 logger.debug("Rollback source is: " + source)
97 execution.setVariable("DCVAMR_source", source)
99 String serviceInstanceId = rollbackData.get("VNF", "serviceInstanceId")
100 logger.debug("Rollback serviceInstanceId is: " + serviceInstanceId)
101 execution.setVariable("DCVAMR_serviceInstanceId", serviceInstanceId)
103 String cloudSiteId = rollbackData.get("VNF", "cloudSiteId")
104 logger.debug("Rollback cloudSiteId is: " + cloudSiteId)
105 execution.setVariable("DCVAMR_cloudSiteId", cloudSiteId)
107 def numOfAddOnModulesString = rollbackData.get("VNFANDMODULES", "numOfCreatedAddOnModules")
108 int numOfAddOnModules = 0
109 if (numOfAddOnModulesString != null) {
110 numOfAddOnModules = Integer.parseInt(numOfAddOnModulesString)
112 execution.setVariable("DCVAMR_numOfAddOnModules", numOfAddOnModules)
114 def baseVfModuleRollbackMap = rollbackData.get("VFMODULE_BASE")
115 if (baseVfModuleRollbackMap == null) {
116 // there are no VF Modules to delete
117 execution.setVariable("DCVAMR_numOfModulesToDelete", 0)
120 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfAddOnModules + 1)
123 // Set aLaCarte to false
124 execution.setVariable("DCVAMR_aLaCarte", false)
127 logger.debug("Rethrowing MSOWorkflowException")
130 logger.debug(" Error Occured in DoCreateVnfAndModulesRollback PreProcessRequest method!" + e.getMessage())
131 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnfAndModulesRollback PreProcessRequest")
134 logger.trace("COMPLETED DoCreateVnfAndModulesRollback PreProcessRequest Process")
139 public void preProcessCreateVfModuleRollback(DelegateExecution execution){
141 execution.setVariable("prefix", Prefix)
142 logger.trace("STARTED preProcessCreateVfModuleRollback")
146 def rollbackData = execution.getVariable("rollbackData")
148 def vfModuleRollbackData = new RollbackData()
150 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
151 logger.debug("numOfModulesToDelete: " + numOfModulesToDelete)
154 if (numOfModulesToDelete > 1) {
155 int addOnModuleIndex = numOfModulesToDelete - 1
156 moduleMap = rollbackData.get("VFMODULE_ADDON_" + addOnModuleIndex)
157 logger.debug("Removing ADDON VF module # " + addOnModuleIndex)
160 moduleMap = rollbackData.get("VFMODULE_BASE")
161 logger.debug("Removing BASE VF module")
163 moduleMap.each{ k, v -> vfModuleRollbackData.put("VFMODULE", "${k}","${v}") }
164 execution.setVariable("DCVAMR_RollbackData", vfModuleRollbackData)
167 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
168 "Exception Occured Processing preProcessCreateVfModuleRollback ", "BPMN",
169 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
170 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessCreateVfModuleRollback Method:\n" + e.getMessage())
172 logger.trace("COMPLETED preProcessCreateVfModuleRollback")
176 public void postProcessCreateVfModuleRollback(DelegateExecution execution){
178 execution.setVariable("prefix", Prefix)
179 logger.trace("STARTED postProcessCreateVfModuleRollback")
180 def rolledBack = false
183 rolledBack = execution.getVariable("DCVM_rolledBack")
184 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
185 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfModulesToDelete - 1)
187 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
188 "Exception Occured Processing postProcessCreateVfModuleRollback ", "BPMN",
189 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
190 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during postProcessCreateVfModuleRollback Method:\n" + e.getMessage())
192 if (rolledBack == false) {
193 logger.debug("Failure on DoCreateVfModuleRollback")
194 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
195 "Unsuccessful rollback of DoCreateVfModule ", "BPMN",
196 ErrorCode.UnknownError.getValue());
197 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during rollback of DoCreateVfModule")
199 logger.trace("COMPLETED postProcessCreateVfModuleRollback")
203 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
205 execution.setVariable("prefix", Prefix)
206 logger.trace("STARTED preProcessSDNCDeactivateRequest")
207 def vnfId = execution.getVariable("vnfId")
208 def serviceInstanceId = execution.getVariable("serviceInstanceId")
213 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
215 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
216 execution.setVariable(Prefix + "deactivateSDNCRequest", deactivateSDNCRequest)
217 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
220 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
221 "Exception Occured Processing preProcessSDNCDeactivateRequest ", "BPMN",
222 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
223 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
225 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
228 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
229 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
230 'execution=' + execution.getId() +
232 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
233 logger.trace('Entered ' + method)
234 execution.setVariable("prefix", Prefix)
235 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
237 String vnfId = execution.getVariable("vnfId")
238 String serviceInstanceId = execution.getVariable("serviceInstanceId")
240 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
242 execution.setVariable(Prefix + "unassignSDNCRequest", unassignSDNCRequest)
243 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
246 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
247 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
249 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
252 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
254 String uuid = execution.getVariable('testReqId') // for junits
256 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
258 def callbackURL = execution.getVariable(Prefix + "sdncCallbackUrl")
259 def requestId = execution.getVariable("msoRequestId")
260 def tenantId = execution.getVariable(Prefix + "tenantId")
261 def source = execution.getVariable(Prefix + "source")
262 def vnfId = execution.getVariable(Prefix + "vnfId")
263 def serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
264 def cloudSiteId = execution.getVariable(Prefix + "cloudSiteId")
267 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
268 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
269 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
270 <sdncadapter:RequestHeader>
271 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
272 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
273 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
274 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
275 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
276 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
277 </sdncadapter:RequestHeader>
278 <sdncadapterworkflow:SDNCRequestData>
279 <request-information>
280 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
281 <request-action>DeleteVnfInstance</request-action>
282 <source>${MsoUtils.xmlEscape(source)}</source>
286 </request-information>
287 <service-information>
289 <subscription-service-type/>
290 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
291 <global-customer-id/>
292 </service-information>
294 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
299 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
300 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
302 </sdncadapterworkflow:SDNCRequestData>
303 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
305 logger.debug("sdncRequest: " + sdncRequest)
309 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
311 execution.setVariable("prefix",Prefix)
312 logger.debug("STARTED ValidateSDNCResponse Process")
314 WorkflowException workflowException = execution.getVariable("WorkflowException")
315 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
317 logger.debug("workflowException: " + workflowException)
319 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
320 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
322 String sdncResponse = response
323 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
324 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
326 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
327 throw new BpmnError("MSOWorkflowException")
329 logger.debug("COMPLETED ValidateSDNCResponse Process")
332 public void setSuccessfulRollbackStatus (DelegateExecution execution){
334 execution.setVariable("prefix", Prefix)
335 logger.trace("STARTED setSuccessfulRollbackStatus")
338 // Set rolledBack to true, rollbackError to null
339 execution.setVariable("rolledBack", true)
340 execution.setVariable("rollbackError", null)
343 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Exception Occured " +
344 "Processing setSuccessfulRollbackStatus ", "BPMN", ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
345 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
347 logger.trace("COMPLETED setSuccessfulRollbackStatus")
350 public void setFailedRollbackStatus (DelegateExecution execution){
352 execution.setVariable("prefix", Prefix)
353 logger.trace("STARTED setFailedRollbackStatus")
356 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
357 execution.setVariable("rolledBack", false)
358 def rollbackError = execution.getVariable("rollbackError")
359 if (rollbackError == null) {
360 execution.setVariable("rollbackError", 'Caught exception in DoCreateVnfAndModulesRollback')
362 execution.setVariable("rollbackData", null)
365 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Exception Occured " +
366 "Processing setFailedRollbackStatus. ", "BPMN",ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
367 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
369 logger.trace("COMPLETED setFailedRollbackStatus")