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