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