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