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