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