Merge "pnf ready event consumer"
[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 \r
26 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
27 import org.openecomp.mso.bpmn.core.domain.ServiceInstance\r
28 import org.openecomp.mso.bpmn.core.domain.ModelInfo\r
29 import org.openecomp.mso.bpmn.core.domain.Resource\r
30 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
31 import org.openecomp.mso.bpmn.common.scripts.AaiUtil\r
32 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
33 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
34 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils\r
35 import org.openecomp.mso.bpmn.core.RollbackData\r
36 import org.openecomp.mso.bpmn.core.WorkflowException\r
37 import org.openecomp.mso.rest.APIResponse;\r
38 import org.openecomp.mso.rest.RESTClient\r
39 import org.openecomp.mso.rest.RESTConfig\r
40 \r
41 import java.util.UUID;\r
42 import javax.xml.parsers.DocumentBuilder\r
43 import javax.xml.parsers.DocumentBuilderFactory\r
44 \r
45 import org.camunda.bpm.engine.delegate.BpmnError\r
46 import org.camunda.bpm.engine.delegate.DelegateExecution\r
47 import org.json.JSONObject;\r
48 import org.json.JSONArray;\r
49 import org.apache.commons.lang3.*\r
50 import org.apache.commons.codec.binary.Base64;\r
51 import org.springframework.web.util.UriUtils;\r
52 \r
53 import org.w3c.dom.Document\r
54 import org.w3c.dom.Element\r
55 import org.w3c.dom.Node\r
56 import org.w3c.dom.NodeList\r
57 import org.xml.sax.InputSource\r
58 /**\r
59  * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.\r
60  *\r
61  * Inputs:\r
62  * @param - msoRequestId\r
63  * @param - globalSubscriberId\r
64  * @param - subscriptionServiceType\r
65  * @param - serviceInstanceId\r
66  * @param - serviceInstanceName - O\r
67  * @param - serviceModelInfo\r
68  * @param - productFamilyId\r
69  * @param - disableRollback\r
70  * @param - failExists - TODO\r
71  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)\r
72  * @param - sdncVersion ("1610")\r
73  * @param - serviceDecomposition - Decomposition for R1710 \r
74  * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)\r
75  *\r
76  * Outputs:\r
77  * @param - rollbackData (localRB->null)\r
78  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)\r
79  * @param - WorkflowException\r
80  * @param - serviceInstanceName - (GET from AAI if null in input)\r
81  *\r
82  */\r
83 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {\r
84 \r
85         String Prefix="DUPDSI_"\r
86         private static final String DebugFlag = "isDebugEnabled"\r
87         \r
88         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
89         JsonUtils jsonUtil = new JsonUtils()\r
90 \r
91         public void preProcessRequest (DelegateExecution execution) {\r
92             //only for dug\r
93                 execution.setVariable("isDebugLogEnabled","true")\r
94                 execution.setVariable("unit_test", "true")\r
95                 execution.setVariable("skipVFC", "true")\r
96                 \r
97                 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'\r
98                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
99                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
100                 String msg = ""\r
101                 utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****",  isDebugEnabled)\r
102                 \r
103                 utils.log("INFO","  unit test : " + execution.getVariable("unit_test"),  isDebugEnabled)        \r
104 \r
105                 try {\r
106                         execution.setVariable("prefix", Prefix)\r
107                         //Inputs\r
108                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology\r
109                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId\r
110                         utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId,  isDebugEnabled)\r
111                         \r
112                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology\r
113                         String serviceType = execution.getVariable("serviceType")\r
114                         utils.log("INFO"," ***** serviceType *****" + serviceType,  isDebugEnabled)\r
115                         \r
116                         //requestDetails.requestParameters. for SDNC assignTopology\r
117                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId\r
118 \r
119                         if (isBlank(globalSubscriberId)) {\r
120                                 msg = "Input globalSubscriberId is null"\r
121                                 utils.log("INFO", msg, isDebugEnabled)\r
122                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
123                         }\r
124                         \r
125                         if (isBlank(serviceType)) {\r
126                                 msg = "Input serviceType is null"\r
127                                 utils.log("INFO", msg, isDebugEnabled)\r
128                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
129                         }\r
130                         \r
131                         //Generated in parent for AAI \r
132                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
133                         if (isBlank(serviceInstanceId)){\r
134                                 msg = "Input serviceInstanceId is null"\r
135                                 utils.log("INFO", msg, isDebugEnabled)\r
136                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
137                         }\r
138                         \r
139                         if (productFamilyId == null) {\r
140                                 execution.setVariable("productFamilyId", "")\r
141                         }\r
142                         \r
143                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')\r
144                         if (isBlank(sdncCallbackUrl)) {\r
145                                 msg = "URN_mso_workflow_sdncadapter_callback is null"\r
146                                 utils.log("INFO", msg, isDebugEnabled)\r
147                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
148                         }\r
149                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)\r
150                         utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)\r
151 \r
152                         //requestDetails.modelInfo.for AAI PUT servieInstanceData                       \r
153                         //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData \r
154                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
155                         //String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
156                         String uuiRequest = execution.getVariable("uuiRequest")\r
157                         utils.log("INFO","uuiRequest: " + uuiRequest, isDebugEnabled)\r
158                         \r
159                         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId")\r
160                         utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)\r
161                         \r
162                         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId")\r
163                         utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)\r
164                         \r
165                         String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")\r
166                         utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled)\r
167                         execution.setVariable("serviceModelName", serviceModelName)\r
168                         \r
169             //aai serviceType and Role can be setted as fixed value now.\r
170                         String aaiServiceType = serviceType\r
171                         String aaiServiceRole = serviceType+"Role"\r
172                         \r
173                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)\r
174                         execution.setVariable("model-invariant-id-target", modelInvariantUuid)\r
175                         execution.setVariable("modelUuid", modelUuid)\r
176                         execution.setVariable("model-version-id-target", modelUuid)\r
177 \r
178                         //AAI PUT\r
179                         String oStatus = execution.getVariable("initialStatus") ?: ""\r
180                         utils.log("INFO","oStatus: " + oStatus, isDebugEnabled)\r
181                         if ("TRANSPORT".equalsIgnoreCase(serviceType))\r
182                         {\r
183                                 oStatus = "Update"\r
184                         }\r
185 \r
186                         String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"\r
187                         utils.log("INFO","statusLine: " + statusLine, isDebugEnabled)   \r
188                         AaiUtil aaiUriUtil = new AaiUtil(this)\r
189                         utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) \r
190                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
191                         utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)\r
192                         String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)\r
193                         utils.log("INFO","namespace: " + namespace, isDebugEnabled)\r
194                         /*\r
195                         String serviceInstanceData =\r
196                                         """<service-instance xmlns=\"${namespace}\">\r
197                                 <service-instance-id>${serviceInstanceId}</service-instance-id>\r
198                                 <service-instance-name>${serviceInstanceName}</service-instance-name>\r
199                                         <service-type>${aaiServiceType}</service-type>\r
200                                         <service-role>${aaiServiceRole}</service-role>\r
201                                         ${statusLine}\r
202                                     <model-invariant-id>${modelInvariantUuid}</model-invariant-id>\r
203                                     <model-version-id>${modelUuid}</model-version-id>\r
204                                         </service-instance>""".trim()\r
205             */\r
206             //begin only for test\r
207                         String serviceInstanceData =\r
208                                         """<service-instance xmlns=\"${namespace}\">\r
209                                 <service-instance-id>${serviceInstanceId}</service-instance-id>\r
210                                 <service-instance-name>${serviceInstanceName}</service-instance-name>\r
211                                         <service-type>${aaiServiceType}</service-type>\r
212                                         <service-role>${aaiServiceRole}</service-role>\r
213                                         ${statusLine}\r
214                                         </service-instance>""".trim()\r
215                         //end only for test\r
216                         execution.setVariable("serviceInstanceData", serviceInstanceData)\r
217                         utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)\r
218                         utils.logAudit(serviceInstanceData)\r
219                         utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)\r
220                         utils.log("INFO", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)\r
221                         \r
222                         execution.setVariable("serviceSDNCCreate", "false")\r
223                         execution.setVariable("operationStatus", "Waiting deploy resource...")                  \r
224 \r
225                 } catch (BpmnError e) {\r
226                         throw e;\r
227                 } catch (Exception ex){\r
228                         msg = "Exception in preProcessRequest " + ex.getMessage()\r
229                         utils.log("INFO", msg, isDebugEnabled)\r
230                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
231                 }\r
232                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
233         }\r
234         \r
235         public void postProcessAAIGET(DelegateExecution execution) {\r
236                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
237                 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)\r
238                 String msg = ""\r
239 \r
240                 try {\r
241                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
242                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
243                         String serviceType = ""\r
244 \r
245                         if(foundInAAI){\r
246                                 utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)\r
247 \r
248                                 String siData = execution.getVariable("GENGS_service")\r
249                                 utils.log("INFO", "SI Data", isDebugEnabled)\r
250                                 if (isBlank(siData))\r
251                                 {\r
252                                         msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId\r
253                                         utils.log("INFO", msg, isDebugEnabled)\r
254                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
255                                 }\r
256                                 else\r
257                                 {\r
258                                         utils.log("INFO", "SI Data" + siData, isDebugEnabled)\r
259                                         \r
260                                         InputSource source = new InputSource(new StringReader(siData));\r
261                                         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();\r
262                                         DocumentBuilder docBuilder = docFactory.newDocumentBuilder()\r
263                                         Document serviceXml = docBuilder.parse(source)\r
264                                         serviceXml.getDocumentElement().normalize()\r
265                                         \r
266                                         // Get Template uuid and version\r
267                                         if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) {\r
268                                             utils.log("INFO", "SI Data model-invariant-id and model-version-id exist:", isDebugEnabled)\r
269                                             def modelInvariantId  = serviceXml.getElementsByTagName("model-invariant-id").item(0).getTextContent()\r
270                                             def modelVersionId  = serviceXml.getElementsByTagName("model-version-id").item(0).getTextContent()\r
271                                             \r
272                                             // Set Original Template info\r
273                                             execution.setVariable("model-invariant-id-original", modelInvariantId)\r
274                                             execution.setVariable("model-version-id-original", modelVersionId)                                  \r
275                                         }\r
276                                         \r
277                                         //Confirm there are no related service instances (vnf/network or volume)\r
278                                         if (utils.nodeExists(siData, "relationship-list")) {\r
279                                                 utils.log("INFO", "SI Data relationship-list exists:", isDebugEnabled)\r
280                                                 \r
281                                                 //test(siData)\r
282                                                 NodeList nodeList = serviceXml.getElementsByTagName("relationship")\r
283                             JSONArray jArray = new JSONArray()\r
284                                                 for (int x = 0; x < nodeList.getLength(); x++) {\r
285                                                         Node node = nodeList.item(x)\r
286                                                         if (node.getNodeType() == Node.ELEMENT_NODE) {\r
287                                                                 Element eElement = (Element) node\r
288                                                                 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()                                                                    //for ns\r
289                                                                 if(e.equals("service-instance")){\r
290                                                                     def relatedObject = eElement.getElementsByTagName("related-link").item(0).getTextContent()\r
291                                                                         utils.log("INFO", "ServiceInstance Related NS :" + relatedObject, isDebugEnabled)\r
292                                     NodeList dataList = node.getChildNodes()\r
293                                     if(null != dataList) {\r
294                                         JSONObject jObj = new JSONObject()\r
295                                         for (int i = 0; i < dataList.getLength(); i++) {\r
296                                             Node dNode = dataList.item(i)\r
297                                             if(dNode.getNodeName() == "relationship-data") {\r
298                                                 Element rDataEle = (Element)dNode\r
299                                                 def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()\r
300                                                 def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()\r
301                                                 if(eKey.equals("service-instance.service-instance-id")){\r
302                                                     jObj.put("resourceInstanceId", eValue)\r
303                                                 }\r
304                                             }\r
305                                             else if(dNode.getNodeName() == "related-to-property"){\r
306                                                  Element rDataEle = (Element)dNode\r
307                                                  def eKey =  rDataEle.getElementsByTagName("property-key").item(0).getTextContent()\r
308                                                  def eValue = rDataEle.getElementsByTagName("property-value").item(0).getTextContent()\r
309                                                  if(eKey.equals("service-instance.service-instance-name")){\r
310                                                         jObj.put("resourceType", eValue)\r
311                                                     }\r
312                                             }\r
313                                         }\r
314                                         utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled)\r
315                                         jArray.put(jObj)\r
316                                     }\r
317                                                         //for overlay/underlay\r
318                                                                 }else if (e.equals("configuration")){\r
319                                     def relatedObject = eElement.getElementsByTagName("related-link").item(0).getTextContent()\r
320                                     utils.log("INFO", "ServiceInstance Related Configuration :" + relatedObject, isDebugEnabled)\r
321                                                                         NodeList dataList = node.getChildNodes()\r
322                                                                         if(null != dataList) {\r
323                                                                                 JSONObject jObj = new JSONObject()\r
324                                                                                 for (int i = 0; i < dataList.getLength(); i++) {\r
325                                                                                         Node dNode = dataList.item(i)\r
326                                                                                         if(dNode.getNodeName() == "relationship-data") {\r
327                                                                                                 Element rDataEle = (Element)dNode\r
328                                                                                                 def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()\r
329                                                                                                 def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()\r
330                                                                                                 if(eKey.equals("configuration.configuration-id")){\r
331                                                                                                     jObj.put("resourceInstanceId", eValue)\r
332                                                                                                 }\r
333                                                                                         }\r
334                                                                                         else if(dNode.getNodeName() == "related-to-property"){\r
335                                                      Element rDataEle = (Element)dNode\r
336                                                      def eKey =  rDataEle.getElementsByTagName("property-key").item(0).getTextContent()\r
337                                                      def eValue = rDataEle.getElementsByTagName("property-value").item(0).getTextContent()\r
338                                                      if(eKey.equals("configuration.configuration-type")){\r
339                                                             jObj.put("resourceType", eValue)\r
340                                                         }\r
341                                                                                         }\r
342                                                                                 }\r
343                                                                                 utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled)\r
344                                         jArray.put(jObj)\r
345                                                                         }                                                                       \r
346                                                                 }\r
347                                                         }\r
348                                                 }\r
349                         execution.setVariable("serviceRelationShip", jArray.toString())\r
350                                         }\r
351                                 }\r
352                         }else{\r
353                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
354                                 if(!succInAAI){\r
355                                         utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)\r
356                                         WorkflowException workflowException = execution.getVariable("WorkflowException")\r
357                                         utils.logAudit("workflowException: " + workflowException)\r
358                                         if(workflowException != null){\r
359                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
360                                         }\r
361                                         else\r
362                                         {\r
363                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI\r
364                                                 utils.log("INFO", msg, isDebugEnabled)\r
365                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
366                                         }\r
367                                 }\r
368 \r
369                                 utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)\r
370                         }\r
371                 }catch (BpmnError e) {\r
372                         throw e;\r
373                 } catch (Exception ex) {\r
374                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()\r
375                         utils.log("INFO", msg, isDebugEnabled)\r
376                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
377                 }\r
378                 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)\r
379         }\r
380         \r
381         \r
382         public void preInitResourcesOperStatus(DelegateExecution execution){\r
383         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
384 \r
385         utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)\r
386         try{\r
387             String serviceId = execution.getVariable("serviceInstanceId")\r
388             String operationId = execution.getVariable("operationId")\r
389             String operationType = execution.getVariable("operationType")\r
390             String resourceTemplateUUIDs = ""\r
391             String result = "processing"\r
392             String progress = "10"\r
393             String reason = ""\r
394             String operationContent = "Prepare service updating"\r
395             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)\r
396             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
397             execution.setVariable("serviceInstanceId", serviceId)\r
398             execution.setVariable("operationId", operationId)\r
399             execution.setVariable("operationType", operationType)\r
400 \r
401                         List<Resource> resourceList = new ArrayList<String>()\r
402                         List<Resource> addResourceList =  execution.getVariable("addResourceList")\r
403                         List<Resource> delResourceList =  execution.setVariable("delResourceList")\r
404                         resourceList.addAll(addResourceList)\r
405                         resourceList.addAll(delResourceList)\r
406                         for(Resource resource : resourceList){\r
407                                 resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"\r
408                         }\r
409                         \r
410                         def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
411                         execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
412                         utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
413 \r
414                         String payload =\r
415                                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
416                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
417                         <soapenv:Header/>\r
418                         <soapenv:Body>\r
419                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
420                                                                 <serviceId>${serviceId}</serviceId>\r
421                                                                 <operationId>${operationId}</operationId>\r
422                                                                 <operationType>${operationType}</operationType>\r
423                                                                 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>\r
424                             </ns:initResourceOperationStatus>\r
425                         </soapenv:Body>\r
426                         </soapenv:Envelope>"""\r
427 \r
428                         payload = utils.formatXml(payload)\r
429                         execution.setVariable("CVFMI_initResOperStatusRequest", payload)\r
430                         utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)\r
431                         utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)\r
432 \r
433         }catch(Exception e){\r
434             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)\r
435             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())\r
436         }\r
437         utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  \r
438     }\r
439     \r
440     /**\r
441          * Init the service Operation Status\r
442          */\r
443         public void preUpdateServiceOperationStatus(DelegateExecution execution){\r
444         def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'\r
445                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
446                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
447         \r
448         try{\r
449             String serviceId = execution.getVariable("serviceInstanceId")\r
450             String operationId = execution.getVariable("operationId")\r
451                         String operationType = execution.getVariable("operationType")\r
452             String serviceName = execution.getVariable("serviceInstanceName")\r
453             String userId = ""\r
454             String result = "processing"\r
455             String progress = execution.getVariable("progress")\r
456                         utils.log("INFO", "progress: " + progress , isDebugEnabled)\r
457                         if ("100".equalsIgnoreCase(progress))\r
458                         {\r
459                                 result = "finished"\r
460                         }\r
461             String reason = ""\r
462             String operationContent = "Prepare service : " + execution.getVariable("operationStatus")\r
463                         \r
464             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)\r
465             serviceId = UriUtils.encode(serviceId,"UTF-8")\r
466             execution.setVariable("serviceInstanceId", serviceId)\r
467             execution.setVariable("operationId", operationId)\r
468             execution.setVariable("operationType", operationType)\r
469 \r
470             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
471             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
472             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
473 \r
474             execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")\r
475                         String payload =\r
476                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
477                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
478                         <soapenv:Header/>\r
479                         <soapenv:Body>\r
480                             <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
481                             <serviceId>${serviceId}</serviceId>\r
482                             <operationId>${operationId}</operationId>\r
483                             <serviceName>${serviceName}</serviceName>\r
484                             <operationType>${operationType}</operationType>\r
485                             <userId>${userId}</userId>\r
486                             <result>${result}</result>\r
487                             <operationContent>${operationContent}</operationContent>\r
488                             <progress>${progress}</progress>\r
489                             <reason>${reason}</reason>\r
490                         </ns:updateServiceOperationStatus>\r
491                     </soapenv:Body>\r
492                 </soapenv:Envelope>"""\r
493 \r
494             payload = utils.formatXml(payload)\r
495             execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)\r
496             utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)\r
497            \r
498 \r
499         }catch(Exception e){\r
500             utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)\r
501             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())\r
502         }\r
503         utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)  \r
504         utils.log("INFO", "Exited " + method, isDebugEnabled)\r
505         }\r
506     \r
507     public void postResourcesOperStatus(DelegateExecution execution) {\r
508         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
509     \r
510     }\r
511     \r
512     public void preCompareModelVersions(DelegateExecution execution) {\r
513         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
514 \r
515     }\r
516 \r
517     public void postCompareModelVersions(DelegateExecution execution) {\r
518         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
519     }\r
520     \r
521     public void preProcessForAddResource(DelegateExecution execution) {\r
522         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
523 \r
524     }\r
525 \r
526     public void postProcessForAddResource(DelegateExecution execution) {\r
527         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
528                 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)\r
529                 \r
530                 ServiceDecomposition serviceDecomposition_Target = execution.getVariable("serviceDecomposition_Target")\r
531                 execution.setVariable("serviceDecomposition", serviceDecomposition_Target)\r
532     \r
533                 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)\r
534     }\r
535     \r
536     public void preProcessForDeleteResource(DelegateExecution execution) {\r
537         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
538 \r
539     }\r
540 \r
541     public void postProcessForDeleteResource(DelegateExecution execution) {\r
542         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
543     \r
544     } \r
545     \r
546         public void preProcessAAIGET2(DelegateExecution execution) {\r
547         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")   \r
548         }\r
549         \r
550         public void postProcessAAIGET2(DelegateExecution execution) {\r
551                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
552                 utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)\r
553                 String msg = ""\r
554 \r
555                 try {\r
556                         String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
557                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
558                         if(!succInAAI){\r
559                                 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)\r
560                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
561                                 utils.logAudit("workflowException: " + workflowException)\r
562                                 if(workflowException != null){\r
563                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
564                                 }\r
565                                 else\r
566                                 {\r
567                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI\r
568                                         utils.log("INFO", msg, isDebugEnabled)\r
569                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
570                                 }\r
571                         }\r
572                         else\r
573                         {\r
574                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
575                                 if(foundInAAI){\r
576                                         String aaiService = execution.getVariable("GENGS_service")\r
577                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {\r
578                                                 execution.setVariable("serviceInstanceVersion",  utils.getNodeText1(aaiService, "resource-version"))\r
579                                                 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)\r
580                                         }\r
581                                 }\r
582                         }\r
583                 } catch (BpmnError e) {\r
584                         throw e;\r
585                 } catch (Exception ex) {\r
586                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()\r
587                         utils.log("INFO", msg, isDebugEnabled)\r
588                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
589                 }\r
590                 utils.log("INFO"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)\r
591         }\r
592 \r
593         public void preProcessAAIPUT(DelegateExecution execution) {             \r
594                 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'\r
595                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
596                 utils.log("INFO","Entered " + method, isDebugEnabled)\r
597                 String msg = ""\r
598                 utils.log("INFO"," ***** preProcessAAIPUTt *****",  isDebugEnabled)\r
599 \r
600                 String modelUuid = execution.getVariable("modelUuid")\r
601                 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")\r
602                 execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)\r
603 \r
604                 AaiUtil aaiUriUtil = new AaiUtil(this)\r
605                 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) \r
606                 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
607                 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)\r
608                 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)\r
609                 utils.log("INFO","namespace: " + namespace, isDebugEnabled)\r
610 \r
611                 String serviceInstanceData =\r
612                                 """<service-instance xmlns=\"${namespace}\">\r
613                                <model-version-id">${modelUuid}</model-version-id>\r
614                                  </service-instance>""".trim()\r
615 \r
616                 execution.setVariable("serviceInstanceData", serviceInstanceData)\r
617                 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)\r
618                 utils.logAudit(serviceInstanceData)\r
619                 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)\r
620                 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)\r
621         \r
622                 utils.log("INFO", "Exited " + method, isDebugEnabled)\r
623         }       \r
624         \r
625         public void postProcessAAIPUT(DelegateExecution execution) {\r
626                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
627                 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)\r
628                 String msg = ""\r
629                 try {\r
630                         String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
631                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")\r
632                         if(!succInAAI){\r
633                                 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)\r
634                                 WorkflowException workflowException = execution.getVariable("WorkflowException")\r
635                                 utils.logAudit("workflowException: " + workflowException)\r
636                                 if(workflowException != null){\r
637                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
638                                 }\r
639                         }\r
640                         else\r
641                         {\r
642                                 //start rollback set up\r
643                                 RollbackData rollbackData = new RollbackData()\r
644                                 def disableRollback = execution.getVariable("disableRollback")\r
645                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())\r
646                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")\r
647                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)\r
648                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))\r
649                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))\r
650                                 execution.setVariable("rollbackData", rollbackData)\r
651                         }\r
652 \r
653                 } catch (BpmnError e) {\r
654                         throw e;\r
655                 } catch (Exception ex) {\r
656                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()\r
657                         utils.log("INFO", msg, isDebugEnabled)\r
658                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
659                 }\r
660                 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)\r
661         }       \r
662 \r
663         public void preProcessRollback (DelegateExecution execution) {\r
664                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
665                 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)\r
666                 try {\r
667                         \r
668                         Object workflowException = execution.getVariable("WorkflowException");\r
669 \r
670                         if (workflowException instanceof WorkflowException) {\r
671                                 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)\r
672                                 execution.setVariable("prevWorkflowException", workflowException);\r
673                                 //execution.setVariable("WorkflowException", null);\r
674                         }\r
675                 } catch (BpmnError e) {\r
676                         utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)\r
677                 } catch(Exception ex) {\r
678                         String msg = "Exception in preProcessRollback. " + ex.getMessage()\r
679                         utils.log("INFO", msg, isDebugEnabled)\r
680                 }\r
681                 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)\r
682         }\r
683 \r
684         public void postProcessRollback (DelegateExecution execution) {\r
685                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
686                 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)\r
687                 String msg = ""\r
688                 try {\r
689                         Object workflowException = execution.getVariable("prevWorkflowException");\r
690                         if (workflowException instanceof WorkflowException) {\r
691                                 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)\r
692                                 execution.setVariable("WorkflowException", workflowException);\r
693                         }\r
694                         execution.setVariable("rollbackData", null)\r
695                 } catch (BpmnError b) {\r
696                         utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)\r
697                         throw b;\r
698                 } catch(Exception ex) {\r
699                         msg = "Exception in postProcessRollback. " + ex.getMessage()\r
700                         utils.log("INFO", msg, isDebugEnabled)\r
701                 }\r
702                 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)\r
703         }\r
704 \r
705         \r
706         public void postConfigRequest(execution){\r
707             //now do noting\r
708         }\r
709 \r
710         \r
711 }\r
712         \r