Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / CreateVnfInfra.groovy
index 6168acd..24487d5 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
@@ -23,9 +23,12 @@ package org.openecomp.mso.bpmn.infrastructure.scripts
 import java.util.UUID;
 
 import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.runtime.Execution;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
 
 import static org.apache.commons.lang3.StringUtils.*;
+import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
+import org.json.JSONObject;
+import org.json.JSONArray;
 
 import org.openecomp.mso.bpmn.common.scripts.AaiUtil;
 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
@@ -33,7 +36,9 @@ import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;
 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
 import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.bpmn.core.domain.VnfResource
 import org.openecomp.mso.bpmn.core.json.JsonUtils;
+import org.openecomp.mso.bpmn.infrastructure.aai.AAICreateResources;
 
 
 /**
@@ -47,6 +52,8 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
        ExceptionUtil exceptionUtil = new ExceptionUtil()
        JsonUtils jsonUtil = new JsonUtils()
        VidUtils vidUtils = new VidUtils(this)
+       CatalogDbUtils cutils = new CatalogDbUtils()
+       AAICreateResources aaiCR = new AAICreateResources()
 
        /**
         * This method gets and validates the incoming
@@ -55,11 +62,12 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
         * @param - execution
         *
         */
-       public void preProcessRequest(Execution execution) {
+       public void preProcessRequest(DelegateExecution execution) {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
                utils.log("DEBUG", " *** STARTED CreateVnfInfra PreProcessRequest Process*** ", isDebugEnabled)
-
+               
+               setBasicDBAuthHeader(execution, isDebugEnabled)
                execution.setVariable("CREVI_sentSyncResponse", false)
 
                try{
@@ -101,7 +109,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                                def vnfModelInfo = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo")
                                execution.setVariable("CREVI_vnfModelInfo", vnfModelInfo)
 
-                               String modelInvariantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelInvariantId")
+                               String modelInvariantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelInvariantUuid")
                                execution.setVariable("CREVI_modelInvariantId", modelInvariantId)
                                utils.log("DEBUG", "Incoming Invariant Id is: " + modelInvariantId, isDebugEnabled)
 
@@ -157,7 +165,13 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                                }
                                execution.setVariable("CREVI_sdncCallbackUrl", sdncCallbackUrl)
                                
-                               def vnfInputParameters = jsonUtil.getJsonValue(createVnfRequest, "requestParameters.userParams")
+                               def vnfInputParameters = null
+                               try {
+                                       vnfInputParameters = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestParameters.userParams")
+                               }
+                               catch (Exception e) {
+                                       utils.log("DEBUG", "userParams are not present in the request", isDebugEnabled)
+                               }
                                execution.setVariable("CREVI_vnfInputParameters", vnfInputParameters)
                                
                                
@@ -179,7 +193,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PreProcessRequest Process ***", isDebugEnabled)
        }
 
-       public void sendSyncResponse (Execution execution) {
+       public void sendSyncResponse (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
 
@@ -205,78 +219,8 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                utils.log("DEBUG", "*** COMPLETED CreateVnfInfra SendSyncResponse Process ***", isDebugEnabled)
        }
 
-       public void prepareCreateGenericVnf (Execution execution) {
-               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               execution.setVariable("prefix",Prefix)
-
-               utils.log("DEBUG", " *** STARTED CreateVnfInfra PrepareCreateGenericVnf Process *** ", isDebugEnabled)
-               try {
-                       //Get Vnf Info
-                       String vnfId = execution.getVariable("CREVI_vnfId")
-                       def vnfName = execution.getVariable("CREVI_vnfName")
-                       def vnfType = execution.getVariable("CREVI_vnfType")
-                       def serviceId = execution.getVariable("CREVI_serviceId")
-                       def orchStatus = execution.getVariable("CREVI_orchStatus")
-                       def modelInvariantId = execution.getVariable("CREVI_modelInvariantId")
-                       def modelVersion = execution.getVariable("CREVI_modelVersion")
-                       // TODO: 1702 Variable
-                       def equipmentRole = execution.getVariable("CREVI_equipmentRole")
-
-                       //Get Service Instance Info
-                       def serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
-                       String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
-
-                       int custStart = siRelatedLink.indexOf("customer/")
-                       int custEnd = siRelatedLink.indexOf("/service-subscriptions")
-                       String globalCustId = siRelatedLink.substring(custStart + 9, custEnd)
-                       int serviceStart = siRelatedLink.indexOf("service-subscription/")
-                       int serviceEnd = siRelatedLink.indexOf("/service-instances/")
-                       String serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
-
-                       //Get Namespace
-                       AaiUtil aaiUtil = new AaiUtil(this)
-                       def aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)
-                       String namespace = aaiUtil.getNamespaceFromUri(aai_uri)
-
-                       String payload =
-                                       """<generic-vnf xmlns="${namespace}">
-                               <vnf-id>${vnfId}</vnf-id>
-                               <vnf-name>${vnfName}</vnf-name>
-                               <service-id>${serviceId}</service-id>
-                               <vnf-type>${vnfType}</vnf-type>
-                               <orchestration-status>${orchStatus}</orchestration-status>
-                               <persona-model-id>${modelInvariantId}</persona-model-id>
-                               <persona-model-version>${modelVersion}</persona-model-version>
-                               <relationship-list>
-                                       <relationship>
-                               <related-to>service-instance</related-to>
-                               <related-link>${siRelatedLink}</related-link>
-                               <relationship-data>
-                               <relationship-key>customer.global-customer-id</relationship-key>
-                               <relationship-value>${globalCustId}</relationship-value>
-                       </relationship-data>
-                               <relationship-data>
-                               <relationship-key>service-subscription.service-type</relationship-key>
-                               <relationship-value>${serviceType}</relationship-value>
-                               </relationship-data>
-                                       <relationship-data>
-                               <relationship-key>service-instance.service-instance-id</relationship-key>
-                               <relationship-value>${serviceInstanceId}</relationship-value>
-                               </relationship-data>
-                       </relationship>
-                               </relationship-list>
-                       </generic-vnf>"""
-
-                       execution.setVariable("CREVI_genericVnfPayload", payload)
-
-               }catch(Exception ex) {
-                       utils.log("DEBUG", "Error Occured in CreateVnfInfra PrepareCreateGenericVnf Process " + ex.getMessage(), isDebugEnabled)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCreateGenericVnf Process")
-               }
-               utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCreateGenericVnf Process ***", isDebugEnabled)
-       }
        
-       public void preProcessSDNCAssignRequest(Execution execution){
+       public void preProcessSDNCAssignRequest(DelegateExecution execution){
                def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix", Prefix)
                logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
@@ -302,7 +246,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
        }
        
-       public void preProcessSDNCActivateRequest(Execution execution) {
+       public void preProcessSDNCActivateRequest(DelegateExecution execution) {
                def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
                        'execution=' + execution.getId() +
                        ')'
@@ -327,7 +271,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                logDebug("======== COMPLETED  preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
        }
        
-       public String buildSDNCRequest(Execution execution, String svcInstId, String action){
+       public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
                
                                String uuid = execution.getVariable('testReqId') // for junits
                                if(uuid==null){
@@ -390,7 +334,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                        return sdncRequest              
        }
                
-       public void validateSDNCResponse(Execution execution, String response, String method){
+       public void validateSDNCResponse(DelegateExecution execution, String response, String method){
                def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
                logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
@@ -416,7 +360,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
        }
 
-       public void prepareCompletionHandlerRequest(Execution execution){
+       public void prepareCompletionHandlerRequest(DelegateExecution execution){
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
 
@@ -449,7 +393,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCompletionHandlerRequest Process ***", isDebugEnabled)
        }
 
-       public void sendErrorResponse(Execution execution){
+       public void sendErrorResponse(DelegateExecution execution){
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
 
@@ -474,7 +418,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                utils.log("DEBUG", "*** COMPLETED CreateVnfInfra sendErrorResponse Process ***", isDebugEnabled)
        }
 
-       public void prepareFalloutRequest(Execution execution){
+       public void prepareFalloutRequest(DelegateExecution execution){
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
 
@@ -499,4 +443,109 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor {
                utils.log("DEBUG", "*** COMPLETED CreateVnfInfra prepareFalloutRequest Process ***", isDebugEnabled)
        }
 
+       
+       public void queryCatalogDB (DelegateExecution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               execution.setVariable("prefix",Prefix)
+
+               utils.log("DEBUG", " *** STARTED CreateVnfInfra QueryCatalogDB Process *** ", isDebugEnabled)
+               try {
+                       //Get Vnf Info
+                       String vnfModelInfo = execution.getVariable("CREVI_vnfModelInfo")
+                       String vnfModelCustomizationUuid = jsonUtil.getJsonValueForKey(vnfModelInfo, "modelCustomizationUuid")
+                       utils.log("DEBUG", "querying Catalog DB by vnfModelCustomizationUuid: " + vnfModelCustomizationUuid, isDebugEnabled)
+                                               
+                       JSONArray vnfs = cutils.getAllVnfsByVnfModelCustomizationUuid(execution,
+                                                       vnfModelCustomizationUuid, "v2")
+                       utils.log("DEBUG", "obtained VNF list: " + vnfs, isDebugEnabled)
+                       
+                       if (vnfs == null) {
+                               utils.log("ERROR", "No matching VNFs in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "No matching VNFs in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid)
+                       }
+                       
+                       // Only one match here
+                       JSONObject vnf = vnfs.get(0)
+                       
+                       if (vnf == null) {
+                               utils.log("ERROR", "No matching VNF in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "No matching VNF in Catalog DB for vnfModelCustomizationUuid=" + vnfModelCustomizationUuid)
+                       }                       
+                       
+                       VnfResource vnfResource = new VnfResource()
+                       String nfType = jsonUtil.getJsonValueForKey(vnf, "nfType")
+                       vnfResource.setNfType(nfType)
+                       String nfRole = jsonUtil.getJsonValueForKey(vnf, "nfRole")
+                       vnfResource.setNfRole(nfRole)
+                       String nfFunction = jsonUtil.getJsonValueForKey(vnf, "nfFunction")
+                       vnfResource.setNfFunction(nfFunction)
+                       String nfNamingCode = jsonUtil.getJsonValueForKey(vnf, "nfNamingCode")
+                       vnfResource.setNfNamingCode(nfNamingCode)
+                       
+                       execution.setVariable("CREVI_vnfResourceDecomposition", vnfResource)
+                       
+               }catch(BpmnError e) {
+                       throw e;                        
+               }catch(Exception ex) {
+                       utils.log("DEBUG", "Error Occurred in CreateVnfInfra QueryCatalogDB Process " + ex.getMessage(), isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in CreateVnfInfra QueryCatalogDB Process")
+               }
+               
+               
+               utils.log("DEBUG", "*** COMPLETED CreateVnfInfra QueryCatalogDb Process ***", isDebugEnabled)
+       }
+       public void createPlatform (DelegateExecution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** START createPlatform *****",  isDebugEnabled)
+               
+               String request = execution.getVariable("bpmnRequest")
+               String platformName = jsonUtil.getJsonValue(request, "requestDetails.platform.platformName")
+               String vnfId = execution.getVariable("CREVI_vnfId")
+       
+               utils.log("DEBUG","Platform NAME: " + platformName, isDebugEnabled)
+               utils.log("DEBUG","VnfID: " + vnfId, isDebugEnabled)
+               
+               if(platformName == null||platformName.equals("")){
+                       String msg = "Exception in createPlatform. platformName was not found in the request.";
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }else{
+                       utils.log("DEBUG", "platformName was found.", isDebugEnabled)
+                       try{
+                               AAICreateResources aaiCR = new AAICreateResources()
+                               aaiCR.createAAIPlatform(platformName, vnfId)
+                       }catch(Exception ex){
+                               String msg = "Exception in createPlatform. " + ex.getMessage();
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+                       }
+               }
+               utils.log("DEBUG"," *** Exit createPlatform *** ", isDebugEnabled)
+       }
+       public void createLineOfBusiness (DelegateExecution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** START createLineOfBusiness *****",  isDebugEnabled)
+               
+               String request = execution.getVariable("bpmnRequest")
+               String lineOfBusiness = jsonUtil.getJsonValue(request, "requestDetails.lineOfBusiness.lineOfBusinessName")
+               String vnfId = execution.getVariable("CREVI_vnfId")
+       
+               utils.log("DEBUG","LineOfBusiness NAME: " + lineOfBusiness, isDebugEnabled)
+               utils.log("DEBUG","VnfID: " + vnfId, isDebugEnabled)
+               
+               if(lineOfBusiness == null || lineOfBusiness.equals("")){
+                       utils.log("DEBUG", "LineOfBusiness was not found. Continuing on with flow...", isDebugEnabled)
+               }else{
+                       utils.log("DEBUG", "LineOfBusiness was found.", isDebugEnabled)
+                       try{
+                               AAICreateResources aaiCR = new AAICreateResources()
+                               aaiCR.createAAILineOfBusiness(lineOfBusiness, vnfId)
+                       }catch(Exception ex){
+                               String msg = "Exception in LineOfBusiness. " + ex.getMessage();
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+                       }
+               }
+               utils.log("DEBUG"," *** Exit createLineOfBusiness *** ", isDebugEnabled)
+       }
 }