8a6cac4a91de596aaf1a82a114612c1ec0c05597
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateVnf.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.bpmn.infrastructure.scripts
21
22 import static org.apache.commons.lang3.StringUtils.*
23 import org.openecomp.mso.bpmn.core.RollbackData
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.runtime.Execution
26 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.bpmn.core.json.JsonUtils
33
34
35 /**
36  * This class supports the DoCreateVnf building block subflow
37  * with the creation of a generic vnf for
38  * infrastructure.
39  *
40  */
41 class DoCreateVnf extends AbstractServiceTaskProcessor {
42
43         String Prefix="DoCVNF_"
44         ExceptionUtil exceptionUtil = new ExceptionUtil()
45         JsonUtils jsonUtil = new JsonUtils()
46         VidUtils vidUtils = new VidUtils(this)
47         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
48
49         /**
50          * This method gets and validates the incoming
51          * request.
52          *
53          * @param - execution
54          *
55          */
56         public void preProcessRequest(Execution execution) {
57                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
58                 execution.setVariable("prefix",Prefix)
59                 utils.log("DEBUG", " *** STARTED DoCreateVnf PreProcessRequest Process*** ", isDebugEnabled)
60         
61                 // DISABLE SDNC INTERACTION FOR NOW
62                 execution.setVariable("SDNCInteractionEnabled", false)
63                 
64                 
65                 /*******************/
66                 try{
67                         // Get Variables
68                                                 
69                         String vnfModelInfo = execution.getVariable("vnfModelInfo")                     
70                         String serviceModelInfo = execution.getVariable("serviceModelInfo")
71                         
72                         String requestId = execution.getVariable("msoRequestId")
73                         execution.setVariable("DoCVNF_requestId", requestId)
74                         execution.setVariable("mso-request-id", requestId)
75                         utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
76
77                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
78                         execution.setVariable("DoCVNF_serviceInstanceId", serviceInstanceId)
79                         utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
80
81                         String vnfType = execution.getVariable("vnfType")
82                         execution.setVariable("DoCVNF_vnfType", vnfType)
83                         utils.log("DEBUG", "Incoming Vnf Type is: " + vnfType, isDebugEnabled)
84
85                         String vnfName = execution.getVariable("vnfName")
86                         if (vnfName.equals("") || vnfName.equals("null")) {
87                                 vnfName = null
88                         }
89                         execution.setVariable("DoCVNF_vnfName", vnfName)
90                         utils.log("DEBUG", "Incoming Vnf Name is: " + vnfName, isDebugEnabled)
91
92                         String serviceId = execution.getVariable("productFamilyId")
93                         execution.setVariable("DoCVNF_serviceId", serviceId)
94                         utils.log("DEBUG", "Incoming Service Id is: " + serviceId, isDebugEnabled)
95
96                         String source = "VID"
97                         execution.setVariable("DoCVNF_source", source)
98                         utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
99
100                         String suppressRollback = execution.getVariable("disableRollback")
101                         execution.setVariable("DoCVNF_suppressRollback", suppressRollback)
102                         utils.log("DEBUG", "Incoming Suppress Rollback is: " + suppressRollback, isDebugEnabled)
103                         
104                         String modelInvariantId = jsonUtil.getJsonValue(vnfModelInfo, "modelInvariantId")
105                         execution.setVariable("DoCVNF_modelInvariantId", modelInvariantId)
106                         utils.log("DEBUG", "Incoming Invariant Id is: " + modelInvariantId, isDebugEnabled)
107                         
108                         String modelVersionId = jsonUtil.getJsonValue(vnfModelInfo, "modelVersionId")
109                         if (modelVersionId == null) {
110                                 modelVersionId = ""
111                         }
112                         execution.setVariable("DoCVNF_modelVersionId", modelVersionId)
113                         utils.log("DEBUG", "Incoming Version Id is: " + modelVersionId, isDebugEnabled)
114
115                         String modelVersion = jsonUtil.getJsonValue(vnfModelInfo, "modelVersion")
116                         execution.setVariable("DoCVNF_modelVersion", modelVersion)
117                         utils.log("DEBUG", "Incoming Model Version is: " + modelVersion, isDebugEnabled)
118                         
119                         String modelName = jsonUtil.getJsonValue(vnfModelInfo, "modelName")
120                         execution.setVariable("DoCVNF_modelName", modelName)
121                         utils.log("DEBUG", "Incoming Model Name is: " + modelName, isDebugEnabled)
122                         
123                         String modelCustomizationId = jsonUtil.getJsonValue(vnfModelInfo, "modelCustomizationId")
124                         if (modelCustomizationId == null) {
125                                 modelCustomizationId = ""
126                         }
127                         execution.setVariable("DoCVNF_modelCustomizationId", modelCustomizationId)
128                         utils.log("DEBUG", "Incoming Model Customization Id is: " + modelCustomizationId, isDebugEnabled)
129                                 
130                         String cloudSiteId = execution.getVariable("lcpCloudRegionId")
131                         execution.setVariable("DoCVNF_cloudSiteId", cloudSiteId)
132                         utils.log("DEBUG", "Incoming Cloud Site Id is: " + cloudSiteId, isDebugEnabled)
133                                 
134                         String tenantId = execution.getVariable("tenantId")
135                         execution.setVariable("DoCVNF_tenantId", tenantId)
136                         utils.log("DEBUG", "Incoming Tenant Id is: " + tenantId, isDebugEnabled)                        
137                         
138                         String globalSubscriberId = execution.getVariable("globalSubscriberId")
139                         if (globalSubscriberId == null) {
140                                 globalSubscriberId = ""
141                         }
142                         execution.setVariable("DoCVNF_globalSubscriberId", globalSubscriberId)
143                         utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
144                         
145                         String sdncVersion = execution.getVariable("sdncVersion")
146                         if (sdncVersion == null) {
147                                 sdncVersion = "1702"
148                         }
149                         execution.setVariable("DoCVNF_sdncVersion", sdncVersion)
150                         utils.log("DEBUG", "Incoming Sdnc Version is: " + sdncVersion, isDebugEnabled)
151
152                         //For Completion Handler & Fallout Handler
153                         String requestInfo =
154                                 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
155                                         <request-id>${requestId}</request-id>
156                                         <action>CREATE</action>
157                                         <source>${source}</source>
158                                    </request-info>"""
159
160                         execution.setVariable("DoCVNF_requestInfo", requestInfo)
161                         //TODO: Orch Status - TBD, will come from SDN-C Response in 1702
162                         String orchStatus = "Created"
163                         execution.setVariable("DoCVNF_orchStatus", orchStatus)
164
165                         //TODO: Equipment Role - Should come from SDN-C Response in 1702
166                         String equipmentRole = " "
167                         execution.setVariable("DoCVNF_equipmentRole", equipmentRole)
168                         String vnfId = execution.getVariable("testVnfId") // for junits
169                         if(isBlank(vnfId)){
170                                 vnfId = execution.getVariable("vnfId")
171                                 if (isBlank(vnfId)) {
172                                         vnfId = UUID.randomUUID().toString()
173                                         utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
174                                 }
175                         }
176                         execution.setVariable("DoCVNF_vnfId", vnfId)
177
178                         // Setting for Sub Flow Calls
179                         execution.setVariable("DoCVNF_type", "generic-vnf")
180                         execution.setVariable("GENGS_type", "service-instance")
181                                 
182                         String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
183                         if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
184                                 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
185                                 logError(msg)
186                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
187                         }
188                         execution.setVariable("DoCVNF_sdncCallbackUrl", sdncCallbackUrl)
189                         utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
190                         logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugEnabled)
191                         
192                         def rollbackData = execution.getVariable("RollbackData")
193                         if (rollbackData == null) {
194                                 rollbackData = new RollbackData()
195                         }
196                         
197                         execution.setVariable("RollbackData", rollbackData)
198                         
199                 }catch(BpmnError b){
200                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
201                         throw b
202                 }catch(Exception e){
203                         utils.log("DEBUG", " Error Occured in DoCreateVnf PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
204                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PreProcessRequest")
205
206                 }
207                 utils.log("DEBUG", "*** COMPLETED DoCreateVnf PreProcessRequest Process ***", isDebugEnabled)
208         }
209
210         
211         public void prepareCreateGenericVnf (Execution execution) {
212                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
213                 execution.setVariable("prefix",Prefix)
214
215                 utils.log("DEBUG", " *** STARTED DoCreateVnf PrepareCreateGenericVnf Process *** ", isDebugEnabled)
216                 try {
217                         //Get Vnf Info
218                         String vnfId = execution.getVariable("DoCVNF_vnfId")
219                         def vnfName = execution.getVariable("DoCVNF_vnfName")
220                         if (vnfName == null) {
221                                 vnfName = "sdncGenerated"
222                                 utils.log("DEBUG", "Sending a dummy VNF name to AAI - the name will be generated by SDNC: " + vnfName, isDebugEnabled)
223                         }
224                         def vnfType = execution.getVariable("DoCVNF_vnfType")
225                         def serviceId = execution.getVariable("DoCVNF_serviceId")
226                         def orchStatus = execution.getVariable("DoCVNF_orchStatus")
227                         def modelInvariantId = execution.getVariable("DoCVNF_modelInvariantId")
228                         def modelVersionId = execution.getVariable("DoCVNF_modelVersionId")
229                         def modelCustomizationId = execution.getVariable("DoCVNF_modelCustomizationId")
230                         // TODO: 1702 Variable
231                         def equipmentRole = execution.getVariable("DoCVNF_equipmentRole")
232
233                         //Get Service Instance Info
234                         def serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
235                         String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
236
237                         int custStart = siRelatedLink.indexOf("customer/")
238                         int custEnd = siRelatedLink.indexOf("/service-subscriptions")
239                         String globalCustId = siRelatedLink.substring(custStart + 9, custEnd)
240                         int serviceStart = siRelatedLink.indexOf("service-subscription/")
241                         int serviceEnd = siRelatedLink.indexOf("/service-instances/")
242                         String serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
243
244                         //Get Namespace
245                         AaiUtil aaiUtil = new AaiUtil(this)
246                         def aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)
247                         String namespace = aaiUtil.getNamespaceFromUri(execution, aai_uri)
248
249                         String payload =
250                                         """<generic-vnf xmlns="${namespace}">
251                                 <vnf-id>${vnfId}</vnf-id>
252                                 <vnf-name>${vnfName}</vnf-name>
253                                 <service-id>${serviceId}</service-id>
254                                 <vnf-type>${vnfType}</vnf-type>
255                                 <prov-status>PREPROV</prov-status>
256                                 <orchestration-status>${orchStatus}</orchestration-status>
257                                 <model-invariant-id>${modelInvariantId}</model-invariant-id>
258                                 <model-version-id>${modelVersionId}</model-version-id>
259                                 <model-customization-id>${modelCustomizationId}</model-customization-id>
260                                 <relationship-list>
261                                         <relationship>
262                         <related-to>service-instance</related-to>
263                         <related-link>${siRelatedLink}</related-link>
264                         <relationship-data>
265                                 <relationship-key>customer.global-customer-id</relationship-key>
266                                 <relationship-value>${globalCustId}</relationship-value>
267                         </relationship-data>
268                         <relationship-data>
269                                 <relationship-key>service-subscription.service-type</relationship-key>
270                                 <relationship-value>${serviceType}</relationship-value>
271                         </relationship-data>
272                                         <relationship-data>
273                                 <relationship-key>service-instance.service-instance-id</relationship-key>
274                                 <relationship-value>${serviceInstanceId}</relationship-value>
275                         </relationship-data>
276                         </relationship>
277                                 </relationship-list>
278                         </generic-vnf>"""
279
280                         execution.setVariable("DoCVNF_genericVnfPayload", payload)
281
282                 }catch(Exception ex) {
283                         utils.log("DEBUG", "Error Occured in DoCreateVnf PrepareCreateGenericVnf Process " + ex.getMessage(), isDebugEnabled)
284                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PrepareCreateGenericVnf Process")
285                 }
286                 utils.log("DEBUG", "*** COMPLETED DoCreateVnf PrepareCreateGenericVnf Process ***", isDebugEnabled)
287         }
288         
289         public void postProcessCreateGenericVnf (Execution execution) {
290                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
291                 execution.setVariable("prefix",Prefix)
292
293                 utils.log("DEBUG", " *** STARTED DoCreateVnf PostProcessCreateGenericVnf Process *** ", isDebugEnabled)
294                 try {
295                         //Get Vnf Info
296                         String vnfId = execution.getVariable("DoCVNF_vnfId")
297                         def rollbackData = execution.getVariable("RollbackData")
298                         rollbackData.put("VNF", "vnfId", vnfId)
299                         execution.setVariable("RollbackData", rollbackData)
300                 }catch(Exception ex) {
301                         utils.log("DEBUG", "Error Occured in DoCreateVnf PostProcessCreateGenericVnf Process " + ex.getMessage(), isDebugEnabled)
302                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PostProcessCreateGenericVnf Process")
303                 }
304                 utils.log("DEBUG", "*** COMPLETED DoCreateVnf PostProcessCreateGenericVnf Process ***", isDebugEnabled)
305         }
306         
307         
308         public void preProcessSDNCAssignRequest(Execution execution){
309                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
310                 execution.setVariable("prefix", Prefix)
311                 logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
312                 def vnfId = execution.getVariable("DoCVNF_vnfId")
313                 def serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
314                 logDebug("NEW VNF ID: " + vnfId, isDebugLogEnabled)
315                 utils.logAudit("NEW VNF ID: " + vnfId)
316
317                 try{
318                         //Build SDNC Request
319                         
320                         String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
321
322                         assignSDNCRequest = utils.formatXml(assignSDNCRequest)
323                         execution.setVariable("DoCVNF_assignSDNCRequest", assignSDNCRequest)
324                         logDebug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest, isDebugLogEnabled)
325                         utils.logAudit("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
326
327                 }catch(Exception e){
328                         utils.log("ERROR", "Exception Occured Processing preProcessSDNCAssignRequest. Exception is:\n" + e, isDebugLogEnabled)
329                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCAssignRequest Method:\n" + e.getMessage())
330                 }
331                 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
332         }
333         
334         public void preProcessSDNCActivateRequest(Execution execution) {
335                 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
336                         'execution=' + execution.getId() +
337                         ')'
338                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
339                 logDebug('Entered ' + method, isDebugLogEnabled)
340                 execution.setVariable("prefix", Prefix)
341                 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
342                 try{
343                         String vnfId = execution.getVariable("DoCVNF_vnfId")
344                         String serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
345
346                         String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
347
348                         execution.setVariable("DoCVNF_activateSDNCRequest", activateSDNCRequest)
349                         logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
350                         utils.logAudit("Outgoing CommitSDNCRequest is: \n"  + activateSDNCRequest)
351
352                 }catch(Exception e){
353                         log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
354                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCActivateRequest Method:\n" + e.getMessage())
355                 }
356                 logDebug("======== COMPLETED  preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
357         }
358         
359         public String buildSDNCRequest(Execution execution, String svcInstId, String action){
360                 
361                                 String uuid = execution.getVariable('testReqId') // for junits
362                                 if(uuid==null){
363                                         uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
364                                 }
365                                 def callbackURL = execution.getVariable("DoCVNF_sdncCallbackUrl")
366                                 def requestId = execution.getVariable("DoCVNF_requestId")
367                                 def serviceId = execution.getVariable("DoCVNF_serviceId")
368                                 def vnfType = execution.getVariable("DoCVNF_vnfType")
369                                 def vnfName = execution.getVariable("DoCVNF_vnfName")
370                                 // Only send vnfName to SDNC if it is not null, otherwise it will get generated by SDNC on Assign
371                                 String vnfNameString = ""
372                                 if (vnfName != null) {
373                                         vnfNameString = """<vnf-name>${vnfName}</vnf-name>"""                                   
374                                 }
375                                 def tenantId = execution.getVariable("DoCVNF_tenantId")
376                                 def source = execution.getVariable("DoCVNF_source")
377                                 def vnfId = execution.getVariable("DoCVNF_vnfId")
378                                 def cloudSiteId = execution.getVariable("DoCVNF_cloudSiteId")                           
379                                 def modelCustomizationId = execution.getVariable("DoCVNF_modelCustomizationId")
380                                 def serviceModelInfo = execution.getVariable("serviceModelInfo")
381                                 def vnfModelInfo = execution.getVariable("vnfModelInfo")
382                                 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
383                                 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)                               
384                                 def globalSubscriberId = execution.getVariable("DoCVNF_globalSubscriberId")
385                                 def sdncVersion = execution.getVariable("DoCVNF_sdncVersion")
386                                                 
387                                 String sdncVNFParamsXml = ""
388                 
389                                 if(execution.getVariable("DoCVNF_vnfParamsExistFlag") == true){
390                                         sdncVNFParamsXml = buildSDNCParamsXml(execution)
391                                 }else{
392                                         sdncVNFParamsXml = ""
393                                 }
394                 
395                                 String sdncRequest =
396                                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
397                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
398                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
399            <sdncadapter:RequestHeader>
400                                 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
401                                 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
402                                 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
403                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
404                                 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
405                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
406                 </sdncadapter:RequestHeader>
407         <sdncadapterworkflow:SDNCRequestData>
408                 <request-information>
409                         <request-id>${requestId}</request-id>
410                         <request-action>CreateVnfInstance</request-action>
411                         <source>${source}</source>
412                         <notification-url/>
413                         <order-number/>
414                         <order-version/>
415                 </request-information>
416                 <service-information>
417                         <service-id>${serviceId}</service-id>
418                         <subscription-service-type>${serviceId}</subscription-service-type>
419                         ${serviceEcompModelInformation}                 
420                         <service-instance-id>${svcInstId}</service-instance-id>
421                         <global-customer-id>${globalSubscriberId}</global-customer-id>                  
422                 </service-information>
423                 <vnf-information>
424                         <vnf-id>${vnfId}</vnf-id>
425                         <vnf-type>${vnfType}</vnf-type>
426                         ${vnfEcompModelInformation}                     
427                 </vnf-information>
428                 <vnf-request-input>                     
429                         ${vnfNameString}
430                         <tenant>${tenantId}</tenant>            
431                         <aic-cloud-region>${cloudSiteId}</aic-cloud-region>                     
432                         ${sdncVNFParamsXml}
433                 </vnf-request-input>
434         </sdncadapterworkflow:SDNCRequestData>
435         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
436                 
437                         utils.logAudit("sdncRequest:  " + sdncRequest)
438                         return sdncRequest
439         }
440                 
441         public void validateSDNCResponse(Execution execution, String response, String method){
442                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
443                 execution.setVariable("prefix",Prefix)
444                 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
445
446                 WorkflowException workflowException = execution.getVariable("WorkflowException")
447                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
448
449                 utils.logAudit("workflowException: " + workflowException)
450
451                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
452                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
453
454                 utils.logAudit("SDNCResponse: " + response)
455
456                 String sdncResponse = response
457                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
458                         logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse, isDebugLogEnabled)
459                         if(method.equals("get")){
460                                 String topologyGetResponse = execution.getVariable("DoCVNF_getSDNCAdapterResponse")
461                                 String data = utils.getNodeXml(topologyGetResponse, "response-data")
462                                 data = data.replaceAll("&lt;", "<")
463                                 data = data.replaceAll("&gt;", ">")
464                                 utils.log("DEBUG", "topologyGetResponseData: " + data, isDebugLogEnabled)
465                                 String vnfName = utils.getNodeText1(data, "vnf-name")
466                                 utils.log("DEBUG", "vnfName received from SDNC: " + vnfName, isDebugLogEnabled)
467                                 execution.setVariable("vnfName", vnfName)
468                                 execution.setVariable("DoCVNF_vnfName", vnfName)
469                         }
470                         
471                 }else{
472                         logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
473                         throw new BpmnError("MSOWorkflowException")
474                 }
475                 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
476         }
477         
478         public void preProcessSDNCGetRequest(Execution execution){
479                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
480                 execution.setVariable("prefix", Prefix)
481                 utils.log("DEBUG", " ======== STARTED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
482                 try{
483                         def serviceInstanceId = execution.getVariable('DoCVNF_serviceInstanceId')
484                         
485                         String uuid = execution.getVariable('testReqId') // for junits
486                         if(uuid==null){
487                                 uuid = execution.getVariable("mso-request-id") + "-" +  System.currentTimeMillis()
488                         }
489                                         
490                         def callbackUrl = execution.getVariable("DoCVFM_sdncCallbackUrl")
491                         utils.logAudit("callbackUrl:" + callbackUrl)
492                         
493                         def vnfId = execution.getVariable('DCVFM_vnfId')
494                         
495                         def svcInstId = ""
496                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
497                                 svcInstId = vnfId
498                         }
499                         else {
500                                 svcInstId = serviceInstanceId
501                         }
502                         // serviceOperation will be retrieved from "object-path" element
503                         // in SDNC Assign Response for VNF
504                         String response = execution.getVariable("DoCVNF_assignSDNCAdapterResponse")
505                         utils.logAudit("DoCVNF_assignSDNCAdapterResponse is: \n" + response)
506                         
507                         String serviceOperation = ""
508                         
509                         String data = utils.getNodeXml(response, "response-data")
510                         data = data.replaceAll("&lt;", "<")
511                         data = data.replaceAll("&gt;", ">")
512                         utils.log("DEBUG", "responseData: " + data, isDebugLogEnabled)
513                         serviceOperation = utils.getNodeText1(data, "object-path")
514                         utils.log("DEBUG", "VNF with sdncVersion of 1707 or later - service operation: " + serviceOperation, isDebugLogEnabled)                 
515                         
516
517                         //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
518                         sleep(5000)
519
520                         String SDNCGetRequest =
521                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
522                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
523                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
524                                         <sdncadapter:RequestHeader>
525                                         <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
526                                         <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
527                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
528                                         <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
529                                         <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
530                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
531                                 </sdncadapter:RequestHeader>
532                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
533                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
534
535                         utils.logAudit("SDNCGetRequest: \n" + SDNCGetRequest)
536                         execution.setVariable("DoCVNF_getSDNCRequest", SDNCGetRequest)
537                         utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
538
539                 }catch(Exception e){
540                         utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
541                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
542                 }
543                 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
544         }
545         
546         /**
547          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
548          *
549          * @param execution The flow's execution instance.
550          */
551         public void prepUpdateAAIGenericVnf(Execution execution) {
552                 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
553                         'execution=' + execution.getId() +
554                         ')'
555                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
556                 logDebug('Entered ' + method, isDebugLogEnabled)
557  
558                 try {
559                         def vnfId = execution.getVariable('DoCVNF_vnfId')
560                         logDebug("VNF ID: " + vnfId, isDebugLogEnabled)         
561  
562                         String updateAAIGenericVnfRequest = """
563                                         <UpdateAAIGenericVnfRequest>
564                                                 <vnf-id>${vnfId}</vnf-id>
565                                                 <orchestration-status>Active</orchestration-status>                                             
566                                         </UpdateAAIGenericVnfRequest>
567                                 """
568                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
569                                 execution.setVariable('DoCVNF_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
570                                 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
571                                 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
572  
573  
574                         logDebug('Exited ' + method, isDebugLogEnabled)
575                 } catch (BpmnError e) {
576                         throw e;
577                 } catch (Exception e) {
578                         logError('Caught exception in ' + method, e)
579                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
580                 }
581         }
582  
583
584
585         
586 }