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