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