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.delegate.DelegateExecution
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 - globalCustomerId - O
50 * @param - subscriptionServiceType - O
51 * @param - parentServiceInstanceId
52 * @param - allottedResourceId
55 * @param - rollbackData - N/A
56 * @param - rolledBack - true if no deletions performed
57 * @param - WorkflowException - O
58 * @param - wasDeleted - O (ie not silentSuccess)
61 public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
63 private static final String DebugFlag = "isDebugLogEnabled"
65 String Prefix="DDARTXC_"
66 ExceptionUtil exceptionUtil = new ExceptionUtil()
68 public void preProcessRequest (DelegateExecution execution) {
70 def isDebugEnabled = execution.getVariable(DebugFlag)
72 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
75 execution.setVariable("prefix", Prefix)
78 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
79 if (isBlank(sdncCallbackUrl)) {
80 msg = "URN_mso_workflow_sdncadapter_callback is null"
81 utils.log("DEBUG", msg, isDebugEnabled)
82 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
84 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
85 utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
88 if (isBlank(execution.getVariable("serviceInstanceId"))){
89 msg = "Input serviceInstanceId is null"
90 utils.log("DEBUG", msg, isDebugEnabled)
91 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
93 if (isBlank(execution.getVariable("allottedResourceId"))){
94 msg = "Input allottedResourceId is null"
95 utils.log("DEBUG", msg, isDebugEnabled)
96 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
100 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
102 } catch (Exception ex){
103 msg = "Exception in preProcessRequest " + ex.getMessage()
104 utils.log("DEBUG", msg, isDebugEnabled)
105 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
107 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
110 public void getAaiAR (DelegateExecution execution) {
112 def isDebugEnabled = execution.getVariable(DebugFlag)
113 utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled)
115 String allottedResourceId = execution.getVariable("allottedResourceId")
117 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
118 String ar = arUtils.getARbyId(execution, allottedResourceId)
121 if (isBlank(ar)) // AR was !found
123 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
127 String aaiARPath = execution.getVariable("aaiARPath")
128 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
129 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
131 if (!isBlank(errorMsg)) {
132 utils.log("DEBUG", errorMsg, isDebugEnabled)
133 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
135 utils.log("DEBUG"," ***** getAaiAR *****", isDebugEnabled)
139 // aaiARPath set during query (existing AR)
140 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
141 def isDebugEnabled = execution.getVariable(DebugFlag)
142 utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled)
143 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
144 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
145 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
146 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
149 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
151 def isDebugEnabled = execution.getVariable(DebugFlag)
153 utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled)
154 String sdncReq = null
158 String allottedResourceId = execution.getVariable("allottedResourceId")
159 String serviceInstanceId = execution.getVariable("serviceInstanceId")
160 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
161 String globalCustomerId = execution.getVariable("globalCustomerId")
162 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
164 String callbackUrl = execution.getVariable("sdncCallbackUrl")
165 String requestId = execution.getVariable("msoRequestId")
167 String serviceChainServiceInstanceId = ""
168 String sourceNetworkId = ""
169 String sourceNetworkRole = ""
170 String allottedResourceRole = ""
172 String arModelInfo = ""
173 String modelInvariantId = ""
174 String modelVersion = ""
175 String modelUUId = ""
176 String modelCustomizationId = ""
177 String modelName = ""
181 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
182 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
183 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
184 <sdncadapter:RequestHeader>
185 <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
186 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
187 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
188 <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
189 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
190 </sdncadapter:RequestHeader>
191 <sdncadapterworkflow:SDNCRequestData>
192 <request-information>
193 <request-id>${requestId}</request-id>
194 <request-action>DeleteTunnelXConnInstance</request-action>
199 </request-information>
200 <service-information>
201 <service-id></service-id>
202 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
203 <onap-model-information></onap-model-information>
204 <service-instance-id>${serviceInstanceId}</service-instance-id>
206 <global-customer-id>${globalCustomerId}</global-customer-id>
207 </service-information>
208 <allotted-resource-information>
209 <allotted-resource-id>${allottedResourceId}</allotted-resource-id>
210 <allotted-resource-type>tunnelxconn</allotted-resource-type>
211 <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id>
212 <onap-model-information>
213 <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid>
214 <model-uuid>${modelUUId}</model-uuid>
215 <model-customization-uuid>${modelCustomizationId}</model-customization-uuid>
216 <model-version>${modelVersion}</model-version>
217 <model-name>${modelName}</model-name>
218 </onap-model-information>
219 </allotted-resource-information>
220 <tunnelxconn-request-input>
221 </tunnelxconn-request-input>
222 </sdncadapterworkflow:SDNCRequestData>
223 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
225 utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled)
226 sdncReq = utils.formatXml(sdncReq)
228 } catch(Exception ex) {
229 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
230 utils.log("DEBUG", msg, isDebugEnabled)
231 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
233 utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled)
237 public void preProcessSDNCUnassign(DelegateExecution execution) {
239 def isDebugEnabled = execution.getVariable(DebugFlag)
241 utils.log("DEBUG"," ***** preProcessSDNCUnassign *****", isDebugEnabled)
244 String sdncRequestId = UUID.randomUUID().toString()
245 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
246 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
247 utils.logAudit("sdncUnassignRequest: " + sdncUnassignReq)
248 } catch (BpmnError e) {
250 } catch(Exception ex) {
251 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
252 utils.log("DEBUG", msg, isDebugEnabled)
253 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
255 utils.log("DEBUG"," *****Exit preProcessSDNCUnassign *****", isDebugEnabled)
258 public void preProcessSDNCDelete(DelegateExecution execution) {
260 def isDebugEnabled = execution.getVariable(DebugFlag)
262 utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled)
265 String sdncRequestId = UUID.randomUUID().toString()
266 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
267 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
268 utils.logAudit("sdncDeleteReq: " + sdncDeleteReq)
269 } catch (BpmnError e) {
271 } catch(Exception ex) {
272 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
273 utils.log("DEBUG", msg, isDebugEnabled)
274 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
276 utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
279 public void preProcessSDNCDeactivate(DelegateExecution execution) {
281 def isDebugEnabled = execution.getVariable(DebugFlag)
283 utils.log("DEBUG"," ***** preProcessSDNCDeactivate *****", isDebugEnabled)
286 String sdncRequestId = UUID.randomUUID().toString()
287 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
288 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
289 utils.logAudit("sdncDeactivateReq: " + sdncDeactivateReq)
290 } catch (BpmnError e) {
292 } catch(Exception ex) {
293 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
294 utils.log("DEBUG", msg, isDebugEnabled)
295 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
297 utils.log("DEBUG"," *****Exit preProcessSDNCDeactivate *****", isDebugEnabled)
300 public void validateSDNCResp(DelegateExecution execution, String response, String method){
302 def isDebugLogEnabled=execution.getVariable(DebugFlag)
303 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
307 WorkflowException workflowException = execution.getVariable("WorkflowException")
308 utils.logAudit("workflowException: " + workflowException)
310 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
311 utils.logAudit("SDNCResponse: " + response)
313 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
314 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
316 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
317 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled)
320 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
321 utils.log("DEBUG", method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode, isDebugLogEnabled)
322 if (sdncRespCode.equals("404") && "deactivate".equals(method))
324 execution.setVariable("ARNotFoundInSDNC", true)
325 if ("true".equals(execution.getVariable("failNotFound")))
327 msg = "Allotted Resource Not found in SDNC"
328 utils.log("DEBUG", msg, isDebugLogEnabled)
329 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
333 execution.setVariable("wasDeleted", false)
338 throw new BpmnError("MSOWorkflowException")
341 } catch (BpmnError e) {
343 } catch(Exception ex) {
344 msg = "Exception in validateSDNCResp. " + ex.getMessage()
345 utils.log("DEBUG", msg, isDebugLogEnabled)
346 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
348 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
351 public void deleteAaiAR(DelegateExecution execution){
352 def isDebugLogEnabled = execution.getVariable(DebugFlag)
354 utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled)
355 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
356 String ar = null //need to get resource-version again
357 String arLink = execution.getVariable("aaiARPath")
358 if (!isBlank(arLink))
360 ar = arUtils.getARbyLink(execution, arLink, "")
362 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
363 } catch (BpmnError e) {
365 }catch(Exception ex){
366 utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled)
367 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
369 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)