Merge "Exception in AAIRestClientImpl.java"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoUpdateE2EServiceInstance.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. \r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts;\r
21 \r
22 import static org.apache.commons.lang3.StringUtils.*;\r
23 import groovy.xml.XmlUtil\r
24 import groovy.json.*\r
25 import groovy.util.XmlParser\r
26 \r
27 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
28 import org.openecomp.mso.bpmn.core.domain.ServiceInstance\r
29 import org.openecomp.mso.bpmn.core.domain.ModelInfo\r
30 import org.openecomp.mso.bpmn.core.domain.Resource\r
31 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
32 import org.openecomp.mso.bpmn.common.scripts.AaiUtil\r
33 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
34 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
35 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils\r
36 import org.openecomp.mso.bpmn.core.RollbackData\r
37 import org.openecomp.mso.bpmn.core.WorkflowException\r
38 import org.openecomp.mso.rest.APIResponse;\r
39 import org.openecomp.mso.rest.RESTClient\r
40 import org.openecomp.mso.rest.RESTConfig\r
41 \r
42 import java.util.UUID;\r
43 import javax.xml.parsers.DocumentBuilder\r
44 import javax.xml.parsers.DocumentBuilderFactory\r
45 \r
46 import org.camunda.bpm.engine.delegate.BpmnError\r
47 import org.camunda.bpm.engine.delegate.DelegateExecution\r
48 import org.json.JSONObject;\r
49 import org.json.JSONArray;\r
50 import org.apache.commons.lang3.*\r
51 import org.apache.commons.codec.binary.Base64;\r
52 import org.springframework.web.util.UriUtils;\r
53 \r
54 \r
55 /**\r
56  * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.\r
57  *\r
58  * Inputs:\r
59  * @param - msoRequestId\r
60  * @param - globalSubscriberId\r
61  * @param - subscriptionServiceType\r
62  * @param - serviceInstanceId\r
63  * @param - serviceInstanceName - O\r
64  * @param - serviceModelInfo\r
65  * @param - productFamilyId\r
66  * @param - disableRollback\r
67  * @param - failExists - TODO\r
68  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)\r
69  * @param - sdncVersion ("1610")\r
70  * @param - serviceDecomposition - Decomposition for R1710 \r
71  * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)\r
72  *\r
73  * Outputs:\r
74  * @param - rollbackData (localRB->null)\r
75  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)\r
76  * @param - WorkflowException\r
77  * @param - serviceInstanceName - (GET from AAI if null in input)\r
78  *\r
79  */\r
80 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {\r
81 \r
82         String Prefix="DUPDSI_"\r
83         private static final String DebugFlag = "isDebugEnabled"\r
84         \r
85         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
86         JsonUtils jsonUtil = new JsonUtils()\r
87 \r
88         public void preProcessRequest (DelegateExecution execution) {\r
89                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
90                 \r
91                 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'          \r
92                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
93                 String msg = ""\r
94                 utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****",  isDebugEnabled)\r
95 \r
96                 try {\r
97                         execution.setVariable("prefix", Prefix)\r
98                         //Inputs\r
99                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology\r
100                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId\r
101                         utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId,  isDebugEnabled)\r
102                         \r
103                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology\r
104                         String serviceType = execution.getVariable("serviceType")\r
105                         utils.log("INFO"," ***** serviceType *****" + serviceType,  isDebugEnabled)\r
106                         \r
107                         //requestDetails.requestParameters. for SDNC assignTopology\r
108                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId\r
109 \r
110                         if (isBlank(globalSubscriberId)) {\r
111                                 msg = "Input globalSubscriberId is null"\r
112                                 utils.log("INFO", msg, isDebugEnabled)\r
113                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
114                         }\r
115                         \r
116                         if (isBlank(serviceType)) {\r
117                                 msg = "Input serviceType is null"\r
118                                 utils.log("INFO", msg, isDebugEnabled)\r
119                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
120                         }\r
121                         \r
122                         //Generated in parent for AAI \r
123                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
124                         if (isBlank(serviceInstanceId)){\r
125                                 msg = "Input serviceInstanceId is null"\r
126                                 utils.log("INFO", msg, isDebugEnabled)\r
127                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
128                         }\r
129                         \r
130                         if (productFamilyId == null) {\r
131                                 execution.setVariable("productFamilyId", "")\r
132                         }\r
133 \r
134                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
135                         String uuiRequest = execution.getVariable("uuiRequest")\r
136                         utils.log("INFO","uuiRequest: " + uuiRequest, isDebugEnabled)\r
137                         \r
138                         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")\r
139                         utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)\r
140                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)\r
141                         execution.setVariable("model-invariant-id-target", modelInvariantUuid)\r
142                         \r
143                         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")\r
144                         utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)\r
145                         execution.setVariable("modelUuid", modelUuid)\r
146                         execution.setVariable("model-version-id-target", modelUuid)\r
147                         \r
148                         String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")\r
149                         utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled)\r
150                         if(serviceModelName == null) {\r
151                                 serviceModelName = ""\r
152                         }\r
153                         execution.setVariable("serviceModelName", serviceModelName)\r
154                                 \r
155                 } catch (BpmnError e) {\r
156                         throw e;\r
157                 } catch (Exception ex){\r
158                         msg = "Exception in preProcessRequest " + ex.getMessage()\r
159                         utils.log("INFO", msg, isDebugEnabled)\r
160                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
161                 }\r
162                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
163         }\r
164         \r
165         public void postProcessAAIGET(DelegateExecution execution) {\r
166                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
167                 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)\r
168                 String msg = ""\r
169 \r
170                 try {\r
171                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
172                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
173                         String serviceType = ""\r
174 \r
175                         if(foundInAAI){\r
176                                 utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)\r
177 \r
178                                 String siData = execution.getVariable("GENGS_service")\r
179                                 utils.log("INFO", "SI Data", isDebugEnabled)\r
180                                 if (isBlank(siData))\r
181                                 {\r
182                                         msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId\r
183                                         utils.log("INFO", msg, isDebugEnabled)\r
184                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
185                                 }\r
186 \r
187                                 utils.log("INFO", "SI Data" + siData, isDebugEnabled)                           \r
188 \r
189                                 // Get Template uuid and version\r
190                                 if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) {\r
191                                         utils.log("INFO", "SI Data model-invariant-id and model-version-id exist:", isDebugEnabled)\r
192 \r
193                                         def modelInvariantId  = utils.getNodeText1(siData, "model-invariant-id")\r
194                                         def modelVersionId  = utils.getNodeText1(siData, "model-version-id")\r
195 \r
196                                         // Set Original Template info\r
197                                         execution.setVariable("model-invariant-id-original", modelInvariantId)\r
198                                         execution.setVariable("model-version-id-original", modelVersionId)\r
199                                 }\r
200                                 \r
201                                 //get related service instances (vnf/network or volume) for delete\r
202                                 if (utils.nodeExists(siData, "relationship-list")) {\r
203                                         utils.log("INFO", "SI Data relationship-list exists:", isDebugEnabled)\r
204 \r
205                                         JSONArray jArray = new JSONArray()\r
206 \r
207                                         XmlParser xmlParser = new XmlParser()\r
208                                         Node root = xmlParser.parseText(siData)\r
209                                         def relation_list = utils.getChildNode(root, 'relationship-list')\r
210                                         def relationships = utils.getIdenticalChildren(relation_list, 'relationship')                                   \r
211 \r
212                                         for (def relation: relationships) {\r
213                                                 def jObj = getRelationShipData(relation, isDebugEnabled)\r
214                                                 jArray.put(jObj)\r
215                                         }\r
216 \r
217                                         execution.setVariable("serviceRelationShip", jArray.toString())\r
218                                 }\r
219                         }else{\r
220                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
221                                 if(!succInAAI){\r
222                                         utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)\r
223                                         WorkflowException workflowException = execution.getVariable("WorkflowException")\r
224                                         utils.logAudit("workflowException: " + workflowException)\r
225                                         if(workflowException != null){\r
226                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
227                                         }\r
228                                         else\r
229                                         {\r
230                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI\r
231                                                 utils.log("INFO", msg, isDebugEnabled)\r
232                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
233                                         }\r
234                                 }\r
235 \r
236                                 utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)\r
237                         }\r
238                 }catch (BpmnError e) {\r
239                         throw e;\r
240                 } catch (Exception ex) {\r
241                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()\r
242                         utils.log("INFO", msg, isDebugEnabled)\r
243                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
244                 }\r
245                 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)\r
246         }\r
247         \r
248         private JSONObject getRelationShipData(node, isDebugEnabled){           \r
249                 JSONObject jObj = new JSONObject()\r
250                 \r
251                 def relation  = utils.nodeToString(node)\r
252                 def rt  = utils.getNodeText1(relation, "related-to")\r
253                 \r
254                 def rl  = utils.getNodeText1(relation, "related-link")\r
255                 utils.log("INFO", "ServiceInstance Related NS/Configuration :" + rl, isDebugEnabled)\r
256                 \r
257                 def rl_datas = utils.getIdenticalChildren(node, "relationship-data")    \r
258                 for(def rl_data : rl_datas) {\r
259                         def eKey =  utils.getChildNodeText(rl_data, "relationship-key")\r
260                         def eValue = utils.getChildNodeText(rl_data, "relationship-value")\r
261 \r
262                         if ((rt == "service-instance" && eKey.equals("service-instance.service-instance-id"))\r
263                         //for overlay/underlay\r
264                         || (rt == "configuration" && eKey.equals("configuration.configuration-id"))){\r
265                                 jObj.put("resourceInstanceId", eValue)\r
266                         }\r
267                 }\r
268 \r
269                 def rl_props = utils.getIdenticalChildren(node, "related-to-property")\r
270                 for(def rl_prop : rl_props) {\r
271                         def eKey =  utils.getChildNodeText(rl_prop, "property-key")\r
272                         def eValue = utils.getChildNodeText(rl_prop, "property-value")\r
273                         if((rt == "service-instance" && eKey.equals("service-instance.service-instance-name"))\r
274                         //for overlay/underlay\r
275                         || (rt == "configuration" && eKey.equals("configuration.configuration-type"))){\r
276                                 jObj.put("resourceType", eValue)\r
277                         }\r
278                 }\r
279 \r
280                 utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled)                \r
281 \r
282                 return jObj\r
283         }\r
284         \r
285         public void preInitResourcesOperStatus(DelegateExecution execution){\r
286         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
287 \r
288         utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)\r
289         try{\r
290             String serviceId = execution.getVariable("serviceInstanceId")\r
291             String operationId = execution.getVariable("operationId")\r
292             String operationType = execution.getVariable("operationType")\r
293             String resourceTemplateUUIDs = ""\r
294             String result = "processing"\r
295             String progress = "10"\r
296             String reason = ""\r
297             String operationContent = "Prepare service updating"\r
298             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)\r
299             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
300             execution.setVariable("serviceInstanceId", serviceId)\r
301             execution.setVariable("operationId", operationId)\r
302             execution.setVariable("operationType", operationType)\r
303 \r
304                         List<Resource> resourceList = new ArrayList<String>()\r
305                         List<Resource> addResourceList =  execution.getVariable("addResourceList")\r
306                         List<Resource> delResourceList =  execution.getVariable("delResourceList")\r
307                         resourceList.addAll(addResourceList)\r
308                         resourceList.addAll(delResourceList)\r
309                         for(Resource resource : resourceList){\r
310                                 resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"\r
311                         }\r
312                         \r
313                         def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
314                         execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
315                         utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
316 \r
317                         String payload =\r
318                                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
319                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
320                         <soapenv:Header/>\r
321                         <soapenv:Body>\r
322                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
323                                                                 <serviceId>${serviceId}</serviceId>\r
324                                                                 <operationId>${operationId}</operationId>\r
325                                                                 <operationType>${operationType}</operationType>\r
326                                                                 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>\r
327                             </ns:initResourceOperationStatus>\r
328                         </soapenv:Body>\r
329                         </soapenv:Envelope>"""\r
330 \r
331                         payload = utils.formatXml(payload)\r
332                         execution.setVariable("CVFMI_initResOperStatusRequest", payload)\r
333                         utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)\r
334                         utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)\r
335 \r
336         }catch(Exception e){\r
337             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)\r
338             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())\r
339         }\r
340         utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  \r
341     }\r
342     \r
343     /**\r
344          * Init the service Operation Status\r
345          */\r
346         public void preUpdateServiceOperationStatus(DelegateExecution execution){\r
347         def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'\r
348                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
349                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
350         \r
351         try{\r
352             String serviceId = execution.getVariable("serviceInstanceId")\r
353             String operationId = execution.getVariable("operationId")\r
354                         String operationType = execution.getVariable("operationType")\r
355             String serviceName = execution.getVariable("serviceInstanceName")\r
356             String userId = ""\r
357             String result = "processing"\r
358             String progress = execution.getVariable("progress")\r
359                         utils.log("INFO", "progress: " + progress , isDebugEnabled)\r
360                         if ("100".equalsIgnoreCase(progress))\r
361                         {\r
362                                 result = "finished"\r
363                         }\r
364             String reason = ""\r
365             String operationContent = "Prepare service : " + execution.getVariable("operationStatus")\r
366                         \r
367             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)\r
368             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
369             execution.setVariable("serviceInstanceId", serviceId)\r
370             execution.setVariable("operationId", operationId)\r
371             execution.setVariable("operationType", operationType)\r
372 \r
373             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
374             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
375             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
376 \r
377             execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")\r
378                         String payload =\r
379                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
380                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
381                         <soapenv:Header/>\r
382                         <soapenv:Body>\r
383                             <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
384                             <serviceId>${serviceId}</serviceId>\r
385                             <operationId>${operationId}</operationId>\r
386                             <serviceName>${serviceName}</serviceName>\r
387                             <operationType>${operationType}</operationType>\r
388                             <userId>${userId}</userId>\r
389                             <result>${result}</result>\r
390                             <operationContent>${operationContent}</operationContent>\r
391                             <progress>${progress}</progress>\r
392                             <reason>${reason}</reason>\r
393                         </ns:updateServiceOperationStatus>\r
394                     </soapenv:Body>\r
395                 </soapenv:Envelope>"""\r
396 \r
397             payload = utils.formatXml(payload)\r
398             execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)\r
399             utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)\r
400            \r
401 \r
402         }catch(Exception e){\r
403             utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)\r
404             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())\r
405         }\r
406         utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)  \r
407         utils.log("INFO", "Exited " + method, isDebugEnabled)\r
408         }\r
409     \r
410     public void postResourcesOperStatus(DelegateExecution execution) {\r
411         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
412     \r
413     }\r
414     \r
415     public void preCompareModelVersions(DelegateExecution execution) {\r
416         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
417 \r
418     }\r
419 \r
420     public void postCompareModelVersions(DelegateExecution execution) {\r
421         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
422     }\r
423     \r
424     public void preProcessForAddResource(DelegateExecution execution) {\r
425         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
426                 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)\r
427                 \r
428             execution.setVariable("operationType", "create")\r
429         \r
430                 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)\r
431     }\r
432 \r
433     public void postProcessForAddResource(DelegateExecution execution) {\r
434         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
435                 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)\r
436                 \r
437                 execution.setVariable("operationType", "update")\r
438 \r
439                 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)\r
440     }\r
441     \r
442     public void preProcessForDeleteResource(DelegateExecution execution) {\r
443         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
444                 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)\r
445                 \r
446                 execution.setVariable("operationType", "delete")\r
447                 \r
448                 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)\r
449 \r
450     }\r
451 \r
452     public void postProcessForDeleteResource(DelegateExecution execution) {\r
453         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
454                 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)\r
455                 \r
456                 execution.setVariable("operationType", "update")\r
457 \r
458                 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)\r
459     } \r
460     \r
461         public void preProcessAAIGET2(DelegateExecution execution) {\r
462         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")   \r
463         }\r
464         \r
465         public void postProcessAAIGET2(DelegateExecution execution) {\r
466                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
467                 utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)\r
468                 String msg = ""\r
469 \r
470                 try {\r
471                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
472                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
473                         if(!succInAAI){\r
474                                 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)\r
475                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
476                                 utils.logAudit("workflowException: " + workflowException)\r
477                                 if(workflowException != null){\r
478                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
479                                 }\r
480                                 else\r
481                                 {\r
482                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI\r
483                                         utils.log("INFO", msg, isDebugEnabled)\r
484                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
485                                 }\r
486                         }\r
487                         else\r
488                         {\r
489                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
490                                 if(foundInAAI){\r
491                                         String aaiService = execution.getVariable("GENGS_service")\r
492                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {\r
493                                                 execution.setVariable("serviceInstanceVersion",  utils.getNodeText1(aaiService, "resource-version"))\r
494                                                 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)\r
495                                         }\r
496                                 }\r
497                         }\r
498                 } catch (BpmnError e) {\r
499                         throw e;\r
500                 } catch (Exception ex) {\r
501                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()\r
502                         utils.log("INFO", msg, isDebugEnabled)\r
503                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
504                 }\r
505                 utils.log("INFO"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)\r
506         }\r
507 \r
508         public void preProcessAAIPUT(DelegateExecution execution) {             \r
509                 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'\r
510                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
511                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
512                 String msg = ""\r
513                 utils.log("INFO"," ***** preProcessAAIPUTt *****",  isDebugEnabled)\r
514 \r
515                 String modelUuid = execution.getVariable("modelUuid")\r
516                 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")\r
517                 execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)\r
518 \r
519                 AaiUtil aaiUriUtil = new AaiUtil(this)\r
520                 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) \r
521                 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
522                 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)\r
523                 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)\r
524                 utils.log("INFO","namespace: " + namespace, isDebugEnabled)\r
525 \r
526                 String serviceInstanceData =\r
527                                 """<service-instance xmlns=\"${namespace}\">\r
528                                <model-version-id">${modelUuid}</model-version-id>\r
529                                  </service-instance>""".trim()\r
530 \r
531                 execution.setVariable("serviceInstanceData", serviceInstanceData)\r
532                 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)\r
533                 utils.logAudit(serviceInstanceData)\r
534                 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)\r
535                 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)\r
536         \r
537                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
538         }       \r
539         \r
540         public void postProcessAAIPUT(DelegateExecution execution) {\r
541                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
542                 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)\r
543                 String msg = ""\r
544                 try {\r
545                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
546                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")\r
547                         if(!succInAAI){\r
548                                 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)\r
549                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
550                                 utils.logAudit("workflowException: " + workflowException)\r
551                                 if(workflowException != null){\r
552                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
553                                 }\r
554                         }\r
555                         else\r
556                         {\r
557                                 //start rollback set up\r
558                                 RollbackData rollbackData = new RollbackData()\r
559                                 def disableRollback = execution.getVariable("disableRollback")\r
560                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())\r
561                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")\r
562                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)\r
563                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))\r
564                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))\r
565                                 execution.setVariable("rollbackData", rollbackData)\r
566                         }\r
567 \r
568                 } catch (BpmnError e) {\r
569                         throw e;\r
570                 } catch (Exception ex) {\r
571                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()\r
572                         utils.log("INFO", msg, isDebugEnabled)\r
573                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
574                 }\r
575                 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)\r
576         }       \r
577 \r
578         public void preProcessRollback (DelegateExecution execution) {\r
579                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
580                 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)\r
581                 try {\r
582                         \r
583                         Object workflowException = execution.getVariable("WorkflowException");\r
584 \r
585                         if (workflowException instanceof WorkflowException) {\r
586                                 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)\r
587                                 execution.setVariable("prevWorkflowException", workflowException);\r
588                                 //execution.setVariable("WorkflowException", null);\r
589                         }\r
590                 } catch (BpmnError e) {\r
591                         utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)\r
592                 } catch(Exception ex) {\r
593                         String msg = "Exception in preProcessRollback. " + ex.getMessage()\r
594                         utils.log("INFO", msg, isDebugEnabled)\r
595                 }\r
596                 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)\r
597         }\r
598 \r
599         public void postProcessRollback (DelegateExecution execution) {\r
600                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
601                 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)\r
602                 String msg = ""\r
603                 try {\r
604                         Object workflowException = execution.getVariable("prevWorkflowException");\r
605                         if (workflowException instanceof WorkflowException) {\r
606                                 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)\r
607                                 execution.setVariable("WorkflowException", workflowException);\r
608                         }\r
609                         execution.setVariable("rollbackData", null)\r
610                 } catch (BpmnError b) {\r
611                         utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)\r
612                         throw b;\r
613                 } catch(Exception ex) {\r
614                         msg = "Exception in postProcessRollback. " + ex.getMessage()\r
615                         utils.log("INFO", msg, isDebugEnabled)\r
616                 }\r
617                 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)\r
618         }\r
619 \r
620         \r
621         public void postConfigRequest(execution){\r
622             //now do noting\r
623         }\r
624 \r
625         \r
626 }\r
627         \r