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