2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.common.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.onap.so.bpmn.core.UrnPropertiesReader;
25 import org.onap.so.rest.APIResponse;
26 import org.onap.so.rest.RESTClient
27 import org.onap.so.rest.RESTConfig
28 import org.onap.so.logger.MessageEnum
29 import org.onap.so.logger.MsoLogger
32 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AaiUtil.class);
35 public MsoUtils utils = new MsoUtils()
36 public static final String AAI_NAMESPACE_STRING_KEY = 'mso.workflow.global.default.aai.namespace'
37 public static final String DEFAULT_VERSION_KEY = 'mso.workflow.global.default.aai.version'
39 private String aaiNamespace = null;
41 private AbstractServiceTaskProcessor taskProcessor
43 public AaiUtil(AbstractServiceTaskProcessor taskProcessor) {
44 this.taskProcessor = taskProcessor
47 public String getNetworkGenericVnfEndpoint(DelegateExecution execution) {
48 String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
49 def uri = getNetworkGenericVnfUri(execution)
50 msoLogger.debug('AaiUtil.getNetworkGenericVnfEndpoint() - AAI endpoint: ' + endpoint + uri)
54 public String getNetworkGenericVnfUri(DelegateExecution execution) {
55 def uri = getUri(execution, 'generic-vnf')
56 msoLogger.debug('AaiUtil.getNetworkGenericVnfUri() - AAI URI: ' + uri)
60 public String getNetworkVpnBindingUri(DelegateExecution execution) {
61 def uri = getUri(execution, 'vpn-binding')
62 msoLogger.debug('AaiUtil.getNetworkVpnBindingUri() - AAI URI: ' + uri)
66 public String getNetworkPolicyUri(DelegateExecution execution) {
67 def uri = getUri(execution, 'network-policy')
68 msoLogger.debug('AaiUtil.getNetworkPolicyUri() - AAI URI: ' + uri)
72 public String getNetworkTableReferencesUri(DelegateExecution execution) {
73 def uri = getUri(execution, 'route-table-reference')
74 msoLogger.debug('AaiUtil.getNetworkTableReferencesUri() - AAI URI: ' + uri)
78 public String getNetworkVceUri(DelegateExecution execution) {
79 def uri = getUri(execution, 'vce')
80 msoLogger.debug('AaiUtil.getNetworkVceUri() - AAI URI: ' + uri)
84 public String getNetworkL3NetworkUri(DelegateExecution execution) {
85 def uri = getUri(execution, 'l3-network')
86 msoLogger.debug('AaiUtil.getNetworkL3NetworkUri() - AAI URI: ' + uri)
90 public String getBusinessCustomerUri(DelegateExecution execution) {
91 def uri = getUri(execution, 'customer')
92 msoLogger.debug('AaiUtil.getBusinessCustomerUri() - AAI URI: ' + uri)
96 public String getBusinessSPPartnerUri(DelegateExecution execution) {
97 def uri = getUri(execution, 'sp-partner')
98 msoLogger.debug('AaiUtil.getBusinessSPPartnerUri() - AAI URI: ' + uri)
102 public String getAAIServiceInstanceUri(DelegateExecution execution) {
103 String uri = getBusinessCustomerUri(execution)
105 uri = uri +"/" + execution.getVariable("globalSubscriberId") + "/service-subscriptions/service-subscription/" + UriUtils.encode(execution.getVariable("serviceType"),"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(execution.getVariable("serviceInstanceId"),"UTF-8")
107 msoLogger.debug('AaiUtil.getAAIRequestInputUri() - AAI URI: ' + uri)
111 //public String getBusinessCustomerUriv7(DelegateExecution execution) {
112 // // //def uri = getUri(execution, BUSINESS_CUSTOMERV7)
113 // def uri = getUri(execution, 'Customer')
114 // msoLogger.debug('AaiUtil.getBusinessCustomerUriv7() - AAI URI: ' + uri)
118 public String getCloudInfrastructureCloudRegionEndpoint(DelegateExecution execution) {
119 String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
120 def uri = getCloudInfrastructureCloudRegionUri(execution)
121 msoLogger.debug('AaiUtil.getCloudInfrastructureCloudRegionEndpoint() - AAI endpoint: ' + endpoint + uri)
122 return endpoint + uri
125 public String getCloudInfrastructureCloudRegionUri(DelegateExecution execution) {
126 def uri = getUri(execution, 'cloud-region')
127 msoLogger.debug('AaiUtil.getCloudInfrastructureCloudRegionUri() - AAI URI: ' + uri)
131 public String getCloudInfrastructureTenantUri(DelegateExecution execution) {
132 def uri = getUri(execution, 'tenant')
133 msoLogger.debug('AaiUtil.getCloudInfrastructureTenantUri() - AAI URI: ' + uri)
137 public String getSearchNodesQueryUri(DelegateExecution execution) {
138 def uri = getUri(execution, 'nodes-query')
139 msoLogger.debug('AaiUtil.getSearchNodesQueryUri() - AAI URI: ' + uri)
143 public String getSearchNodesQueryEndpoint(DelegateExecution execution) {
144 String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
145 def uri = getSearchNodesQueryUri(execution)
146 msoLogger.debug('AaiUtil.getSearchNodesQueryEndpoint() - AAI endpoint: ' + endpoint + uri)
147 return endpoint + uri
150 public String getSearchGenericQueryUri(DelegateExecution execution) {
151 def uri = getUri(execution, 'generic-query')
152 msoLogger.debug('AaiUtil.getSearchGenericQueryUri() - AAI URI: ' + uri)
156 public String getVersion(DelegateExecution execution, resourceName, processKey) {
157 def versionWithResourceKey = "mso.workflow.default.aai.${resourceName}.version"
158 def versionWithProcessKey = "mso.workflow.custom.${processKey}.aai.version"
160 def version = UrnPropertiesReader.getVariable(versionWithProcessKey, execution)
162 msoLogger.debug("AaiUtil.getVersion() - using flow specific ${versionWithProcessKey}=${version}")
166 version = UrnPropertiesReader.getVariable(versionWithResourceKey, execution)
168 msoLogger.debug("AaiUtil.getVersion() - using resource specific ${versionWithResourceKey}=${version}")
172 version = UrnPropertiesReader.getVariable(DEFAULT_VERSION_KEY, execution)
174 msoLogger.debug("AaiUtil.getVersion() - using default version ${DEFAULT_VERSION_KEY}=${version}")
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}")
181 public String getUri(DelegateExecution execution, resourceName) {
183 def processKey = taskProcessor.getMainProcessKey(execution)
186 setNamespace(execution)
188 // Check for flow+resource specific first
189 def key = "mso.workflow.${processKey}.aai.${resourceName}.uri"
190 def uri = UrnPropertiesReader.getVariable(key, execution)
192 msoLogger.debug("AaiUtil.getUri() - using flow+resource specific key: ${key}=${uri}")
196 // Check for versioned key
197 def version = getVersion(execution, resourceName, processKey)
198 key = "mso.workflow.default.aai.v${version}.${resourceName}.uri"
199 uri = UrnPropertiesReader.getVariable(key, execution)
202 msoLogger.debug("AaiUtil.getUri() - using versioned URI key: ${key}=${uri}")
206 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
209 public String setNamespace(DelegateExecution execution) {
210 def key = AAI_NAMESPACE_STRING_KEY
211 aaiNamespace = UrnPropertiesReader.getVariable(key, execution)
212 if (aaiNamespace == null ) {
213 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
218 * This method can be used for getting the building namespace out of uri.
219 * NOTE: A getUri() method needs to be invoked first.
220 * Alternative method is the getNamespaceFromUri(DelegateExecution execution, String uri)
221 * return namespace (plus version from uri)
228 public String getNamespaceFromUri(String uri) {
229 if (aaiNamespace == null) {
230 throw new Exception('Internal Error: AAI Namespace has not been set yet. A getUri() method needs to be invoked first.')
232 String namespace = aaiNamespace
234 String version = getVersionFromUri(uri)
235 return namespace + "v"+version
242 * This method can be used for building namespace with aai version out of uri.
243 * NOTE: 2 arguments: DelegateExecution execution & String uri
249 public String getNamespaceFromUri(DelegateExecution execution, String uri) {
250 String namespace = UrnPropertiesReader.getVariable(AAI_NAMESPACE_STRING_KEY, execution)
251 if (namespace == null ) {
252 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + AAI_NAMESPACE_STRING_KEY + ' not defined in the MSO URN properties file')
255 String version = getVersionFromUri(uri)
256 return namespace + "v"+version
263 * This is used to extract the version from uri.
269 private String getVersionFromUri(String uri) {
271 def savedVersion = ""
272 for (int x=2; x<6; x++) {
273 version = uri.substring(uri.indexOf("v")+1, uri.indexOf("v")+x)
274 if (!Character.isDigit(version.charAt(version.size()-1))) {
277 savedVersion = version
284 * This reusable method can be used for making AAI Get Calls. The url should
285 * be passed as a parameter along with the execution. The method will
286 * return an APIResponse.
291 * @return APIResponse
294 public APIResponse executeAAIGetCall(DelegateExecution execution, String url){
295 msoLogger.trace("STARTED Execute AAI Get Process ")
296 APIResponse apiResponse = null
298 String uuid = utils.getRequestID()
299 msoLogger.debug("Generated uuid is: " + uuid)
300 msoLogger.debug("URL to be used is: " + url)
302 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
304 RESTConfig config = new RESTConfig(url);
305 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
307 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
308 client.addAuthorizationHeader(basicAuthCred)
310 apiResponse = client.get()
312 msoLogger.trace("COMPLETED Execute AAI Get Process ")
314 msoLogger.debug("Exception occured while executing AAI Get Call. Exception is: \n" + e)
315 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
322 * This reusable method can be used for making AAI httpPut Calls. The url should
323 * be passed as a parameter along with the execution and payload. The method will
324 * return an APIResponse.
330 * @return APIResponse
333 public APIResponse executeAAIPutCall(DelegateExecution execution, String url, String payload){
334 msoLogger.trace("Started Execute AAI Put Process ")
335 APIResponse apiResponse = null
337 String uuid = utils.getRequestID()
338 msoLogger.debug("Generated uuid is: " + uuid)
339 msoLogger.debug("URL to be used is: " + url)
341 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
343 RESTConfig config = new RESTConfig(url);
344 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/xml").addHeader("Accept","application/xml");
345 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
346 client.addAuthorizationHeader(basicAuthCred)
348 apiResponse = client.httpPut(payload)
350 msoLogger.trace("Completed Execute AAI Put Process ")
352 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Put Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
353 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
359 * This reusable method can be used for making AAI httpPatch Calls. The url should
360 * be passed as a parameter along with the execution and payload. The method will
361 * return an APIResponse.
367 * @return APIResponse
370 public APIResponse executeAAIPatchCall(DelegateExecution execution, String url, String payload){
371 msoLogger.trace("Started Execute AAI Patch Process ")
372 APIResponse apiResponse = null
374 String uuid = utils.getRequestID()
375 msoLogger.debug("Generated uuid is: " + uuid)
377 msoLogger.debug("URL to be used is: " + url)
379 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
381 RESTConfig config = new RESTConfig(url);
382 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/merge-patch+json").addHeader("Accept","application/json");
383 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
384 client.addAuthorizationHeader(basicAuthCred)
386 apiResponse = client.httpPatch(payload)
388 msoLogger.trace("Completed Execute AAI Patch Process ")
390 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Patch Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
391 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
398 * This reusable method can be used for making AAI Delete Calls. The url should
399 * be passed as a parameter along with the execution. The method will
400 * return an APIResponse.
405 * @return APIResponse
408 public APIResponse executeAAIDeleteCall(DelegateExecution execution, String url){
409 msoLogger.trace("Started Execute AAI Delete Process ")
410 APIResponse apiResponse = null
412 String uuid = utils.getRequestID()
413 msoLogger.debug("Generated uuid is: " + uuid)
414 msoLogger.debug("URL to be used is: " + url)
416 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
418 RESTConfig config = new RESTConfig(url);
419 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
420 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
421 client.addAuthorizationHeader(basicAuthCred)
423 apiResponse = client.delete()
425 msoLogger.trace("Completed Execute AAI Delete Process ")
427 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Delete Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
428 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
434 * This reusable method can be used for making AAI Delete Calls. The url should
435 * be passed as a parameter along with the execution. The method will
436 * return an APIResponse.
442 * @return APIResponse
445 public APIResponse executeAAIDeleteCall(DelegateExecution execution, String url, String payload, String authHeader){
446 msoLogger.trace("Started Execute AAI Delete Process ")
447 APIResponse apiResponse = null
449 String uuid = utils.getRequestID()
450 msoLogger.debug("Generated uuid is: " + uuid)
452 msoLogger.debug("URL to be used is: " + url)
454 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
455 RESTConfig config = new RESTConfig(url);
456 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml").addAuthorizationHeader(authHeader);
457 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
458 client.addAuthorizationHeader(basicAuthCred)
460 apiResponse = client.httpDelete(payload)
462 msoLogger.trace("Completed Execute AAI Delete Process ")
464 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Delete Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
465 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
471 * This reusable method can be used for making AAI Post Calls. The url
472 * and payload should be passed as a parameters along with the execution.
473 * The method will return an APIResponse.
479 * @return APIResponse
482 public APIResponse executeAAIPostCall(DelegateExecution execution, String url, String payload){
483 msoLogger.trace("Started Execute AAI Post Process ")
484 APIResponse apiResponse = null
486 String uuid = utils.getRequestID()
487 msoLogger.debug("Generated uuid is: " + uuid)
488 msoLogger.debug("URL to be used is: " + url)
490 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
491 RESTConfig config = new RESTConfig(url);
492 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
494 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
495 client.addAuthorizationHeader(basicAuthCred)
497 apiResponse = client.httpPost(payload)
499 msoLogger.trace("Completed Execute AAI Post Process ")
501 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Post Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
502 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
508 * This reusable method can be used for making AAI Post Calls. The url
509 * and payload should be passed as a parameters along with the execution.
510 * The method will return an APIResponse.
515 * @param authenticationHeader - addAuthenticationHeader value
516 * @param headerName - name of header you want to add, i.e. addHeader(headerName, headerValue)
517 * @param headerValue - the header's value, i.e. addHeader(headerName, headerValue)
519 * @return APIResponse
522 public APIResponse executeAAIPostCall(DelegateExecution execution, String url, String payload, String authenticationHeaderValue, String headerName, String headerValue){
523 msoLogger.trace("Started Execute AAI Post Process ")
524 APIResponse apiResponse = null
526 msoLogger.debug("URL to be used is: " + url)
528 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
530 RESTConfig config = new RESTConfig(url);
531 RESTClient client = new RESTClient(config).addAuthorizationHeader(authenticationHeaderValue).addHeader(headerName, headerValue)
532 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
533 client.addAuthorizationHeader(basicAuthCred)
535 apiResponse = client.httpPost(payload)
537 msoLogger.trace("Completed Execute AAI Post Process ")
539 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Post Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
540 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
546 /* Utility to get the Cloud Region from AAI
547 * Returns String cloud region id, (ie, cloud-region-id)
549 * @param url - url for AAI get cloud region
550 * @param backend - "PO" - real region, or "SDNC" - v2.5 (fake region).
553 public String getAAICloudReqion(DelegateExecution execution, String url, String backend, inputCloudRegion){
556 APIResponse apiResponse = executeAAIGetCall(execution, url)
557 String returnCode = apiResponse.getStatusCode()
558 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
559 msoLogger.debug("Call AAI Cloud Region Return code: " + returnCode)
560 execution.setVariable(execution.getVariable("prefix")+"queryCloudRegionReturnCode", returnCode)
562 if(returnCode == "200"){
563 msoLogger.debug("Call AAI Cloud Region is Successful.")
565 String regionVersion = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-version")
566 msoLogger.debug("Cloud Region Version from AAI for " + backend + " is: " + regionVersion)
567 if (backend == "PO") {
568 regionId = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-id")
569 } else { // backend not "PO"
570 if (regionVersion == "2.5" ) {
571 regionId = "AAIAIC25"
573 regionId = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-id")
576 if(regionId == null){
577 throw new BpmnError("MSOWorkflowException")
579 msoLogger.debug("Cloud Region Id from AAI " + backend + " is: " + regionId)
580 }else if (returnCode == "404"){ // not 200
581 if (backend == "PO") {
582 regionId = inputCloudRegion
583 }else{ // backend not "PO"
584 regionId = "AAIAIC25"
586 msoLogger.debug("Cloud Region value for code='404' of " + backend + " is: " + regionId)
588 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Call AAI Cloud Region is NOT Successful.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
589 throw new BpmnError("MSOWorkflowException")
591 }catch(Exception e) {
592 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while getting the Cloud Reqion.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.getMessage());
593 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
598 /* returns xml Node with service-type of searchValue */
599 def searchServiceType(xmlInput, searchValue){
600 def fxml= new XmlSlurper().parseText(xmlInput)
601 def ret = fxml.'**'.find {it.'service-type' == searchValue}
605 /* returns xml Node with service-instance-id of searchValue */
606 def searchServiceInstanceId(xmlInput, searchValue){
607 def ret = xmlInput.'**'.find {it.'service-instance-id' == searchValue}
612 * Get the lowest unused VF Module index from AAI response for a given module type. The criteria for
613 * determining module type is specified by "key" parameter (for example, "persona-model-id"),
614 * the value for filtering is specified in "value" parameter
617 * @param aaiVnfResponse
621 * @return moduleIndex
624 public int getLowestUnusedVfModuleIndexFromAAIVnfResponse(DelegateExecution execution, String aaiVnfResponse, String key, String value) {
625 if (aaiVnfResponse != null) {
626 String vfModulesText = taskProcessor.utils.getNodeXml(aaiVnfResponse, "vf-modules")
627 if (vfModulesText == null || vfModulesText.isEmpty()) {
628 msoLogger.debug("There are no VF modules in this VNF yet")
632 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
633 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
634 int vfModulesSize = 0
635 if (vfModules != null) {
636 vfModulesSize = vfModules.size()
638 String matchingVfModules = "<vfModules>"
639 for (i in 0..vfModulesSize-1) {
640 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
641 def keyFromAAI = taskProcessor.utils.getNodeText(vfModuleXml, key)
642 if (keyFromAAI != null && keyFromAAI.equals(value)) {
643 matchingVfModules = matchingVfModules + taskProcessor.utils.removeXmlPreamble(vfModuleXml)
646 matchingVfModules = matchingVfModules + "</vfModules>"
647 msoLogger.debug("Matching VF Modules: " + matchingVfModules)
648 String lowestUnusedIndex = taskProcessor.utils.getLowestUnusedIndex(matchingVfModules)
649 return Integer.parseInt(lowestUnusedIndex)
657 private def getPInterface(DelegateExecution execution, String aai_uri) {
659 String namespace = getNamespaceFromUri(aai_uri)
660 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
661 String serviceAaiPath = ${aai_endpoint}${aai_uri}
663 APIResponse response = executeAAIGetCall(execution, serviceAaiPath)
664 return new XmlParser().parseText(response.getResponseBodyAsString())
667 // This method checks if interface is remote
668 private def isPInterfaceRemote(DelegateExecution execution, String uri) {
669 if(uri.contains("ext-aai-network")) {
676 // This method returns Local and remote TPs information from AAI
677 public Map getTPsfromAAI(DelegateExecution execution) {
680 String aai_uri = '/aai/v14/network/logical-links'
682 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
683 String serviceAaiPath = ${aai_endpoint}${aai_uri}
685 APIResponse response = executeAAIGetCall(execution, serviceAaiPath)
687 def logicalLinks = new XmlParser().parseText(response.getResponseBodyAsString())
689 logicalLinks."logical-links".find { link ->
691 def relationship = link."relationship-list"."relationship"
693 if ("p-interface".compareToIgnoreCase(it."related-to")) {
697 if (pInterface.size() == 2) {
701 if (pInterface[0]."related-link".contains("ext-aai-networks")) {
702 remoteTP = pInterface[0]
703 localTP = pInterface[1]
706 if (pInterface[1]."related-link".contains("ext-aai-networks")) {
707 localTP = pInterface[0]
708 remoteTP = pInterface[1]
711 if (localTP != null && remoteTP != null) {
714 var intfLocal = getPInterface(execution, localTP."related-link")
715 tpInfotpInfo.put("local-access-node-id", localTP."related-link".split("/")[6])
717 def networkRef = intfLocal."network-ref".split("/")
718 tpInfo.put("local-access-provider-id", networkRef[1])
719 tpInfo.put("local-access-client-id", networkRef[3])
720 tpInfo.put("local-access-topology-id", networkRef[5])
721 tpInfo.put("local-access-ltp-id", localTP."interface-name")
724 var intfRemote = getPInterface(execution, remoteTP."related-link")
725 tpInfo.put("remote-access-node-id", remoteTP."related-link".split("/")[6])
726 def networkRefRemote = intfRemote."network-ref".split("/")
727 tpInfo.put("remote-access-provider-id", networkRefRemote[1])
728 tpInfo.put("remote-access-client-id", networkRefRemote[3])
729 tpInfo.put("remote-access-topology-id", networkRefRemote[5])
730 tpInfo.put("remote-access-ltp-id", remoteTP."interface-name")