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