Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateE2EServiceInstance.groovy
index 7a7f7cf..eaec39b 100644 (file)
@@ -21,6 +21,7 @@
 package org.openecomp.mso.bpmn.infrastructure.scripts;
 
 import static org.apache.commons.lang3.StringUtils.*;
+import org.apache.http.HttpResponse
 import groovy.xml.XmlUtil
 import groovy.json.*
 
@@ -45,12 +46,11 @@ 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 org.openecomp.mso.bpmn.infrastructure.workflow.service.ServicePluginFactory
 
 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.delegate.DelegateExecution
 import org.json.JSONObject;
@@ -138,8 +138,8 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        String serviceInstanceName = execution.getVariable("serviceInstanceName")
                        String serviceInstanceId = execution.getVariable("serviceInstanceId")
                        String uuiRequest = execution.getVariable("uuiRequest")
-                       String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId")
-                       String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId")
+                       String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
+                       String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
                        String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
                        execution.setVariable("serviceModelName", serviceModelName)
                        //aai serviceType and Role can be setted as fixed value now.
@@ -190,7 +190,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
         try {
-            utils.log("DEBUG", " ***** Inside prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled)
+            utils.log("INFO", " ***** 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.
@@ -212,18 +212,30 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
     public void processDecomposition(DelegateExecution execution) {
         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
     
-        utils.log("DEBUG", " ***** Inside processDecomposition() of  create generic e2e service flow ***** ", isDebugEnabled)    
+        utils.log("INFO", " ***** 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)
+            utils.log("INFO", exceptionMessage, isDebugEnabled)
             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
         }
     }
     
+    public void doServicePreOperation(DelegateExecution execution){
+       //we need a service plugin platform here. 
+       ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+       String uuiRequest = execution.getVariable("uuiRequest")         
+       String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
+       execution.setVariable("uuiRequest", newUuiRequest)      
+    }
+    
     public void doServiceHoming(DelegateExecution execution) {
-        //Now Homing is not clear. So to be implemented.
+       //we need a service plugin platform here. 
+       ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+       String uuiRequest = execution.getVariable("uuiRequest")         
+       String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
+       execution.setVariable("uuiRequest", newUuiRequest)      
     }
     
        public void postProcessAAIGET(DelegateExecution execution) {
@@ -412,8 +424,8 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
             List<Resource>  resourceList = serviceDecomposition.getServiceResources()
             
-            for(String resource : resourceList){
-                    resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"                            
+            for(Resource resource : resourceList){
+                    resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
             }           
 
             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
@@ -426,13 +438,13 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                         <soapenv:Header/>
                         <soapenv:Body>
                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
-                            <serviceId>${serviceId}</serviceId>
-                            <operationId>${operationId}</operationId>
-                            <operationType>${operationType}</operationType>
-                            <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
-                        </ns:initResourceOperationStatus>
-                    </soapenv:Body>
-                </soapenv:Envelope>"""
+                                                               <serviceId>${serviceId}</serviceId>
+                                                               <operationId>${operationId}</operationId>
+                                                               <operationType>${operationType}</operationType>
+                                                               <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
+                            </ns:initResourceOperationStatus>
+                       </soapenv:Body>
+                       </soapenv:Envelope>"""
 
             payload = utils.formatXml(payload)
             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
@@ -445,162 +457,23 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
         }
         utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  
        }
-       
-       /**
-        * prepare resource create request
-        */
-       public void preResourceRequest(execution){
-           String resourceType = execution.getVariable("resourceType")
-           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-           String serviceInstanceName = execution.getVariable("serviceInstanceName")
-           String nsServiceName = resourceType + "_" + serviceInstanceName
-           execution.setVariable("nsServiceName", nsServiceName)
-           utils.log("INFO", "Prepare Resource Request nsServiceName:" + nsServiceName, isDebugEnabled)
-        String globalSubscriberId = execution.getVariable("globalSubscriberId")
-        String serviceType = execution.getVariable("serviceType")
-        String serviceId = execution.getVariable("serviceInstanceId")
-        execution.setVariable("serviceId", serviceId)
-        String operationId = execution.getVariable("operationId")
-        String incomingRequest = execution.getVariable("uuiRequest")
-        String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  
-        String nsServiceDescription = jsonUtil.getJsonValue(incomingRequest, "service.description")  
-        execution.setVariable("nsServiceDescription", nsServiceDescription)
-        utils.log("INFO", "Prepare Resource Request nsServiceDescription:" + nsServiceDescription, isDebugEnabled)
-        List<String> 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, "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 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 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<VnfResource>  vnfResourceList= serviceDecomposition.getServiceVnfs()
-        
-        //here wan is defined as a network resource        
-        List<NetworkResource> networkResourceList = serviceDecomposition.getServiceNetworks()
-
-        //allotted resource
-        List<AllottedResource> arResourceList= serviceDecomposition.getServiceAllottedResources()
-        //define sequenced resource list, we deploy vf first and then network and then ar
-        //this is defaule sequence
-        List<Resource>  sequencedResourceList = new ArrayList<Resource>();
-        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)  
+       // prepare input param for using DoCreateResources.bpmn
+       public void preProcessForAddResource(DelegateExecution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("INFO", " ======== STARTED preProcessForAddResource Process ======== ", isDebugEnabled)
+               
+               ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+               List<Resource> addResourceList = serviceDecomposition.getServiceResources()
+               execution.setVariable("addResourceList", addResourceList)
+               
+               utils.log("INFO", "======== COMPLETED preProcessForAddResource Process ======== ", isDebugEnabled)
        }
+
+       public void postProcessForAddResource(DelegateExecution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               // do nothing now
        
-       public void getCurrentResoure(execution){
-           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")   
-        utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)    
-           def currentIndex = execution.getVariable("currentResourceIndex")
-           List<Resource> 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<String> 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<Resource> 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)      
-     }
 }