X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2FMSOInfrastructureBPMN%2Fsrc%2Fmain%2Fgroovy%2Forg%2Fopenecomp%2Fmso%2Fbpmn%2Finfrastructure%2Fscripts%2FDoCreateE2EServiceInstance.groovy;h=f8706cc2f07b14b9ed60b25c0d64733a20c525a3;hb=refs%2Fchanges%2F25%2F35725%2F1;hp=ca67d5dcddc336428ea912b3d8e53e780dddd81e;hpb=c91753756d54b6cc0e4a6b48a6c9e012b3be8c56;p=so.git diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy index ca67d5dcdd..f8706cc2f0 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy @@ -27,22 +27,34 @@ import groovy.json.* import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition import org.openecomp.mso.bpmn.core.domain.ServiceInstance import org.openecomp.mso.bpmn.core.domain.ModelInfo +import org.openecomp.mso.bpmn.core.domain.Resource +import org.openecomp.mso.bpmn.core.domain.AllottedResource +import org.openecomp.mso.bpmn.core.domain.NetworkResource +import org.openecomp.mso.bpmn.core.domain.VnfResource +import org.openecomp.mso.bpmn.common.recipe.ResourceInput +import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder; +import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient import org.openecomp.mso.bpmn.core.json.JsonUtils import org.openecomp.mso.bpmn.common.scripts.AaiUtil import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils +import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils; import org.openecomp.mso.bpmn.core.RollbackData import org.openecomp.mso.bpmn.core.WorkflowException import org.openecomp.mso.rest.APIResponse; import org.openecomp.mso.rest.RESTClient import org.openecomp.mso.rest.RESTConfig +import java.util.List; import java.util.UUID; +import javax.mail.Quota.Resource; + import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.runtime.Execution import org.json.JSONObject; +import org.json.JSONArray; import org.apache.commons.lang3.* import org.apache.commons.codec.binary.Base64; import org.springframework.web.util.UriUtils; @@ -77,6 +89,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { String Prefix="DCRESI_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() + CatalogDbUtils cutils = new CatalogDbUtils() public void preProcessRequest (Execution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") @@ -127,9 +140,11 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { String uuiRequest = execution.getVariable("uuiRequest") String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId") String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId") + String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName") + execution.setVariable("serviceModelName", serviceModelName) //aai serviceType and Role can be setted as fixed value now. - String aaiServiceType = "voLTE type" - String aaiServiceRole = "voLTE role" + String aaiServiceType = "E2E Service" + String aaiServiceRole = "E2E Service" execution.setVariable("modelInvariantUuid", modelInvariantUuid) execution.setVariable("modelUuid", modelUuid) @@ -170,7 +185,47 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { } utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled) } + + public void prepareDecomposeService(Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + + try { + utils.log("DEBUG", " ***** Inside prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled) + String modelInvariantUuid = execution.getVariable("modelInvariantUuid") + String modelUuid = execution.getVariable("modelUuid") + //here modelVersion is not set, we use modelUuid to decompose the service. + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + + utils.log("DEBUG", " ***** Completed prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled) + } catch (Exception ex) { + // try error in method block + String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage() + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + } + } + public void processDecomposition (Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + + utils.log("DEBUG", " ***** Inside processDecomposition() of create generic e2e service flow ***** ", isDebugEnabled) + try { + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") + } catch (Exception ex) { + String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage() + utils.log("DEBUG", exceptionMessage, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + } + } + + public void doServiceHoming(Execution execution) { + //Now Homing is not clear. So to be implemented. + } + public void postProcessAAIGET(Execution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled) @@ -179,7 +234,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { try { String serviceInstanceName = execution.getVariable("serviceInstanceName") boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(succInAAI != true){ + if(!succInAAI){ utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled) WorkflowException workflowException = execution.getVariable("WorkflowException") utils.logAudit("workflowException: " + workflowException) @@ -196,7 +251,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { else { boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - if(foundInAAI == true){ + if(foundInAAI){ utils.log("INFO","Found Service-instance in AAI", isDebugEnabled) msg = "ServiceInstance already exists in AAI:" + serviceInstanceName utils.log("INFO", msg, isDebugEnabled) @@ -220,7 +275,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { try { String serviceInstanceId = execution.getVariable("serviceInstanceId") boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator") - if(succInAAI != true){ + if(!succInAAI){ utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled) WorkflowException workflowException = execution.getVariable("WorkflowException") utils.logAudit("workflowException: " + workflowException) @@ -259,7 +314,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { try { String serviceInstanceName = execution.getVariable("serviceInstanceName") boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(succInAAI != true){ + if(!succInAAI){ utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled) WorkflowException workflowException = execution.getVariable("WorkflowException") utils.logAudit("workflowException: " + workflowException) @@ -276,7 +331,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { else { boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - if(foundInAAI == true){ + if(foundInAAI){ String aaiService = execution.getVariable("GENGS_service") if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) { execution.setVariable("serviceInstanceName", utils.getNodeText1(aaiService, "service-instance-name")) @@ -354,11 +409,11 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("serviceInstanceId", serviceId) execution.setVariable("operationId", operationId) execution.setVariable("operationType", operationType) - String incomingRequest = execution.getVariable("uuiRequest") - String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources") - List resourceList = jsonUtil.StringArrayToList(execution, resourcesStr) + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") + List resourceList = serviceDecomposition.getServiceResources() + for(String resource : resourceList){ - resourceTemplateUUIDs = resourceTemplateUUIDs + jsonUtil.getJsonValue(resource, "resourceDefId") + ":" + resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":" } def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter" @@ -400,7 +455,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { String serviceInstanceName = execution.getVariable("serviceInstanceName") String nsServiceName = resourceType + "_" + serviceInstanceName execution.setVariable("nsServiceName", nsServiceName) - utils.log("INFO", "Prepare VFC Request nsServiceName:" + nsServiceName, isDebugEnabled) + utils.log("INFO", "Prepare Resource Request nsServiceName:" + nsServiceName, isDebugEnabled) String globalSubscriberId = execution.getVariable("globalSubscriberId") String serviceType = execution.getVariable("serviceType") String serviceId = execution.getVariable("serviceInstanceId") @@ -410,20 +465,142 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources") String nsServiceDescription = jsonUtil.getJsonValue(incomingRequest, "service.description") execution.setVariable("nsServiceDescription", nsServiceDescription) - utils.log("INFO", "Prepare VFC Request nsServiceDescription:" + nsServiceDescription, isDebugEnabled) - List resourceList = jsonUtil.StringArrayToList(execution, resourcesStr) + utils.log("INFO", "Prepare Resource Request nsServiceDescription:" + nsServiceDescription, isDebugEnabled) + List resourceList = jsonUtil.StringArrayToList(execution, resourcesStr) + //reset the variables + execution.setVariable("resourceUUID", "") + execution.setVariable("resourceInvariantUUID", "") + execution.setVariable("resourceParameters", "") for(String resource : resourceList){ String resourceName = jsonUtil.getJsonValue(resource, "resourceName") if(StringUtils.containsIgnoreCase(resourceName, resourceType)){ - String resourceUUID = jsonUtil.getJsonValue(resource, "resourceDefId") + String resourceUUID = jsonUtil.getJsonValue(resource, "resourceId") + String resourceInvariantUUID = jsonUtil.getJsonValue(resource, "resourceDefId") String resourceParameters = jsonUtil.getJsonValue(resource, "nsParameters") execution.setVariable("resourceUUID", resourceUUID) + execution.setVariable("resourceInvariantUUID", resourceInvariantUUID) execution.setVariable("resourceParameters", resourceParameters) - utils.log("INFO", "Prepare VFC Request resourceType:" + resourceType, isDebugEnabled) - utils.log("INFO", "Prepare VFC Request resourceUUID:" + resourceUUID, isDebugEnabled) - utils.log("INFO", "Prepare VFC Request resourceParameters:" + resourceParameters, isDebugEnabled) + utils.log("INFO", "Prepare Resource Request resourceType:" + resourceType, isDebugEnabled) + utils.log("INFO", "Prepare Resource Request resourceUUID:" + resourceUUID, isDebugEnabled) + utils.log("INFO", "Prepare Resource Request resourceParameters:" + resourceParameters, isDebugEnabled) } } - utils.log("INFO", "Prepare VFC Request finished", isDebugEnabled) + utils.log("INFO", "Prepare Controller Request finished", isDebugEnabled) } + /** + * sequence resource. we should analyze resource sequence from service template + * Here we make VF first, and then network for E2E service. + */ + public void sequenceResoure(execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled) + String serviceModelUUID = execution.getVariable("modelUuid") + JSONArray networks = cutils.getAllNetworksByServiceModelUuid(execution, serviceModelUUID) + utils.log("DEBUG", "obtained Network list: " + networks, isDebugEnabled) + if (networks == null) { + utils.log("INFO", "No matching networks in Catalog DB for serviceModelUUID=" + serviceModelUUID, isDebugEnabled) + } + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") + + //we use VF to define a network service + List vnfResourceList= serviceDecomposition.getServiceVnfs() + + //here wan is defined as a network resource + List networkResourceList = serviceDecomposition.getServiceNetworks() + + //allotted resource + List arResourceList= serviceDecomposition.getServiceAllottedResources() + //define sequenced resource list, we deploy vf first and then network and then ar + //this is defaule sequence + List sequencedResourceList = new ArrayList(); + if(null != vnfResourceList){ + sequencedResourceList.addAll(vnfResourceList) + } + if(null != networkResourceList){ + sequencedResourceList.addAll(networkResourceList) + } + if(null != arResourceList){ + sequencedResourceList.addAll(arResourceList) + } + + String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true" + execution.setVariable("isContainsWanResource", isContainsWanResource) + execution.setVariable("currentResourceIndex", 0) + execution.setVariable("sequencedResourceList", sequencedResourceList) + utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled) + utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled) + } + + public void getCurrentResoure(execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled) + def currentIndex = execution.getVariable("currentResourceIndex") + List sequencedResourceList = execution.getVariable("sequencedResourceList") + Resource currentResource = sequencedResourceList.get(currentIndex) + utils.log("INFO", "Now we deal with resouce:" + currentResource.getModelInfo().getModelName(), isDebugEnabled) + utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled) + } + + /** + * sequence resource + */ + public void parseNextResource(execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled) + def currentIndex = execution.getVariable("currentResourceIndex") + def nextIndex = currentIndex + 1 + execution.setVariable("currentResourceIndex", nextIndex) + List sequencedResourceList = execution.getVariable("sequencedResourceList") + if(nextIndex >= sequencedResourceList.size()){ + execution.setVariable("allResourceFinished", "true") + }else{ + execution.setVariable("allResourceFinished", "false") + } + utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled) + } + + /** + * post config request. + */ + public void postConfigRequest(execution){ + //now do noting + } + + public void prepareResourceRecipeRequest(execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("INFO", "======== Start prepareResourceRecipeRequest Process ======== ", isDebugEnabled) + ResourceInput resourceInput = new ResourceInput() + String serviceInstanceName = execution.getVariable("serviceInstanceName") + String resourceInstanceName = resourceType + "_" + serviceInstanceName + resourceInput.setResourceInstanceName(resourceInstanceName) + utils.log("INFO", "Prepare Resource Request resourceInstanceName:" + resourceInstanceName, isDebugEnabled) + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String serviceType = execution.getVariable("serviceType") + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String operationId = execution.getVariable("operationId") + String operationType = execution.getVariable("operationType") + resourceInput.setGlobalSubscriberId(globalSubscriberId) + resourceInput.setServiceType(serviceType) + resourceInput.setServiceInstanceId(serviceInstanceId) + resourceInput.setOperationId(operationId) + resourceInput.setOperationType(operationType); + def currentIndex = execution.getVariable("currentResourceIndex") + List sequencedResourceList = execution.getVariable("sequencedResourceList") + Resource currentResource = sequencedResourceList.get(currentIndex) + String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid() + resourceInput.setResourceCustomizationUuid(resourceCustomizationUuid); + String resourceInvariantUuid = currentResource.getModelInfo().getModelInvariantUuid() + resourceInput.setResourceInvariantUuid(resourceInvariantUuid) + String resourceUuid = currentResource.getModelInfo().getModelUuid() + resourceInput.setResourceUuid(resourceUuid) + + String incomingRequest = execution.getVariable("uuiRequest") + //set the requestInputs from tempalte To Be Done + String serviceModelUuid = execution.getVariable("modelUuid") + String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters") + String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters) + resourceInput.setResourceParameters(resourceParameters) + execution.setVariable("resourceInput", resourceInput) + utils.log("INFO", "======== COMPLETED prepareResourceRecipeRequest Process ======== ", isDebugEnabled) + } }