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