diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy | 96 | ||||
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy | 52 |
2 files changed, 115 insertions, 33 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy index 81e2b40bb2..cae80e9137 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy @@ -7,9 +7,9 @@ * 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. @@ -28,8 +28,6 @@ import org.onap.so.rest.RESTConfig import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger - - class AaiUtil { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AaiUtil.class); @@ -101,6 +99,15 @@ class AaiUtil { return uri } + public String getAAIServiceInstanceUri(DelegateExecution execution) { + String uri = getBusinessCustomerUri(execution) + + 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") + + msoLogger.debug('AaiUtil.getAAIRequestInputUri() - AAI URI: ' + uri) + return uri + } + //public String getBusinessCustomerUriv7(DelegateExecution execution) { // // //def uri = getUri(execution, BUSINESS_CUSTOMERV7) // def uri = getUri(execution, 'Customer') @@ -646,4 +653,85 @@ class AaiUtil { return 0 } } + + private def getPInterface(DelegateExecution execution, String aai_uri) { + + String namespace = getNamespaceFromUri(aai_uri) + String aai_endpoint = execution.getVariable("URN_aai_endpoint") + String serviceAaiPath = ${aai_endpoint}${aai_uri} + + APIResponse response = executeAAIGetCall(execution, serviceAaiPath) + return new XmlParser().parseText(response.getResponseBodyAsString()) + } + + // This method checks if interface is remote + private def isPInterfaceRemote(DelegateExecution execution, String uri) { + if(uri.contains("ext-aai-network")) { + return true + } else { + return false + } + } + + // This method returns Local and remote TPs information from AAI + public Map getTPsfromAAI(DelegateExecution execution) { + Map tpInfo = [:] + + String aai_uri = '/aai/v14/network/logical-links' + + String aai_endpoint = execution.getVariable("URN_aai_endpoint") + String serviceAaiPath = ${aai_endpoint}${aai_uri} + + APIResponse response = executeAAIGetCall(execution, serviceAaiPath) + + def logicalLinks = new XmlParser().parseText(response.getResponseBodyAsString()) + + logicalLinks."logical-links".find { link -> + def pInterface = [] + def relationship = link."relationship-list"."relationship" + relationship.each { + if ("p-interface".compareToIgnoreCase(it."related-to")) { + pInterface.add(it) + } + } + if (pInterface.size() == 2) { + def localTP = null + def remoteTP = null + + if (pInterface[0]."related-link".contains("ext-aai-networks")) { + remoteTP = pInterface[0] + localTP = pInterface[1] + } + + if (pInterface[1]."related-link".contains("ext-aai-networks")) { + localTP = pInterface[0] + remoteTP = pInterface[1] + } + + if (localTP != null && remoteTP != null) { + + // give local tp + var intfLocal = getPInterface(execution, localTP."related-link") + tpInfotpInfo.put("local-access-node-id", localTP."related-link".split("/")[6]) + + def networkRef = intfLocal."network-ref".split("/") + tpInfo.put("local-access-provider-id", networkRef[1]) + tpInfo.put("local-access-client-id", networkRef[3]) + tpInfo.put("local-access-topology-id", networkRef[5]) + tpInfo.put("local-access-ltp-id", localTP."interface-name") + + // give local tp + var intfRemote = getPInterface(execution, remoteTP."related-link") + tpInfo.put("remote-access-node-id", remoteTP."related-link".split("/")[6]) + def networkRefRemote = intfRemote."network-ref".split("/") + tpInfo.put("remote-access-provider-id", networkRefRemote[1]) + tpInfo.put("remote-access-client-id", networkRefRemote[3]) + tpInfo.put("remote-access-topology-id", networkRefRemote[5]) + tpInfo.put("remote-access-ltp-id", remoteTP."interface-name") + } + } + + } + return tpInfo + } }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy index f2f41acb6b..2c2cd8269c 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy @@ -22,6 +22,7 @@ package org.onap.so.bpmn.common.scripts import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor; +import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse import org.onap.so.rest.RESTClient import org.onap.so.rest.RESTConfig @@ -36,8 +37,8 @@ class ExternalAPIUtil { public MsoUtils utils = new MsoUtils() ExceptionUtil exceptionUtil = new ExceptionUtil() - - private AbstractServiceTaskProcessor taskProcessor + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ExternalAPIUtil.class) public static final String PostServiceOrderRequestsTemplate = "{\n" + @@ -62,8 +63,8 @@ class ExternalAPIUtil { "\t\t\"action\": <action>,\n" + "\t\t\"service\": {\n" + "\t\t\t\"serviceState\": <serviceState>,\n" + + "\t\t\t\"id\": <serviceId>,\n" + "\t\t\t\"name\": <serviceName>,\n" + - "\t\t\t\"serviceType\": <serviceType>,\n" + "\t\t\t\"serviceSpecification\": { \n" + "\t\t\t\t\"id\": <serviceUuId> \n" + "\t\t\t},\n" + @@ -82,16 +83,12 @@ class ExternalAPIUtil { "\t} \n" + "}" - public ExternalAPIUtil(AbstractServiceTaskProcessor taskProcessor) { - this.taskProcessor = taskProcessor - } // public String getUri(DelegateExecution execution, resourceName) { // -// def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled') // def uri = execution.getVariable("ExternalAPIURi") // if(uri) { -// taskProcessor.logDebug("ExternalAPIUtil.getUri: " + uri, isDebugLogEnabled) +// msoLogger.debug("ExternalAPIUtil.getUri: " + uri) // return uri // } // @@ -99,21 +96,21 @@ class ExternalAPIUtil { // } public String setTemplate(String template, Map<String, String> valueMap) { - taskProcessor.logDebug("ExternalAPIUtil setTemplate", true); + msoLogger.debug("ExternalAPIUtil setTemplate", true); StringBuffer result = new StringBuffer(); String pattern = "<.*>"; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(template); - taskProcessor.logDebug("ExternalAPIUtil template:" + template, true); + msoLogger.debug("ExternalAPIUtil template:" + template, true); while (m.find()) { String key = template.substring(m.start() + 1, m.end() - 1); - taskProcessor.logDebug("ExternalAPIUtil key:" + key + " contains key? " + valueMap.containsKey(key), true); + msoLogger.debug("ExternalAPIUtil key:" + key + " contains key? " + valueMap.containsKey(key), true); m.appendReplacement(result, valueMap.getOrDefault(key, "\"TBD\"")); } m.appendTail(result); - taskProcessor.logDebug("ExternalAPIUtil return:" + result.toString(), true); + msoLogger.debug("ExternalAPIUtil return:" + result.toString(), true); return result.toString(); } @@ -129,13 +126,12 @@ class ExternalAPIUtil { * */ public APIResponse executeExternalAPIGetCall(DelegateExecution execution, String url){ - def isDebugEnabled = execution.getVariable("isDebugLogEnabled") - taskProcessor.logDebug(" ======== STARTED Execute ExternalAPI Get Process ======== ", isDebugEnabled) + msoLogger.debug(" ======== STARTED Execute ExternalAPI Get Process ======== ") APIResponse apiResponse = null try{ String uuid = utils.getRequestID() - taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled) - taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled) + msoLogger.debug( "Generated uuid is: " + uuid) + msoLogger.debug( "URL to be used is: " + url) String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_externalapi_auth"),execution.getVariable("URN_mso_msoKey")) @@ -147,9 +143,9 @@ class ExternalAPIUtil { } apiResponse = client.get() - taskProcessor.logDebug( "======== COMPLETED Execute ExternalAPI Get Process ======== ", isDebugEnabled) + msoLogger.debug( "======== COMPLETED Execute ExternalAPI Get Process ======== ") }catch(Exception e){ - taskProcessor.logDebug("Exception occured while executing ExternalAPI Get Call. Exception is: \n" + e, isDebugEnabled) + msoLogger.debug("Exception occured while executing ExternalAPI Get Call. Exception is: \n" + e) exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e.getMessage()) } return apiResponse @@ -168,13 +164,12 @@ class ExternalAPIUtil { * */ public APIResponse executeExternalAPIPostCall(DelegateExecution execution, String url, String payload){ - def isDebugEnabled = execution.getVariable("isDebugLogEnabled") - taskProcessor.logDebug( " ======== Started Execute ExternalAPI Post Process ======== ", isDebugEnabled) + msoLogger.debug( " ======== Started Execute ExternalAPI Post Process ======== ") APIResponse apiResponse = null try{ String uuid = utils.getRequestID() - taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled) - taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled) + msoLogger.debug( "Generated uuid is: " + uuid) + msoLogger.debug( "URL to be used is: " + url) String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_externalapi_auth"),execution.getVariable("URN_mso_msoKey")) RESTConfig config = new RESTConfig(url); @@ -185,9 +180,9 @@ class ExternalAPIUtil { } apiResponse = client.httpPost(payload) - taskProcessor.logDebug( "======== Completed Execute ExternalAPI Post Process ======== ", isDebugEnabled) + msoLogger.debug( "======== Completed Execute ExternalAPI Post Process ======== ") }catch(Exception e){ - taskProcessor.utils.log("ERROR", "Exception occured while executing ExternalAPI Post Call. Exception is: \n" + e, isDebugEnabled) + msoLogger.error("Exception occured while executing ExternalAPI Post Call. Exception is: \n" + e) exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e.getMessage()) } return apiResponse @@ -209,11 +204,10 @@ class ExternalAPIUtil { * */ public APIResponse executeExternalAPIPostCall(DelegateExecution execution, String url, String payload, String authenticationHeaderValue, String headerName, String headerValue){ - def isDebugEnabled = execution.getVariable("isDebugLogEnabled") - taskProcessor.logDebug( " ======== Started Execute ExternalAPI Post Process ======== ", isDebugEnabled) + msoLogger.debug( " ======== Started Execute ExternalAPI Post Process ======== ") APIResponse apiResponse = null try{ - taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled) + msoLogger.debug( "URL to be used is: " + url) String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_externalapi_auth"),execution.getVariable("URN_mso_msoKey")) @@ -224,9 +218,9 @@ class ExternalAPIUtil { } apiResponse = client.httpPost(payload) - taskProcessor.logDebug( "======== Completed Execute ExternalAPI Post Process ======== ", isDebugEnabled) + msoLogger.debug( "======== Completed Execute ExternalAPI Post Process ======== ") }catch(Exception e){ - taskProcessor.utils.log("ERROR", "Exception occured while executing ExternalAPI Post Call. Exception is: \n" + e, isDebugEnabled) + msoLogger.error("Exception occured while executing ExternalAPI Post Call. Exception is: \n" + e) exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e.getMessage()) } return apiResponse |