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