Merge remote-tracking branch 'origin/dublin' into 'origin/master'
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / CreateVnfInfra.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.bpmn.common.scripts.CatalogDbUtilsFactory
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.json.JSONArray;
34 import org.json.JSONObject;
35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
36 import org.onap.so.bpmn.common.scripts.CatalogDbUtils;
37 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
38 import org.onap.so.bpmn.common.scripts.MsoUtils
39 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils;
40 import org.onap.so.bpmn.common.scripts.VidUtils;
41 import org.onap.so.bpmn.core.UrnPropertiesReader
42 import org.onap.so.bpmn.core.WorkflowException
43 import org.onap.so.bpmn.core.domain.VnfResource
44 import org.onap.so.bpmn.core.json.JsonUtils;
45 import org.onap.so.bpmn.infrastructure.aai.groovyflows.AAICreateResources;
46 import org.onap.so.logger.MessageEnum
47 import org.slf4j.Logger
48 import org.slf4j.LoggerFactory
49
50
51 /**
52  * This class supports the CreateVnfInfra Flow
53  * with the creation of a generic vnf for
54  * infrastructure.
55  */
56 class CreateVnfInfra extends AbstractServiceTaskProcessor {
57         
58     private static final Logger logger = LoggerFactory.getLogger( CreateVnfInfra.class);
59         
60
61         String Prefix="CREVI_"
62         ExceptionUtil exceptionUtil = new ExceptionUtil()
63         JsonUtils jsonUtil = new JsonUtils()
64         VidUtils vidUtils = new VidUtils(this)
65         CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
66
67         /**
68          * This method gets and validates the incoming
69          * request.
70          *
71          * @param - execution
72          *
73          */
74         public void preProcessRequest(DelegateExecution execution) {
75                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
76                 execution.setVariable("prefix",Prefix)
77                 logger.trace("STARTED CreateVnfInfra PreProcessRequest Process")
78                 
79                 setBasicDBAuthHeader(execution, isDebugEnabled)
80                 execution.setVariable("CREVI_sentSyncResponse", false)
81
82                 try{
83                         // Get Variables
84                         String createVnfRequest = execution.getVariable("bpmnRequest")
85                         execution.setVariable("CREVI_createVnfRequest", createVnfRequest)
86                         logger.debug("Incoming CreateVnfInfra Request is: \n" + createVnfRequest)
87
88                         if(createVnfRequest != null){
89
90                                 String requestId = execution.getVariable("mso-request-id")
91                                 execution.setVariable("CREVI_requestId", requestId)
92                                 logger.debug("Incoming Request Id is: " + requestId)
93
94                                 String serviceInstanceId = execution.getVariable("serviceInstanceId")
95                                 execution.setVariable("CREVI_serviceInstanceId", serviceInstanceId)
96                                 logger.debug("Incoming Service Instance Id is: " + serviceInstanceId)
97
98                                 String vnfType = execution.getVariable("vnfType")
99                                 execution.setVariable("CREVI_vnfType", vnfType)
100                                 logger.debug("Incoming Vnf Type is: " + vnfType)
101
102                                 String vnfName = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.instanceName")
103                                 execution.setVariable("CREVI_vnfName", vnfName)
104                                 logger.debug("Incoming Vnf Name is: " + vnfName)
105
106                                 String serviceId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.productFamilyId")
107                                 execution.setVariable("CREVI_serviceId", serviceId)
108                                 logger.debug("Incoming Service Id is: " + serviceId)
109
110                                 String source = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.source")
111                                 execution.setVariable("CREVI_source", source)
112                                 logger.debug("Incoming Source is: " + source)
113
114                                 String suppressRollback = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.suppressRollback")
115                                 execution.setVariable("CREVI_suppressRollback", suppressRollback)
116                                 logger.debug("Incoming Suppress Rollback is: " + suppressRollback)
117                                 
118                                 def vnfModelInfo = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo")
119                                 execution.setVariable("CREVI_vnfModelInfo", vnfModelInfo)
120
121                                 String modelInvariantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelInvariantUuid")
122                                 execution.setVariable("CREVI_modelInvariantId", modelInvariantId)
123                                 logger.debug("Incoming Invariant Id is: " + modelInvariantId)
124
125                                 String modelVersion = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelVersion")
126                                 execution.setVariable("CREVI_modelVersion", modelVersion)
127                                 logger.debug("Incoming Model Version is: " + modelVersion)
128                                 
129                                 def cloudConfiguration = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.cloudConfiguration")
130                                 execution.setVariable("CREVI_cloudConfiguration", cloudConfiguration)
131                                 
132                                 String cloudSiteId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
133                                 execution.setVariable("CREVI_cloudSiteId", cloudSiteId)
134                                 logger.debug("Incoming Cloud Site Id is: " + cloudSiteId)
135                                 
136                                 String tenantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.cloudConfiguration.tenantId")
137                                 execution.setVariable("CREVI_tenantId", tenantId)
138                                 logger.debug("Incoming Tenant Id is: " + tenantId)
139
140                                 //For Completion Handler & Fallout Handler
141                                 String requestInfo =
142                                 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
143                                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
144                                         <action>CREATE</action>
145                                         <source>${MsoUtils.xmlEscape(source)}</source>
146                                    </request-info>"""
147
148                                 execution.setVariable("CREVI_requestInfo", requestInfo)
149
150                                 //TODO: Orch Status - TBD, will come from SDN-C Response in 1702
151                                 String orchStatus = "Created"
152                                 execution.setVariable("CREVI_orchStatus", orchStatus)
153
154                                 //TODO: Equipment Role - Should come from SDN-C Response in 1702
155                                 String equipmentRole = " "
156                                 execution.setVariable("CREVI_equipmentRole", equipmentRole)
157
158                                 String vnfId = execution.getVariable("testVnfId") // for junits
159                                 if(isBlank(vnfId)){
160                                         vnfId = UUID.randomUUID().toString()
161                                         logger.debug("Generated Vnf Id is: " + vnfId)
162                                 }
163                                 execution.setVariable("CREVI_vnfId", vnfId)
164
165                                 // Setting for Sub Flow Calls
166                                 execution.setVariable("CREVI_type", "generic-vnf")
167                                 execution.setVariable("GENGS_type", "service-instance")
168                                 
169                                 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
170                                 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
171                                         def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
172                                         logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
173                                                         ErrorCode.UnknownError.getValue());
174                                         
175                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
176                                 }
177                                 execution.setVariable("CREVI_sdncCallbackUrl", sdncCallbackUrl)
178                                 
179                                 def vnfInputParameters = null
180                                 try {
181                                         vnfInputParameters = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestParameters.userParams")
182                                 }
183                                 catch (Exception e) {
184                                         logger.debug("userParams are not present in the request")
185                                 }
186                                 execution.setVariable("CREVI_vnfInputParameters", vnfInputParameters)
187                                 
188                                 
189                                 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
190                         }else{
191                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Bpmn Request is Null.")
192                         }
193
194                 }catch(BpmnError b){
195                         logger.debug("Rethrowing MSOWorkflowException")
196                         throw b
197                 }catch(Exception e){
198                         logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), " Error Occurred in " +
199                                         "CreateVnfInfra PreProcessRequest method", "BPMN", ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
200                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in CreateVnfInfra PreProcessRequest")
201
202                 }
203                 logger.trace("COMPLETED CreateVnfInfra PreProcessRequest Process")
204         }
205
206         public void sendSyncResponse (DelegateExecution execution) {
207                 execution.setVariable("prefix",Prefix)
208
209                 logger.trace("STARTED CreateVnfInfra SendSyncResponse Process")
210
211                 try {
212                         String requestId = execution.getVariable("CREVI_requestId")
213                         String vnfId = execution.getVariable("CREVI_vnfId")
214
215                         String createVnfResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
216
217                         logger.debug("CreateVnfInfra Sync Response is: \n"  + createVnfResponse)
218
219                         sendWorkflowResponse(execution, 202, createVnfResponse)
220
221                         execution.setVariable("CREVI_sentSyncResponse", true)
222
223                 } catch (Exception ex) {
224                         logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), " Error Occurred in CreateVnfInfra SendSyncResponse Process", "BPMN",
225                                 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
226                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra SendSyncResponse Process")
227
228                 }
229                 logger.trace("COMPLETED CreateVnfInfra SendSyncResponse Process")
230         }
231
232         
233         public void preProcessSDNCAssignRequest(DelegateExecution execution){
234                 execution.setVariable("prefix", Prefix)
235                 logger.trace("STARTED preProcessSDNCAssignRequest")
236                 def vnfId = execution.getVariable("CREVI_vnfId")                
237                 def serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
238                 logger.debug("NEW VNF ID: " + vnfId)
239
240                 try{
241                         //Build SDNC Request
242                         
243                         String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
244
245                         assignSDNCRequest = utils.formatXml(assignSDNCRequest)
246                         execution.setVariable("CREVI_assignSDNCRequest", assignSDNCRequest)
247                         logger.debug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
248
249                 }catch(Exception e){
250                         logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Exception Occurred Processing preProcessSDNCAssignRequest", "BPMN",
251                                 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
252                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
253                 }
254                 logger.trace("COMPLETED preProcessSDNCAssignRequest")
255         }
256         
257         public void preProcessSDNCActivateRequest(DelegateExecution execution) {
258                 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
259                         'execution=' + execution.getId() +
260                         ')'
261                 logger.trace('Entered ' + method)
262                 execution.setVariable("prefix", Prefix)
263                 logger.trace("STARTED preProcessSDNCActivateRequest Process")
264                 try{
265                         String vnfId = execution.getVariable("CREVI_vnfId")                     
266                         String serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
267
268                         String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
269
270                         execution.setVariable("CREVI_activateSDNCRequest", activateSDNCRequest)
271                         logger.debug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
272
273                 }catch(Exception e){
274                         logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Exception Occured " +
275                                         "Processing preProcessSDNCActivateRequest", "BPMN", ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
276                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCActivateRequest Method:\n" + e.getMessage())
277                 }
278                 logger.trace("COMPLETED  preProcessSDNCActivateRequest Process")
279         }
280         
281         public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
282                 
283                                 String uuid = execution.getVariable('testReqId') // for junits
284                                 if(uuid==null){
285                                         uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
286                                 }
287                                 def callbackURL = execution.getVariable("CREVI_sdncCallbackUrl")
288                                 def requestId = execution.getVariable("CREVI_requestId")
289                                 def serviceId = execution.getVariable("CREVI_serviceId")
290                                 def vnfType = execution.getVariable("CREVI_vnfType")
291                                 def vnfName = execution.getVariable("CREVI_vnfName")
292                                 def tenantId = execution.getVariable("CREVI_tenantId")
293                                 def source = execution.getVariable("CREVI_source")                              
294                                 def vnfId = execution.getVariable("CREVI_vnfId")
295                                 def cloudSiteId = execution.getVariable("CREVI_cloudSiteId")
296                 
297                                 String sdncVNFParamsXml = ""
298                 
299                                 if(execution.getVariable("CREVI_vnfParamsExistFlag") == true){
300                                         sdncVNFParamsXml = buildSDNCParamsXml(execution)
301                                 }else{
302                                         sdncVNFParamsXml = ""
303                                 }
304                 
305                                 String sdncRequest =
306                                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
307                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
308                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
309            <sdncadapter:RequestHeader>
310                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(requestId)}</sdncadapter:RequestId>
311                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
312                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
313                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
314                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
315                 </sdncadapter:RequestHeader>
316         <sdncadapterworkflow:SDNCRequestData>
317                 <request-information>
318                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
319                         <request-action>VNFActivateRequest</request-action>
320                         <source>${MsoUtils.xmlEscape(source)}</source>
321                         <notification-url/>
322                 </request-information>
323                 <service-information>
324                         <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
325                         <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
326                         <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
327                         <subscriber-name>notsurewecare</subscriber-name>
328                 </service-information>
329                 <vnf-request-information>                       
330                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
331                         <vnf-name>${MsoUtils.xmlEscape(vnfName)}</vnf-name>
332                         <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
333                         <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
334                         <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
335                 ${sdncVNFParamsXml}
336                 </vnf-request-information>
337         </sdncadapterworkflow:SDNCRequestData>
338         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
339                 
340                         logger.debug("sdncRequest:  " + sdncRequest)
341                         return sdncRequest              
342         }
343                 
344         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
345                 execution.setVariable("prefix",Prefix)
346                 logger.debug("STARTED ValidateSDNCResponse Process")
347
348                 WorkflowException workflowException = execution.getVariable("WorkflowException")
349                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
350
351                 logger.debug("workflowException: " + workflowException)
352
353                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
354                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
355
356                 logger.debug("SDNCResponse: " + response)
357
358                 String sdncResponse = response
359                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
360                         logger.trace("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)
361                         
362                 }else{
363                         logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
364                         throw new BpmnError("MSOWorkflowException")
365                 }
366                 logger.trace("COMPLETED ValidateSDNCResponse Process")
367         }
368
369         public void prepareCompletionHandlerRequest(DelegateExecution execution){
370                 execution.setVariable("prefix",Prefix)
371
372                 logger.trace("STARTED CreateVnfInfra PrepareCompletionHandlerRequest Process")
373
374                 try {
375                         String requestInfo = execution.getVariable("CREVI_requestInfo")
376                         String vnfId = execution.getVariable("CREVI_vnfId")
377                         requestInfo = utils.removeXmlPreamble(requestInfo)
378
379                         String request =
380                                 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
381                                                                         xmlns:ns="http://org.onap/so/request/types/v1">
382                                                         ${requestInfo}
383                                                         <status-message>Vnf has been created successfully.</status-message>
384                                                         <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
385                                                         <mso-bpel-name>CreateVnfInfra</mso-bpel-name>
386                                                 </aetgt:MsoCompletionRequest>"""
387
388                         execution.setVariable("CREVI_completionHandlerRequest", request)
389                         logger.debug("Completion Handler Request is: " + request)
390
391                         execution.setVariable("WorkflowResponse", "Success") // for junits
392
393                 } catch (Exception ex) {
394                         logger.debug("Error Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage())
395                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process")
396
397                 }
398                 logger.trace("COMPLETED CreateVnfInfra PrepareCompletionHandlerRequest Process")
399         }
400
401         public void sendErrorResponse(DelegateExecution execution){
402                 execution.setVariable("prefix",Prefix)
403
404                 logger.trace("STARTED CreateVnfInfra sendErrorResponse Process")
405                 try {
406                         def sentSyncResponse = execution.getVariable("CREVI_sentSyncResponse")
407                         if(sentSyncResponse == false){
408                                 WorkflowException wfex = execution.getVariable("WorkflowException")
409                                 String response = exceptionUtil.buildErrorResponseXml(wfex)
410
411                                 logger.debug(response)
412                                 sendWorkflowResponse(execution, 500, response)
413                         }else{
414                                 logger.debug("Not Sending Error Response.  Sync Response Already Sent")
415                         }
416
417                 } catch (Exception ex) {
418                         logger.debug("Error Occured in CreateVnfInfra sendErrorResponse Process " + ex.getMessage())
419                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra sendErrorResponse Process")
420
421                 }
422                 logger.trace("COMPLETED CreateVnfInfra sendErrorResponse Process")
423         }
424
425         public void prepareFalloutRequest(DelegateExecution execution){
426                 execution.setVariable("prefix",Prefix)
427
428                 logger.trace("STARTED CreateVnfInfra prepareFalloutRequest Process")
429
430                 try {
431                         WorkflowException wfex = execution.getVariable("WorkflowException")
432                         logger.debug(" Incoming Workflow Exception: " + wfex.toString())
433                         String requestInfo = execution.getVariable("CREVI_requestInfo")
434                         logger.debug(" Incoming Request Info: " + requestInfo)
435
436                         String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
437
438                         execution.setVariable("CREVI_falloutRequest", falloutRequest)
439
440
441                 } catch (Exception ex) {
442                         logger.debug("Error Occured in CreateVnfInfra prepareFalloutRequest Process " + ex.getMessage())
443                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra prepareFalloutRequest Process")
444
445                 }
446                 logger.trace("COMPLETED CreateVnfInfra prepareFalloutRequest Process")
447         }
448
449         
450         public void queryCatalogDB (DelegateExecution execution) {
451                 execution.setVariable("prefix",Prefix)
452
453                 logger.trace("STARTED CreateVnfInfra QueryCatalogDB Process")
454                 try {
455                         //Get Vnf Info
456                         String vnfModelInfo = execution.getVariable("CREVI_vnfModelInfo")
457                         String vnfModelCustomizationUuid = jsonUtil.getJsonValueForKey(vnfModelInfo, "modelCustomizationUuid")
458                         logger.debug("querying Catalog DB by vnfModelCustomizationUuid: " + vnfModelCustomizationUuid)
459                                                 
460                         JSONArray vnfs = catalogDbUtils.getAllVnfsByVnfModelCustomizationUuid(execution,
461                                                         vnfModelCustomizationUuid, "v2")
462                         logger.debug("obtained VNF list: " + vnfs)
463                         
464                         if (vnfs == null) {
465                                 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "No matching " +
466                                                 "VNFs in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid, "BPMN", ErrorCode.UnknownError.getValue(), "");
467                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "No matching VNFs in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid)
468                         }
469                         
470                         // Only one match here
471                         JSONObject vnf = vnfs.get(0)
472                         
473                         if (vnf == null) {
474                                 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "No matching VNF" +
475                                                 " in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid, "BPMN", ErrorCode.UnknownError.getValue(), "");
476                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "No matching VNF in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid)
477                         }                       
478                         
479                         VnfResource vnfResource = new VnfResource()
480                         String nfType = jsonUtil.getJsonValueForKey(vnf, "nfType")
481                         vnfResource.setNfType(nfType)
482                         String nfRole = jsonUtil.getJsonValueForKey(vnf, "nfRole")
483                         vnfResource.setNfRole(nfRole)
484                         String nfFunction = jsonUtil.getJsonValueForKey(vnf, "nfFunction")
485                         vnfResource.setNfFunction(nfFunction)
486                         String nfNamingCode = jsonUtil.getJsonValueForKey(vnf, "nfNamingCode")
487                         vnfResource.setNfNamingCode(nfNamingCode)
488                         
489                         execution.setVariable("CREVI_vnfResourceDecomposition", vnfResource)
490                         
491                 }catch(BpmnError e) {
492                         throw e;                        
493                 }catch(Exception ex) {
494                         logger.debug("Error Occurred in CreateVnfInfra QueryCatalogDB Process " + ex.getMessage())
495                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in CreateVnfInfra QueryCatalogDB Process")
496                 }
497                 
498                 
499                 logger.trace("COMPLETED CreateVnfInfra QueryCatalogDb Process")
500         }
501         public void createPlatform (DelegateExecution execution) {
502                 logger.trace("START createPlatform")
503                 
504                 String request = execution.getVariable("bpmnRequest")
505                 String platformName = jsonUtil.getJsonValue(request, "requestDetails.platform.platformName")
506                 String vnfId = execution.getVariable("CREVI_vnfId")
507         
508                 logger.debug("Platform NAME: " + platformName)
509                 logger.debug("VnfID: " + vnfId)
510                 
511                 if(platformName == null||platformName.equals("")){
512                         String msg = "Exception in createPlatform. platformName was not found in the request.";
513                         logger.debug(msg)
514                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
515                 }else{
516                         logger.debug("platformName was found.")
517                         try{
518                                 AAICreateResources aaiCR = new AAICreateResources()
519                                 aaiCR.createAAIPlatform(platformName, vnfId)
520                         }catch(Exception ex){
521                                 String msg = "Exception in createPlatform. " + ex.getMessage();
522                                 logger.debug(msg)
523                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
524                         }
525                 }
526                 logger.trace("Exit createPlatform")
527         }
528         public void createLineOfBusiness (DelegateExecution execution) {
529                 logger.trace("START createLineOfBusiness")
530                 
531                 String request = execution.getVariable("bpmnRequest")
532                 String lineOfBusiness = jsonUtil.getJsonValue(request, "requestDetails.lineOfBusiness.lineOfBusinessName")
533                 String vnfId = execution.getVariable("CREVI_vnfId")
534         
535                 logger.debug("LineOfBusiness NAME: " + lineOfBusiness)
536                 logger.debug("VnfID: " + vnfId)
537                 
538                 if(lineOfBusiness == null || lineOfBusiness.equals("")){
539                         logger.debug("LineOfBusiness was not found. Continuing on with flow...")
540                 }else{
541                         logger.debug("LineOfBusiness was found.")
542                         try{
543                                 AAICreateResources aaiCR = new AAICreateResources()
544                                 aaiCR.createAAILineOfBusiness(lineOfBusiness, vnfId)
545                         }catch(Exception ex){
546                                 String msg = "Exception in LineOfBusiness. " + ex.getMessage();
547                                 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
548                                                 ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex)
549                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
550                         }
551                 }
552                 logger.trace("Exit createLineOfBusiness")
553         }
554 }