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