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.springframework.web.util.UriUtils
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
49 public String getNetworkGenericVnfEndpoint(DelegateExecution execution) {
50 String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
51 def uri = getNetworkGenericVnfUri(execution)
52 msoLogger.debug('AaiUtil.getNetworkGenericVnfEndpoint() - AAI endpoint: ' + endpoint + uri)
56 public String getNetworkGenericVnfUri(DelegateExecution execution) {
57 def uri = getUri(execution, 'generic-vnf')
58 msoLogger.debug('AaiUtil.getNetworkGenericVnfUri() - AAI URI: ' + uri)
62 public String getNetworkVpnBindingUri(DelegateExecution execution) {
63 def uri = getUri(execution, 'vpn-binding')
64 msoLogger.debug('AaiUtil.getNetworkVpnBindingUri() - AAI URI: ' + uri)
68 public String getNetworkPolicyUri(DelegateExecution execution) {
69 def uri = getUri(execution, 'network-policy')
70 msoLogger.debug('AaiUtil.getNetworkPolicyUri() - AAI URI: ' + uri)
74 public String getNetworkTableReferencesUri(DelegateExecution execution) {
75 def uri = getUri(execution, 'route-table-reference')
76 msoLogger.debug('AaiUtil.getNetworkTableReferencesUri() - AAI URI: ' + uri)
80 public String getNetworkVceUri(DelegateExecution execution) {
81 def uri = getUri(execution, 'vce')
82 msoLogger.debug('AaiUtil.getNetworkVceUri() - AAI URI: ' + uri)
86 public String getNetworkL3NetworkUri(DelegateExecution execution) {
87 def uri = getUri(execution, 'l3-network')
88 msoLogger.debug('AaiUtil.getNetworkL3NetworkUri() - AAI URI: ' + uri)
92 public String getNetworkDeviceUri(DelegateExecution execution) {
93 def uri = getUri(execution, 'device')
94 msoLogger.debug('AaiUtil.getNetworkDeviceUri() - AAI URI: ' + uri)
98 public String getBusinessCustomerUri(DelegateExecution execution) {
99 def uri = getUri(execution, 'customer')
100 msoLogger.debug('AaiUtil.getBusinessCustomerUri() - AAI URI: ' + uri)
104 public String getBusinessSPPartnerUri(DelegateExecution execution) {
105 def uri = getUri(execution, 'sp-partner')
106 msoLogger.debug('AaiUtil.getBusinessSPPartnerUri() - AAI URI: ' + uri)
110 public String getAAIServiceInstanceUri(DelegateExecution execution) {
111 String uri = getBusinessCustomerUri(execution)
113 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")
115 msoLogger.debug('AaiUtil.getAAIRequestInputUri() - AAI URI: ' + uri)
119 //public String getBusinessCustomerUriv7(DelegateExecution execution) {
120 // //def uri = getUri(execution, BUSINESS_CUSTOMERV7)
121 // def uri = getUri(execution, 'Customer')
122 // msoLogger.debug('AaiUtil.getBusinessCustomerUriv7() - AAI URI: ' + uri)
126 public String getCloudInfrastructureCloudRegionEndpoint(DelegateExecution execution) {
127 String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
128 def uri = getCloudInfrastructureCloudRegionUri(execution)
129 msoLogger.debug('AaiUtil.getCloudInfrastructureCloudRegionEndpoint() - AAI endpoint: ' + endpoint + uri)
130 return endpoint + uri
133 public String getCloudInfrastructureCloudRegionUri(DelegateExecution execution) {
134 def uri = getUri(execution, 'cloud-region')
135 msoLogger.debug('AaiUtil.getCloudInfrastructureCloudRegionUri() - AAI URI: ' + uri)
139 public String getCloudInfrastructureTenantUri(DelegateExecution execution) {
140 def uri = getUri(execution, 'tenant')
141 msoLogger.debug('AaiUtil.getCloudInfrastructureTenantUri() - AAI URI: ' + uri)
145 public String getSearchNodesQueryUri(DelegateExecution execution) {
146 def uri = getUri(execution, 'nodes-query')
147 msoLogger.debug('AaiUtil.getSearchNodesQueryUri() - AAI URI: ' + uri)
151 public String getSearchNodesQueryEndpoint(DelegateExecution execution) {
152 String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
153 def uri = getSearchNodesQueryUri(execution)
154 msoLogger.debug('AaiUtil.getSearchNodesQueryEndpoint() - AAI endpoint: ' + endpoint + uri)
155 return endpoint + uri
158 public String getSearchGenericQueryUri(DelegateExecution execution) {
159 def uri = getUri(execution, 'generic-query')
160 msoLogger.debug('AaiUtil.getSearchGenericQueryUri() - AAI URI: ' + uri)
164 public String getVersion(DelegateExecution execution, resourceName, processKey) {
165 def versionWithResourceKey = "mso.workflow.default.aai.${resourceName}.version"
166 def versionWithProcessKey = "mso.workflow.custom.${processKey}.aai.version"
168 def version = UrnPropertiesReader.getVariable(versionWithProcessKey, execution)
170 msoLogger.debug("AaiUtil.getVersion() - using flow specific ${versionWithProcessKey}=${version}")
174 version = UrnPropertiesReader.getVariable(versionWithResourceKey, execution)
176 msoLogger.debug("AaiUtil.getVersion() - using resource specific ${versionWithResourceKey}=${version}")
180 version = UrnPropertiesReader.getVariable(DEFAULT_VERSION_KEY, execution)
182 msoLogger.debug("AaiUtil.getVersion() - using default version ${DEFAULT_VERSION_KEY}=${version}")
186 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, "Internal Error: One of the following should be defined in MSO URN properties file: ${versionWithResourceKey}, ${versionWithProcessKey}, ${DEFAULT_VERSION_KEY}")
189 public String getMainProcessKey(DelegateExecution execution) {
190 DelegateExecution exec = execution
193 DelegateExecution parent = exec.getSuperExecution()
195 if (parent == null) {
196 parent = exec.getParent()
198 if (parent == null) {
206 return execution.getProcessEngineServices().getRepositoryService()
207 .getProcessDefinition(exec.getProcessDefinitionId()).getKey()
210 public String getUri(DelegateExecution execution, resourceName) {
212 def processKey = getMainProcessKey(execution)
215 setNamespace(execution)
217 // Check for flow+resource specific first
218 def key = "mso.workflow.${processKey}.aai.${resourceName}.uri"
219 def uri = UrnPropertiesReader.getVariable(key, execution)
221 msoLogger.debug("AaiUtil.getUri() - using flow+resource specific key: ${key}=${uri}")
225 // Check for versioned key
226 def version = getVersion(execution, resourceName, processKey)
227 key = "mso.workflow.default.aai.v${version}.${resourceName}.uri"
228 uri = UrnPropertiesReader.getVariable(key, execution)
231 msoLogger.debug("AaiUtil.getUri() - using versioned URI key: ${key}=${uri}")
235 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
238 public String setNamespace(DelegateExecution execution) {
239 def key = AAI_NAMESPACE_STRING_KEY
240 aaiNamespace = UrnPropertiesReader.getVariable(key, execution)
241 if (aaiNamespace == null ) {
242 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + key + ' not defined in the MSO URN properties file')
247 * This method can be used for getting the building namespace out of uri.
248 * NOTE: A getUri() method needs to be invoked first.
249 * Alternative method is the getNamespaceFromUri(DelegateExecution execution, String uri)
250 * return namespace (plus version from uri)
257 public String getNamespaceFromUri(String uri) {
258 if (aaiNamespace == null) {
259 throw new Exception('Internal Error: AAI Namespace has not been set yet. A getUri() method needs to be invoked first.')
261 String namespace = aaiNamespace
263 String version = getVersionFromUri(uri)
264 return namespace + "v"+version
271 * This method can be used for building namespace with aai version out of uri.
272 * NOTE: 2 arguments: DelegateExecution execution & String uri
278 public String getNamespaceFromUri(DelegateExecution execution, String uri) {
279 String namespace = UrnPropertiesReader.getVariable(AAI_NAMESPACE_STRING_KEY, execution)
280 if (namespace == null ) {
281 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, 'Internal Error: AAI URI entry for ' + AAI_NAMESPACE_STRING_KEY + ' not defined in the MSO URN properties file')
284 String version = getVersionFromUri(uri)
285 return namespace + "v"+version
292 * This is used to extract the version from uri.
298 private String getVersionFromUri(String uri) {
300 def savedVersion = ""
301 for (int x=2; x<6; x++) {
302 version = uri.substring(uri.indexOf("v")+1, uri.indexOf("v")+x)
303 if (!Character.isDigit(version.charAt(version.size()-1))) {
306 savedVersion = version
313 * This reusable method can be used for making AAI Get Calls. The url should
314 * be passed as a parameter along with the execution. The method will
315 * return an APIResponse.
320 * @return APIResponse
323 public APIResponse executeAAIGetCall(DelegateExecution execution, String url){
324 msoLogger.trace("STARTED Execute AAI Get Process ")
325 APIResponse apiResponse = null
327 String uuid = utils.getRequestID()
328 msoLogger.debug("Generated uuid is: " + uuid)
329 msoLogger.debug("URL to be used is: " + url)
331 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
333 RESTConfig config = new RESTConfig(url);
334 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
336 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
337 client.addAuthorizationHeader(basicAuthCred)
339 apiResponse = client.get()
341 msoLogger.trace("COMPLETED Execute AAI Get Process ")
343 msoLogger.debug("Exception occured while executing AAI Get Call. Exception is: \n" + e)
344 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
351 * This reusable method can be used for making AAI httpPut Calls. The url should
352 * be passed as a parameter along with the execution and payload. The method will
353 * return an APIResponse.
359 * @return APIResponse
362 public APIResponse executeAAIPutCall(DelegateExecution execution, String url, String payload){
363 msoLogger.trace("Started Execute AAI Put Process ")
364 APIResponse apiResponse = null
366 String uuid = utils.getRequestID()
367 msoLogger.debug("Generated uuid is: " + uuid)
368 msoLogger.debug("URL to be used is: " + url)
370 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
372 RESTConfig config = new RESTConfig(url);
373 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/xml").addHeader("Accept","application/xml");
374 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
375 client.addAuthorizationHeader(basicAuthCred)
377 apiResponse = client.httpPut(payload)
379 msoLogger.trace("Completed Execute AAI Put Process ")
381 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Put Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
382 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
388 * This reusable method can be used for making AAI httpPatch Calls. The url should
389 * be passed as a parameter along with the execution and payload. The method will
390 * return an APIResponse.
396 * @return APIResponse
399 public APIResponse executeAAIPatchCall(DelegateExecution execution, String url, String payload){
400 msoLogger.trace("Started Execute AAI Patch Process ")
401 APIResponse apiResponse = null
403 String uuid = utils.getRequestID()
404 msoLogger.debug("Generated uuid is: " + uuid)
406 msoLogger.debug("URL to be used is: " + url)
408 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
410 RESTConfig config = new RESTConfig(url);
411 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/merge-patch+json").addHeader("Accept","application/json");
412 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
413 client.addAuthorizationHeader(basicAuthCred)
415 apiResponse = client.httpPatch(payload)
417 msoLogger.trace("Completed Execute AAI Patch Process ")
419 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Patch Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
420 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
427 * This reusable method can be used for making AAI Delete Calls. The url should
428 * be passed as a parameter along with the execution. The method will
429 * return an APIResponse.
434 * @return APIResponse
437 public APIResponse executeAAIDeleteCall(DelegateExecution execution, String url){
438 msoLogger.trace("Started Execute AAI Delete Process ")
439 APIResponse apiResponse = null
441 String uuid = utils.getRequestID()
442 msoLogger.debug("Generated uuid is: " + uuid)
443 msoLogger.debug("URL to be used is: " + url)
445 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
447 RESTConfig config = new RESTConfig(url);
448 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
449 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
450 client.addAuthorizationHeader(basicAuthCred)
452 apiResponse = client.delete()
454 msoLogger.trace("Completed Execute AAI Delete Process ")
456 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Delete Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
457 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
463 * This reusable method can be used for making AAI Delete Calls. The url should
464 * be passed as a parameter along with the execution. The method will
465 * return an APIResponse.
471 * @return APIResponse
474 public APIResponse executeAAIDeleteCall(DelegateExecution execution, String url, String payload, String authHeader){
475 msoLogger.trace("Started Execute AAI Delete Process ")
476 APIResponse apiResponse = null
478 String uuid = utils.getRequestID()
479 msoLogger.debug("Generated uuid is: " + uuid)
481 msoLogger.debug("URL to be used is: " + url)
483 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
484 RESTConfig config = new RESTConfig(url);
485 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml").addAuthorizationHeader(authHeader);
486 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
487 client.addAuthorizationHeader(basicAuthCred)
489 apiResponse = client.httpDelete(payload)
491 msoLogger.trace("Completed Execute AAI Delete Process ")
493 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Delete Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
494 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
500 * This reusable method can be used for making AAI Post Calls. The url
501 * and payload should be passed as a parameters along with the execution.
502 * The method will return an APIResponse.
508 * @return APIResponse
511 public APIResponse executeAAIPostCall(DelegateExecution execution, String url, String payload){
512 msoLogger.trace("Started Execute AAI Post Process ")
513 APIResponse apiResponse = null
515 String uuid = utils.getRequestID()
516 msoLogger.debug("Generated uuid is: " + uuid)
517 msoLogger.debug("URL to be used is: " + url)
519 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
520 RESTConfig config = new RESTConfig(url);
521 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/xml");
523 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
524 client.addAuthorizationHeader(basicAuthCred)
526 apiResponse = client.httpPost(payload)
528 msoLogger.trace("Completed Execute AAI Post Process ")
530 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Post Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
531 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
537 * This reusable method can be used for making AAI Post Calls. The url
538 * and payload should be passed as a parameters along with the execution.
539 * The method will return an APIResponse.
544 * @param authenticationHeader - addAuthenticationHeader value
545 * @param headerName - name of header you want to add, i.e. addHeader(headerName, headerValue)
546 * @param headerValue - the header's value, i.e. addHeader(headerName, headerValue)
548 * @return APIResponse
551 public APIResponse executeAAIPostCall(DelegateExecution execution, String url, String payload, String authenticationHeaderValue, String headerName, String headerValue){
552 msoLogger.trace("Started Execute AAI Post Process ")
553 APIResponse apiResponse = null
555 msoLogger.debug("URL to be used is: " + url)
557 String basicAuthCred = utils.getBasicAuth(UrnPropertiesReader.getVariable("aai.auth", execution),UrnPropertiesReader.getVariable("mso.msoKey", execution))
559 RESTConfig config = new RESTConfig(url);
560 RESTClient client = new RESTClient(config).addAuthorizationHeader(authenticationHeaderValue).addHeader(headerName, headerValue)
561 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
562 client.addAuthorizationHeader(basicAuthCred)
564 apiResponse = client.httpPost(payload)
566 msoLogger.trace("Completed Execute AAI Post Process ")
568 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Post Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
569 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
575 /* Utility to get the Cloud Region from AAI
576 * Returns String cloud region id, (ie, cloud-region-id)
578 * @param url - url for AAI get cloud region
579 * @param backend - "PO" - real region, or "SDNC" - v2.5 (fake region).
582 public String getAAICloudReqion(DelegateExecution execution, String url, String backend, inputCloudRegion){
585 APIResponse apiResponse = executeAAIGetCall(execution, url)
586 String returnCode = apiResponse.getStatusCode()
587 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
588 msoLogger.debug("Call AAI Cloud Region Return code: " + returnCode)
589 execution.setVariable(execution.getVariable("prefix")+"queryCloudRegionReturnCode", returnCode)
591 if(returnCode == "200"){
592 msoLogger.debug("Call AAI Cloud Region is Successful.")
594 String regionVersion = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-version")
595 msoLogger.debug("Cloud Region Version from AAI for " + backend + " is: " + regionVersion)
596 if (backend == "PO") {
597 regionId = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-id")
598 } else { // backend not "PO"
599 if (regionVersion == "2.5" ) {
600 regionId = "AAIAIC25"
602 regionId = taskProcessor.utils.getNodeText(aaiResponseAsString, "cloud-region-id")
605 if(regionId == null){
606 throw new BpmnError("MSOWorkflowException")
608 msoLogger.debug("Cloud Region Id from AAI " + backend + " is: " + regionId)
609 }else if (returnCode == "404"){ // not 200
610 if (backend == "PO") {
611 regionId = inputCloudRegion
612 }else{ // backend not "PO"
613 regionId = "AAIAIC25"
615 msoLogger.debug("Cloud Region value for code='404' of " + backend + " is: " + regionId)
617 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Call AAI Cloud Region is NOT Successful.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
618 throw new BpmnError("MSOWorkflowException")
620 }catch(Exception e) {
621 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while getting the Cloud Reqion.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.getMessage());
622 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
627 /* returns xml Node with service-type of searchValue */
628 def searchServiceType(xmlInput, searchValue){
629 def fxml= new XmlSlurper().parseText(xmlInput)
630 def ret = fxml.'**'.find {it.'service-type' == searchValue}
634 /* returns xml Node with service-instance-id of searchValue */
635 def searchServiceInstanceId(xmlInput, searchValue){
636 def ret = xmlInput.'**'.find {it.'service-instance-id' == searchValue}
641 * Get the lowest unused VF Module index from AAI response for a given module type. The criteria for
642 * determining module type is specified by "key" parameter (for example, "persona-model-id"),
643 * the value for filtering is specified in "value" parameter
646 * @param aaiVnfResponse
650 * @return moduleIndex
653 public int getLowestUnusedVfModuleIndexFromAAIVnfResponse(DelegateExecution execution, String aaiVnfResponse, String key, String value) {
654 if (aaiVnfResponse != null) {
655 String vfModulesText = taskProcessor.utils.getNodeXml(aaiVnfResponse, "vf-modules")
656 if (vfModulesText == null || vfModulesText.isEmpty()) {
657 msoLogger.debug("There are no VF modules in this VNF yet")
661 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
662 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
663 int vfModulesSize = 0
664 if (vfModules != null) {
665 vfModulesSize = vfModules.size()
667 String matchingVfModules = "<vfModules>"
668 for (i in 0..vfModulesSize-1) {
669 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
670 def keyFromAAI = taskProcessor.utils.getNodeText(vfModuleXml, key)
671 if (keyFromAAI != null && keyFromAAI.equals(value)) {
672 matchingVfModules = matchingVfModules + taskProcessor.utils.removeXmlPreamble(vfModuleXml)
675 matchingVfModules = matchingVfModules + "</vfModules>"
676 msoLogger.debug("Matching VF Modules: " + matchingVfModules)
677 String lowestUnusedIndex = taskProcessor.utils.getLowestUnusedIndex(matchingVfModules)
678 return Integer.parseInt(lowestUnusedIndex)
686 private def getPInterface(DelegateExecution execution, String aai_uri) {
688 String namespace = getNamespaceFromUri(execution, aai_uri)
689 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
690 String serviceAaiPath = aai_endpoint + aai_uri
692 APIResponse response = executeAAIGetCall(execution, serviceAaiPath)
693 return new XmlParser().parseText(response.getResponseBodyAsString())
696 // This method checks if interface is remote
697 private def isPInterfaceRemote(DelegateExecution execution, String uri) {
698 if(uri.contains("ext-aai-network")) {
705 // This method returns Local and remote TPs information from AAI
706 public Map getTPsfromAAI(DelegateExecution execution) {
709 String aai_uri = '/aai/v14/network/logical-links'
711 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
712 String serviceAaiPath = aai_endpoint + aai_uri
714 APIResponse response = executeAAIGetCall(execution, serviceAaiPath)
716 def logicalLinks = new XmlParser().parseText(response.getResponseBodyAsString())
718 logicalLinks."logical-link".each { link ->
719 def isRemoteLink = false
721 def relationship = link."relationship-list"."relationship"
722 relationship.each { rel ->
723 if ("ext-aai-network".compareToIgnoreCase("${rel."related-to"[0]?.text()}") == 0) {
726 if ("p-interface".compareToIgnoreCase("${rel."related-to"[0]?.text()}") == 0) {
731 // if remote link then process
734 // find remote p interface
738 def pInterface0 = pInterfaces[0]
739 def pIntfUrl = "${pInterface0."related-link"[0].text()}"
741 if (isRemotePInterface(execution, pIntfUrl)) {
742 remoteTP = pInterfaces[0]
743 localTP = pInterfaces[1]
745 localTP = pInterfaces[0]
746 remoteTP = pInterfaces[1]
749 if (localTP != null && remoteTP != null) {
752 def tpUrl = "${localTP."related-link"[0]?.text()}"
753 def intfLocal = getPInterface(execution, "${localTP?."related-link"[0]?.text()}")
754 tpInfo.put("local-access-node-id", tpUrl.split("/")[6])
756 def networkRef = "${intfLocal."network-ref"[0]?.text()}".split("/")
757 if (networkRef.size() == 6) {
758 tpInfo.put("local-access-provider-id", networkRef[1])
759 tpInfo.put("local-access-client-id", networkRef[3])
760 tpInfo.put("local-access-topology-id", networkRef[5])
762 def ltpIdStr = tpUrl?.substring(tpUrl?.lastIndexOf("/") + 1)
763 if (ltpIdStr?.contains("-")) {
764 tpInfo.put("local-access-ltp-id", ltpIdStr?.substring(ltpIdStr?.lastIndexOf("-") + 1))
768 tpUrl = "${remoteTP."related-link"[0]?.text()}"
769 def intfRemote = getPInterface(execution, "${remoteTP."related-link"[0].text()}")
770 tpInfo.put("remote-access-node-id", tpUrl.split("/")[6])
772 def networkRefRemote = "${intfRemote."network-ref"[0]?.text()}".split("/")
774 if (networkRefRemote.size() == 6) {
775 tpInfo.put("remote-access-provider-id", networkRefRemote[1])
776 tpInfo.put("remote-access-client-id", networkRefRemote[3])
777 tpInfo.put("remote-access-topology-id", networkRefRemote[5])
779 def ltpIdStrR = tpUrl?.substring(tpUrl?.lastIndexOf("/") + 1)
780 if (ltpIdStrR?.contains("-")) {
781 tpInfo.put("remote-access-ltp-id", ltpIdStrR?.substring(ltpIdStr?.lastIndexOf("-") + 1))
791 // this method check if pInterface is remote
792 private def isRemotePInterface(DelegateExecution execution, String uri) {
793 def aai_uri = uri.substring(0, uri.indexOf("/p-interfaces"))
795 String namespace = getNamespaceFromUri(execution, aai_uri)
796 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
797 String serviceAaiPath = aai_endpoint + aai_uri
799 APIResponse response = executeAAIGetCall(execution, serviceAaiPath)
800 def pnf = new XmlParser().parseText(response.getResponseBodyAsString())
802 def relationship = pnf."relationship-list"."relationship"
804 if ("ext-aai-network".compareToIgnoreCase("${it."related-to"[0]?.text()}") == 0) {