Dynamic Cloud Owner Support
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVnf.groovy
index 7fa8b44..b35aab1 100644 (file)
@@ -24,6 +24,7 @@ import static org.apache.commons.lang3.StringUtils.*
 
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.GenericVnf
 import org.onap.so.bpmn.common.scripts.AaiUtil
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
@@ -105,7 +106,13 @@ class DoCreateVnf extends AbstractServiceTaskProcessor {
 
                        String vnfName = execution.getVariable("vnfName")
                        if (vnfName.equals("") || vnfName.equals("null")) {
-                               vnfName = null
+                               AAIResourcesClient resourceClient = new AAIResourcesClient()
+                               AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, execution.getVariable("vnfId"))
+                               if(resourceClient.exists(uri)){
+                                       exceptionUtil.buildWorkflowException(execution, 5000, "Generic Vnf Already Exist.")
+                               }
+
+
                        }
                        execution.setVariable("DoCVNF_vnfName", vnfName)
                        msoLogger.debug("Incoming Vnf Name is: " + vnfName)
@@ -259,6 +266,9 @@ class DoCreateVnf extends AbstractServiceTaskProcessor {
                        AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
 
                        if(resourceClient.exists(uri)){
+                               Map<String, String> keys = uri.getURIKeys()
+                               execution.setVariable("globalCustomerId", keys.get("global-customer-id"))
+                               execution.setVariable("serviceType", keys.get("service-type"))
                                execution.setVariable("GENGS_siResourceLink", uri.build().toString())
 
                        }else{
@@ -307,14 +317,9 @@ class DoCreateVnf extends AbstractServiceTaskProcessor {
 
                        //Get Service Instance Info
                        String serviceInstanceId = getVariableEnforced(execution, "DoCVNF_serviceInstanceId")
-                       String siRelatedLink = getVariableEnforced(execution, "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)
+                       String globalCustId = execution.getVariable("globalCustomerId")
+                       String serviceType = execution.getVariable("serviceType")
 
                        Map<String, String> payload = new LinkedHashMap<>();
                        payload.put("vnf-id", vnfId);
@@ -339,7 +344,7 @@ class DoCreateVnf extends AbstractServiceTaskProcessor {
                        resourceClient.connect(uri, siUri)
 
                }catch(Exception ex) {
-                       msoLogger.debug("Error Occured in DoCreateVnf CreateGenericVnf Process " + ex.getMessage())
+                       msoLogger.debug("Error Occured in DoCreateVnf CreateGenericVnf Process ", ex)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf CreateGenericVnf Process")
                }
                msoLogger.trace("COMPLETED DoCreateVnf CreateGenericVnf Process")