From 0d5e1abcfdc89dcde7a468560f36c36a5d76ecae Mon Sep 17 00:00:00 2001 From: Yulian Han Date: Tue, 21 Aug 2018 16:33:03 +0800 Subject: conflict process Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa60000016 Issue-ID: SO-683 Signed-off-by: Yulian Han --- .../scripts/DoCreateE2EServiceInstance.groovy | 49 +++- .../workflow/service/ServicePluginFactory.java | 265 ++++++++++++++++----- 2 files changed, 254 insertions(+), 60 deletions(-) (limited to 'bpmn/so-bpmn-infrastructure-common') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy index 4939173d65..5922ad10a0 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy @@ -42,9 +42,11 @@ import org.onap.so.client.aai.AAIObjectType import org.onap.so.client.aai.AAIResourcesClient import org.onap.so.client.aai.entities.AAIResultWrapper import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory import org.onap.so.client.aai.entities.uri.AAIUriFactory import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger +import org.onap.so.rest.APIResponse import org.springframework.web.util.UriUtils; import groovy.json.* @@ -331,6 +333,37 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { } + public void saveServiceInputToAAI(DelegateExecution execution) { + AaiUtil aaiUriUtil = new AaiUtil(this) + + // create url for AAI requestInput + String aai_uri = aaiUriUtil.getAAIServiceInstanceUri(execution) + String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri) + + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String serviceInstanceName = execution.getVariable("serviceInstanceName") + String serviceType = execution.getVariable("serviceType") + String uuiRequest = execution.getVariable("uuiRequest") + + String payload = + """< xmlns=\"${namespace}\"> + + ${serviceInstanceId} + ${serviceInstanceName} + ${serviceType} + ${uuiRequest} + """.trim() + utils.logAudit(payload) + + String aai_endpoint = execution.getVariable("URN_aai_endpoint") + String serviceAaiPath = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(serviceInstanceId,"UTF-8") + + APIResponse response = aaiUriUtil.executeAAIPutCall(execution, serviceAaiPath, payload) + int responseCode = response.getStatusCode() + execution.setVariable(Prefix + "PutSppartnerResponseCode", responseCode) + } + + public void postProcessAAIGET2(DelegateExecution execution) { msoLogger.trace("postProcessAAIGET2 ") String msg = "" @@ -469,15 +502,25 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { // if site location is in local Operator, create all resources in local ONAP; // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP public void doProcessSiteLocation(DelegateExecution execution){ - msoLogger.trace("======== Start doProcessSiteLocation Process ======== ") ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") String uuiRequest = execution.getVariable("uuiRequest") - ServiceDecomposition serviceDecompositionforLocal = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest); - execution.setVariable("serviceDecomposition", serviceDecompositionforLocal) + uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest); + execution.setVariable("uuiRequest", uuiRequest) + execution.setVariable("serviceDecomposition", serviceDecomposition) msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ") } + + // Allocate cross link TPs(terminal points) for sotn network only + public void doTPResourcesAllocation(DelegateExecution execution){ + msoLogger.trace("======== Start doTPResourcesAllocation Process ======== ") + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") + String uuiRequest = execution.getVariable("uuiRequest") + uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest); + execution.setVariable("uuiRequest", uuiRequest) + msoLogger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ") + } // prepare input param for using DoCreateResources.bpmn public void preProcessForAddResource(DelegateExecution execution) { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java index 7226feb552..a6bdb59296 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java @@ -20,7 +20,6 @@ package org.onap.so.bpmn.infrastructure.workflow.service; -import org.json.JSONObject; import java.io.IOException; import java.net.SocketTimeoutException; import java.util.ArrayList; @@ -43,6 +42,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; +import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.runtime.Execution; import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.core.domain.ServiceDecomposition; @@ -50,9 +50,7 @@ import org.onap.so.bpmn.core.domain.Resource; import org.onap.so.bpmn.core.json.JsonUtils; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; - +import org.onap.so.bpmn.common.scripts.AaiUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -60,17 +58,17 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class ServicePluginFactory { // SOTN calculate route - public static final String OOF_Default_EndPoint = "http://192.168.1.223:8443/oof/sotncalc"; + public static final String OOF_DEFAULT_ENDPOINT = "http://192.168.1.223:8443/oof/sotncalc"; - public static final String Third_SP_Default_EndPoint = "http://192.168.1.223:8443/sp/resourcemgr/querytps"; + public static final String THIRD_SP_DEFAULT_ENDPOINT = "http://192.168.1.223:8443/sp/resourcemgr/querytps"; - public static final String Inventory_OSS_Default_EndPoint = "http://192.168.1.199:8443/oss/inventory"; + public static final String INVENTORY_OSS_DEFAULT_ENDPOINT = "http://192.168.1.199:8443/oss/inventory"; private static final int DEFAULT_TIME_OUT = 60000; static JsonUtils jsonUtil = new JsonUtils(); - private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, ServicePluginFactory.class); + private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ServicePluginFactory.class); private static ServicePluginFactory instance; @@ -81,76 +79,230 @@ public class ServicePluginFactory { } return instance; } - - private ServicePluginFactory() { - - } - private String getInventoryOSSEndPoint(){ - return UrnPropertiesReader.getVariable("mso.service-plugin.inventory-oss-endpoint", Inventory_OSS_Default_EndPoint); + return UrnPropertiesReader.getVariable("mso.service-plugin.inventory-oss-endpoint", INVENTORY_OSS_DEFAULT_ENDPOINT); } + private String getThirdSPEndPoint(){ - return UrnPropertiesReader.getVariable("mso.service-plugin.third-sp-endpoint", Third_SP_Default_EndPoint); + return UrnPropertiesReader.getVariable("mso.service-plugin.third-sp-endpoint", THIRD_SP_DEFAULT_ENDPOINT); } private String getOOFCalcEndPoint(){ - return UrnPropertiesReader.getVariable("mso.service-plugin.oof-calc-endpoint", OOF_Default_EndPoint); + return UrnPropertiesReader.getVariable("mso.service-plugin.oof-calc-endpoint", OOF_DEFAULT_ENDPOINT); } + + @SuppressWarnings("unchecked") + public String doProcessSiteLocation(ServiceDecomposition serviceDecomposition, String uuiRequest) { + if(!isNeedProcessSite(uuiRequest)) { + return uuiRequest; + } - public ServiceDecomposition doProcessSiteLocation(ServiceDecomposition serviceDecomposition, String uuiRequest) { - ServiceDecomposition serviceDecompositionforLocal = serviceDecomposition; + Map uuiObject = getJsonObject(uuiRequest, Map.class); + Map serviceObject = (Map) uuiObject.get("service"); + Map serviceParametersObject = (Map) serviceObject.get("parameters"); + Map serviceRequestInputs = (Map) serviceParametersObject.get("requestInputs"); + List resources = (List) serviceParametersObject.get("resources"); - if (isSiteLocationLocal(serviceDecomposition, uuiRequest)) { - return serviceDecomposition; + if (isSiteLocationLocal(serviceRequestInputs, resources)) { + // resources changed : added TP info + String newRequest = getJsonString(uuiObject); + return newRequest; } List addResourceList = serviceDecomposition.getServiceResources(); for (Resource resource : addResourceList) { String resourcemodelName = resource.getModelInfo().getModelName(); - if (!StringUtils.containsIgnoreCase(resourcemodelName, "sp-partner")) { - serviceDecompositionforLocal.deleteResource(resource); + if (!StringUtils.containsIgnoreCase(resourcemodelName, "sp-partner") + || !StringUtils.containsIgnoreCase(resourcemodelName, "sppartner")) { + // change serviceDecomposition + serviceDecomposition.deleteResource(resource); break; } - if (!StringUtils.containsIgnoreCase(resourcemodelName, "sppartner")) { - serviceDecompositionforLocal.deleteResource(resource); + } + + return uuiRequest; + } + + private boolean isNeedProcessSite(String uuiRequest) { + return uuiRequest.toLowerCase().contains("site_address") && uuiRequest.toLowerCase().contains("sotncondition_clientsignal"); + } + + @SuppressWarnings("unchecked") + private boolean isSiteLocationLocal(Map serviceRequestInputs, List resources) { + Map tpInfoMap = getTPforVPNAttachment(serviceRequestInputs); + + if(tpInfoMap.isEmpty()) { + return true; + } + String host = (String) tpInfoMap.get("host"); + // host is empty means TP is in local, not empty means TP is in remote ONAP + if (!host.isEmpty()) { + return false; + } + + Map accessTPInfo = new HashMap(); + accessTPInfo.put("access-provider-id", tpInfoMap.get("access-provider-id")); + accessTPInfo.put("access-client-id", tpInfoMap.get("access-client-id")); + accessTPInfo.put("access-topology-id", tpInfoMap.get("access-topology-id")); + accessTPInfo.put("access-node-id", tpInfoMap.get("access-node-id")); + accessTPInfo.put("access-ltp-id", tpInfoMap.get("access-ltp-id")); + + // change resources + String resourceName = (String) accessTPInfo.get("resourceName"); + for(Object curResource : resources) { + Map resource = (Map)curResource; + String curResourceName = (String) resource.get("resourceName"); + curResourceName = curResourceName.replaceAll(" ", ""); + if(resourceName.equalsIgnoreCase(curResourceName)) { + putResourceRequestInputs(resource, accessTPInfo); break; } } - return serviceDecompositionforLocal; + return true; } + + @SuppressWarnings("unchecked") + private Map getTPforVPNAttachment(Map serviceRequestInputs) { + Object location = ""; + Object clientSignal = ""; + String vpnAttachmentResourceName = ""; - public boolean isSiteLocationLocal(ServiceDecomposition serviceDecomposition, String uuiRequest) { - boolean isSiteLocationLocal = true; - - String serviceModelName = serviceDecomposition.getModelInfo().getModelName(); - String serviceParameters = JsonUtils.getJsonValue(uuiRequest, "service.parameters"); - String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs"); - JSONObject inputParameters = new JSONObject(requestInputs); - - if(StringUtils.containsIgnoreCase(serviceModelName, "site") && inputParameters.has("location")) - { - Object location = inputParameters.get("location"); - JSONObject locationObj = new JSONObject(location); - String locationONAP = queryLocationFromInventoryOSS(locationObj); - if(StringUtils.containsIgnoreCase(locationONAP, "remote")) { - isSiteLocationLocal = false; + // support R2 uuiReq and R1 uuiReq + // logic for R2 uuiRequest params in service level + for (Entry entry : serviceRequestInputs.entrySet()) { + String key = entry.getKey(); + if (key.toLowerCase().contains("site_address")) { + location = entry.getValue(); + } + if (key.toLowerCase().contains("sotncondition_clientsignal")) { + clientSignal = entry.getValue(); + vpnAttachmentResourceName = key.substring(0, key.indexOf("_")); } } - return isSiteLocationLocal; + Map tpInfoMap = new HashMap(); + + // Site resource has location param and SOTNAttachment resource has clientSignal param + if("".equals(location) || "".equals(clientSignal) ) { + return tpInfoMap; + } + + // Query terminal points from InventoryOSS system by location. + String locationAddress = (String) location; + List locationTPList = queryAccessTPbyLocationFromInventoryOSS(locationAddress); + if(locationTPList != null && !locationTPList.isEmpty()) { + tpInfoMap = (Map) locationTPList.get(0); + // add resourceName + tpInfoMap.put("resourceName", vpnAttachmentResourceName); + LOGGER.debug("Get Terminal TP from InventoryOSS"); + return tpInfoMap; + } + + return tpInfoMap; } - private String queryLocationFromInventoryOSS(JSONObject locationObj) { - String reqContent = getJsonString(locationObj); + @SuppressWarnings("unchecked") + private List queryAccessTPbyLocationFromInventoryOSS(String locationAddress) { + Map locationSrc = new HashMap(); + locationSrc.put("location", locationAddress); + String reqContent = getJsonString(locationSrc); String url = getInventoryOSSEndPoint(); String responseContent = sendRequest(url, "POST", reqContent); - String locationONAP = ""; + List accessTPs = new ArrayList(); if (null != responseContent) { - locationONAP = getJsonObject(responseContent, String.class); + accessTPs = getJsonObject(responseContent, List.class); + } + return accessTPs; + } + + @SuppressWarnings("unchecked") + private void putResourceRequestInputs(Map resource, Map resourceInputs) { + Map resourceParametersObject = new HashMap(); + Map resourceRequestInputs = new HashMap(); + resourceRequestInputs.put("requestInputs", resourceInputs); + resourceParametersObject.put("parameters", resourceRequestInputs); + + if(resource.containsKey("parameters")) { + Map resParametersObject = (Map) resource.get("parameters"); + if(resParametersObject.containsKey("requestInputs")) { + Map resRequestInputs = (Map) resourceParametersObject.get("requestInputs"); + resRequestInputs.putAll(resourceInputs); + } + else { + resParametersObject.putAll(resourceRequestInputs); + } } - return locationONAP; + else { + resource.putAll(resourceParametersObject); + } + + return; + } + + + + @SuppressWarnings("unchecked") + public String doTPResourcesAllocation(DelegateExecution execution, String uuiRequest) { + Map uuiObject = getJsonObject(uuiRequest, Map.class); + Map serviceObject = (Map) uuiObject.get("service"); + Map serviceParametersObject = (Map) serviceObject.get("parameters"); + Map serviceRequestInputs = (Map) serviceParametersObject.get("requestInputs"); + + if(!isNeedAllocateCrossTPResources(serviceRequestInputs)) { + return uuiRequest; + } + + allocateCrossTPResources(execution, serviceRequestInputs); + String newRequest = getJsonString(uuiObject); + return newRequest; + } + + @SuppressWarnings("unchecked") + private boolean isNeedAllocateCrossTPResources(Map serviceRequestInputs) { + if(serviceRequestInputs.containsKey("CallSource")) + { + String callSource = (String) serviceRequestInputs.get("CallSource"); + if("ExternalAPI".equalsIgnoreCase(callSource)) { + return false; + } + } + return true; + } + + @SuppressWarnings("unchecked") + private void allocateCrossTPResources(DelegateExecution execution, Map serviceRequestInputs) { + + AaiUtil aai = new AaiUtil(null); + Map crossTPs = aai.getTPsfromAAI(execution); + + if(crossTPs == null || crossTPs.isEmpty()) { + serviceRequestInputs.put("local-access-provider-id", ""); + serviceRequestInputs.put("local-access-client-id", ""); + serviceRequestInputs.put("local-access-topology-id", ""); + serviceRequestInputs.put("local-access-node-id", ""); + serviceRequestInputs.put("local-access-ltp-id", ""); + serviceRequestInputs.put("remote-access-provider-id", ""); + serviceRequestInputs.put("remote-access-client-id", ""); + serviceRequestInputs.put("remote-access-topology-id", ""); + serviceRequestInputs.put("remote-access-node-id", ""); + serviceRequestInputs.put("remote-access-ltp-id", ""); + } + else { + serviceRequestInputs.put("local-access-provider-id", crossTPs.get("local-access-provider-id")); + serviceRequestInputs.put("local-access-client-id", crossTPs.get("local-access-client-id")); + serviceRequestInputs.put("local-access-topology-id", crossTPs.get("local-access-topology-id")); + serviceRequestInputs.put("local-access-node-id", crossTPs.get("local-access-node-id")); + serviceRequestInputs.put("local-access-ltp-id", crossTPs.get("local-access-ltp-id")); + serviceRequestInputs.put("remote-access-provider-id", crossTPs.get("remote-access-provider-id")); + serviceRequestInputs.put("remote-access-client-id", crossTPs.get("remote-client-id")); + serviceRequestInputs.put("remote-access-topology-id", crossTPs.get("remote-topology-id")); + serviceRequestInputs.put("remote-access-node-id", crossTPs.get("remote-node-id")); + serviceRequestInputs.put("remote-access-ltp-id", crossTPs.get("remote-ltp-id")); + } + + return; } public String preProcessService(ServiceDecomposition serviceDecomposition, String uuiRequest) { @@ -211,8 +363,7 @@ public class ServicePluginFactory { for (Object resource : resources) { Map resourceObject = (Map) resource; Map resourceParametersObject = (Map) resourceObject.get("parameters"); - Map resourceRequestInputs = (Map) resourceParametersObject - .get("requestInputs"); + Map resourceRequestInputs = (Map) resourceParametersObject.get("requestInputs"); for (Entry entry : resourceRequestInputs.entrySet()) { if (entry.getKey().toLowerCase().contains("location")) { if ("".equals(srcLocation)) { @@ -258,14 +409,14 @@ public class ServicePluginFactory { } private List queryTerminalPointsFromServiceProviderSystem(String srcLocation, String dstLocation) { - Map locationSrc = new HashMap<>(); + Map locationSrc = new HashMap(); locationSrc.put("location", srcLocation); - Map locationDst = new HashMap<>(); + Map locationDst = new HashMap(); locationDst.put("location", dstLocation); - List> locations = new ArrayList<>(); + List> locations = new ArrayList>(); locations.add(locationSrc); locations.add(locationDst); - List returnList = new ArrayList<>(); + List returnList = new ArrayList(); String reqContent = getJsonString(locations); String url = getThirdSPEndPoint(); String responseContent = sendRequest(url, "POST", reqContent); @@ -275,12 +426,12 @@ public class ServicePluginFactory { return returnList; } + @SuppressWarnings("unchecked") private Map getVPNResourceRequestInputs(List resources) { for (Object resource : resources) { Map resourceObject = (Map) resource; Map resourceParametersObject = (Map) resourceObject.get("parameters"); - Map resourceRequestInputs = (Map) resourceParametersObject - .get("requestInputs"); + Map resourceRequestInputs = (Map) resourceParametersObject.get("requestInputs"); for (Entry entry : resourceRequestInputs.entrySet()) { if (entry.getKey().toLowerCase().contains("vpntype")) { return resourceRequestInputs; @@ -307,7 +458,7 @@ public class ServicePluginFactory { Map serviceObject = (Map) uuiObject.get("service"); Map serviceParametersObject = (Map) serviceObject.get("parameters"); Map serviceRequestInputs = (Map) serviceParametersObject.get("requestInputs"); - Map oofQueryObject = new HashMap<>(); + Map oofQueryObject = new HashMap(); List resources = (List) serviceParametersObject.get("resources"); oofQueryObject.put("src-access-provider-id", serviceRequestInputs.get("inner-src-access-provider-id")); oofQueryObject.put("src-access-client-id", serviceRequestInputs.get("inner-src-access-client-id")); @@ -323,7 +474,7 @@ public class ServicePluginFactory { String url = getOOFCalcEndPoint(); String responseContent = sendRequest(url, "POST", oofRequestReq); - List returnList = new ArrayList<>(); + List returnList = new ArrayList(); if (null != responseContent) { returnList = getJsonObject(responseContent, List.class); } @@ -336,7 +487,7 @@ public class ServicePluginFactory { } private Map getReturnRoute(List returnList){ - Map returnRoute = new HashMap<>(); + Map returnRoute = new HashMap(); for(Object returnVpn :returnList){ Map returnVpnInfo = (Map) returnVpn; String accessTopoId = (String)returnVpnInfo.get("access-topology-id"); -- cgit 1.2.3-korg