aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/AaiUtil.groovy
blob: 95a577c946338a68c2eda12d5d5e45d5a5cdc7e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*-
 * ============LICENSE_START=======================================================
 * OPENECOMP - MSO
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.mso.bpmn.common.scripts
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.runtime.Execution
import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
import org.openecomp.mso.rest.APIResponse;
import org.openecomp.mso.rest.RESTClient
import org.openecomp.mso.rest.RESTConfig

class AaiUtil {
	
	public MsoUtils utils = new MsoUtils()
	public static final String AAI_NAMESPACE_STRING = 'http://org.openecomp.aai.inventory/'
	public static final String DEFAULT_VERSION_KEY = 'URN_mso_workflow_global_default_aai_version'
	
	private AbstractServiceTaskProcessor taskProcessor

	public AaiUtil(AbstractServiceTaskProcessor taskProcessor) {
		this.taskProcessor = taskProcessor
	}
	
	public String getNetworkGenericVnfEndpoint(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		String endpoint = execution.getVariable("URN_aai_endpoint")
		def uri = getNetworkGenericVnfUri(execution)
		taskProcessor.logDebug('AaiUtil.getNetworkGenericVnfEndpoint() - AAI endpoint: ' + endpoint + uri, isDebugLogEnabled)
		return endpoint + uri
	}

