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 --- .../workflow/service/ServicePluginFactory.java | 265 ++++++++++++++++----- 1 file changed, 208 insertions(+), 57 deletions(-) (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap') 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