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.ErrorCode
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution;
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.MsoUtils
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.bpmn.core.RollbackData
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.logger.MessageEnum
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
40 * This class supports the macro VID Flow
41 * with the rollback of a creation of a generic vnf and related VF modules.
43 class DoCreateVnfAndModulesRollback extends AbstractServiceTaskProcessor {
45 private static final Logger logger = LoggerFactory.getLogger( DoCreateVnfAndModulesRollback.class);
46 String Prefix="DCVAMR_"
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 JsonUtils jsonUtil = new JsonUtils()
52 * This method gets and validates the incoming
58 public void preProcessRequest(DelegateExecution execution) {
60 execution.setVariable("prefix",Prefix)
61 logger.debug("STARTED DoCreateVnfAndModulesRollback PreProcessRequest Process")
64 // Get Rollback Variables
66 def rollbackData = execution.getVariable("rollbackData")
67 logger.debug("Incoming RollbackData is: " + rollbackData.toString())
68 execution.setVariable("rolledBack", null)
69 execution.setVariable("rollbackError", null)
71 if (execution.getVariable("disableRollback").equals("true" ))
73 execution.setVariable("skipRollback", true)
76 String vnfId = rollbackData.get("VNF", "vnfId")
77 logger.debug("Rollback vnfId is: " + vnfId)
78 execution.setVariable("DCVAMR_vnfId", vnfId)
80 execution.setVariable("mso-request-id", execution.getVariable("msoRequestId"))
82 execution.setVariable("DCVAMR_rollbackSDNCAssign", rollbackData.get("VNF", "rollbackSDNCAssign"))
83 execution.setVariable("DCVAMR_rollbackSDNCActivate", rollbackData.get("VNF", "rollbackSDNCActivate"))
84 execution.setVariable("DCVAMR_rollbackVnfCreate", rollbackData.get("VNF", "rollbackVnfCreate"))
86 String sdncCallbackUrl = rollbackData.get("VNF", "sdncCallbackUrl")
87 logger.debug("Rollback sdncCallbackUrl is: " + sdncCallbackUrl)
88 execution.setVariable("DCVAMR_sdncCallbackUrl", sdncCallbackUrl)
90 String tenantId= rollbackData.get("VNF", "tenantId")
91 logger.debug("Rollback tenantId is: " + tenantId)
92 execution.setVariable("DCVAMR_tenantId", tenantId)
94 String source= rollbackData.get("VNF", "source")
95 logger.debug("Rollback source is: " + source)
96 execution.setVariable("DCVAMR_source", source)
98 String serviceInstanceId = rollbackData.get("VNF", "serviceInstanceId")
99 logger.debug("Rollback serviceInstanceId is: " + serviceInstanceId)
100 execution.setVariable("DCVAMR_serviceInstanceId", serviceInstanceId)
102 String cloudSiteId = rollbackData.get("VNF", "cloudSiteId")
103 logger.debug("Rollback cloudSiteId is: " + cloudSiteId)
104 execution.setVariable("DCVAMR_cloudSiteId", cloudSiteId)
106 def numOfAddOnModulesString = rollbackData.get("VNFANDMODULES", "numOfCreatedAddOnModules")
107 int numOfAddOnModules = 0
108 if (numOfAddOnModulesString != null) {
109 numOfAddOnModules = Integer.parseInt(numOfAddOnModulesString)
111 execution.setVariable("DCVAMR_numOfAddOnModules", numOfAddOnModules)
113 def baseVfModuleRollbackMap = rollbackData.get("VFMODULE_BASE")
114 if (baseVfModuleRollbackMap == null) {
115 // there are no VF Modules to delete
116 execution.setVariable("DCVAMR_numOfModulesToDelete", 0)
119 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfAddOnModules + 1)
122 // Set aLaCarte to false
123 execution.setVariable("DCVAMR_aLaCarte", false)
126 logger.debug("Rethrowing MSOWorkflowException")
129 logger.debug(" Error Occured in DoCreateVnfAndModulesRollback PreProcessRequest method!" + e.getMessage())
130 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnfAndModulesRollback PreProcessRequest")
133 logger.trace("COMPLETED DoCreateVnfAndModulesRollback PreProcessRequest Process")
138 public void preProcessCreateVfModuleRollback(DelegateExecution execution){
140 execution.setVariable("prefix", Prefix)
141 logger.trace("STARTED preProcessCreateVfModuleRollback")
145 def rollbackData = execution.getVariable("rollbackData")
147 def vfModuleRollbackData = new RollbackData()
149 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
150 logger.debug("numOfModulesToDelete: " + numOfModulesToDelete)
153 if (numOfModulesToDelete > 1) {
154 int addOnModuleIndex = numOfModulesToDelete - 1
155 moduleMap = rollbackData.get("VFMODULE_ADDON_" + addOnModuleIndex)
156 logger.debug("Removing ADDON VF module # " + addOnModuleIndex)
159 moduleMap = rollbackData.get("VFMODULE_BASE")
160 logger.debug("Removing BASE VF module")
162 moduleMap.each{ k, v -> vfModuleRollbackData.put("VFMODULE", "${k}","${v}") }
163 execution.setVariable("DCVAMR_RollbackData", vfModuleRollbackData)
166 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
167 "Exception Occured Processing preProcessCreateVfModuleRollback ", "BPMN",
168 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
169 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessCreateVfModuleRollback Method:\n" + e.getMessage())
171 logger.trace("COMPLETED preProcessCreateVfModuleRollback")
175 public void postProcessCreateVfModuleRollback(DelegateExecution execution){
177 execution.setVariable("prefix", Prefix)
178 logger.trace("STARTED postProcessCreateVfModuleRollback")
179 def rolledBack = false
182 rolledBack = execution.getVariable("DCVM_rolledBack")
183 def numOfModulesToDelete = execution.getVariable("DCVAMR_numOfModulesToDelete")
184 execution.setVariable("DCVAMR_numOfModulesToDelete", numOfModulesToDelete - 1)
186 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
187 "Exception Occured Processing postProcessCreateVfModuleRollback ", "BPMN",
188 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
189 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during postProcessCreateVfModuleRollback Method:\n" + e.getMessage())
191 if (rolledBack == false) {
192 logger.debug("Failure on DoCreateVfModuleRollback")
193 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
194 "Unsuccessful rollback of DoCreateVfModule ", "BPMN",
195 ErrorCode.UnknownError.getValue());
196 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during rollback of DoCreateVfModule")
198 logger.trace("COMPLETED postProcessCreateVfModuleRollback")
202 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
204 execution.setVariable("prefix", Prefix)
205 logger.trace("STARTED preProcessSDNCDeactivateRequest")
206 def vnfId = execution.getVariable("vnfId")
207 def serviceInstanceId = execution.getVariable("serviceInstanceId")
212 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
214 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
215 execution.setVariable(Prefix + "deactivateSDNCRequest", deactivateSDNCRequest)
216 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
219 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
220 "Exception Occured Processing preProcessSDNCDeactivateRequest ", "BPMN",
221 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
222 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
224 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
227 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
228 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
229 'execution=' + execution.getId() +
231 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
232 logger.trace('Entered ' + method)
233 execution.setVariable("prefix", Prefix)
234 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
236 String vnfId = execution.getVariable("vnfId")
237 String serviceInstanceId = execution.getVariable("serviceInstanceId")
239 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
241 execution.setVariable(Prefix + "unassignSDNCRequest", unassignSDNCRequest)
242 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
245 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
246 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
248 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
251 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
253 String uuid = execution.getVariable('testReqId') // for junits
255 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
257 def callbackURL = execution.getVariable(Prefix + "sdncCallbackUrl")
258 def requestId = execution.getVariable("msoRequestId")
259 def tenantId = execution.getVariable(Prefix + "tenantId")
260 def source = execution.getVariable(Prefix + "source")
261 def vnfId = execution.getVariable(Prefix + "vnfId")
262 def serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
263 def cloudSiteId = execution.getVariable(Prefix + "cloudSiteId")
266 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
267 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
268 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
269 <sdncadapter:RequestHeader>
270 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
271 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
272 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
273 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
274 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
275 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
276 </sdncadapter:RequestHeader>
277 <sdncadapterworkflow:SDNCRequestData>
278 <request-information>
279 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
280 <request-action>DeleteVnfInstance</request-action>
281 <source>${MsoUtils.xmlEscape(source)}</source>
285 </request-information>
286 <service-information>
288 <subscription-service-type/>
289 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
290 <global-customer-id/>
291 </service-information>
293 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
298 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
299 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
301 </sdncadapterworkflow:SDNCRequestData>
302 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
304 logger.debug("sdncRequest: " + sdncRequest)
308 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
310 execution.setVariable("prefix",Prefix)
311 logger.debug("STARTED ValidateSDNCResponse Process")
313 WorkflowException workflowException = execution.getVariable("WorkflowException")
314 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
316 logger.debug("workflowException: " + workflowException)
318 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
319 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
321 String sdncResponse = response
322 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
323 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
325 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
326 throw new BpmnError("MSOWorkflowException")
328 logger.debug("COMPLETED ValidateSDNCResponse Process")
331 public void setSuccessfulRollbackStatus (DelegateExecution execution){
333 execution.setVariable("prefix", Prefix)
334 logger.trace("STARTED setSuccessfulRollbackStatus")
337 // Set rolledBack to true, rollbackError to null
338 execution.setVariable("rolledBack", true)
339 execution.setVariable("rollbackError", null)
342 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Exception Occured " +
343 "Processing setSuccessfulRollbackStatus ", "BPMN", ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
344 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
346 logger.trace("COMPLETED setSuccessfulRollbackStatus")
349 public void setFailedRollbackStatus (DelegateExecution execution){
351 execution.setVariable("prefix", Prefix)
352 logger.trace("STARTED setFailedRollbackStatus")
355 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
356 execution.setVariable("rolledBack", false)
357 def rollbackError = execution.getVariable("rollbackError")
358 if (rollbackError == null) {
359 execution.setVariable("rollbackError", 'Caught exception in DoCreateVnfAndModulesRollback')
361 execution.setVariable("rollbackData", null)
364 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Exception Occured " +
365 "Processing setFailedRollbackStatus. ", "BPMN",ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
366 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
368 logger.trace("COMPLETED setFailedRollbackStatus")