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 com.att.bpm.scripts
22 import java.io.Serializable;
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.runtime.Execution
27 import org.openecomp.mso.rest.APIResponse
28 import org.openecomp.mso.rest.RESTClient
29 import org.openecomp.mso.rest.RESTConfig
30 import org.openecomp.mso.bpmn.core.RollbackData
31 import org.openecomp.mso.bpmn.core.WorkflowException
35 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
38 ExceptionUtil exceptionUtil = new ExceptionUtil()
40 public void initProcessVariables(Execution execution) {
41 execution.setVariable("prefix",Prefix)
44 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
45 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
46 public void preProcessRequest(Execution execution) {
47 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
49 initProcessVariables(execution)
51 def rollbackData = execution.getVariable("RollbackData")
52 String vnfId = rollbackData.get("VFMODULE", "vnfid")
53 execution.setVariable("DCVFMR_vnfId", vnfId)
54 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
55 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
56 String source = rollbackData.get("VFMODULE", "source")
57 execution.setVariable("DCVFMR_source", source)
58 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
59 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
60 String serviceId = rollbackData.get("VFMODULE", "service-id")
61 execution.setVariable("DCVFMR_serviceId", serviceId)
62 String vnfType = rollbackData.get("VFMODULE", "vnftype")
63 execution.setVariable("DCVFMR_vnfType", vnfType)
64 String vnfName = rollbackData.get("VFMODULE", "vnfname")
65 execution.setVariable("DCVFMR_vnfName", vnfName)
66 String tenantId = rollbackData.get("VFMODULE", "tenantid")
67 execution.setVariable("DCVFMR_tenantId", tenantId)
68 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
69 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
70 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
71 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
72 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
73 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
74 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
75 execution.setVariable("DCVFMR_heatStackId", heatStackId)
76 String requestId = rollbackData.get("VFMODULE", "attmsorequestid")
77 execution.setVariable("DCVFMR_requestId", requestId)
78 //String serviceInstanceId = rollbackData.get("VFMODULE", "attmsoserviceinstanceid")
79 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
80 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
81 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
82 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
83 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
84 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
85 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
87 // formulate the request for PrepareUpdateAAIVfModule
88 String request = """<PrepareUpdateAAIVfModuleRequest>
89 <vnf-id>${vnfId}</vnf-id>
90 <vf-module-id>${vfModuleId}</vf-module-id>
91 <orchestration-status>pending-delete</orchestration-status>
92 </PrepareUpdateAAIVfModuleRequest>""" as String
93 utils.log("DEBUG", "PrepareUpdateAAIVfModuleRequest :" + request, isDebugEnabled)
94 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
97 // build a SDNC vnf-topology-operation request for the specified action
98 // (note: the action passed is expected to be 'changedelete' or 'delete')
99 public void prepSDNCAdapterRequest(Execution execution) {
100 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
101 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
103 def callbackUrl = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
105 String source = execution.getVariable("DCVFMR_source")
106 String serviceId = execution.getVariable("DCVFMR_serviceId")
107 String vnfId = execution.getVariable("DCVFMR_vnfId")
108 String vnfType = execution.getVariable("DCVFMR_vnfType")
109 String vnfName = execution.getVariable("DCVFMR_vnfName")
110 String tenantId = execution.getVariable("DCVFMR_tenantId")
111 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
112 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
113 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
114 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
115 String requestId = execution.getVariable("DCVFMR_requestId")
117 String serviceInstanceIdToSdnc = ""
118 if (srvInstId != null && !srvInstId.isEmpty()) {
119 serviceInstanceIdToSdnc = srvInstId
121 serviceInstandIdToSdnc = vfModuleId
124 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
125 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
128 def requestAction = ""
130 if (doSDNCActivateRollback.equals("true")) {
132 requestAction = "DisconnectVNFRequest"
134 else if (doSDNCAssignRollback.equals("true")) {
136 requestAction = "VNFActivateRequest"
142 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://ecomp.att.com/mso/request/types/v1"
143 xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
144 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
145 <sdncadapter:RequestHeader>
146 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
147 <sdncadapter:SvcInstanceId>${vfModuleId}</sdncadapter:SvcInstanceId>
148 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
149 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
150 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
151 </sdncadapter:RequestHeader>
152 <sdncadapterworkflow:SDNCRequestData>
153 <request-information>
154 <request-id>${requestId}</request-id>
155 <request-action>${requestAction}</request-action>
156 <source>${source}</source>
160 </request-information>
161 <service-information>
162 <service-id>${serviceId}</service-id>
163 <service-type>${serviceId}</service-type>
164 <service-instance-id>${serviceInstanceIdToSdnc}</service-instance-id>
165 <subscriber-name>notsurewecare</subscriber-name>
166 </service-information>
167 <vnf-request-information>
168 <vnf-id>${vfModuleId}</vnf-id>
169 <vnf-type>${vfModuleModelName}</vnf-type>
170 <vnf-name>${vfModuleName}</vnf-name>
171 <generic-vnf-id>${vnfId}</generic-vnf-id>
172 <generic-vnf-name>${vnfName}</generic-vnf-name>
173 <generic-vnf-type>${vnfType}</generic-vnf-type>
174 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
175 <tenant>${tenantId}</tenant>
176 </vnf-request-information>
177 </sdncadapterworkflow:SDNCRequestData>
178 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
180 utils.log("DEBUG", "sdncAdapterWorkflowRequest: " + request, isDebugEnabled)
181 execution.setVariable("sdncAdapterWorkflowRequest", request)
184 // parse the incoming DELETE_VF_MODULE request
185 // and formulate the outgoing VnfAdapterDeleteV1 request
186 public void prepVNFAdapterRequest(Execution execution) {
187 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
188 String requestId = UUID.randomUUID().toString()
189 String origRequestId = execution.getVariable("DCVFMR_requestId")
190 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
191 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
192 String vnfId = execution.getVariable("DCVFMR_vnfId")
193 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
194 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
195 String tenantId = execution.getVariable("DCVFMR_tenantId")
196 def messageId = execution.getVariable('att-mso-request-id') + '-' +
197 System.currentTimeMillis()
198 def notificationUrl = execution.getVariable("URN_mso_workflow_vnfadapter_rest_callback")
199 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
200 if ('true'.equals(useQualifiedHostName)) {
201 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
205 <deleteVfModuleRequest>
206 <cloudSiteId>${aicCloudRegion}</cloudSiteId>
207 <tenantId>${tenantId}</tenantId>
208 <vnfId>${vnfId}</vnfId>
209 <vfModuleId>${vfModuleId}</vfModuleId>
210 <vfModuleStackId>${vfModuleStackId}</vfModuleStackId>
211 <skipAAI>true</skipAAI>
213 <requestId>${origRequestId}</requestId>
214 <serviceInstanceId>${srvInstId}</serviceInstanceId>
216 <messageId>${messageId}</messageId>
217 <notificationUrl>${notificationUrl}</notificationUrl>
218 </deleteVfModuleRequest>
221 utils.log("DEBUG", "vnfAdapterRestV1Request: " + request, isDebugEnabled)
222 execution.setVariable("vnfAdapterRestV1Request", request)
225 // parse the incoming DELETE_VF_MODULE request
226 // and formulate the outgoing UpdateAAIVfModuleRequest request
227 public void prepUpdateAAIVfModule(Execution execution) {
228 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
229 String vnfId = execution.getVariable("DCVFMR_vnfId")
230 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
231 // formulate the request for UpdateAAIVfModule
232 String request = """<UpdateAAIVfModuleRequest>
233 <vnf-id>${vnfId}</vnf-id>
234 <vf-module-id>${vfModuleId}</vf-module-id>
235 <heat-stack-id>DELETE</heat-stack-id>
236 <orchestration-status>deleted</orchestration-status>
237 </UpdateAAIVfModuleRequest>""" as String
238 utils.log("DEBUG", "UpdateAAIVfModuleRequest :" + request, isDebugEnabled)
239 execution.setVariable("UpdateAAIVfModuleRequest", request)
242 // parse the incoming DELETE_VF_MODULE request
243 // and formulate the outgoing DeleteAAIVfModuleRequest request
244 public void prepDeleteAAIVfModule(Execution execution) {
245 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
246 String vnfId = execution.getVariable("DCVFMR_vnfId")
247 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
248 // formulate the request for UpdateAAIVfModule
249 String request = """<DeleteAAIVfModuleRequest>
250 <vnf-id>${vnfId}</vnf-id>
251 <vf-module-id>${vfModuleId}</vf-module-id>
252 </DeleteAAIVfModuleRequest>""" as String
253 utils.log("DEBUG", "DeleteAAIVfModuleRequest :" + request, isDebugEnabled)
254 execution.setVariable("DeleteAAIVfModuleRequest", request)
257 // generates a WorkflowException if
259 public void handleDoDeleteVfModuleFailure(Execution execution) {
260 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
261 utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
262 + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), isDebugEnabled)
263 String processKey = getProcessKey(execution);
264 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
268 public void sdncValidateResponse(Execution execution, String response){
269 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
270 execution.setVariable("prefix",Prefix)
272 WorkflowException workflowException = execution.getVariable("WorkflowException")
273 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
275 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
276 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
278 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
279 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
281 throw new BpmnError("MSOWorkflowException")