a66e88852bea01ed8aba067551539d0ebfe590d8
[so.git] /
1 /*
2  * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
3  */
4 package org.openecomp.mso.bpmn.vcpe.scripts;
5
6 import org.openecomp.mso.bpmn.common.scripts.*;
7 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
8 import org.openecomp.mso.bpmn.core.WorkflowException
9 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
10 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
11 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
12 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
13 import org.openecomp.mso.rest.APIResponse
14
15 import java.util.UUID;
16 import org.camunda.bpm.engine.delegate.BpmnError
17 import org.camunda.bpm.engine.runtime.Execution
18 import org.apache.commons.lang3.*
19 import org.springframework.web.util.UriUtils;
20 import static org.apache.commons.lang3.StringUtils.*
21
22 /**
23  * This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process.
24  *
25  * @author
26  * 
27  * Inputs:
28  * @param - msoRequestId
29  * @param - isDebugLogEnabled
30  * @param - disableRollback - O ignored
31  * @param - failNotfound  - O 
32  * @param - serviceInstanceId
33  * @param - allottedResourceId 
34  *
35  * Outputs:
36  * @param - rollbackData - N/A
37  * @param - rolledBack - true if no deletions performed
38  * @param - WorkflowException - O
39  * @param - wasDeleted - O (ie not silentSuccess)
40  *
41  */
42 public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
43
44         String Prefix="DDARTXC_"
45         ExceptionUtil exceptionUtil = new ExceptionUtil()
46
47         public void preProcessRequest (Execution execution) {
48
49                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
50                 String msg = ""
51                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
52
53                 try {
54                         execution.setVariable("prefix", Prefix)
55
56                         //Config Inputs
57                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
58                         if (isBlank(sdncCallbackUrl)) {
59                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
60                                 utils.log("DEBUG", msg, isDebugEnabled)
61                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
62                         }
63                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
64                         utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
65
66                         //Request Inputs
67                         if (isBlank(execution.getVariable("serviceInstanceId"))){
68                                 msg = "Input serviceInstanceId is null"
69                                 utils.log("DEBUG", msg, isDebugEnabled)
70                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
71                         }
72                         if (isBlank(execution.getVariable("allottedResourceId"))){
73                                 msg = "Input allottedResourceId is null"
74                                 utils.log("DEBUG", msg, isDebugEnabled)
75                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
76                         }
77
78                 }catch(BpmnError b){
79                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
80                         throw b
81                 } catch (Exception ex){
82                         msg = "Exception in preProcessRequest " + ex.getMessage()
83                         utils.log("DEBUG", msg, isDebugEnabled)
84                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
85                 }
86                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
87         }
88
89         public void getAaiAR (Execution execution) {
90
91                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
92                 utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled)
93
94                 String allottedResourceId = execution.getVariable("allottedResourceId")
95
96                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
97                 String ar = arUtils.getARbyId(execution, allottedResourceId)
98
99                 String errorMsg = ""
100                 if (isBlank(ar)) // AR was !found
101                 {
102                         errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
103                 }
104                 else
105                 {
106                         String aaiARPath = execution.getVariable("aaiARPath")
107                         String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
108                         execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
109                 }
110                 if (!isBlank(errorMsg)) {
111                         utils.log("DEBUG", errorMsg, isDebugEnabled)
112                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
113                 }
114                 utils.log("DEBUG"," ***** getAaiAR *****",  isDebugEnabled)
115
116         }
117
118         // aaiARPath set during query (existing AR)
119         public void updateAaiAROrchStatus(Execution execution, String status){
120                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
121                 utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled)
122                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
123                 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) 
124                 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
125                 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
126         }
127
128         public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) {
129
130                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
131                 String msg = ""
132                 utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled)
133                 String sdncReq = null
134
135                 try {
136
137                         String allottedResourceId = execution.getVariable("allottedResourceId")
138                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
139                         String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
140
141                         String callbackUrl = execution.getVariable("sdncCallbackUrl")
142                         String requestId = execution.getVariable("msoRequestId")
143
144                         String serviceChainServiceInstanceId = ""
145                         String sourceNetworkId = ""
146                         String sourceNetworkRole = ""
147                         String allottedResourceRole = ""
148
149                         String arModelInfo = ""
150                         String modelInvariantId = ""
151                         String modelVersion = ""
152                         String modelUUId = ""
153                         String modelCustomizationId = ""
154                         String modelName = ""
155
156
157                         sdncReq =
158                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
159                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
160                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
161                                    <sdncadapter:RequestHeader>
162                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
163                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
164                                                         <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
165                                                         <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
166                                                         <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
167                                         </sdncadapter:RequestHeader>
168                                 <sdncadapterworkflow:SDNCRequestData>
169                                         <request-information>
170                                                 <request-id>${requestId}</request-id>
171                                                 <request-action>DeleteTunnelXConnInstance</request-action>
172                                                 <source>MSO</source>
173                                                 <notification-url/>
174                                                 <order-number/>
175                                                 <order-version/>
176                                         </request-information>
177                                         <service-information>
178                                                 <service-id></service-id>
179                                                 <subscription-service-type></subscription-service-type>
180                                                 <ecomp-model-information></ecomp-model-information>
181                                                 <service-instance-id>${parentServiceInstanceId}</service-instance-id>
182                                                 <subscriber-name/>
183                                                 <global-customer-id></global-customer-id>
184                                         </service-information>
185                                         <allotted-resource-information>
186                                                 <allotted-resource-id>${allottedResourceId}</allotted-resource-id>    
187                                                 <allotted-resource-type>tunnelxconn</allotted-resource-type>
188                                                 <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id>   
189                                                 <ecomp-model-information>
190                                                         <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid>
191                                                         <model-uuid>${modelUUId}</model-uuid>
192                                                         <model-customization-uuid>${modelCustomizationId}</model-customization-uuid>
193                                                         <model-version>${modelVersion}</model-version>
194                                                         <model-name>${modelName}</model-name>
195                                                 </ecomp-model-information>
196                                         </allotted-resource-information>
197                                         <tunnelxconn-request-input>
198                                         </tunnelxconn-request-input>
199                                 </sdncadapterworkflow:SDNCRequestData>
200                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
201
202                         utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled)
203                         sdncReq = utils.formatXml(sdncReq)
204
205                 } catch(Exception ex) {
206                         msg = "Exception in buildSDNCRequest. " + ex.getMessage()
207                         utils.log("DEBUG", msg, isDebugEnabled)
208                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
209                 }
210                 utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled)
211                 return sdncReq
212         }
213
214         public void preProcessSDNCUnassign(Execution execution) {
215
216                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
217                 String msg = ""
218                 utils.log("DEBUG"," ***** preProcessSDNCUnassign *****", isDebugEnabled)
219
220                 try {
221                         String sdncRequestId = UUID.randomUUID().toString()
222                         String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
223                         execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
224                         utils.logAudit("sdncUnassignRequest:  " + sdncUnassignReq)
225                 } catch (BpmnError e) {
226                         throw e;
227                 } catch(Exception ex) {
228                         msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
229                         utils.log("DEBUG", msg, isDebugEnabled)
230                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
231                 }
232                 utils.log("DEBUG"," *****Exit preProcessSDNCUnassign *****", isDebugEnabled)
233         }
234
235         public void preProcessSDNCDelete(Execution execution) {
236
237                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
238                 String msg = ""
239                 utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled)
240
241                 try {
242                         String sdncRequestId = UUID.randomUUID().toString()
243                         String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
244                         execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
245                         utils.logAudit("sdncDeleteReq:  " + sdncDeleteReq)
246                 } catch (BpmnError e) {
247                         throw e;
248                 } catch(Exception ex) {
249                         msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
250                         utils.log("DEBUG", msg, isDebugEnabled)
251                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
252                 }
253                 utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
254         }
255
256         public void preProcessSDNCDeactivate(Execution execution) {
257
258                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
259                 String msg = ""
260                 utils.log("DEBUG"," ***** preProcessSDNCDeactivate *****", isDebugEnabled)
261
262                 try {
263                         String sdncRequestId = UUID.randomUUID().toString()
264                         String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
265                         execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
266                         utils.logAudit("sdncDeactivateReq:  " + sdncDeactivateReq)
267                 } catch (BpmnError e) {
268                         throw e;
269                 } catch(Exception ex) {
270                         msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
271                         utils.log("DEBUG", msg, isDebugEnabled)
272                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
273                 }
274                 utils.log("DEBUG"," *****Exit preProcessSDNCDeactivate *****", isDebugEnabled)
275         }
276
277         public void validateSDNCResp(Execution execution, String response, String method){
278
279                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
280                 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
281                 String msg = ""
282
283                 try {
284                         WorkflowException workflowException = execution.getVariable("WorkflowException")
285                         utils.logAudit("workflowException: " + workflowException)
286
287                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
288                         utils.logAudit("SDNCResponse: " + response)
289
290                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
291                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
292
293                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
294                                 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + response, isDebugLogEnabled)
295
296                         }else{
297                                 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
298                                 utils.log("DEBUG", method + " AllottedResource received error response from SDNC. ResponseCode:" +  sdncRespCode, isDebugLogEnabled)
299                                 if (sdncRespCode.equals("404") && "deactivate".equals(method))
300                                 {
301                                         execution.setVariable("ARNotFoundInSDNC", true)
302                                         if ("true".equals(execution.getVariable("failNotFound")))
303                                         {
304                                                 msg = "Allotted Resource Not found in SDNC"
305                                                 utils.log("DEBUG", msg, isDebugEnabled)
306                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
307                                         }
308                                         else
309                                         {
310                                                 execution.setVariable("wasDeleted", false)
311                                         }
312                                 }
313                                 else
314                                 {
315                                         throw new BpmnError("MSOWorkflowException")
316                                 }
317                         }
318                 } catch (BpmnError e) {
319                         throw e;
320                 } catch(Exception ex) {
321                         msg = "Exception in validateSDNCResp. " + ex.getMessage()
322                         utils.log("DEBUG", msg, isDebugEnabled)
323                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
324                 }
325                 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
326         }
327
328         public void deleteAaiAR(Execution execution){
329                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
330                 try{
331                         utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled)
332                         AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
333                         String ar = null //need to get resource-version again 
334                         String arLink = execution.getVariable("aaiARPath")
335                         if (!isBlank(arLink))
336                         {
337                                 ar = arUtils.getARbyLink(execution, arLink, "")
338                         }
339                         arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
340                 } catch (BpmnError e) {
341                         throw e;
342                 }catch(Exception ex){
343                         utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled)
344                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
345                 }
346                 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)
347         }
348
349 }