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