Merge "add junit coverage"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAICreateTasks.java
index 524098b..b9f73f3 100644 (file)
@@ -71,13 +71,13 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
+import com.google.common.base.Strings;
 
 @Component
 public class AAICreateTasks {
 
     private static final Logger logger = LoggerFactory.getLogger(AAICreateTasks.class);
     private static final String networkTypeProvider = "PROVIDER";
-    private static final String A_LA_CARTE = "aLaCarte";
     private static String NETWORK_COLLECTION_NAME = "networkCollectionName";
     private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
     private static String HEAT_STACK_ID = "heatStackId";
@@ -105,6 +105,14 @@ public class AAICreateTasks {
     @Autowired
     private Environment env;
 
+    /**
+     * This method is used for creating the service instance in A&AI.
+     *
+     * It will check the alaCarte and create the service instance in A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createServiceInstance(BuildingBlockExecution execution) {
         try {
             ServiceInstance serviceInstance =
@@ -116,6 +124,12 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating and subscribing the service in A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createServiceSubscription(BuildingBlockExecution execution) {
         try {
             ServiceInstance serviceInstance =
@@ -137,6 +151,12 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creation of the project A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createProject(BuildingBlockExecution execution) {
         try {
             ServiceInstance serviceInstance =
@@ -154,29 +174,46 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating OwningEntity A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createOwningEntity(BuildingBlockExecution execution) {
         try {
             ServiceInstance serviceInstance =
                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
             OwningEntity owningEntity = serviceInstance.getOwningEntity();
-            String owningEntityId = owningEntity.getOwningEntityId();
-            String owningEntityName = owningEntity.getOwningEntityName();
-            if (owningEntityId == null || "".equals(owningEntityId)) {
-                String msg = "Exception in AAICreateOwningEntity. OwningEntityId is null.";
+            if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId())
+                    && Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
+                String msg = "Exception in AAICreateOwningEntity. OwningEntityId and Name are null.";
                 execution.setVariable("ErrorCreateOEAAI", msg);
                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+            } else if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId())
+                    && !Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
+                if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
+                    org.onap.aai.domain.yang.OwningEntity aaiEntity =
+                            aaiSIResources.getOwningEntityByName(owningEntity.getOwningEntityName());
+                    owningEntity.setOwningEntityId(aaiEntity.getOwningEntityId());
+                    owningEntity.setOwningEntityName(owningEntity.getOwningEntityName());
+                    aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
+                } else {
+                    owningEntity.setOwningEntityId(UUID.randomUUID().toString());
+                    aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
+                }
             } else {
                 if (aaiSIResources.existsOwningEntity(owningEntity)) {
                     aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
                 } else {
-                    if (owningEntityName == null || "".equals(owningEntityName)) {
+                    if (Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
                         String msg =
                                 "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
                         logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
                                 ErrorCode.UnknownError.getValue(), msg);
                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
                     } else {
-                        if (aaiSIResources.existsOwningEntityName(owningEntityName)) {
+                        if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
                             String msg =
                                     "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)";
                             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg,
@@ -193,13 +230,19 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating Vnf in A&AI.
+     *
+     * It will check if the Vnf Name is exits in A&AI then it will throw the duplicate name exception.
+     *
+     * Otherwise it will create the vnf amd connect to the serviceinstance.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createVnf(BuildingBlockExecution execution) {
         try {
-            Boolean alaCarte = execution.getVariable(A_LA_CARTE);
             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
-            if (Boolean.TRUE.equals(alaCarte) && aaiVnfResources.checkNameInUse(vnf.getVnfName())) {
-                throw new DuplicateNameException("generic-vnf", vnf.getVnfName());
-            }
             ServiceInstance serviceInstance =
                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
             execution.setVariable("homing", Boolean.TRUE.equals(vnf.isCallHoming()));
@@ -209,6 +252,12 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for separating (,) from the string.
+     *
+     * @param str
+     * @throws @return
+     */
     public void createPlatform(BuildingBlockExecution execution) {
         try {
             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
@@ -228,10 +277,22 @@ public class AAICreateTasks {
 
     }
 
+    /**
+     * This method is used for separating (,) from the string.
+     *
+     * @param str
+     * @throws @return
+     */
     public List<String> splitCDL(String str) {
         return Stream.of(str.split(",")).map(String::trim).map(elem -> new String(elem)).collect(Collectors.toList());
     }
 
+    /**
+     * This method is used for creating the type of business in A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createLineOfBusiness(BuildingBlockExecution execution) {
         try {
             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
@@ -251,6 +312,12 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating the volume group in A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createVolumeGroup(BuildingBlockExecution execution) {
         try {
             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
@@ -258,10 +325,6 @@ public class AAICreateTasks {
             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
             VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
             CloudRegion cloudRegion = gBBInput.getCloudRegion();
-            Boolean alaCarte = execution.getVariable(A_LA_CARTE);
-            if (Boolean.TRUE.equals(alaCarte) && aaiVolumeGroupResources.checkNameInUse(volumeGroup)) {
-                throw new DuplicateNameException("volume-group", volumeGroup.getVolumeGroupName());
-            }
             aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
             aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
             aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion);
@@ -270,14 +333,16 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating the vfModule in A&AI.
+     *
+     * @param execution
+     * @throws @return
+     */
     public void createVfModule(BuildingBlockExecution execution) {
         try {
             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
-            Boolean alaCarte = execution.getVariable(A_LA_CARTE);
-            if (Boolean.TRUE.equals(alaCarte) && aaiVfModuleResources.checkNameInUse(vfModule)) {
-                throw new DuplicateNameException("vf-module", vfModule.getVfModuleName());
-            }
             int moduleIndex = 0;
             if (vfModule.getModelInfoVfModule() != null
                     && !Boolean.TRUE.equals(vfModule.getModelInfoVfModule().getIsBaseBoolean())) {
@@ -292,7 +357,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -307,6 +372,7 @@ public class AAICreateTasks {
                 logger.info("VolumeGroup not found. Skipping Connect between VfModule and VolumeGroup");
             }
             if (volumeGroup != null) {
+                logger.debug("Connecting VfModule to VolumGroup");
                 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup,
                         execution.getGeneralBuildingBlock().getCloudRegion());
             }
@@ -317,7 +383,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to execute Create L3Network operation (PUT )in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -338,6 +404,12 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating the customer in A&AI.
+     *
+     * @param execution
+     * @throws Exception
+     */
     public void createCustomer(BuildingBlockExecution execution) throws Exception {
         try {
             Customer customer = execution.getGeneralBuildingBlock().getCustomer();
@@ -350,7 +422,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to execute NetworkCollection operation (PUT) in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -370,7 +442,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to execute NetworkCollectionInstanceGroup operation (PUT) in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -391,7 +463,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -406,7 +478,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -422,7 +494,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -445,7 +517,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -460,7 +532,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -477,7 +549,7 @@ public class AAICreateTasks {
 
     /**
      * BPMN access method to establish relationships in AAI
-     * 
+     *
      * @param execution
      * @throws Exception
      */
@@ -495,6 +567,11 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for configuring the service in A&AI.
+     *
+     * @param execution @throws
+     */
     public void createConfiguration(BuildingBlockExecution execution) {
         try {
             Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
@@ -504,6 +581,11 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used for creating vnf instance group in A&AI.
+     *
+     * @param execution @throws
+     */
     public void createInstanceGroupVnf(BuildingBlockExecution execution) {
         try {
             ServiceInstance serviceInstance =
@@ -515,6 +597,11 @@ public class AAICreateTasks {
         }
     }
 
+    /**
+     * This method is used to put the network policy in A&AI.
+     *
+     * @param execution @throws
+     */
     public void createNetworkPolicies(BuildingBlockExecution execution) {
         try {
             String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
@@ -549,10 +636,10 @@ public class AAICreateTasks {
 
     /**
      * Groups existing vf modules by the model uuid of our new vf module and returns the lowest unused index
-     * 
+     *
      * if we have a module type A, and there are 3 instances of those, and then module type B has 2 instances, if we are
      * adding a new module type A, the vf-module-index should be 3 assuming contiguous indices (not 5, or 2)
-     * 
+     *
      */
     protected int getLowestUnusedVfModuleIndexFromAAIVnfResponse(GenericVnf genericVnf, VfModule newVfModule) {