	public String getNetworkGenericVnfUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'generic_vnf')
		taskProcessor.logDebug('AaiUtil.getNetworkGenericVnfUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}
		
	public String getNetworkVpnBindingUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'vpn_binding')
		taskProcessor.logDebug('AaiUtil.getNetworkVpnBindingUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getNetworkPolicyUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'network_policy')
		taskProcessor.logDebug('AaiUtil.getNetworkPolicyUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getNetworkTableReferencesUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'route_table_reference')
		taskProcessor.logDebug('AaiUtil.getNetworkTableReferencesUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}
	
	public String getNetworkVceUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'vce')
		taskProcessor.logDebug('AaiUtil.getNetworkVceUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getNetworkL3NetworkUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'l3_network')
		taskProcessor.logDebug('AaiUtil.getNetworkL3NetworkUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getBusinessCustomerUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'customer')
		taskProcessor.logDebug('AaiUtil.getBusinessCustomerUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	//public String getBusinessCustomerUriv7(Execution execution) {
	//	def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
	//	//def uri = getUri(execution, BUSINESS_CUSTOMERV7)
	//	def uri = getUri(execution, 'Customer')
	//	taskProcessor.logDebug('AaiUtil.getBusinessCustomerUriv7() - AAI URI: ' + uri, isDebugLogEnabled)
	//	return uri
	//}

	public String getCloudInfrastructureCloudRegionEndpoint(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		String endpoint = execution.getVariable("URN_aai_endpoint")
		def uri = getCloudInfrastructureCloudRegionUri(execution)
		taskProcessor.logDebug('AaiUtil.getCloudInfrastructureCloudRegionEndpoint() - AAI endpoint: ' + endpoint + uri, isDebugLogEnabled)
		return endpoint + uri
	}
	
	public String getCloudInfrastructureCloudRegionUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'cloud_region')
		taskProcessor.logDebug('AaiUtil.getCloudInfrastructureCloudRegionUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getCloudInfrastructureTenantUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'tenant')
		taskProcessor.logDebug('AaiUtil.getCloudInfrastructureTenantUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getSearchNodesQueryUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'nodes_query')
		taskProcessor.logDebug('AaiUtil.getSearchNodesQueryUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}
	
	public String getSearchNodesQueryEndpoint(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		String endpoint = execution.getVariable("URN_aai_endpoint")
		def uri = getSearchNodesQueryUri(execution)
		taskProcessor.logDebug('AaiUtil.getSearchNodesQueryEndpoint() - AAI endpoint: ' + endpoint + uri, isDebugLogEnabled)
		return endpoint + uri
	}
	
	public String getSearchGenericQueryUri(Execution execution) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def uri = getUri(execution, 'generic_query')
		taskProcessor.logDebug('AaiUtil.getSearchGenericQueryUri() - AAI URI: ' + uri, isDebugLogEnabled)
		return uri
	}

	public String getVersion(Execution execution, resourceName, processKey) {
		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')

		resourceName = resourceName.replaceAll('-', '_')
		
		def versionWithResourceKey = "URN_mso_workflow_default_aai_${resourceName}_version"
		def versionWithProcessKey = "URN_mso_workflow_custom_${processKey}_aai_version"

		def version = execution.getVariable(versionWithProcessKey)
		if (version) {
			taskProcessor.logDebug("AaiUtil.getVersion() - using flow specific ${versionWithProcessKey}=${version}", isDebugLogEnabled)
			return version 
		}
		
		version = execution.getVariable(versionWithResourceKey)
		if (version) {
			taskProcessor.logDebug("AaiUtil.getVersion() - using resource specific ${versionWithResourceKey}=${version}", isDebugLogEnabled)
			return version
		}
		
		version = execution.getVariable(DEFAULT_VERSION_KEY)
		if (version) {
			taskProcessor.logDebug("AaiUtil.getVersion() - using default version ${DEFAULT_VERSION_KEY}=${version}", isDebugLogEnabled)
			return version
		}
		
		(new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, "Internal Error: One of the following should be defined in MSO URN properties file: ${versionWithResourceKey}, ${versionWithProcessKey}, ${DEFAULT_VERSION_KEY}")
	}
	
	public String getUri(Execution execution, resourceName) {

		def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
		def processKey = taskProcessor.getMainProcessKey(execution)
		
		resourceName = resourceName.replaceAll('-', '_')
		
		// Check for flow+resource specific first
		def key = "URN_mso_workflow_${processKey}_aai_${resourceName}_uri"
		def uri = execution.getVariable(key)
		if(uri) {
			taskProcessor.logDebug("AaiUtil.getUri() - using flow+resource specific key: ${key}=${uri}", isDebugLogEnabled)
			return uri
		}
		
		// Check for versioned key
		def version = getVersion(execution, resourceName, processKey)
		key = "URN_mso_workflow_default_aai_v${version}_${resourceName}_uri"
		uri = execution.getVariable(key)

		if(uri) {
			taskProcessor.logDebug("AaiUtil.getUri() - using versioned URI key: ${key}=${uri}", isDebugLogEnabled)
			return uri
		}

		(new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
	}

	public String getNamespaceFromUri(String uri) {
		String namespace = AAI_NAMESPACE_STRING
		if(uri!=null){
			return namespace + uri.substring(uri.indexOf("v"),  uri.indexOf("v")+2)
		}else{
			return namespace
		}
	}


	
	/**
	 * This reusable method can be used for making AAI Get Calls. The url should
	 * be passed as a parameter along with the execution.  The method will
	 * return an APIResponse.
	 *
	 * @param execution
	 * @param url
	 *
	 * @return APIResponse
	 */
	public APIResponse executeAAIGetCall(Execution execution, String url){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		taskProcessor.logDebug(" ======== STARTED Execute AAI Get Process ======== ", isDebugEnabled)
		try{
			String uuid = UUID.randomUUID()
			taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
			taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
					
			String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))

			RESTConfig config = new RESTConfig(url);
			RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");

			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}

			APIResponse apiResponse = client.get()
			return apiResponse

		}catch(Exception e){
			taskProcessor.logDebug("Exception occured while executing AAI Get Call. Exception is: \n" + e, isDebugEnabled)
			return e
		}
		taskProcessor.logDebug( "======== COMPLETED Execute AAI Get Process ======== ", isDebugEnabled)
	}

	/**
	 * This reusable method can be used for making AAI httpPut Calls. The url should
	 * be passed as a parameter along with the execution and payload.  The method will
	 * return an APIResponse.
	 *
	 * @param execution
	 * @param url
	 * @param payload
	 *
	 * @return APIResponse
	 */
	public APIResponse executeAAIPutCall(Execution execution, String url, String payload){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		taskProcessor.logDebug( " ======== Started Execute AAI Put Process ======== ", isDebugEnabled)
		try{
			String uuid = UUID.randomUUID()
			taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
			taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
			
			String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))

			RESTConfig config = new RESTConfig(url);
			RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/xml").addHeader("Accept","application/xml");
			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}
			APIResponse apiResponse = client.httpPut(payload)

			return apiResponse
		}catch(Exception e){
			taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Put Call. Exception is: \n" + e, isDebugEnabled)
			return e
		}
		taskProcessor.logDebug( "======== Completed Execute AAI Put Process ======== ", isDebugEnabled)
	}
	
	/**
	 * This reusable method can be used for making AAI httpPatch Calls. The url should
	 * be passed as a parameter along with the execution and payload.  The method will
	 * return an APIResponse.
	 *
	 * @param execution
	 * @param url
	 * @param payload
	 *
	 * @return APIResponse
	 */
	public APIResponse executeAAIPatchCall(Execution execution, String url, String payload){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		taskProcessor.logDebug( " ======== Started Execute AAI Patch Process ======== ", isDebugEnabled)
		try{
			String uuid = UUID.randomUUID()
			taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)

			taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)

			String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
			
			RESTConfig config = new RESTConfig(url);
			RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/merge-patch+json").addHeader("Accept","application/json");
			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}
			APIResponse apiResponse = client.httpPatch(payload)

			return apiResponse
		}catch(Exception e){
			taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Patch Call. Exception is: \n" + e, isDebugEnabled)
			return e
		}
		taskProcessor.logDebug( "======== Completed Execute AAI Patch Process ======== ", isDebugEnabled)
	}


	/**
	 * This reusable method can be used for making AAI Delete Calls. The url should
	 * be passed as a parameter along with the execution.  The method will
	 * return an APIResponse.
	 *
	 * @param execution
	 * @param url
	 *
	 * @return APIResponse
	 */
	public APIResponse executeAAIDeleteCall(Execution execution, String url){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		taskProcessor.logDebug( " ======== Started Execute AAI Delete Process ======== ", isDebugEnabled)
		try{
			String uuid = UUID.randomUUID()
			taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
			taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)

			String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
			
			RESTConfig config = new RESTConfig(url);
			RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}
			APIResponse apiResponse = client.delete()

			return apiResponse

		}catch(Exception e){
			taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Delete Call. Exception is: \n" + e, isDebugEnabled)
			return e
		}
		taskProcessor.logDebug( "======== Completed Execute AAI Delete Process ======== ", isDebugEnabled)
	}

	/**
	 * This reusable method can be used for making AAI Delete Calls. The url should
	 * be passed as a parameter along with the execution.  The method will
	 * return an APIResponse.
	 *
	 * @param execution
	 * @param url
	 * @param payload
	 *
	 * @return APIResponse
	 */
	public APIResponse executeAAIDeleteCall(Execution execution, String url, String payload, String authHeader){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		taskProcessor.logDebug( " ======== Started Execute AAI Delete Process ======== ", isDebugEnabled)
		try{
			String uuid = UUID.randomUUID()
			taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
			taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
			
			String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
			RESTConfig config = new RESTConfig(url);
			RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml").addAuthorizationHeader(authHeader);
			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}
			
			APIResponse apiResponse = client.httpDelete(payload)

			return apiResponse

		}catch(Exception e){
			taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Delete Call. Exception is: \n" + e, isDebugEnabled)
			return e
		}
		taskProcessor.logDebug( "======== Completed Execute AAI Delete Process ======== ", isDebugEnabled)
	}
	
	/**
	 * This reusable method can be used for making AAI Post Calls. The url should
	 * be passed as a parameter along with the execution.  The method will
	 * return an APIResponse.
	 *
	 * @param execution
	 * @param url
	 * @param payload
	 *
	 * @return APIResponse
	 */
	public APIResponse executeAAIPostCall(Execution execution, String url, String payload){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		taskProcessor.logDebug( " ======== Started Execute AAI Post Process ======== ", isDebugEnabled)
		try{
			String uuid = UUID.randomUUID()
			taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
			taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)

			String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
			RESTConfig config = new RESTConfig(url);
			RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}
			APIResponse apiResponse = client.httpPost(payload)

			return apiResponse

		}catch(Exception e){
			taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)
			return e
		}
		taskProcessor.logDebug( "======== Completed Execute AAI Post Process ======== ", isDebugEnabled)
	}

	/** Utilitty to get the Cloud Region from AAI
	 * Returns String cloud region id, (ie, cloud-region-id)
	 * @param execution
	 * @param url  - url for AAI get cloud region
	 * @param backend - "PO" - real region, or "SDNC" - v2.5 (fake region).
	 */

	//TODO: We should refactor this method to return WorkflowException instead of Error. Also to throw MSOWorkflowException which the calling flow will then catch.

	public String getAAICloudReqion(Execution execution, String url, String backend, inputCloudRegion){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")

		try {
		  APIResponse apiResponse = executeAAIGetCall(execution, url)
		  String returnCode = apiResponse.getStatusCode()
		  String aaiResponseAsString = apiResponse.getResponseBodyAsString()
		  taskProcessor.utils.log("DEBUG", "Call AAI Cloud Region Return code: " + returnCode, isDebugEnabled)
		  execution.setVariable(execution.getVariable("prefix")+"queryCloudRegionReturnCode", returnCode)
		  //taskProcessor.utils.log("DEBUG", "Call AAI Cloud Region Response: " + aaiResponseAsString, isDebugEnabled)
		  //execution.setVariable(execution.getVariable("prefix")+"queryCloudRegionResponse", aaiResponseAsString)
		  String regionId = ""
		  if (returnCode == "200") {
			 taskProcessor.utils.log("DEBUG", "Call AAI Cloud Region is Successful.", isDebugEnabled)
			   try {
			   String regionVersion = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-version")
			   taskProcessor.utils.log("DEBUG", "Cloud Region Version from AAI for " + backend + " is: " + regionVersion, isDebugEnabled)
			   if (backend == "PO") {
				  regionId = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-id")
			   } else { // backend not "PO"
				  if (regionVersion == "2.5" ) {
					  regionId = "AAIAIC25"
				  } else {
					  regionId = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-id")
				  }
			   }

			   taskProcessor.utils.log("DEBUG", "Cloud Region Id from AAI " + backend + " is: " + regionId, isDebugEnabled)
			   return regionId

			 } catch (Exception e) {
				  taskProcessor.utils.log("ERROR", "Exception occured while getting the Cloud Reqion. Exception is: \n" + e, isDebugEnabled)
				  return "ERROR"
			 }
		  } else { // not 200
		      if (returnCode == "404") {
				 if (backend == "PO") {
					  regionId = inputCloudRegion
				 } else  {  // backend not "PO"
					  regionId = "AAIAIC25"
				 }
				 taskProcessor.utils.log("DEBUG", "Cloud Region value for code='404' of " + backend + " is: " + regionId, isDebugEnabled)
				  return regionId
		      } else {
			      taskProcessor.utils.log("ERROR", "Call AAI Cloud Region is NOT Successful.", isDebugEnabled)
			      return "ERROR"
		      }
		  }
		}catch(Exception e) {
		   taskProcessor.utils.log("ERROR", "Exception occured while getting the Cloud Reqion. Exception is: \n" + e, isDebugEnabled)
		   return "ERROR"
		}
	}

	/* returns xml Node with service-type of searchValue */
	def searchServiceType(xmlInput, searchValue){
		def fxml= new XmlSlurper().parseText(xmlInput)
		def ret = fxml.'**'.find {it.'service-type' == searchValue}
		return ret
	}

	/* returns xml Node with service-instance-id of searchValue */
	def searchServiceInstanceId(xmlInput, searchValue){
		def ret = xmlInput.'**'.find {it.'service-instance-id' == searchValue}
		return ret
	}

	
	/**
	 * Get the lowest unused VF Module index from AAI response for a given module type. The criteria for 
	 * determining module type is specified by "key" parameter (for example, "persona-model-id"),
	 * the value for filtering is specified in "value" parameter
	 * 
	 * @param execution
	 * @param aaiVnfResponse
	 * @param key
	 * @param value
	 *
	 * @return moduleIndex
	 * 
	 */
	public int getLowestUnusedVfModuleIndexFromAAIVnfResponse(Execution execution, String aaiVnfResponse, String key, String value) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		if (aaiVnfResponse != null) {
			String vfModulesText = taskProcessor.utils.getNodeXml(aaiVnfResponse, "vf-modules")
			if (vfModulesText == null || vfModulesText.isEmpty()) {
				taskProcessor.utils.log("DEBUG", "There are no VF modules in this VNF yet", isDebugEnabled)
				return 0				
			}
			else {
				def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
				def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
				int vfModulesSize = 0
				if (vfModules != null) {
					vfModulesSize = vfModules.size()
				}
				String matchingVfModules = "<vfModules>"
				for (i in 0..vfModulesSize-1) {
					def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
					def keyFromAAI = taskProcessor.utils.getNodeText(vfModuleXml, key)
					if (keyFromAAI != null && keyFromAAI.equals(value)) {
						matchingVfModules = matchingVfModules + taskProcessor.utils.removeXmlPreamble(vfModuleXml)
					}
				}
				matchingVfModules = matchingVfModules + "</vfModules>"				
				taskProcessor.utils.log("DEBUG", "Matching VF Modules: " + matchingVfModules, isDebugEnabled)
				String lowestUnusedIndex = taskProcessor.utils.getLowestUnusedIndex(matchingVfModules)
				return Integer.parseInt(lowestUnusedIndex)
			}			
		}
		else {
			return 0
		}
	}

}