Groovy Compile
[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                                 execution.setVariable("GENGS_siResourceLink", uri.build().toString())
263
264                         }else{
265                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
266                         }
267
268                 }catch(BpmnError e) {
269                         throw e;
270                 }catch(Exception ex) {
271                         String msg = "Exception in getServiceInstance. " + ex.getMessage()
272                         msoLogger.debug(msg)
273                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
274                 }
275         }
276
277         private Object getVariableEnforced(DelegateExecution execution, String name){
278                 Object enforced = execution.getVariable(name)
279                 if(!enforced){
280                 return "";
281                 }
282                 return enforced;
283         }
284
285         public void createGenericVnf (DelegateExecution execution) {
286                 execution.setVariable("prefix",Prefix)
287                 msoLogger.trace("STARTED DoCreateVnf CreateGenericVnf Process")
288                 try {
289                         //Get Vnf Info
290                         String vnfId = getVariableEnforced(execution, "DoCVNF_vnfId")
291                         String vnfName = getVariableEnforced(execution, "DoCVNF_vnfName")
292                         if (vnfName == null) {
293                                 vnfName = "sdncGenerated"
294                                 msoLogger.debug("Sending a dummy VNF name to AAI - the name will be generated by SDNC: " + vnfName)
295                         }
296                         String vnfType = getVariableEnforced(execution, "DoCVNF_vnfType")
297                         String serviceId = getVariableEnforced(execution, "DoCVNF_serviceId")
298                         String orchStatus = getVariableEnforced(execution, "DoCVNF_orchStatus")
299                         String modelInvariantId = getVariableEnforced(execution, "DoCVNF_modelInvariantId")
300                         String modelVersionId = getVariableEnforced(execution, "DoCVNF_modelVersionId")
301                         String modelCustomizationId = getVariableEnforced(execution, "DoCVNF_modelCustomizationId")
302                         String equipmentRole = getVariableEnforced(execution, "DoCVNF_equipmentRole")
303                         String nfType = getVariableEnforced(execution, "DoCVNF_nfType")
304                         String nfRole = getVariableEnforced(execution, "DoCVNF_nfRole")
305                         String nfFunction = getVariableEnforced(execution, "DoCVNF_nfFunction")
306                         String nfNamingCode = getVariableEnforced(execution, "DoCVNF_nfNamingCode")
307
308                         //Get Service Instance Info
309                         String serviceInstanceId = getVariableEnforced(execution, "DoCVNF_serviceInstanceId")
310                         String siRelatedLink = getVariableEnforced(execution, "GENGS_siResourceLink")
311
312                         int custStart = siRelatedLink.indexOf("customer/")
313                         int custEnd = siRelatedLink.indexOf("/service-subscriptions")
314                         String globalCustId = siRelatedLink.substring(custStart + 9, custEnd)
315                         int serviceStart = siRelatedLink.indexOf("service-subscription/")
316                         int serviceEnd = siRelatedLink.indexOf("/service-instances/")
317                         String serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
318
319                         Map<String, String> payload = new LinkedHashMap<>();
320                         payload.put("vnf-id", vnfId);
321                         payload.put("vnf-name", vnfName);
322                         payload.put("service-id", serviceId);
323                         payload.put("vnf-type", vnfType);
324                         payload.put("prov-status", "PREPROV");
325                         payload.put("orchestration-status", orchStatus);
326                         payload.put("model-invariant-id", modelInvariantId);
327                         payload.put("model-version-id", modelVersionId);
328                         payload.put("model-customization-id", modelCustomizationId);
329                         payload.put("nf-type", nfType);
330                         payload.put("nf-role", nfRole);
331                         payload.put("nf-function", nfFunction);
332                         payload.put("nf-naming-code", nfNamingCode);
333
334                         AAIResourcesClient resourceClient = new AAIResourcesClient();
335                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
336                         resourceClient.create(uri, payload)
337
338                         AAIResourceUri siUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustId, serviceType, serviceInstanceId)
339                         resourceClient.connect(uri, siUri)
340
341                 }catch(Exception ex) {
342                         msoLogger.debug("Error Occured in DoCreateVnf CreateGenericVnf Process " + ex.getMessage())
343                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf CreateGenericVnf Process")
344                 }
345                 msoLogger.trace("COMPLETED DoCreateVnf CreateGenericVnf Process")
346         }
347
348         public void postProcessCreateGenericVnf (DelegateExecution execution) {
349                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
350                 execution.setVariable("prefix",Prefix)
351
352                 msoLogger.trace("STARTED DoCreateVnf PostProcessCreateGenericVnf Process")
353                 try {
354                         //Get Vnf Info
355                         String vnfId = execution.getVariable("DoCVNF_vnfId")
356                         def rollbackData = execution.getVariable("rollbackData")
357                         rollbackData.put("VNF", "vnfId", vnfId)
358                         rollbackData.put("VNF", "rollbackVnfCreate", "true")
359                         execution.setVariable("rollbackData", rollbackData)
360                 }catch(Exception ex) {
361                         msoLogger.debug("Error Occured in DoCreateVnf PostProcessCreateGenericVnf Process " + ex.getMessage())
362                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PostProcessCreateGenericVnf Process")
363                 }
364                 msoLogger.trace("COMPLETED DoCreateVnf PostProcessCreateGenericVnf Process")
365         }
366
367
368         public void preProcessSDNCAssignRequest(DelegateExecution execution){
369                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
370                 execution.setVariable("prefix", Prefix)
371                 msoLogger.trace("STARTED preProcessSDNCAssignRequest")
372                 def vnfId = execution.getVariable("DoCVNF_vnfId")
373                 def serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
374                 msoLogger.debug("NEW VNF ID: " + vnfId)
375
376                 try{
377                         //Build SDNC Request
378
379                         String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
380
381                         assignSDNCRequest = utils.formatXml(assignSDNCRequest)
382                         execution.setVariable("DoCVNF_assignSDNCRequest", assignSDNCRequest)
383                         msoLogger.debug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
384
385                 }catch(Exception e){
386                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCAssignRequest" , "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e)
387                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCAssignRequest Method:\n" + e.getMessage())
388                 }
389                 msoLogger.trace("COMPLETED preProcessSDNCAssignRequest")
390         }
391
392         public void preProcessSDNCActivateRequest(DelegateExecution execution) {
393                 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
394                         'execution=' + execution.getId() +
395                         ')'
396                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
397                 msoLogger.trace('Entered ' + method)
398                 execution.setVariable("prefix", Prefix)
399                 msoLogger.trace("STARTED preProcessSDNCActivateRequest Process")
400                 try{
401                         String vnfId = execution.getVariable("DoCVNF_vnfId")
402                         String serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
403
404                         String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
405
406                         execution.setVariable("DoCVNF_activateSDNCRequest", activateSDNCRequest)
407                         msoLogger.debug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
408
409                 }catch(Exception e){
410                         msoLogger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
411                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCActivateRequest Method:\n" + e.getMessage())
412                 }
413                 msoLogger.trace("COMPLETED  preProcessSDNCActivateRequest Process")
414         }
415
416         public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
417
418                                 String uuid = execution.getVariable('testReqId') // for junits
419                                 if(uuid==null){
420                                         uuid = execution.getVariable("DoCVNF_requestId") + "-" +        System.currentTimeMillis()
421                                 }
422                                 def callbackURL = execution.getVariable("DoCVNF_sdncCallbackUrl")
423                                 def requestId = execution.getVariable("DoCVNF_requestId")
424                                 def serviceId = execution.getVariable("DoCVNF_serviceId")
425                                 def vnfType = execution.getVariable("DoCVNF_vnfType")
426                                 def vnfName = execution.getVariable("DoCVNF_vnfName")
427                                 // Only send vnfName to SDNC if it is not null, otherwise it will get generated by SDNC on Assign
428                                 String vnfNameString = ""
429                                 if (vnfName != null) {
430                                         vnfNameString = """<vnf-name>${MsoUtils.xmlEscape(vnfName)}</vnf-name>"""
431                                 }
432                                 def tenantId = execution.getVariable("DoCVNF_tenantId")
433                                 def source = execution.getVariable("DoCVNF_source")
434                                 def vnfId = execution.getVariable("DoCVNF_vnfId")
435                                 def cloudSiteId = execution.getVariable("DoCVNF_cloudSiteId")
436                                 def modelCustomizationId = execution.getVariable("DoCVNF_modelCustomizationId")
437                                 def serviceModelInfo = execution.getVariable("serviceModelInfo")
438                                 def vnfModelInfo = execution.getVariable("vnfModelInfo")
439                                 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
440                                 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
441                                 def globalSubscriberId = execution.getVariable("DoCVNF_globalSubscriberId")
442                                 def sdncVersion = execution.getVariable("DoCVNF_sdncVersion")
443
444                                 String sdncVNFParamsXml = ""
445
446                                 if(execution.getVariable("DoCVNF_vnfParamsExistFlag") == true){
447                                         sdncVNFParamsXml = buildSDNCParamsXml(execution)
448                                 }else{
449                                         sdncVNFParamsXml = ""
450                                 }
451
452                                 String sdncRequest =
453                                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
454                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
455                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
456            <sdncadapter:RequestHeader>
457                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
458                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
459                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
460                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
461                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
462                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
463                 </sdncadapter:RequestHeader>
464         <sdncadapterworkflow:SDNCRequestData>
465                 <request-information>
466                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
467                         <request-action>CreateVnfInstance</request-action>
468                         <source>${MsoUtils.xmlEscape(source)}</source>
469                         <notification-url/>
470                         <order-number/>
471                         <order-version/>
472                 </request-information>
473                 <service-information>
474                         <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
475                         <subscription-service-type>${MsoUtils.xmlEscape(serviceId)}</subscription-service-type>
476                         ${serviceEcompModelInformation}
477                         <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
478                         <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
479                 </service-information>
480                 <vnf-information>
481                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
482                         <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
483                         ${vnfEcompModelInformation}
484                 </vnf-information>
485                 <vnf-request-input>
486                         ${vnfNameString}
487                         <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
488                         <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
489                         ${sdncVNFParamsXml}
490                 </vnf-request-input>
491         </sdncadapterworkflow:SDNCRequestData>
492         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
493
494                         msoLogger.debug("sdncRequest:  " + sdncRequest)
495                         return sdncRequest
496         }
497
498         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
499                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
500                 execution.setVariable("prefix",Prefix)
501                 msoLogger.debug("STARTED ValidateSDNCResponse Process")
502
503                 WorkflowException workflowException = execution.getVariable("WorkflowException")
504                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
505
506                 msoLogger.debug("workflowException: " + workflowException)
507
508                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
509                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
510
511                 msoLogger.debug("SDNCResponse: " + response)
512
513                 String sdncResponse = response
514                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
515                         msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)
516                         if(method.equals("get")){
517                                 String topologyGetResponse = execution.getVariable("DoCVNF_getSDNCAdapterResponse")
518                                 String data = utils.getNodeXml(topologyGetResponse, "response-data")
519                                 msoLogger.debug("topologyGetResponseData: " + data)
520                                 String vnfName = utils.getNodeText(data, "vnf-name")
521                                 msoLogger.debug("vnfName received from SDNC: " + vnfName)
522                                 execution.setVariable("vnfName", vnfName)
523                                 execution.setVariable("DoCVNF_vnfName", vnfName)
524                         }
525                         def rollbackData = execution.getVariable("rollbackData")
526                         if (method.equals("assign")) {
527                                 rollbackData.put("VNF", "rollbackSDNCAssign", "true")
528                         }
529                         else if (method.equals("activate")) {
530                                 rollbackData.put("VNF", "rollbackSDNCActivate", "true")
531                         }
532                         execution.setVariable("rollbackData", rollbackData)
533
534
535                 }else{
536                         msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
537                         throw new BpmnError("MSOWorkflowException")
538                 }
539                 msoLogger.debug("COMPLETED ValidateSDNCResponse Process")
540         }
541
542         public void preProcessSDNCGetRequest(DelegateExecution execution){
543                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
544                 execution.setVariable("prefix", Prefix)
545                 msoLogger.trace("STARTED preProcessSDNCGetRequest Process")
546                 try{
547                         def serviceInstanceId = execution.getVariable('DoCVNF_serviceInstanceId')
548
549                         String uuid = execution.getVariable('testReqId') // for junits
550                         if(uuid==null){
551                                 uuid = execution.getVariable("mso-request-id") + "-" +  System.currentTimeMillis()
552                         }
553
554                         def callbackUrl = execution.getVariable("DoCVFM_sdncCallbackUrl")
555                         msoLogger.debug("callbackUrl:" + callbackUrl)
556
557                         def vnfId = execution.getVariable('DCVFM_vnfId')
558
559                         def svcInstId = ""
560                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
561                                 svcInstId = vnfId
562                         }
563                         else {
564                                 svcInstId = serviceInstanceId
565                         }
566                         // serviceOperation will be retrieved from "object-path" element
567                         // in SDNC Assign Response for VNF
568                         String response = execution.getVariable("DoCVNF_assignSDNCAdapterResponse")
569                         msoLogger.debug("DoCVNF_assignSDNCAdapterResponse is: \n" + response)
570
571                         String serviceOperation = ""
572
573                         String data = utils.getNodeXml(response, "response-data")
574                         msoLogger.debug("responseData: " + data)
575                         serviceOperation = utils.getNodeText(data, "object-path")
576                         msoLogger.debug("VNF with sdncVersion of 1707 or later - service operation: " + serviceOperation)
577
578
579                         //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
580                         sleep(5000)
581
582                         String SDNCGetRequest =
583                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
584                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
585                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
586                                         <sdncadapter:RequestHeader>
587                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
588                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
589                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
590                                         <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
591                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
592                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
593                                 </sdncadapter:RequestHeader>
594                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
595                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
596
597
598                         execution.setVariable("DoCVNF_getSDNCRequest", SDNCGetRequest)
599                         msoLogger.debug("Outgoing GetSDNCRequest is: \n" + SDNCGetRequest)
600
601                 }catch(Exception e){
602                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest. ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
603                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
604                 }
605                 msoLogger.trace("COMPLETED preProcessSDNCGetRequest Process")
606         }
607
608         /**
609          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
610          *
611          * @param execution The flow's execution instance.
612          */
613         public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
614                 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
615                         'execution=' + execution.getId() +
616                         ')'
617                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
618                 msoLogger.trace('Entered ' + method)
619
620                 try {
621                         def vnfId = execution.getVariable('DoCVNF_vnfId')
622                         msoLogger.debug("VNF ID: " + vnfId)
623
624                         String updateAAIGenericVnfRequest = """
625                                         <UpdateAAIGenericVnfRequest>
626                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
627                                                 <orchestration-status>Active</orchestration-status>
628                                         </UpdateAAIGenericVnfRequest>
629                                 """
630                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
631                                 execution.setVariable('DoCVNF_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
632                                 msoLogger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
633
634
635                         msoLogger.trace('Exited ' + method)
636                 } catch (BpmnError e) {
637                         throw e;
638                 } catch (Exception e) {
639                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Caught exception in " + method , "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
640                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
641                 }
642         }
643
644
645 }