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=========================================================
20 package org.openecomp.mso.bpmn.vcpe.scripts;
22 import org.openecomp.mso.bpmn.common.scripts.*;
23 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
24 import org.openecomp.mso.bpmn.core.WorkflowException
25 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
26 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
27 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
28 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
29 import org.openecomp.mso.rest.APIResponse
31 import java.util.UUID;
32 import org.camunda.bpm.engine.delegate.BpmnError
33 import org.camunda.bpm.engine.runtime.Execution
34 import org.apache.commons.lang3.*
35 import org.springframework.web.util.UriUtils;
36 import static org.apache.commons.lang3.StringUtils.*
39 * This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process.
44 * @param - msoRequestId
45 * @param - isDebugLogEnabled
46 * @param - disableRollback - O ignored
47 * @param - failNotfound - O
48 * @param - serviceInstanceId
49 * @param - allottedResourceId
52 * @param - rollbackData - N/A
53 * @param - rolledBack - true if no deletions performed
54 * @param - WorkflowException - O
55 * @param - wasDeleted - O (ie not silentSuccess)
58 public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
60 private static final String DebugFlag = "isDebugLogEnabled"
62 String Prefix="DDARTXC_"
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 public void preProcessRequest (Execution execution) {
67 def isDebugEnabled = execution.getVariable(DebugFlag)
69 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
72 execution.setVariable("prefix", Prefix)
75 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
76 if (isBlank(sdncCallbackUrl)) {
77 msg = "URN_mso_workflow_sdncadapter_callback is null"
78 utils.log("DEBUG", msg, isDebugEnabled)
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
81 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
82 utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
85 if (isBlank(execution.getVariable("serviceInstanceId"))){
86 msg = "Input serviceInstanceId is null"
87 utils.log("DEBUG", msg, isDebugEnabled)
88 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
90 if (isBlank(execution.getVariable("allottedResourceId"))){
91 msg = "Input allottedResourceId is null"
92 utils.log("DEBUG", msg, isDebugEnabled)
93 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
97 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
99 } catch (Exception ex){
100 msg = "Exception in preProcessRequest " + ex.getMessage()
101 utils.log("DEBUG", msg, isDebugEnabled)
102 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
104 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
107 public void getAaiAR (Execution execution) {
109 def isDebugEnabled = execution.getVariable(DebugFlag)
110 utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled)
112 String allottedResourceId = execution.getVariable("allottedResourceId")
114 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
115 String ar = arUtils.getARbyId(execution, allottedResourceId)
118 if (isBlank(ar)) // AR was !found
120 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
124 String aaiARPath = execution.getVariable("aaiARPath")
125 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
126 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
128 if (!isBlank(errorMsg)) {
129 utils.log("DEBUG", errorMsg, isDebugEnabled)
130 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
132 utils.log("DEBUG"," ***** getAaiAR *****", isDebugEnabled)
136 // aaiARPath set during query (existing AR)
137 public void updateAaiAROrchStatus(Execution execution, String status){
138 def isDebugEnabled = execution.getVariable(DebugFlag)
139 utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled)
140 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
141 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
142 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
143 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
146 public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) {
148 def isDebugEnabled = execution.getVariable(DebugFlag)
150 utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled)
151 String sdncReq = null
155 String allottedResourceId = execution.getVariable("allottedResourceId")
156 String serviceInstanceId = execution.getVariable("serviceInstanceId")
157 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
159 String callbackUrl = execution.getVariable("sdncCallbackUrl")
160 String requestId = execution.getVariable("msoRequestId")
162 String serviceChainServiceInstanceId = ""
163 String sourceNetworkId = ""
164 String sourceNetworkRole = ""
165 String allottedResourceRole = ""
167 String arModelInfo = ""
168 String modelInvariantId = ""
169 String modelVersion = ""
170 String modelUUId = ""
171 String modelCustomizationId = ""
172 String modelName = ""
176 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
177 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
178 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
179 <sdncadapter:RequestHeader>
180 <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
181 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
182 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
183 <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
184 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
185 </sdncadapter:RequestHeader>
186 <sdncadapterworkflow:SDNCRequestData>
187 <request-information>
188 <request-id>${requestId}</request-id>
189 <request-action>DeleteTunnelXConnInstance</request-action>
194 </request-information>
195 <service-information>
196 <service-id></service-id>
197 <subscription-service-type></subscription-service-type>
198 <ecomp-model-information></ecomp-model-information>
199 <service-instance-id>${parentServiceInstanceId}</service-instance-id>
201 <global-customer-id></global-customer-id>
202 </service-information>
203 <allotted-resource-information>
204 <allotted-resource-id>${allottedResourceId}</allotted-resource-id>
205 <allotted-resource-type>tunnelxconn</allotted-resource-type>
206 <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id>
207 <ecomp-model-information>
208 <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid>
209 <model-uuid>${modelUUId}</model-uuid>
210 <model-customization-uuid>${modelCustomizationId}</model-customization-uuid>
211 <model-version>${modelVersion}</model-version>
212 <model-name>${modelName}</model-name>
213 </ecomp-model-information>
214 </allotted-resource-information>
215 <tunnelxconn-request-input>
216 </tunnelxconn-request-input>
217 </sdncadapterworkflow:SDNCRequestData>
218 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
220 utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled)
221 sdncReq = utils.formatXml(sdncReq)
223 } catch(Exception ex) {
224 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
225 utils.log("DEBUG", msg, isDebugEnabled)
226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
228 utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled)
232 public void preProcessSDNCUnassign(Execution execution) {
234 def isDebugEnabled = execution.getVariable(DebugFlag)
236 utils.log("DEBUG"," ***** preProcessSDNCUnassign *****", isDebugEnabled)
239 String sdncRequestId = UUID.randomUUID().toString()
240 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
241 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
242 utils.logAudit("sdncUnassignRequest: " + sdncUnassignReq)
243 } catch (BpmnError e) {
245 } catch(Exception ex) {
246 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
247 utils.log("DEBUG", msg, isDebugEnabled)
248 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
250 utils.log("DEBUG"," *****Exit preProcessSDNCUnassign *****", isDebugEnabled)
253 public void preProcessSDNCDelete(Execution execution) {
255 def isDebugEnabled = execution.getVariable(DebugFlag)
257 utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled)
260 String sdncRequestId = UUID.randomUUID().toString()
261 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
262 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
263 utils.logAudit("sdncDeleteReq: " + sdncDeleteReq)
264 } catch (BpmnError e) {
266 } catch(Exception ex) {
267 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
268 utils.log("DEBUG", msg, isDebugEnabled)
269 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
271 utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
274 public void preProcessSDNCDeactivate(Execution execution) {
276 def isDebugEnabled = execution.getVariable(DebugFlag)
278 utils.log("DEBUG"," ***** preProcessSDNCDeactivate *****", isDebugEnabled)
281 String sdncRequestId = UUID.randomUUID().toString()
282 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
283 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
284 utils.logAudit("sdncDeactivateReq: " + sdncDeactivateReq)
285 } catch (BpmnError e) {
287 } catch(Exception ex) {
288 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
289 utils.log("DEBUG", msg, isDebugEnabled)
290 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
292 utils.log("DEBUG"," *****Exit preProcessSDNCDeactivate *****", isDebugEnabled)
295 public void validateSDNCResp(Execution execution, String response, String method){
297 def isDebugLogEnabled=execution.getVariable(DebugFlag)
298 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
302 WorkflowException workflowException = execution.getVariable("WorkflowException")
303 utils.logAudit("workflowException: " + workflowException)
305 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
306 utils.logAudit("SDNCResponse: " + response)
308 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
309 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
311 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
312 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled)
315 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
316 utils.log("DEBUG", method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode, isDebugLogEnabled)
317 if (sdncRespCode.equals("404") && "deactivate".equals(method))
319 execution.setVariable("ARNotFoundInSDNC", true)
320 if ("true".equals(execution.getVariable("failNotFound")))
322 msg = "Allotted Resource Not found in SDNC"
323 utils.log("DEBUG", msg, isDebugLogEnabled)
324 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
328 execution.setVariable("wasDeleted", false)
333 throw new BpmnError("MSOWorkflowException")
336 } catch (BpmnError e) {
338 } catch(Exception ex) {
339 msg = "Exception in validateSDNCResp. " + ex.getMessage()
340 utils.log("DEBUG", msg, isDebugLogEnabled)
341 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
343 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
346 public void deleteAaiAR(Execution execution){
347 def isDebugLogEnabled = execution.getVariable(DebugFlag)
349 utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled)
350 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
351 String ar = null //need to get resource-version again
352 String arLink = execution.getVariable("aaiARPath")
353 if (!isBlank(arLink))
355 ar = arUtils.getARbyLink(execution, arLink, "")
357 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
358 } catch (BpmnError e) {
360 }catch(Exception ex){
361 utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled)
362 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
364 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)