2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.common.scripts
\r
22 import org.camunda.bpm.engine.delegate.BpmnError
\r
23 import org.camunda.bpm.engine.runtime.Execution
\r
24 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
\r
25 import org.openecomp.mso.rest.APIResponse;
\r
26 import org.openecomp.mso.rest.RESTClient
\r
27 import org.openecomp.mso.rest.RESTConfig
\r
31 public MsoUtils utils = new MsoUtils()
\r
32 public static final String AAI_NAMESPACE_STRING_KEY = 'URN_mso_workflow_global_default_aai_namespace'
\r
33 public static final String DEFAULT_VERSION_KEY = 'URN_mso_workflow_global_default_aai_version'
\r
35 private String aaiNamespace = null;
\r
37 private AbstractServiceTaskProcessor taskProcessor
\r
39 public AaiUtil(AbstractServiceTaskProcessor taskProcessor) {
\r
40 this.taskProcessor = taskProcessor
\r
43 public String getNetworkGenericVnfEndpoint(Execution execution) {
\r
44 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
45 String endpoint = execution.getVariable("URN_aai_endpoint")
\r
46 def uri = getNetworkGenericVnfUri(execution)
\r
47 taskProcessor.logDebug('AaiUtil.getNetworkGenericVnfEndpoint() - AAI endpoint: ' + endpoint + uri, isDebugLogEnabled)
\r
48 return endpoint + uri
\r
51 public String getNetworkGenericVnfUri(Execution execution) {
\r
52 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
53 def uri = getUri(execution, 'generic_vnf')
\r
54 taskProcessor.logDebug('AaiUtil.getNetworkGenericVnfUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
58 public String getNetworkVpnBindingUri(Execution execution) {
\r
59 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
60 def uri = getUri(execution, 'vpn_binding')
\r
61 taskProcessor.logDebug('AaiUtil.getNetworkVpnBindingUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
65 public String getNetworkPolicyUri(Execution execution) {
\r
66 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
67 def uri = getUri(execution, 'network_policy')
\r
68 taskProcessor.logDebug('AaiUtil.getNetworkPolicyUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
72 public String getNetworkTableReferencesUri(Execution execution) {
\r
73 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
74 def uri = getUri(execution, 'route_table_reference')
\r
75 taskProcessor.logDebug('AaiUtil.getNetworkTableReferencesUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
79 public String getNetworkVceUri(Execution execution) {
\r
80 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
81 def uri = getUri(execution, 'vce')
\r
82 taskProcessor.logDebug('AaiUtil.getNetworkVceUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
86 public String getNetworkL3NetworkUri(Execution execution) {
\r
87 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
88 def uri = getUri(execution, 'l3_network')
\r
89 taskProcessor.logDebug('AaiUtil.getNetworkL3NetworkUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
93 public String getBusinessCustomerUri(Execution execution) {
\r
94 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
95 def uri = getUri(execution, 'customer')
\r
96 taskProcessor.logDebug('AaiUtil.getBusinessCustomerUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
100 //public String getBusinessCustomerUriv7(Execution execution) {
\r
101 // def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
102 // //def uri = getUri(execution, BUSINESS_CUSTOMERV7)
\r
103 // def uri = getUri(execution, 'Customer')
\r
104 // taskProcessor.logDebug('AaiUtil.getBusinessCustomerUriv7() - AAI URI: ' + uri, isDebugLogEnabled)
\r
108 public String getCloudInfrastructureCloudRegionEndpoint(Execution execution) {
\r
109 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
110 String endpoint = execution.getVariable("URN_aai_endpoint")
\r
111 def uri = getCloudInfrastructureCloudRegionUri(execution)
\r
112 taskProcessor.logDebug('AaiUtil.getCloudInfrastructureCloudRegionEndpoint() - AAI endpoint: ' + endpoint + uri, isDebugLogEnabled)
\r
113 return endpoint + uri
\r
116 public String getCloudInfrastructureCloudRegionUri(Execution execution) {
\r
117 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
118 def uri = getUri(execution, 'cloud_region')
\r
119 taskProcessor.logDebug('AaiUtil.getCloudInfrastructureCloudRegionUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
123 public String getCloudInfrastructureTenantUri(Execution execution) {
\r
124 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
125 def uri = getUri(execution, 'tenant')
\r
126 taskProcessor.logDebug('AaiUtil.getCloudInfrastructureTenantUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
130 public String getSearchNodesQueryUri(Execution execution) {
\r
131 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
132 def uri = getUri(execution, 'nodes_query')
\r
133 taskProcessor.logDebug('AaiUtil.getSearchNodesQueryUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
137 public String getSearchNodesQueryEndpoint(Execution execution) {
\r
138 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
139 String endpoint = execution.getVariable("URN_aai_endpoint")
\r
140 def uri = getSearchNodesQueryUri(execution)
\r
141 taskProcessor.logDebug('AaiUtil.getSearchNodesQueryEndpoint() - AAI endpoint: ' + endpoint + uri, isDebugLogEnabled)
\r
142 return endpoint + uri
\r
145 public String getSearchGenericQueryUri(Execution execution) {
\r
146 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
147 def uri = getUri(execution, 'generic_query')
\r
148 taskProcessor.logDebug('AaiUtil.getSearchGenericQueryUri() - AAI URI: ' + uri, isDebugLogEnabled)
\r
152 public String getVersion(Execution execution, resourceName, processKey) {
\r
153 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
155 resourceName = resourceName.replaceAll('-', '_')
\r
157 def versionWithResourceKey = "URN_mso_workflow_default_aai_${resourceName}_version"
\r
158 def versionWithProcessKey = "URN_mso_workflow_custom_${processKey}_aai_version"
\r
160 def version = execution.getVariable(versionWithProcessKey)
\r
162 taskProcessor.logDebug("AaiUtil.getVersion() - using flow specific ${versionWithProcessKey}=${version}", isDebugLogEnabled)
\r
166 version = execution.getVariable(versionWithResourceKey)
\r
168 taskProcessor.logDebug("AaiUtil.getVersion() - using resource specific ${versionWithResourceKey}=${version}", isDebugLogEnabled)
\r
172 version = execution.getVariable(DEFAULT_VERSION_KEY)
\r
174 taskProcessor.logDebug("AaiUtil.getVersion() - using default version ${DEFAULT_VERSION_KEY}=${version}", isDebugLogEnabled)
\r
178 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, "Internal Error: One of the following should be defined in MSO URN properties file: ${versionWithResourceKey}, ${versionWithProcessKey}, ${DEFAULT_VERSION_KEY}")
\r
181 public String getUri(Execution execution, resourceName) {
\r
183 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
184 def processKey = taskProcessor.getMainProcessKey(execution)
\r
185 resourceName = resourceName.replaceAll('-', '_')
\r
188 setNamespace(execution)
\r
190 // Check for flow+resource specific first
\r
191 def key = "URN_mso_workflow_${processKey}_aai_${resourceName}_uri"
\r
192 def uri = execution.getVariable(key)
\r
194 taskProcessor.logDebug("AaiUtil.getUri() - using flow+resource specific key: ${key}=${uri}", isDebugLogEnabled)
\r
198 // Check for versioned key
\r
199 def version = getVersion(execution, resourceName, processKey)
\r
200 key = "URN_mso_workflow_default_aai_v${version}_${resourceName}_uri"
\r
201 uri = execution.getVariable(key)
\r
204 taskProcessor.logDebug("AaiUtil.getUri() - using versioned URI key: ${key}=${uri}", isDebugLogEnabled)
\r
208 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
\r
211 public String setNamespace(Execution execution) {
\r
212 def key = AAI_NAMESPACE_STRING_KEY
\r
213 aaiNamespace = execution.getVariable(key)
\r
214 if (aaiNamespace == null ) {
\r
215 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
\r
220 * This method can be used for getting the building namespace out of uri.
\r
221 * NOTE: A getUri() method needs to be invoked first.
\r
222 * Alternative method is the getNamespaceFromUri(Execution execution, String uri)
\r
223 * return namespace (plus version from uri)
\r
227 * @return namespace
\r
230 public String getNamespaceFromUri(String uri) {
\r
231 if (aaiNamespace == null) {
\r
232 throw new Exception('Internal Error: AAI Namespace has not been set yet. A getUri() method needs to be invoked first.')
\r
234 String namespace = aaiNamespace
\r
236 String version = getVersionFromUri(uri)
\r
237 return namespace + "v"+version
\r
244 * This method can be used for building namespace with aai version out of uri.
\r
245 * NOTE: 2 arguments: Execution execution & String uri
\r
249 * @return namespace
\r
251 public String getNamespaceFromUri(Execution execution, String uri) {
\r
252 String namespace = execution.getVariable(AAI_NAMESPACE_STRING_KEY)
\r
253 if (namespace == null ) {
\r
254 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + AAI_NAMESPACE_STRING_KEY + ' not defined in the MSO URN properties file')
\r
257 String version = getVersionFromUri(uri)
\r
258 return namespace + "v"+version
\r
265 * This is used to extract the version from uri.
\r
271 private String getVersionFromUri(String uri) {
\r
273 def savedVersion = ""
\r
274 for (int x=2; x<6; x++) {
\r
275 version = uri.substring(uri.indexOf("v")+1, uri.indexOf("v")+x)
\r
276 if (!Character.isDigit(version.charAt(version.size()-1))) {
\r
279 savedVersion = version
\r
281 return savedVersion
\r
286 * This reusable method can be used for making AAI Get Calls. The url should
\r
287 * be passed as a parameter along with the execution. The method will
\r
288 * return an APIResponse.
\r
293 * @return APIResponse
\r
296 public APIResponse executeAAIGetCall(Execution execution, String url){
\r
297 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
298 taskProcessor.logDebug(" ======== STARTED Execute AAI Get Process ======== ", isDebugEnabled)
\r
299 APIResponse apiResponse = null
\r
301 String uuid = utils.getRequestID()
\r
302 taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
\r
303 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
305 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
307 RESTConfig config = new RESTConfig(url);
\r
308 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
\r
310 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
311 client.addAuthorizationHeader(basicAuthCred)
\r
313 apiResponse = client.get()
\r
315 taskProcessor.logDebug( "======== COMPLETED Execute AAI Get Process ======== ", isDebugEnabled)
\r
316 }catch(Exception e){
\r
317 taskProcessor.logDebug("Exception occured while executing AAI Get Call. Exception is: \n" + e, isDebugEnabled)
\r
318 throw new BpmnError("MSOWorkflowException")
\r
325 * This reusable method can be used for making AAI httpPut Calls. The url should
\r
326 * be passed as a parameter along with the execution and payload. The method will
\r
327 * return an APIResponse.
\r
333 * @return APIResponse
\r
336 public APIResponse executeAAIPutCall(Execution execution, String url, String payload){
\r
337 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
338 taskProcessor.logDebug( " ======== Started Execute AAI Put Process ======== ", isDebugEnabled)
\r
339 APIResponse apiResponse = null
\r
341 String uuid = utils.getRequestID()
\r
342 taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
\r
343 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
345 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
347 RESTConfig config = new RESTConfig(url);
\r
348 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/xml").addHeader("Accept","application/xml");
\r
349 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
350 client.addAuthorizationHeader(basicAuthCred)
\r
352 apiResponse = client.httpPut(payload)
\r
354 taskProcessor.logDebug( "======== Completed Execute AAI Put Process ======== ", isDebugEnabled)
\r
355 }catch(Exception e){
\r
356 taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Put Call. Exception is: \n" + e, isDebugEnabled)
\r
357 throw new BpmnError("MSOWorkflowException")
\r
363 * This reusable method can be used for making AAI httpPatch Calls. The url should
\r
364 * be passed as a parameter along with the execution and payload. The method will
\r
365 * return an APIResponse.
\r
371 * @return APIResponse
\r
374 public APIResponse executeAAIPatchCall(Execution execution, String url, String payload){
\r
375 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
376 taskProcessor.logDebug( " ======== Started Execute AAI Patch Process ======== ", isDebugEnabled)
\r
377 APIResponse apiResponse = null
\r
379 String uuid = utils.getRequestID()
\r
380 taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
\r
382 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
384 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
386 RESTConfig config = new RESTConfig(url);
\r
387 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/merge-patch+json").addHeader("Accept","application/json");
\r
388 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
389 client.addAuthorizationHeader(basicAuthCred)
\r
391 apiResponse = client.httpPatch(payload)
\r
393 taskProcessor.logDebug( "======== Completed Execute AAI Patch Process ======== ", isDebugEnabled)
\r
394 }catch(Exception e){
\r
395 taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Patch Call. Exception is: \n" + e, isDebugEnabled)
\r
396 throw new BpmnError("MSOWorkflowException")
\r
403 * This reusable method can be used for making AAI Delete Calls. The url should
\r
404 * be passed as a parameter along with the execution. The method will
\r
405 * return an APIResponse.
\r
410 * @return APIResponse
\r
413 public APIResponse executeAAIDeleteCall(Execution execution, String url){
\r
414 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
415 taskProcessor.logDebug( " ======== Started Execute AAI Delete Process ======== ", isDebugEnabled)
\r
416 APIResponse apiResponse = null
\r
418 String uuid = utils.getRequestID()
\r
419 taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
\r
420 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
422 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
424 RESTConfig config = new RESTConfig(url);
\r
425 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
\r
426 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
427 client.addAuthorizationHeader(basicAuthCred)
\r
429 apiResponse = client.delete()
\r
431 taskProcessor.logDebug( "======== Completed Execute AAI Delete Process ======== ", isDebugEnabled)
\r
432 }catch(Exception e){
\r
433 taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Delete Call. Exception is: \n" + e, isDebugEnabled)
\r
434 throw new BpmnError("MSOWorkflowException")
\r
440 * This reusable method can be used for making AAI Delete Calls. The url should
\r
441 * be passed as a parameter along with the execution. The method will
\r
442 * return an APIResponse.
\r
448 * @return APIResponse
\r
451 public APIResponse executeAAIDeleteCall(Execution execution, String url, String payload, String authHeader){
\r
452 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
453 taskProcessor.logDebug( " ======== Started Execute AAI Delete Process ======== ", isDebugEnabled)
\r
454 APIResponse apiResponse = null
\r
456 String uuid = utils.getRequestID()
\r
457 taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
\r
459 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
461 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
462 RESTConfig config = new RESTConfig(url);
\r
463 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml").addAuthorizationHeader(authHeader);
\r
464 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
465 client.addAuthorizationHeader(basicAuthCred)
\r
467 apiResponse = client.httpDelete(payload)
\r
469 taskProcessor.logDebug( "======== Completed Execute AAI Delete Process ======== ", isDebugEnabled)
\r
470 }catch(Exception e){
\r
471 taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Delete Call. Exception is: \n" + e, isDebugEnabled)
\r
472 throw new BpmnError("MSOWorkflowException")
\r
478 * This reusable method can be used for making AAI Post Calls. The url
\r
479 * and payload should be passed as a parameters along with the execution.
\r
480 * The method will return an APIResponse.
\r
486 * @return APIResponse
\r
489 public APIResponse executeAAIPostCall(Execution execution, String url, String payload){
\r
490 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
491 taskProcessor.logDebug( " ======== Started Execute AAI Post Process ======== ", isDebugEnabled)
\r
492 APIResponse apiResponse = null
\r
494 String uuid = utils.getRequestID()
\r
495 taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
\r
496 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
498 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
499 RESTConfig config = new RESTConfig(url);
\r
500 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
\r
502 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
503 client.addAuthorizationHeader(basicAuthCred)
\r
505 apiResponse = client.httpPost(payload)
\r
507 taskProcessor.logDebug( "======== Completed Execute AAI Post Process ======== ", isDebugEnabled)
\r
508 }catch(Exception e){
\r
509 taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)
\r
510 throw new BpmnError("MSOWorkflowException")
\r
516 * This reusable method can be used for making AAI Post Calls. The url
\r
517 * and payload should be passed as a parameters along with the execution.
\r
518 * The method will return an APIResponse.
\r
523 * @param authenticationHeader - addAuthenticationHeader value
\r
524 * @param headerName - name of header you want to add, i.e. addHeader(headerName, headerValue)
\r
525 * @param headerValue - the header's value, i.e. addHeader(headerName, headerValue)
\r
527 * @return APIResponse
\r
530 public APIResponse executeAAIPostCall(Execution execution, String url, String payload, String authenticationHeaderValue, String headerName, String headerValue){
\r
531 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
532 taskProcessor.logDebug( " ======== Started Execute AAI Post Process ======== ", isDebugEnabled)
\r
533 APIResponse apiResponse = null
\r
535 taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
\r
537 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
\r
539 RESTConfig config = new RESTConfig(url);
\r
540 RESTClient client = new RESTClient(config).addAuthorizationHeader(authenticationHeaderValue).addHeader(headerName, headerValue)
\r
541 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
\r
542 client.addAuthorizationHeader(basicAuthCred)
\r
544 apiResponse = client.httpPost(payload)
\r
546 taskProcessor.logDebug( "======== Completed Execute AAI Post Process ======== ", isDebugEnabled)
\r
547 }catch(Exception e){
\r
548 taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)
\r
549 throw new BpmnError("MSOWorkflowException")
\r
555 /* Utility to get the Cloud Region from AAI
\r
556 * Returns String cloud region id, (ie, cloud-region-id)
\r
558 * @param url - url for AAI get cloud region
\r
559 * @param backend - "PO" - real region, or "SDNC" - v2.5 (fake region).
\r
562 public String getAAICloudReqion(Execution execution, String url, String backend, inputCloudRegion){
\r
563 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
564 String regionId = ""
\r
566 APIResponse apiResponse = executeAAIGetCall(execution, url)
\r
567 String returnCode = apiResponse.getStatusCode()
\r
568 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
569 taskProcessor.utils.log("DEBUG", "Call AAI Cloud Region Return code: " + returnCode, isDebugEnabled)
\r
570 execution.setVariable(execution.getVariable("prefix")+"queryCloudRegionReturnCode", returnCode)
\r
572 if(returnCode == "200"){
\r
573 taskProcessor.utils.log("DEBUG", "Call AAI Cloud Region is Successful.", isDebugEnabled)
\r
575 String regionVersion = taskProcessor.utils.getNodeText1(aaiResponseAsString, "cloud-region-version")
\r
576 taskProcessor.utils.log("DEBUG", "Cloud Region Version from AAI for " + backend + " is: " + regionVersion, isDebugEnabled)
\r
577 if (backend == "PO") {
\r
578 regionId = taskProcessor.utils.getNodeText1(aaiResponseAsString, "cloud-region-id")
\r
579 } else { // backend not "PO"
\r
580 if (regionVersion == "2.5" ) {
\r
581 regionId = "AAIAIC25"
\r
583 regionId = taskProcessor.utils.getNodeText1(aaiResponseAsString, "cloud-region-id")
\r
586 if(regionId == null){
\r
587 throw new BpmnError("MSOWorkflowException")
\r
589 taskProcessor.utils.log("DEBUG", "Cloud Region Id from AAI " + backend + " is: " + regionId, isDebugEnabled)
\r
590 }else if (returnCode == "404"){ // not 200
\r
591 if (backend == "PO") {
\r
592 regionId = inputCloudRegion
\r
593 }else{ // backend not "PO"
\r
594 regionId = "AAIAIC25"
\r
596 taskProcessor.utils.log("DEBUG", "Cloud Region value for code='404' of " + backend + " is: " + regionId, isDebugEnabled)
\r
598 taskProcessor.utils.log("ERROR", "Call AAI Cloud Region is NOT Successful.", isDebugEnabled)
\r
599 throw new BpmnError("MSOWorkflowException")
\r
601 }catch(Exception e) {
\r
602 taskProcessor.utils.log("ERROR", "Exception occured while getting the Cloud Reqion. Exception is: \n" + e, isDebugEnabled)
\r
603 throw new BpmnError("MSOWorkflowException")
\r
608 /* returns xml Node with service-type of searchValue */
\r
609 def searchServiceType(xmlInput, searchValue){
\r
610 def fxml= new XmlSlurper().parseText(xmlInput)
\r
611 def ret = fxml.'**'.find {it.'service-type' == searchValue}
\r
615 /* returns xml Node with service-instance-id of searchValue */
\r
616 def searchServiceInstanceId(xmlInput, searchValue){
\r
617 def ret = xmlInput.'**'.find {it.'service-instance-id' == searchValue}
\r
622 * Get the lowest unused VF Module index from AAI response for a given module type. The criteria for
\r
623 * determining module type is specified by "key" parameter (for example, "persona-model-id"),
\r
624 * the value for filtering is specified in "value" parameter
\r
627 * @param aaiVnfResponse
\r
631 * @return moduleIndex
\r
634 public int getLowestUnusedVfModuleIndexFromAAIVnfResponse(Execution execution, String aaiVnfResponse, String key, String value) {
\r
635 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
636 if (aaiVnfResponse != null) {
\r
637 String vfModulesText = taskProcessor.utils.getNodeXml(aaiVnfResponse, "vf-modules")
\r
638 if (vfModulesText == null || vfModulesText.isEmpty()) {
\r
639 taskProcessor.utils.log("DEBUG", "There are no VF modules in this VNF yet", isDebugEnabled)
\r
643 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
\r
644 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
\r
645 int vfModulesSize = 0
\r
646 if (vfModules != null) {
\r
647 vfModulesSize = vfModules.size()
\r
649 String matchingVfModules = "<vfModules>"
\r
650 for (i in 0..vfModulesSize-1) {
\r
651 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
\r
652 def keyFromAAI = taskProcessor.utils.getNodeText(vfModuleXml, key)
\r
653 if (keyFromAAI != null && keyFromAAI.equals(value)) {
\r
654 matchingVfModules = matchingVfModules + taskProcessor.utils.removeXmlPreamble(vfModuleXml)
\r
657 matchingVfModules = matchingVfModules + "</vfModules>"
\r
658 taskProcessor.utils.log("DEBUG", "Matching VF Modules: " + matchingVfModules, isDebugEnabled)
\r
659 String lowestUnusedIndex = taskProcessor.utils.getLowestUnusedIndex(matchingVfModules)
\r
660 return Integer.parseInt(lowestUnusedIndex)
\r