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 DoDeleteVfModule extends AbstractServiceTaskProcessor{
37 def Prefix="DoDVfMod_"
39 public void initProcessVariables(Execution execution) {
40 execution.setVariable("prefix",Prefix)
43 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
44 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
45 public void preProcessRequest(Execution execution) {
46 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
47 def xml = execution.getVariable("DoDeleteVfModuleRequest")
48 utils.logAudit("DoDeleteVfModule Request: " + xml)
50 utils.log("DEBUG", "input request xml: " + xml, isDebugEnabled)
51 initProcessVariables(execution)
52 def vnfId = utils.getNodeText1(xml,"vnf-id")
53 def vfModuleId = utils.getNodeText1(xml,"vf-module-id")
54 // execution.setVariable("DoDVfMod_vnfId", vnfId)
55 // execution.setVariable("DoDVfMod_vfModuleId", vfModuleId)
56 // formulate the request for PrepareUpdateAAIVfModule
57 String request = """<PrepareUpdateAAIVfModuleRequest>
58 <vnf-id>${vnfId}</vnf-id>
59 <vf-module-id>${vfModuleId}</vf-module-id>
60 <orchestration-status>pending-delete</orchestration-status>
61 </PrepareUpdateAAIVfModuleRequest>""" as String
62 utils.log("DEBUG", "PrepareUpdateAAIVfModuleRequest :" + request, isDebugEnabled)
63 utils.logAudit("UpdateAAIVfModule Request: " + request)
64 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
65 execution.setVariable("DoDVfMod_vfModuleFromAAI", null)
68 // build a SDNC vnf-topology-operation request for the specified action
69 // (note: the action passed is expected to be 'changedelete' or 'delete')
70 public void prepSDNCAdapterRequest(Execution execution, String action) {
71 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
72 def xml = execution.getVariable("DoDeleteVfModuleRequest")
73 utils.logAudit("DoDeleteVfModule Request: " + xml)
75 def srvInstId = execution.getVariable("att-mso-service-instance-id")
76 def callbackUrl = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
77 utils.log("DEBUG", "input request xml: " + xml, isDebugEnabled)
81 requestId = execution.getVariable("att-mso-request-id")
82 } catch (Exception ex) {
83 requestId = utils.getNodeText1(xml, "request-id")
86 String source = utils.getNodeText1(xml, "source")
87 String serviceId = utils.getNodeText1(xml, "service-id")
88 String vnfId = utils.getNodeText1(xml, "vnf-id")
89 String vnfType = utils.getNodeText1(xml, "vnf-type")
90 String vnfName = utils.getNodeText1(xml, "vnf-name")
91 String tenantId = utils.getNodeText1(xml, "tenant-id")
92 String vfModuleId = utils.getNodeText1(xml, "vf-module-id")
93 String serviceInstanceIdToSdnc = ""
94 if (xml.contains("service-instance-id")) {
95 serviceInstanceIdToSdnc = utils.getNodeText1(xml, "service-instance-id")
97 serviceInstanceIdToSdnc = vfModuleId
99 String vfModuleName = utils.getNodeText1(xml, "vf-module-name")
100 // Get vfModuleName from AAI response if it was not specified on the request
101 if (vfModuleName == null || vfModuleName.isEmpty()) {
102 if (execution.getVariable("DoDVfMod_vfModuleFromAAI") != null) {
103 VfModule vfModuleFromAAI = execution.getVariable("DoDVfMod_vfModuleFromAAI")
104 vfModuleName = vfModuleFromAAI.getElementText("vf-module-name")
107 String vfModuleModelName = utils.getNodeText1(xml, "vf-module-model-name")
108 String cloudSiteId = utils.getNodeText1(xml, "aic-cloud-region")
109 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://ecomp.att.com/mso/request/types/v1"
110 xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
111 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
112 <sdncadapter:RequestHeader>
113 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
114 <sdncadapter:SvcInstanceId>${vfModuleId}</sdncadapter:SvcInstanceId>
115 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
116 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
117 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
118 </sdncadapter:RequestHeader>
119 <sdncadapterworkflow:SDNCRequestData>
120 <request-information>
121 <request-id>${requestId}</request-id>
122 <request-action>DisconnectVNFRequest</request-action>
123 <source>${source}</source>
127 </request-information>
128 <service-information>
129 <service-id>${serviceId}</service-id>
130 <service-type>${serviceId}</service-type>
131 <service-instance-id>${serviceInstanceIdToSdnc}</service-instance-id>
132 <subscriber-name>notsurewecare</subscriber-name>
133 </service-information>
134 <vnf-request-information>
135 <vnf-id>${vfModuleId}</vnf-id>
136 <vnf-type>${vfModuleModelName}</vnf-type>
137 <vnf-name>${vfModuleName}</vnf-name>
138 <generic-vnf-id>${vnfId}</generic-vnf-id>
139 <generic-vnf-name>${vnfName}</generic-vnf-name>
140 <generic-vnf-type>${vnfType}</generic-vnf-type>
141 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
142 <tenant>${tenantId}</tenant>
143 </vnf-request-information>
144 </sdncadapterworkflow:SDNCRequestData>
145 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
147 utils.log("DEBUG", "sdncAdapterWorkflowRequest: " + request, isDebugEnabled)
148 utils.logAudit("DoDeleteVfModule - SDNCAdapterWorkflowRequest: " + request)
149 execution.setVariable("sdncAdapterWorkflowRequest", request)
152 // parse the incoming DELETE_VF_MODULE request
153 // and formulate the outgoing VnfAdapterDeleteV1 request
154 public void prepVNFAdapterRequest(Execution execution) {
155 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
156 def xml = execution.getVariable("DoDeleteVfModuleRequest")
157 def requestId = UUID.randomUUID().toString()
158 def origRequestId = execution.getVariable('att-mso-request-id')
159 def srvInstId = execution.getVariable('att-mso-service-instance-id')
160 def aicCloudRegion = utils.getNodeText1(xml, "aic-cloud-region")
161 def vnfId = utils.getNodeText1(xml, "vnf-id")
162 def vnfName = utils.getNodeText1(xml, "vnf-name")
163 def vfModuleId = utils.getNodeText1(xml, "vf-module-id")
164 def vfModuleStackId = execution.getVariable('DoDVfMod_heatStackId')
165 def tenantId = utils.getNodeText1(xml, "tenant-id")
166 def messageId = execution.getVariable('att-mso-request-id') + '-' +
167 System.currentTimeMillis()
168 def notificationUrl = execution.getVariable("URN_mso_workflow_vnfadapter_rest_callback")
169 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
170 if ('true'.equals(useQualifiedHostName)) {
171 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
175 <deleteVfModuleRequest>
176 <cloudSiteId>${aicCloudRegion}</cloudSiteId>
177 <tenantId>${tenantId}</tenantId>
178 <vnfId>${vnfId}</vnfId>
179 <vfModuleId>${vfModuleId}</vfModuleId>
180 <vfModuleStackId>${vfModuleStackId}</vfModuleStackId>
181 <skipAAI>true</skipAAI>
183 <requestId>${origRequestId}</requestId>
184 <serviceInstanceId>${srvInstId}</serviceInstanceId>
186 <messageId>${messageId}</messageId>
187 <notificationUrl>${notificationUrl}</notificationUrl>
188 </deleteVfModuleRequest>
191 utils.log("DEBUG", "vnfAdapterRestV1Request: " + request, isDebugEnabled)
192 utils.logAudit("deleteVfModuleRequest: " + request)
193 execution.setVariable("vnfAdapterRestV1Request", request)
196 // parse the incoming DELETE_VF_MODULE request
197 // and formulate the outgoing UpdateAAIVfModuleRequest request
198 public void prepUpdateAAIVfModule(Execution execution) {
199 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
200 def xml = execution.getVariable("DoDeleteVfModuleRequest")
201 utils.log("DEBUG", "input request xml: " + xml, isDebugEnabled)
202 initProcessVariables(execution)
203 def vnfId = utils.getNodeText1(xml,"vnf-id")
204 def vfModuleId = utils.getNodeText1(xml,"vf-module-id")
205 // formulate the request for UpdateAAIVfModule
206 String request = """<UpdateAAIVfModuleRequest>
207 <vnf-id>${vnfId}</vnf-id>
208 <vf-module-id>${vfModuleId}</vf-module-id>
209 <heat-stack-id>DELETE</heat-stack-id>
210 <orchestration-status>deleted</orchestration-status>
211 </UpdateAAIVfModuleRequest>""" as String
212 utils.log("DEBUG", "UpdateAAIVfModuleRequest :" + request, isDebugEnabled)
213 utils.logAudit("UpdateAAIVfModuleRequest: " + request)
214 execution.setVariable("UpdateAAIVfModuleRequest", request)
217 // parse the incoming DELETE_VF_MODULE request
218 // and formulate the outgoing DeleteAAIVfModuleRequest request
219 public void prepDeleteAAIVfModule(Execution execution) {
220 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
221 def xml = execution.getVariable("DoDeleteVfModuleRequest")
222 utils.log("DEBUG", "input request xml: " + xml, isDebugEnabled)
223 initProcessVariables(execution)
224 def vnfId = utils.getNodeText1(xml,"vnf-id")
225 def vfModuleId = utils.getNodeText1(xml,"vf-module-id")
226 // formulate the request for UpdateAAIVfModule
227 String request = """<DeleteAAIVfModuleRequest>
228 <vnf-id>${vnfId}</vnf-id>
229 <vf-module-id>${vfModuleId}</vf-module-id>
230 </DeleteAAIVfModuleRequest>""" as String
231 utils.log("DEBUG", "DeleteAAIVfModuleRequest :" + request, isDebugEnabled)
232 utils.logAudit("DeleteAAIVfModuleRequest: " + request)
233 execution.setVariable("DeleteAAIVfModuleRequest", request)
236 // generates a WorkflowException if
238 public void handleDoDeleteVfModuleFailure(Execution execution) {
239 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
240 utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
241 + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), isDebugEnabled)
242 String processKey = getProcessKey(execution);
243 WorkflowException exception = new WorkflowException(processKey, 5000,
244 execution.getVariable("DoDVfMod_deleteGenericVnfResponse"))
245 execution.setVariable("WorkflowException", exception)
248 public void sdncValidateResponse(Execution execution, String response){
249 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
250 execution.setVariable("prefix",Prefix)
252 WorkflowException workflowException = execution.getVariable("WorkflowException")
253 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
255 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
256 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
258 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
259 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
261 throw new BpmnError("MSOWorkflowException")