From 1bda61168585eaa76a03a16f5e5ec215c4c9ab18 Mon Sep 17 00:00:00 2001 From: Elaine_Han Date: Fri, 10 Aug 2018 15:43:04 +0800 Subject: Site service process with location Delete real existing resources Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa70000006 Issue-ID: SO-683 Signed-off-by: Yulian Han --- .../scripts/Create3rdONAPE2EServiceInstance.groovy | 3 +- .../scripts/DoCreateE2EServiceInstance.groovy | 13 ++++ .../scripts/DoDeleteE2EServiceInstance.groovy | 17 ++++- .../workflow/service/ServicePluginFactory.java | 68 ++++++++++++++++- .../subprocess/DoCreateE2EServiceInstance.bpmn | 86 +++++++++------------- 5 files changed, 130 insertions(+), 57 deletions(-) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy index 80e6e758c0..1eb626101e 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy @@ -164,7 +164,8 @@ public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso //uuiRequest String incomingRequest = resourceInputObj.getRequestsInputs() String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters") - JSONObject inputParameters = new JSONObject(customizeResourceParam(serviceParameters)) + String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs") + JSONObject inputParameters = new JSONObject(customizeResourceParam(requestInputs)) execution.setVariable(Prefix + "ServiceParameters", inputParameters) // CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call) 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 b5d196181b..4939173d65 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 @@ -466,6 +466,19 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ") } + // 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) + + msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ") + } + // prepare input param for using DoCreateResources.bpmn public void preProcessForAddResource(DelegateExecution execution) { msoLogger.trace("STARTED preProcessForAddResource Process ") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy index 6d23ae7c65..827d44726b 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy @@ -336,6 +336,11 @@ public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor { String sppartnerName = "sp-partner" + eValue jObj.put("resourceType", sppartnerName) } + else if(eKey.equals(rt + ".id")){ + jObj.put("resourceInstanceId", eValue) + String resourceName = rt + eValue; + jObj.put("resourceType", resourceName) + } } def rl_props = utils.getIdenticalChildren(node, "related-to-property") @@ -412,6 +417,8 @@ public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor { if (serviceRelationShip != null) { relationShipList = jsonSlurper.parseText(serviceRelationShip) } + + List deleteRealResourceList = new ArrayList(); //Set the real resource instance id to the decomosed resource list for (Resource resource: deleteResourceList) { @@ -421,13 +428,17 @@ public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor { if (relationShipList != null) { relationShipList.each { if (StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())) { - resource.setResourceId(it.resourceInstanceId); + resource.setResourceId(it.resourceInstanceId) + deleteRealResourceList.add(resource) } } } } - execution.setVariable("deleteResourceList", deleteResourceList) - utils.log("DEBUG", "delete resource list : " + deleteResourceList, isDebugEnabled) + + // only delete real existing resources + execution.setVariable("deleteResourceList", deleteRealResourceList) + + utils.log("DEBUG", "delete resource list : " + deleteRealResourceList, isDebugEnabled) } catch (Exception ex) { String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage() utils.log("DEBUG", exceptionMessage, isDebugEnabled) 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 bd781756a5..7226feb552 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,6 +20,7 @@ package org.onap.so.bpmn.infrastructure.workflow.service; +import org.json.JSONObject; import java.io.IOException; import java.net.SocketTimeoutException; import java.util.ArrayList; @@ -27,7 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; - +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.apache.http.client.HttpClient; @@ -45,6 +46,7 @@ import org.apache.http.util.EntityUtils; import org.camunda.bpm.engine.runtime.Execution; import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.core.domain.ServiceDecomposition; +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; @@ -61,6 +63,8 @@ public class ServicePluginFactory { 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 Inventory_OSS_Default_EndPoint = "http://192.168.1.199:8443/oss/inventory"; private static final int DEFAULT_TIME_OUT = 60000; @@ -77,7 +81,15 @@ public class ServicePluginFactory { } return instance; } + + private ServicePluginFactory() { + + } + + private String getInventoryOSSEndPoint(){ + 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); } @@ -86,6 +98,60 @@ public class ServicePluginFactory { return UrnPropertiesReader.getVariable("mso.service-plugin.oof-calc-endpoint", OOF_Default_EndPoint); } + public ServiceDecomposition doProcessSiteLocation(ServiceDecomposition serviceDecomposition, String uuiRequest) { + ServiceDecomposition serviceDecompositionforLocal = serviceDecomposition; + + if (isSiteLocationLocal(serviceDecomposition, uuiRequest)) { + return serviceDecomposition; + } + + List addResourceList = serviceDecomposition.getServiceResources(); + for (Resource resource : addResourceList) { + String resourcemodelName = resource.getModelInfo().getModelName(); + if (!StringUtils.containsIgnoreCase(resourcemodelName, "sp-partner")) { + serviceDecompositionforLocal.deleteResource(resource); + break; + } + if (!StringUtils.containsIgnoreCase(resourcemodelName, "sppartner")) { + serviceDecompositionforLocal.deleteResource(resource); + break; + } + } + + return serviceDecompositionforLocal; + } + + 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; + } + } + + return isSiteLocationLocal; + } + + private String queryLocationFromInventoryOSS(JSONObject locationObj) { + String reqContent = getJsonString(locationObj); + String url = getInventoryOSSEndPoint(); + String responseContent = sendRequest(url, "POST", reqContent); + String locationONAP = ""; + if (null != responseContent) { + locationONAP = getJsonObject(responseContent, String.class); + } + return locationONAP; + } public String preProcessService(ServiceDecomposition serviceDecomposition, String uuiRequest) { diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn index eeaa5e451a..0b890d8573 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1qiiycn @@ -76,7 +76,7 @@ ddsi.postProcessAAIPUT(execution)]]> - SequenceFlow_03ebqhf + SequenceFlow_1m2tm19 SequenceFlow_1qctzm0 - SequenceFlow_1hbesp9 + SequenceFlow_1m2tm19 - - - SequenceFlow_01s0ef2 - SequenceFlow_03ebqhf + + SequenceFlow_13xfsff + SequenceFlow_0y3i2k7 +dcsi.doProcessSiteLocation(execution)]]> @@ -191,7 +190,7 @@ dcsi.doServiceHoming(execution)]]> SequenceFlow_0d0c20n - SequenceFlow_13xfsff + SequenceFlow_0y3i2k7 SequenceFlow_0bf6bzp def csi = new DoCreateE2EServiceInstance() csi.postProcessForAddResource(execution)]]> - + SequenceFlow_0a6vgsu - - - - SequenceFlow_1hbesp9 - SequenceFlow_01s0ef2 - - + + @@ -305,17 +297,17 @@ dcsi.doServicePreOperation(execution)]]> - - + + - + - + - + @@ -418,37 +410,30 @@ dcsi.doServicePreOperation(execution)]]> - - - - - - - - + - + - - + + - + - + - + @@ -471,13 +456,6 @@ dcsi.doServicePreOperation(execution)]]> - - - - - - - @@ -485,16 +463,20 @@ dcsi.doServicePreOperation(execution)]]> - - - + + + + + + + + + + - + - - - -- cgit 1.2.3-korg