You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/06/20 09:20:11 UTC

[38/50] [abbrv] merge to master

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f41c800d/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 9005ee5,131d340..ef6968e
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@@ -39,7 -39,7 +39,6 @@@ import javax.naming.NamingException
  import javax.naming.directory.DirContext;
  import javax.naming.directory.InitialDirContext;
  
- import com.cloud.event.UsageEventUtils;
 -import com.cloud.utils.Pair;
  import org.apache.cloudstack.acl.SecurityChecker;
  import org.apache.cloudstack.api.ApiConstants.LDAPParams;
  import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
@@@ -126,7 -125,7 +126,6 @@@ import com.cloud.exception.ConcurrentOp
  import com.cloud.exception.InsufficientAddressCapacityException;
  import com.cloud.exception.InsufficientCapacityException;
  import com.cloud.exception.InvalidParameterValueException;
--import com.cloud.exception.MissingParameterValueException;
  import com.cloud.exception.PermissionDeniedException;
  import com.cloud.exception.ResourceAllocationException;
  import com.cloud.exception.ResourceUnavailableException;
@@@ -192,6 -193,6 +191,7 @@@ import com.cloud.user.User
  import com.cloud.user.UserContext;
  import com.cloud.user.dao.AccountDao;
  import com.cloud.utils.NumbersUtil;
++import com.cloud.utils.Pair;
  import com.cloud.utils.StringUtils;
  import com.cloud.utils.component.ManagerBase;
  import com.cloud.utils.crypt.DBEncryptionUtil;
@@@ -318,7 -319,7 +318,8 @@@ public class ConfigurationManagerImpl e
      DedicatedResourceDao _dedicatedDao;
  
      // FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
--    @Inject protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao;
++    @Inject
++    protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao;
  
      private int _maxVolumeSizeInGb = Integer.parseInt(Config.MaxVolumeSize.getDefaultValue());
      private long _defaultPageSize = Long.parseLong(Config.DefaultPageSize.getDefaultValue());
@@@ -328,11 -329,11 +329,11 @@@
      public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
          String maxVolumeSizeInGbString = _configDao.getValue(Config.MaxVolumeSize.key());
          _maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString,
--        	Integer.parseInt(Config.MaxVolumeSize.getDefaultValue()));
++                Integer.parseInt(Config.MaxVolumeSize.getDefaultValue()));
  
          String defaultPageSizeString = _configDao.getValue(Config.DefaultPageSize.key());
          _defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString,
--        	Long.parseLong(Config.DefaultPageSize.getDefaultValue()));
++                Long.parseLong(Config.DefaultPageSize.getDefaultValue()));
  
          populateConfigValuesForValidationSet();
          return true;
@@@ -374,13 -375,13 +375,22 @@@
          if (mgtCidr == null || mgtCidr.trim().isEmpty()) {
              String[] localCidrs = NetUtils.getLocalCidrs();
              if (localCidrs.length > 0) {
--                s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]);
++                s_logger.warn("Management network CIDR is not configured originally. Set it default to "
++                        + localCidrs[0]);
  
--                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], "");
--                _configDao.update(Config.ManagementNetwork.key(), Config.ManagementNetwork.getCategory(), localCidrs[0]);
++                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0),
++                        "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], "");
++                _configDao
++                        .update(Config.ManagementNetwork.key(), Config.ManagementNetwork.getCategory(), localCidrs[0]);
              } else {
                  s_logger.warn("Management network CIDR is not properly configured and we are not able to find a default setting");
--                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not properly configured and we are not able to find a default setting", "");
++                _alertMgr
++                        .sendAlert(
++                                AlertManager.ALERT_TYPE_MANAGMENT_NODE,
++                                0,
++                                new Long(0),
++                                "Management network CIDR is not properly configured and we are not able to find a default setting",
++                                "");
              }
          }
  
@@@ -394,7 -395,7 +404,8 @@@
  
      @Override
      @DB
--    public String updateConfiguration(long userId, String name, String category, String value, String scope, Long resourceId) {
++    public String updateConfiguration(long userId, String name, String category, String value, String scope,
++            Long resourceId) {
  
          String validationMsg = validateConfigurationValue(name, value, scope);
  
@@@ -403,62 -404,62 +414,74 @@@
              throw new InvalidParameterValueException(validationMsg);
          }
  
--        // If scope of the parameter is given then it needs to be updated in the corresponding details table,
--        // if scope is mentioned as global or not mentioned then it is normal global parameter updation
--        if (scope != null && !scope.isEmpty() && !Config.ConfigurationParameterScope.global.toString().equalsIgnoreCase(scope)) {
++        // If scope of the parameter is given then it needs to be updated in the
++        // corresponding details table,
++        // if scope is mentioned as global or not mentioned then it is normal
++        // global parameter updation
++        if (scope != null && !scope.isEmpty()
++                && !Config.ConfigurationParameterScope.global.toString().equalsIgnoreCase(scope)) {
              switch (Config.ConfigurationParameterScope.valueOf(scope)) {
--                case zone:      DataCenterVO zone = _zoneDao.findById(resourceId);
--                                if (zone == null) {
--                                    throw new InvalidParameterValueException("unable to find zone by id " + resourceId);
--                                }
--                                DcDetailVO dcDetailVO = _dcDetailsDao.findDetail(resourceId, name.toLowerCase());
--                                if (dcDetailVO == null) {
--                                    dcDetailVO = new DcDetailVO(resourceId, name, value);
--                                    _dcDetailsDao.persist(dcDetailVO);
--                                } else {
--                                    dcDetailVO.setValue(value);
--                                    _dcDetailsDao.update(dcDetailVO.getId(), dcDetailVO);
--                                } break;
--                case cluster:   ClusterVO cluster = _clusterDao.findById(resourceId);
--                                if (cluster == null) {
--                                    throw new InvalidParameterValueException("unable to find cluster by id " + resourceId);
--                                }
--                                ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(resourceId, name);
--                                if (clusterDetailsVO == null) {
--                                    clusterDetailsVO = new ClusterDetailsVO(resourceId, name, value);
--                                    _clusterDetailsDao.persist(clusterDetailsVO);
--                                } else {
--                                    clusterDetailsVO.setValue(value);
--                                    _clusterDetailsDao.update(clusterDetailsVO.getId(), clusterDetailsVO);
--                                } break;
--
--                case storagepool:      StoragePoolVO pool = _storagePoolDao.findById(resourceId);
--                                if (pool == null) {
--                                    throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId);
--                                }
--                                StoragePoolDetailVO storagePoolDetailVO = _storagePoolDetailsDao.findDetail(resourceId, name);
--                                if (storagePoolDetailVO == null) {
--                                    storagePoolDetailVO = new StoragePoolDetailVO(resourceId, name, value);
--                                    _storagePoolDetailsDao.persist(storagePoolDetailVO);
--
--                                } else {
--                                    storagePoolDetailVO.setValue(value);
--                                    _storagePoolDetailsDao.update(storagePoolDetailVO.getId(), storagePoolDetailVO);
--                                } break;
--
--                case account:   AccountVO account = _accountDao.findById(resourceId);
--                                if (account == null) {
--                                    throw new InvalidParameterValueException("unable to find account by id " + resourceId);
--                                }
--                                AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(resourceId, name);
--                                if (accountDetailVO == null) {
--                                    accountDetailVO = new AccountDetailVO(resourceId, name, value);
--                                    _accountDetailsDao.persist(accountDetailVO);
--                                } else {
--                                    accountDetailVO.setValue(value);
--                                    _accountDetailsDao.update(accountDetailVO.getId(), accountDetailVO);
--                                } break;
--                default:        throw new InvalidParameterValueException("Scope provided is invalid");
++            case zone:
++                DataCenterVO zone = _zoneDao.findById(resourceId);
++                if (zone == null) {
++                    throw new InvalidParameterValueException("unable to find zone by id " + resourceId);
++                }
++                DcDetailVO dcDetailVO = _dcDetailsDao.findDetail(resourceId, name.toLowerCase());
++                if (dcDetailVO == null) {
++                    dcDetailVO = new DcDetailVO(resourceId, name, value);
++                    _dcDetailsDao.persist(dcDetailVO);
++                } else {
++                    dcDetailVO.setValue(value);
++                    _dcDetailsDao.update(dcDetailVO.getId(), dcDetailVO);
++                }
++                break;
++            case cluster:
++                ClusterVO cluster = _clusterDao.findById(resourceId);
++                if (cluster == null) {
++                    throw new InvalidParameterValueException("unable to find cluster by id " + resourceId);
++                }
++                ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(resourceId, name);
++                if (clusterDetailsVO == null) {
++                    clusterDetailsVO = new ClusterDetailsVO(resourceId, name, value);
++                    _clusterDetailsDao.persist(clusterDetailsVO);
++                } else {
++                    clusterDetailsVO.setValue(value);
++                    _clusterDetailsDao.update(clusterDetailsVO.getId(), clusterDetailsVO);
++                }
++                break;
++
++            case storagepool:
++                StoragePoolVO pool = _storagePoolDao.findById(resourceId);
++                if (pool == null) {
++                    throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId);
++                }
++                StoragePoolDetailVO storagePoolDetailVO = _storagePoolDetailsDao.findDetail(resourceId, name);
++                if (storagePoolDetailVO == null) {
++                    storagePoolDetailVO = new StoragePoolDetailVO(resourceId, name, value);
++                    _storagePoolDetailsDao.persist(storagePoolDetailVO);
++
++                } else {
++                    storagePoolDetailVO.setValue(value);
++                    _storagePoolDetailsDao.update(storagePoolDetailVO.getId(), storagePoolDetailVO);
++                }
++                break;
++
++            case account:
++                AccountVO account = _accountDao.findById(resourceId);
++                if (account == null) {
++                    throw new InvalidParameterValueException("unable to find account by id " + resourceId);
++                }
++                AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(resourceId, name);
++                if (accountDetailVO == null) {
++                    accountDetailVO = new AccountDetailVO(resourceId, name, value);
++                    _accountDetailsDao.persist(accountDetailVO);
++                } else {
++                    accountDetailVO.setValue(value);
++                    _accountDetailsDao.update(accountDetailVO.getId(), accountDetailVO);
++                }
++                break;
++            default:
++                throw new InvalidParameterValueException("Scope provided is invalid");
              }
              return value;
          }
@@@ -482,7 -483,7 +505,8 @@@
  
                  pstmt.executeUpdate();
              } catch (Throwable e) {
--                throw new CloudRuntimeException("Failed to update guest.network.device in host_details due to exception ", e);
++                throw new CloudRuntimeException(
++                        "Failed to update guest.network.device in host_details due to exception ", e);
              }
          } else if (Config.XenPrivateNetwork.key().equalsIgnoreCase(name)) {
              String sql = "update host_details set value=? where name=?";
@@@ -493,7 -494,7 +517,8 @@@
  
                  pstmt.executeUpdate();
              } catch (Throwable e) {
--                throw new CloudRuntimeException("Failed to update private.network.device in host_details due to exception ", e);
++                throw new CloudRuntimeException(
++                        "Failed to update private.network.device in host_details due to exception ", e);
              }
          } else if (Config.XenPublicNetwork.key().equalsIgnoreCase(name)) {
              String sql = "update host_details set value=? where name=?";
@@@ -504,7 -505,7 +529,8 @@@
  
                  pstmt.executeUpdate();
              } catch (Throwable e) {
--                throw new CloudRuntimeException("Failed to update public.network.device in host_details due to exception ", e);
++                throw new CloudRuntimeException(
++                        "Failed to update public.network.device in host_details due to exception ", e);
              }
          } else if (Config.XenStorageNetwork1.key().equalsIgnoreCase(name)) {
              String sql = "update host_details set value=? where name=?";
@@@ -515,7 -516,7 +541,8 @@@
  
                  pstmt.executeUpdate();
              } catch (Throwable e) {
--                throw new CloudRuntimeException("Failed to update storage.network.device1 in host_details due to exception ", e);
++                throw new CloudRuntimeException(
++                        "Failed to update storage.network.device1 in host_details due to exception ", e);
              }
          } else if (Config.XenStorageNetwork2.key().equals(name)) {
              String sql = "update host_details set value=? where name=?";
@@@ -526,18 -527,18 +553,23 @@@
  
                  pstmt.executeUpdate();
              } catch (Throwable e) {
--                throw new CloudRuntimeException("Failed to update storage.network.device2 in host_details due to exception ", e);
++                throw new CloudRuntimeException(
++                        "Failed to update storage.network.device2 in host_details due to exception ", e);
              }
          } else if (Config.SystemVMUseLocalStorage.key().equalsIgnoreCase(name)) {
              if (s_logger.isDebugEnabled()) {
--                s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value + ", need to update System VM offerings");
++                s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value
++                        + ", need to update System VM offerings");
              }
              boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key()));
--            ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.consoleProxyDefaultOffUniqueName);
++            ServiceOfferingVO serviceOffering = _serviceOfferingDao
++                    .findByName(ServiceOffering.consoleProxyDefaultOffUniqueName);
              if (serviceOffering != null) {
                  serviceOffering.setUseLocalStorage(useLocalStorage);
                  if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
--                    throw new CloudRuntimeException("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage);
++                    throw new CloudRuntimeException(
++                            "Failed to update ConsoleProxy offering's use_local_storage option to value:"
++                                    + useLocalStorage);
                  }
              }
  
@@@ -545,7 -546,7 +577,9 @@@
              if (serviceOffering != null) {
                  serviceOffering.setUseLocalStorage(useLocalStorage);
                  if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
--                    throw new CloudRuntimeException("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage);
++                    throw new CloudRuntimeException(
++                            "Failed to update SoftwareRouter offering's use_local_storage option to value:"
++                                    + useLocalStorage);
                  }
              }
  
@@@ -553,7 -554,7 +587,9 @@@
              if (serviceOffering != null) {
                  serviceOffering.setUseLocalStorage(useLocalStorage);
                  if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
--                    throw new CloudRuntimeException("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage);
++                    throw new CloudRuntimeException(
++                            "Failed to update SecondaryStorage offering's use_local_storage option to value:"
++                                    + useLocalStorage);
                  }
              }
          }
@@@ -572,8 -573,8 +608,9 @@@
          Long clusterId = cmd.getClusterId();
          Long storagepoolId = cmd.getStoragepoolId();
          Long accountId = cmd.getAccountId();
--        UserContext.current().setEventDetails(" Name: " + name + " New Value: " + (((name.toLowerCase()).contains("password")) ? "*****" :
--                (((value == null) ? "" : value))));
++        UserContext.current().setEventDetails(
++                " Name: " + name + " New Value: "
++                        + (((name.toLowerCase()).contains("password")) ? "*****" : (((value == null) ? "" : value))));
          // check if config value exists
          ConfigurationVO config = _configDao.findByName(name);
          if (config == null) {
@@@ -614,7 -615,7 +651,8 @@@
          }
  
          if (paramCountCheck > 1) {
--            throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
++            throw new InvalidParameterValueException(
++                    "cannot handle multiple IDs, provide only one ID corresponding to the scope");
          }
  
          String updatedValue = updateConfiguration(userId, name, config.getCategory(), value, scope, id);
@@@ -638,7 -639,7 +676,8 @@@
                  s_logger.error("Invalid scope id provided for the parameter " + name);
                  return "Invalid scope id provided for the parameter " + name;
              }
--            if ((name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) && value == null) {
++            if ((name.equalsIgnoreCase("cpu.overprovisioning.factor") || name
++                    .equalsIgnoreCase("mem.overprovisioning.factor")) && value == null) {
                  s_logger.error("value cannot be null for cpu.overprovisioning.factor/mem.overprovisioning.factor");
                  return "value cannot be null for cpu.overprovisioning.factor/mem.overprovisioning.factor";
              }
@@@ -684,11 -685,11 +723,13 @@@
              try {
                  int val = Integer.parseInt(value);
                  if (val <= 0) {
--                    throw new InvalidParameterValueException("Please enter a positive value for the configuration parameter:" + name);
++                    throw new InvalidParameterValueException(
++                            "Please enter a positive value for the configuration parameter:" + name);
                  }
              } catch (NumberFormatException e) {
                  s_logger.error("There was an error trying to parse the integer value for:" + name);
--                throw new InvalidParameterValueException("There was an error trying to parse the integer value for:" + name);
++                throw new InvalidParameterValueException("There was an error trying to parse the integer value for:"
++                        + name);
              }
          }
  
@@@ -701,7 -702,7 +742,8 @@@
              if (range.equals("privateip")) {
                  try {
                      if (!NetUtils.isSiteLocalAddress(value)) {
--                        s_logger.error("privateip range " + value + " is not a site local address for configuration variable " + name);
++                        s_logger.error("privateip range " + value
++                                + " is not a site local address for configuration variable " + name);
                          return "Please enter a site local IP address.";
                      }
                  } catch (NullPointerException e) {
@@@ -719,7 -720,7 +761,8 @@@
                      return "Please enter hypervisor list, seperated by comma";
                  }
                  for (String hypervisor : hypervisors) {
--                    if (HypervisorType.getType(hypervisor) == HypervisorType.Any || HypervisorType.getType(hypervisor) == HypervisorType.None) {
++                    if (HypervisorType.getType(hypervisor) == HypervisorType.Any
++                            || HypervisorType.getType(hypervisor) == HypervisorType.None) {
                          return "Please enter valid hypervisor type";
                      }
                  }
@@@ -733,8 -734,8 +776,9 @@@
                      if (route != null) {
                          String routeToVerify = route.trim();
                          if (!NetUtils.isValidCIDR(routeToVerify)) {
--                            throw new InvalidParameterValueException("Invalid value for blacklisted route: " + route + ". Valid format is list" +
--                            		" of cidrs separated by coma. Example: 10.1.1.0/24,192.168.0.0/24");
++                            throw new InvalidParameterValueException("Invalid value for blacklisted route: " + route
++                                    + ". Valid format is list"
++                                    + " of cidrs separated by coma. Example: 10.1.1.0/24,192.168.0.0/24");
                          }
                      }
                  }
@@@ -814,8 -815,8 +858,10 @@@
              String errorMsg = table.get(2);
  
              String dbName;
--            if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance") || tableName.equals("usage_ip_address") || tableName.equals("usage_network")
--                    || tableName.equals("usage_job") || tableName.equals("account") || tableName.equals("user_statistics")) {
++            if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance")
++                    || tableName.equals("usage_ip_address") || tableName.equals("usage_network")
++                    || tableName.equals("usage_job") || tableName.equals("account")
++                    || tableName.equals("user_statistics")) {
                  dbName = "cloud_usage";
              } else {
                  dbName = "cloud";
@@@ -823,7 -824,7 +869,8 @@@
  
              String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?";
  
--            if (tableName.equals("host") || tableName.equals("cluster") || tableName.equals("volumes") || tableName.equals("vm_instance")) {
++            if (tableName.equals("host") || tableName.equals("cluster") || tableName.equals("volumes")
++                    || tableName.equals("vm_instance")) {
                  selectSql += " and removed IS NULL";
              }
  
@@@ -836,17 -837,17 +883,20 @@@
                      throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg);
                  }
              } catch (SQLException ex) {
--                throw new CloudRuntimeException("The Management Server failed to detect if pod is deletable. Please contact Cloud Support.");
++                throw new CloudRuntimeException(
++                        "The Management Server failed to detect if pod is deletable. Please contact Cloud Support.");
              }
          }
      }
  
--    private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr, boolean checkForDuplicates,
++    private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr,
++            String startIp, String endIp, String allocationStateStr, boolean checkForDuplicates,
              boolean skipGatewayOverlapCheck) {
          if (checkForDuplicates) {
              // Check if the pod already exists
              if (validPod(podName, zoneId)) {
--                throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone " + zoneId + ". Please specify a different pod name. ");
++                throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone "
++                        + zoneId + ". Please specify a different pod name. ");
              }
          }
  
@@@ -890,8 -891,8 +940,9 @@@
          if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) {
              checkPodCidrSubnets(zoneId, podId, cidr);
              /*
--             * Commenting out due to Bug 11593 - CIDR conflicts with zone when extending pod but not when creating it
--             *
++             * Commenting out due to Bug 11593 - CIDR conflicts with zone when
++             * extending pod but not when creating it
++             * 
               * checkCidrVlanOverlap(zoneId, cidr);
               */
          }
@@@ -900,7 -901,7 +951,8 @@@
              try {
                  Grouping.AllocationState.valueOf(allocationStateStr);
              } catch (IllegalArgumentException ex) {
--                throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state");
++                throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr
++                        + "' to a supported state");
              }
          }
      }
@@@ -924,7 -925,7 +976,8 @@@
          txn.start();
  
          // Delete private ip addresses for the pod if there are any
--        List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId), pod.getDataCenterId());
++        List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId),
++                pod.getDataCenterId());
          if (!privateIps.isEmpty()) {
              if (!(_privateIpAddressDao.deleteIpAddressByPod(podId))) {
                  throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
@@@ -932,7 -933,7 +985,8 @@@
          }
  
          // Delete link local ip addresses for the pod
--        List<DataCenterLinkLocalIpAddressVO> localIps = _LinkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId());
++        List<DataCenterLinkLocalIpAddressVO> localIps = _LinkLocalIpAllocDao.listByPodIdDcId(podId,
++                pod.getDataCenterId());
          if (!localIps.isEmpty()) {
              if (!(_LinkLocalIpAllocDao.deleteIpAddressByPod(podId))) {
                  throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
@@@ -967,12 -968,12 +1021,14 @@@
  
      @Override
      public Pod editPod(UpdatePodCmd cmd) {
--        return editPod(cmd.getId(), cmd.getPodName(), cmd.getStartIp(), cmd.getEndIp(), cmd.getGateway(), cmd.getNetmask(), cmd.getAllocationState());
++        return editPod(cmd.getId(), cmd.getPodName(), cmd.getStartIp(), cmd.getEndIp(), cmd.getGateway(),
++                cmd.getNetmask(), cmd.getAllocationState());
      }
  
      @Override
      @DB
--    public Pod editPod(long id, String name, String startIp, String endIp, String gateway, String netmask, String allocationStateStr) {
++    public Pod editPod(long id, String name, String startIp, String endIp, String gateway, String netmask,
++            String allocationStateStr) {
  
          // verify parameters
          HostPodVO pod = _podDao.findById(id);
@@@ -995,13 -996,13 +1051,15 @@@
                  long oldCidr = pod.getCidrSize();
  
                  if (newCidr > oldCidr) {
--                    throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
++                    throw new CloudRuntimeException(
++                            "The specified pod has allocated private IP addresses, so its IP address range can be extended only");
                  }
              }
  
              if (startIp != null && !startIp.equals(existingPodIpRange[0])) {
                  if (NetUtils.ipRangesOverlap(startIp, null, existingPodIpRange[0], existingPodIpRange[1])) {
--                    throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
++                    throw new CloudRuntimeException(
++                            "The specified pod has allocated private IP addresses, so its IP address range can be extended only");
                  } else {
                      leftRangeToAdd = new String[2];
                      long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1;
@@@ -1012,7 -1013,7 +1070,8 @@@
  
              if (endIp != null && !endIp.equals(existingPodIpRange[1])) {
                  if (NetUtils.ipRangesOverlap(endIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) {
--                    throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only");
++                    throw new CloudRuntimeException(
++                            "The specified pod has allocated private IP addresses, so its IP address range can be extended only");
                  } else {
                      rightRangeToAdd = new String[2];
                      long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1;
@@@ -1057,7 -1058,7 +1116,8 @@@
          // Verify pod's attributes
          String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
          boolean checkForDuplicates = !oldPodName.equals(name);
--        checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates, false);
++        checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr,
++                checkForDuplicates, false);
  
          Transaction txn = Transaction.currentTxn();
          try {
@@@ -1116,7 -1117,7 +1176,8 @@@
      }
  
      @Override
--    public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState) {
++    public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask,
++            String allocationState) {
          String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
          Long userId = UserContext.current().getCallerUserId();
  
@@@ -1128,7 -1129,7 +1189,8 @@@
  
      @Override
      @DB
--    public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr, boolean skipGatewayOverlapCheck) {
++    public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp,
++            String endIp, String allocationStateStr, boolean skipGatewayOverlapCheck) {
  
          // Check if the zone is valid
          if (!validZone(zoneId)) {
@@@ -1138,7 -1139,7 +1200,8 @@@
          // Check if zone is disabled
          DataCenterVO zone = _zoneDao.findById(zoneId);
          Account account = UserContext.current().getCaller();
--        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
++        if (Grouping.AllocationState.Disabled == zone.getAllocationState()
++                && !_accountMgr.isRootAdmin(account.getType())) {
              throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
          }
  
@@@ -1154,7 -1155,7 +1217,8 @@@
          }
  
          // Validate new pod settings
--        checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true, skipGatewayOverlapCheck);
++        checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true,
++                skipGatewayOverlapCheck);
  
          // Create the new pod in the database
          String ipRange;
@@@ -1258,7 -1259,7 +1322,8 @@@
                  selectSql += " AND taken IS NOT NULL";
              }
  
--            if (tableName.equals("host_pod_ref") || tableName.equals("host") || tableName.equals("volumes") || tableName.equals("physical_network")) {
++            if (tableName.equals("host_pod_ref") || tableName.equals("host") || tableName.equals("volumes")
++                    || tableName.equals("physical_network")) {
                  selectSql += " AND removed is NULL";
              }
  
@@@ -1275,18 -1276,18 +1340,21 @@@
                      throw new CloudRuntimeException("The zone is not deletable because " + errorMsg);
                  }
              } catch (SQLException ex) {
--                throw new CloudRuntimeException("The Management Server failed to detect if zone is deletable. Please contact Cloud Support.");
++                throw new CloudRuntimeException(
++                        "The Management Server failed to detect if zone is deletable. Please contact Cloud Support.");
              }
          }
  
      }
  
--    private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr,
--    								 String ip6Dns1, String ip6Dns2) {
++    private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1,
++            String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr, String ip6Dns1,
++            String ip6Dns2) {
          if (checkForDuplicates) {
              // Check if a zone with the specified name already exists
              if (validZone(zoneName)) {
--                throw new InvalidParameterValueException("A zone with that name already exists. Please specify a unique zone name.");
++                throw new InvalidParameterValueException(
++                        "A zone with that name already exists. Please specify a unique zone name.");
              }
          }
  
@@@ -1329,7 -1330,7 +1397,8 @@@
              try {
                  Grouping.AllocationState.valueOf(allocationStateStr);
              } catch (IllegalArgumentException ex) {
--                throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state");
++                throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr
++                        + "' to a supported state");
              }
          }
      }
@@@ -1347,12 -1348,12 +1416,15 @@@
              throw new InvalidParameterValueException("The start address of the IP range is not in the CIDR subnet.");
          }
  
--        if (endIp != null && !NetUtils.getCidrSubNet(endIp, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) {
++        if (endIp != null
++                && !NetUtils.getCidrSubNet(endIp, cidrSize).equalsIgnoreCase(
++                        NetUtils.getCidrSubNet(cidrAddress, cidrSize))) {
              throw new InvalidParameterValueException("The end address of the IP range is not in the CIDR subnet.");
          }
  
          if (endIp != null && NetUtils.ip2Long(startIp) > NetUtils.ip2Long(endIp)) {
--            throw new InvalidParameterValueException("The start IP address must have a lower value than the end IP address.");
++            throw new InvalidParameterValueException(
++                    "The start IP address must have a lower value than the end IP address.");
          }
  
      }
@@@ -1365,7 -1366,7 +1437,9 @@@
          for (IPAddressVO publicIPVO : existingPublicIPs) {
              long publicIP = NetUtils.ip2Long(publicIPVO.getAddress().addr());
              if ((publicIP >= privateStartIp) && (publicIP <= privateEndIp)) {
--                throw new InvalidParameterValueException("The Start IP and endIP address range overlap with Public IP :" + publicIPVO.getAddress().addr());
++                throw new InvalidParameterValueException(
++                        "The Start IP and endIP address range overlap with Public IP :"
++                                + publicIPVO.getAddress().addr());
              }
          }
      }
@@@ -1380,7 -1381,7 +1454,9 @@@
              if (!NetUtils.isValidIp(IpRange[0]) || !NetUtils.isValidIp(IpRange[1]))
                  continue;
              if (NetUtils.ipRangesOverlap(startIp, endIp, IpRange[0], IpRange[1])) {
--                throw new InvalidParameterValueException("The Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + IpRange[1]);
++                throw new InvalidParameterValueException(
++                        "The Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":"
++                                + IpRange[1]);
              }
          }
      }
@@@ -1448,7 -1449,7 +1524,6 @@@
          return true;
      }
  
--
      @Override
      @DB
      public LDAPConfigCmd listLDAPConfig(LDAPConfigCmd cmd) {
@@@ -1458,13 -1459,13 +1533,13 @@@
          cmd.setPort(port == null ? 0 : Integer.valueOf(port));
          String queryFilter = _configDao.getValue(LDAPParams.queryfilter.toString());
          cmd.setQueryFilter(queryFilter == null ? "" : queryFilter);
--        String searchBase =  _configDao.getValue(LDAPParams.searchbase.toString());
++        String searchBase = _configDao.getValue(LDAPParams.searchbase.toString());
          cmd.setSearchBase(searchBase == null ? "" : searchBase);
--        String useSSL =  _configDao.getValue(LDAPParams.usessl.toString());
++        String useSSL = _configDao.getValue(LDAPParams.usessl.toString());
          cmd.setUseSSL(useSSL == null ? Boolean.FALSE : Boolean.valueOf(useSSL));
--        String binddn =  _configDao.getValue(LDAPParams.dn.toString());
++        String binddn = _configDao.getValue(LDAPParams.dn.toString());
          cmd.setBindDN(binddn == null ? "" : binddn);
--        String truststore =  _configDao.getValue(LDAPParams.truststore.toString());
++        String truststore = _configDao.getValue(LDAPParams.truststore.toString());
          cmd.setTrustStore(truststore == null ? "" : truststore);
          return cmd;
      }
@@@ -1473,7 -1474,7 +1548,8 @@@
      @DB
      public boolean updateLDAP(LDAPConfigCmd cmd) {
          try {
--            // set the ldap details in the zone details table with a zone id of -12
++            // set the ldap details in the zone details table with a zone id of
++            // -12
              String hostname = cmd.getHostname();
              Integer port = cmd.getPort();
              String queryFilter = cmd.getQueryFilter();
@@@ -1485,12 -1486,12 +1561,14 @@@
              String trustStorePassword = cmd.getTrustStorePassword();
  
              if (bindDN != null && bindPasswd == null) {
--                throw new InvalidParameterValueException("If you specify a bind name then you need to provide bind password too.");
++                throw new InvalidParameterValueException(
++                        "If you specify a bind name then you need to provide bind password too.");
              }
  
              // check query filter if it contains valid substitution
--            if (!queryFilter.contains("%u") && !queryFilter.contains("%n") && !queryFilter.contains("%e")){
--                throw new InvalidParameterValueException("QueryFilter should contain at least one of the substitutions: %u, %n or %e: " + queryFilter);
++            if (!queryFilter.contains("%u") && !queryFilter.contains("%n") && !queryFilter.contains("%e")) {
++                throw new InvalidParameterValueException(
++                        "QueryFilter should contain at least one of the substitutions: %u, %n or %e: " + queryFilter);
              }
  
              // check if the info is correct
@@@ -1501,7 -1502,7 +1579,8 @@@
                  env.put(Context.SECURITY_PROTOCOL, "ssl");
                  protocol = "ldaps://";
                  if (trustStore == null || trustStorePassword == null) {
--                    throw new InvalidParameterValueException("If you plan to use SSL then you need to configure the trust store.");
++                    throw new InvalidParameterValueException(
++                            "If you plan to use SSL then you need to configure the trust store.");
                  }
                  System.setProperty("javax.net.ssl.trustStore", trustStore);
                  System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
@@@ -1519,21 -1520,21 +1598,24 @@@
              // store the result in DB Configuration
              ConfigurationVO cvo = _configDao.findByName(LDAPParams.hostname.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.hostname.toString(), null, "Hostname or ip address of the ldap server eg: my.ldap.com");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.hostname.toString(),
++                        null, "Hostname or ip address of the ldap server eg: my.ldap.com");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(hostname));
              _configDao.persist(cvo);
  
              cvo = _configDao.findByName(LDAPParams.port.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.port.toString(), null, "Specify the LDAP port if required, default is 389");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.port.toString(), null,
++                        "Specify the LDAP port if required, default is 389");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(port.toString()));
              _configDao.persist(cvo);
  
              cvo = _configDao.findByName(LDAPParams.queryfilter.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.queryfilter.toString(), null,
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.queryfilter.toString(),
++                        null,
                          "You specify a query filter here, which narrows down the users, who can be part of this domain");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(queryFilter));
@@@ -1541,7 -1542,7 +1623,8 @@@
  
              cvo = _configDao.findByName(LDAPParams.searchbase.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.searchbase.toString(), null,
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.searchbase.toString(),
++                        null,
                          "The search base defines the starting point for the search in the directory tree Example:  dc=cloud,dc=com.");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(searchBase));
@@@ -1549,42 -1550,42 +1632,48 @@@
  
              cvo = _configDao.findByName(LDAPParams.usessl.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.usessl.toString(), null, "Check Use SSL if the external LDAP server is configured for LDAP over SSL.");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.usessl.toString(), null,
++                        "Check Use SSL if the external LDAP server is configured for LDAP over SSL.");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(useSSL.toString()));
              _configDao.persist(cvo);
  
              cvo = _configDao.findByName(LDAPParams.dn.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.dn.toString(), null, "Specify the distinguished name of a user with the search permission on the directory");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.dn.toString(), null,
++                        "Specify the distinguished name of a user with the search permission on the directory");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(bindDN));
              _configDao.persist(cvo);
  
              cvo = _configDao.findByName(LDAPParams.passwd.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.passwd.toString(), null, "Enter the password");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.passwd.toString(), null,
++                        "Enter the password");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(bindPasswd));
              _configDao.persist(cvo);
  
              cvo = _configDao.findByName(LDAPParams.truststore.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.truststore.toString(), null, "Enter the path to trusted keystore");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.truststore.toString(),
++                        null, "Enter the path to trusted keystore");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(trustStore));
              _configDao.persist(cvo);
  
              cvo = _configDao.findByName(LDAPParams.truststorepass.toString());
              if (cvo == null) {
--                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server", LDAPParams.truststorepass.toString(), null, "Enter the password for trusted keystore");
++                cvo = new ConfigurationVO("Hidden", "DEFAULT", "management-server",
++                        LDAPParams.truststorepass.toString(), null, "Enter the password for trusted keystore");
              }
              cvo.setValue(DBEncryptionUtil.encrypt(trustStorePassword));
              _configDao.persist(cvo);
  
              s_logger.debug("The ldap server is configured: " + hostname);
          } catch (NamingException ne) {
--            throw new InvalidParameterValueException("Naming Exception, check you ldap data ! " + ne.getMessage() + (ne.getCause() != null ? ("; Caused by:" + ne.getCause().getMessage()) : ""));
++            throw new InvalidParameterValueException("Naming Exception, check you ldap data ! " + ne.getMessage()
++                    + (ne.getCause() != null ? ("; Caused by:" + ne.getCause().getMessage()) : ""));
          }
          return true;
      }
@@@ -1690,7 -1691,7 +1779,7 @@@
          }
  
          if (internalDns2 == null) {
--        	internalDns2 = zone.getInternalDns2();
++            internalDns2 = zone.getInternalDns2();
          }
  
          if (guestCidr == null) {
@@@ -1707,7 -1708,7 +1796,10 @@@
          }
  
          boolean checkForDuplicates = !zoneName.equals(oldZoneName);
--        checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr, ip6Dns1, ip6Dns2);// not allowing updating domain associated with a zone, once created
++        checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null,
++                allocationStateStr, ip6Dns1, ip6Dns2);// not allowing updating
++                                                      // domain associated with
++                                                      // a zone, once created
  
          zone.setName(zoneName);
          zone.setDns1(dns1);
@@@ -1753,20 -1754,20 +1845,27 @@@
                  // check if zone has necessary trafficTypes before enabling
                  try {
                      PhysicalNetwork mgmtPhyNetwork;
-                         // zone should have a physical network with management traffiType
-                         mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
-                     if (NetworkType.Advanced == zone.getNetworkType() && ! zone.isSecurityGroupEnabled() ) {
-                         // advanced zone without SG should have a physical network with public Thpe
 -                    // zone should have a physical network with management traffiType
 -                    mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
 -                    if (NetworkType.Advanced == zone.getNetworkType() && ! zone.isSecurityGroupEnabled() ) {
 -                        // advanced zone without SG should have a physical network with public Thpe
++                    // zone should have a physical network with management
++                    // traffiType
++                    mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,
++                            TrafficType.Management);
++                    if (NetworkType.Advanced == zone.getNetworkType() && !zone.isSecurityGroupEnabled()) {
++                        // advanced zone without SG should have a physical
++                        // network with public Thpe
                          _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public);
                      }
  
                      try {
                          _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage);
                      } catch (InvalidParameterValueException noStorage) {
--                        PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management);
--                        _networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), mgmtTraffic.getKvmNetworkLabel(),
--                                mgmtTraffic.getVmwareNetworkLabel(), mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan());
--                        s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network " + mgmtPhyNetwork.getId() + " with same configure of management traffic type");
++                        PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(),
++                                TrafficType.Management);
++                        _networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(),
++                                TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(),
++                                mgmtTraffic.getKvmNetworkLabel(), mgmtTraffic.getVmwareNetworkLabel(),
++                                mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan());
++                        s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network "
++                                + mgmtPhyNetwork.getId() + " with same configure of management traffic type");
                      }
                  } catch (InvalidParameterValueException ex) {
                      throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage());
@@@ -1790,8 -1791,8 +1889,10 @@@
  
      @Override
      @DB
--    public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain, Long domainId,
--            NetworkType zoneType, String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2) {
++    public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1,
++            String internalDns2, String guestCidr, String domain, Long domainId, NetworkType zoneType,
++            String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled,
++            boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2) {
  
          // checking the following params outside checkzoneparams method as we do
          // not use these params for updatezone
@@@ -1809,7 -1810,7 +1910,8 @@@
              }
          }
  
--        checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, ip6Dns1, ip6Dns2);
++        checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr,
++                ip6Dns1, ip6Dns2);
  
          byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes();
          String zoneToken = UUID.nameUUIDFromBytes(bytes).toString();
@@@ -1817,18 -1818,18 +1919,22 @@@
          try {
              txn.start();
              // Create the new zone in the database
--            DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, null, null, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2);
++            DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr,
++                    null, null, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled,
++                    ip6Dns1, ip6Dns2);
              if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
                  Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
                  zone.setAllocationState(allocationState);
              } else {
--                // Zone will be disabled since 3.0. Admin should enable it after physical network and providers setup.
++                // Zone will be disabled since 3.0. Admin should enable it after
++                // physical network and providers setup.
                  zone.setAllocationState(Grouping.AllocationState.Disabled);
              }
              zone = _zoneDao.persist(zone);
              if (domainId != null) {
--                //zone is explicitly dedicated to this domain
--                DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null);
++                // zone is explicitly dedicated to this domain
++                DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null,
++                        domainId, null);
                  _dedicatedDao.persist(dedicatedResource);
              }
  
@@@ -1869,7 -1870,7 +1975,8 @@@
                  } else if (offering.getTrafficType() == TrafficType.Control) {
                      broadcastDomainType = BroadcastDomainType.LinkLocal;
                  } else if (offering.getTrafficType() == TrafficType.Public) {
--                    if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) {
++                    if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled())
++                            || zone.getNetworkType() == NetworkType.Basic) {
                          broadcastDomainType = BroadcastDomainType.Vlan;
                      } else {
                          continue;
@@@ -1911,7 -1912,7 +2018,8 @@@
              allocationState = Grouping.AllocationState.Disabled.toString();
          }
  
--        if (!(type.equalsIgnoreCase(NetworkType.Basic.toString())) && !(type.equalsIgnoreCase(NetworkType.Advanced.toString()))) {
++        if (!(type.equalsIgnoreCase(NetworkType.Basic.toString()))
++                && !(type.equalsIgnoreCase(NetworkType.Advanced.toString()))) {
              throw new InvalidParameterValueException("Invalid zone type; only Advanced and Basic values are supported");
          } else if (type.equalsIgnoreCase(NetworkType.Basic.toString())) {
              isBasic = true;
@@@ -1938,7 -1939,7 +2046,8 @@@
              isSecurityGroupEnabled = true;
          }
  
--        return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType, allocationState, networkDomain,
++        return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, guestCidr,
++                domainVO != null ? domainVO.getName() : null, domainId, zoneType, allocationState, networkDomain,
                  isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2);
      }
  
@@@ -1948,27 -1949,27 +2057,32 @@@
  
          String name = cmd.getServiceOfferingName();
          if ((name == null) || (name.length() == 0)) {
--            throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
++            throw new InvalidParameterValueException(
++                    "Failed to create service offering: specify the name that has non-zero length");
          }
  
          String displayText = cmd.getDisplayText();
          if ((displayText == null) || (displayText.length() == 0)) {
--            throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length");
++            throw new InvalidParameterValueException("Failed to create service offering " + name
++                    + ": specify the display text that has non-zero length");
          }
  
          Long cpuNumber = cmd.getCpuNumber();
          if ((cpuNumber == null) || (cpuNumber.intValue() <= 0) || (cpuNumber.intValue() > 2147483647)) {
--            throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the cpu number value between 1 and 2147483647");
++            throw new InvalidParameterValueException("Failed to create service offering " + name
++                    + ": specify the cpu number value between 1 and 2147483647");
          }
  
          Long cpuSpeed = cmd.getCpuSpeed();
          if ((cpuSpeed == null) || (cpuSpeed.intValue() <= 0) || (cpuSpeed.intValue() > 2147483647)) {
--            throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the cpu speed value between 1 and 2147483647");
++            throw new InvalidParameterValueException("Failed to create service offering " + name
++                    + ": specify the cpu speed value between 1 and 2147483647");
          }
  
          Long memory = cmd.getMemory();
          if ((memory == null) || (memory.intValue() < 32) || (memory.intValue() > 2147483647)) {
--            throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the memory value between 32 and 2147483647 MB");
++            throw new InvalidParameterValueException("Failed to create service offering " + name
++                    + ": specify the memory value between 32 and 2147483647 MB");
          }
  
          // check if valid domain
@@@ -1982,7 -1983,7 +2096,8 @@@
              if (storageType.equalsIgnoreCase(ServiceOffering.StorageType.local.toString())) {
                  localStorageRequired = true;
              } else if (!storageType.equalsIgnoreCase(ServiceOffering.StorageType.shared.toString())) {
--                throw new InvalidParameterValueException("Invalid storage type " + storageType + " specified, valid types are: 'local' and 'shared'");
++                throw new InvalidParameterValueException("Invalid storage type " + storageType
++                        + " specified, valid types are: 'local' and 'shared'");
              }
          }
  
@@@ -2004,7 -2005,7 +2119,8 @@@
              } else if (VirtualMachine.Type.InternalLoadBalancerVm.toString().toLowerCase().equals(vmTypeString)) {
                  vmType = VirtualMachine.Type.InternalLoadBalancerVm;
              } else {
--                throw new InvalidParameterValueException("Invalid systemVmType. Supported types are: " + VirtualMachine.Type.DomainRouter + ", " + VirtualMachine.Type.ConsoleProxy + ", "
++                throw new InvalidParameterValueException("Invalid systemVmType. Supported types are: "
++                        + VirtualMachine.Type.DomainRouter + ", " + VirtualMachine.Type.ConsoleProxy + ", "
                          + VirtualMachine.Type.SecondaryStorageVm);
              }
          } else {
@@@ -2013,7 -2014,7 +2129,8 @@@
          }
  
          if (cmd.getNetworkRate() != null && !allowNetworkRate) {
--            throw new InvalidParameterValueException("Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype");
++            throw new InvalidParameterValueException(
++                    "Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype");
          }
  
          if (cmd.getDeploymentPlanner() != null) {
@@@ -2038,10 -2039,10 +2155,11 @@@
      @ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering")
      public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_type,
              String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired,
--            boolean offerHA, boolean limitResourceUse, boolean volatileVm,  String tags, Long domainId, String hostTag,
++            boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag,
              Integer networkRate, String deploymentPlanner, Map<String, String> details) {
          tags = cleanupTags(tags);
--        ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type,
++        ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA,
++                limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type,
                  domainId, hostTag, deploymentPlanner);
  
          if ((offering = _serviceOfferingDao.persist(offering)) != null) {
@@@ -2129,7 -2130,7 +2247,8 @@@
  
      @Override
      @ActionEvent(eventType = EventTypes.EVENT_DISK_OFFERING_CREATE, eventDescription = "creating disk offering")
--    public DiskOfferingVO createDiskOffering(Long domainId, String name, String description, Long numGibibytes, String tags, boolean isCustomized, boolean localStorageRequired, boolean isDisplayOfferingEnabled) {
++    public DiskOfferingVO createDiskOffering(Long domainId, String name, String description, Long numGibibytes,
++            String tags, boolean isCustomized, boolean localStorageRequired, boolean isDisplayOfferingEnabled) {
          long diskSize = 0;// special case for custom disk offerings
          if (numGibibytes != null && (numGibibytes <= 0)) {
              throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb.");
@@@ -2185,11 -2186,11 +2304,13 @@@
              if (storageType.equalsIgnoreCase(ServiceOffering.StorageType.local.toString())) {
                  localStorageRequired = true;
              } else if (!storageType.equalsIgnoreCase(ServiceOffering.StorageType.shared.toString())) {
--                throw new InvalidParameterValueException("Invalid storage type " + storageType + " specified, valid types are: 'local' and 'shared'");
++                throw new InvalidParameterValueException("Invalid storage type " + storageType
++                        + " specified, valid types are: 'local' and 'shared'");
              }
          }
  
--        return createDiskOffering(domainId, name, description, numGibibytes, tags, isCustomized, localStorageRequired, isDisplayOfferingEnabled);
++        return createDiskOffering(domainId, name, description, numGibibytes, tags, isCustomized, localStorageRequired,
++                isDisplayOfferingEnabled);
      }
  
      @Override
@@@ -2309,8 -2310,8 +2430,10 @@@
  
      @Override
      @DB
--    @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_CREATE, eventDescription = "creating vlan ip range", async = false)
--    public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException {
++    @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_CREATE, eventDescription = "creating vlan ip range",
++            async = false)
++    public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException,
++            ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException {
          Long zoneId = cmd.getZoneId();
          Long podId = cmd.getPodId();
          String startIP = cmd.getStartIp();
@@@ -2385,7 -2386,7 +2508,7 @@@
                  physicalNetworkId = network.getPhysicalNetworkId();
              }
          } else if (ipv6) {
--        	throw new InvalidParameterValueException("Only support IPv6 on extending existed network");
++            throw new InvalidParameterValueException("Only support IPv6 on extending existed network");
          }
  
          // Verify that zone exists
@@@ -2395,9 -2396,9 +2518,10 @@@
          }
  
          if (ipv6) {
--        	if (network.getGuestType() != GuestType.Shared || zone.isSecurityGroupEnabled()) {
--        		throw new InvalidParameterValueException("Only support IPv6 on extending existed share network without SG");
--        	}
++            if (network.getGuestType() != GuestType.Shared || zone.isSecurityGroupEnabled()) {
++                throw new InvalidParameterValueException(
++                        "Only support IPv6 on extending existed share network without SG");
++            }
          }
          // verify that physical network exists
          PhysicalNetworkVO pNtwk = null;
@@@ -2419,34 -2420,34 +2543,41 @@@
              } else {
                  if (forVirtualNetwork) {
                      // default physical network with public traffic in the zone
--                    physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId();
++                    physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,
++                            TrafficType.Public).getId();
                  } else {
                      if (zone.getNetworkType() == DataCenter.NetworkType.Basic) {
--                        // default physical network with guest traffic in the zone
--                        physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
++                        // default physical network with guest traffic in the
++                        // zone
++                        physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,
++                                TrafficType.Guest).getId();
                      } else if (zone.getNetworkType() == DataCenter.NetworkType.Advanced) {
                          if (zone.isSecurityGroupEnabled()) {
--                            physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
++                            physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,
++                                    TrafficType.Guest).getId();
                          } else {
--                            throw new InvalidParameterValueException("Physical Network Id is null, please provide the Network id for Direct vlan creation ");
++                            throw new InvalidParameterValueException(
++                                    "Physical Network Id is null, please provide the Network id for Direct vlan creation ");
                          }
                      }
                  }
              }
          }
  
--
          // Check if zone is enabled
          Account caller = UserContext.current().getCaller();
--        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
++        if (Grouping.AllocationState.Disabled == zone.getAllocationState()
++                && !_accountMgr.isRootAdmin(caller.getType())) {
              throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
          }
  
          if (zone.isSecurityGroupEnabled() && zone.getNetworkType() != DataCenter.NetworkType.Basic && forVirtualNetwork) {
--            throw new InvalidParameterValueException("Can't add virtual ip range into a zone with security group enabled");
++            throw new InvalidParameterValueException(
++                    "Can't add virtual ip range into a zone with security group enabled");
          }
  
--        // If networkId is not specified, and vlan is Virtual or Direct Untagged, try to locate default networks
++        // If networkId is not specified, and vlan is Virtual or Direct
++        // Untagged, try to locate default networks
          if (forVirtualNetwork) {
              if (network == null) {
                  // find default public network in the zone
@@@ -2469,47 -2470,47 +2600,51 @@@
                      zoneId = network.getDataCenterId();
                  }
              } else if (network.getGuestType() == null || network.getGuestType() == Network.GuestType.Isolated) {
--                throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId + " with type: " + network.getGuestType());
++                throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId
++                        + " with type: " + network.getGuestType());
              }
          }
  
-         boolean sameSubnet=false;
 -        Pair<Boolean,Pair<String,String>> sameSubnet= null;
++        Pair<Boolean, Pair<String, String>> sameSubnet = null;
          // Can add vlan range only to the network which allows it
          if (!network.getSpecifyIpRanges()) {
              throw new InvalidParameterValueException("Network " + network + " doesn't support adding ip ranges");
          }
  
--        if ( zone.getNetworkType() == DataCenter.NetworkType.Advanced ) {
++        if (zone.getNetworkType() == DataCenter.NetworkType.Advanced) {
              if (network.getTrafficType() == TrafficType.Guest) {
                  if (network.getGuestType() != GuestType.Shared) {
--                    throw new InvalidParameterValueException("Can execute createVLANIpRanges on shared guest network, but type of this guest network "
--                            + network.getId() + " is " + network.getGuestType());
++                    throw new InvalidParameterValueException(
++                            "Can execute createVLANIpRanges on shared guest network, but type of this guest network "
++                                    + network.getId() + " is " + network.getGuestType());
                  }
  
                  List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
                  VlanVO vlan = vlans.get(0);
--                if ( vlans != null && vlans.size() > 0 ) {
--                    if ( vlanId == null ) {
++                if (vlans != null && vlans.size() > 0) {
++                    if (vlanId == null) {
                          vlanId = vlan.getVlanTag();
                      } else if (!vlan.getVlanTag().equals(vlanId)) {
--                        throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" +
--                                + network.getId() + ", only one vlan is allowed on guest network");
++                        throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag()
++                                + " on network :" + +network.getId() + ", only one vlan is allowed on guest network");
                      }
                  }
--               sameSubnet=validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr,startIPv6, endIPv6, network);
++                sameSubnet = validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6,
++                        ip6Gateway, ip6Cidr, startIPv6, endIPv6, network);
  
              }
  
          } else if (network.getTrafficType() == TrafficType.Management) {
--                      throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
--        }
--        else if (zone.getNetworkType() == NetworkType.Basic){
--                 List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
--                 sameSubnet=validateIpRange(startIP,endIP,newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr, startIPv6, endIPv6, network);
++            throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
++        } else if (zone.getNetworkType() == NetworkType.Basic) {
++            List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
++            sameSubnet = validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway,
++                    ip6Cidr, startIPv6, endIPv6, network);
          }
  
-         if (zoneId == null || (ipv4 && (newVlanGateway == null || newVlanNetmask == null)) || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
-             throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
 -        if (zoneId == null  || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
 -            throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
++        if (zoneId == null || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
++            throw new InvalidParameterValueException(
++                    "Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
          }
  
          if (forVirtualNetwork) {
@@@ -2517,109 -2518,147 +2652,157 @@@
  
                  long accountIpRange = NetUtils.ip2Long(endIP) - NetUtils.ip2Long(startIP) + 1;
  
--                //check resource limits
++                // check resource limits
                  _resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountIpRange);
              }
          }
          // Check if the IP range overlaps with the private ip
          if (ipv4) {
--        	checkOverlapPrivateIpRange(zoneId, startIP, endIP);
++            checkOverlapPrivateIpRange(zoneId, startIP, endIP);
          }
          Transaction txn = Transaction.currentTxn();
          txn.start();
 +
+         if (sameSubnet == null || sameSubnet.first() == false) {
 -            s_logger.info("adding a new subnet to the network "+network.getId());
 -        }
 -        else {
 -            // if it is same subnet the user might not send the vlan and the netmask details. so we are
 -            //figuring out while validation and setting them here.
++            s_logger.info("adding a new subnet to the network " + network.getId());
++        } else {
++            // if it is same subnet the user might not send the vlan and the
++            // netmask details. so we are
++            // figuring out while validation and setting them here.
+             newVlanGateway = sameSubnet.second().first();
+             newVlanNetmask = sameSubnet.second().second();
+         }
 -        Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, 
 +        Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP,
                  endIP, newVlanGateway, newVlanNetmask, vlanId, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
--        //create an entry in the nic_secondary table. This will be the new gateway that will be configured on the corresponding routervm.
-         if (sameSubnet == false) {
-            s_logger.info("adding a new subnet to the network "+network.getId());
-         }
 -
++        // create an entry in the nic_secondary table. This will be the new
++        // gateway that will be configured on the corresponding routervm.
  
          txn.commit();
  
          return vlan;
      }
  
-     public boolean validateIpRange(String startIP, String endIP, String newVlanGateway, String newVlanNetmask, List<VlanVO> vlans, boolean ipv4, boolean ipv6, String ip6Gateway, String ip6Cidr, String startIPv6, String endIPv6, Network network) {
-         String vlanGateway;
-         String vlanNetmask;
-         boolean sameSubnet = false;
-         if ( vlans != null && vlans.size() > 0 ) {
 -    public int checkIfSubsetOrSuperset(String newVlanGateway, String newVlanNetmask, VlanVO vlan, String startIP, String endIP) {
 -        if (newVlanGateway == null && newVlanNetmask==null) {
++    public int checkIfSubsetOrSuperset(String newVlanGateway, String newVlanNetmask, VlanVO vlan, String startIP,
++            String endIP) {
++        if (newVlanGateway == null && newVlanNetmask == null) {
+             newVlanGateway = vlan.getVlanGateway();
+             newVlanNetmask = vlan.getVlanNetmask();
 -            //this means he is trying to add to the existing  subnet.
++            // this means he is trying to add to the existing subnet.
+             if (NetUtils.sameSubnet(startIP, newVlanGateway, newVlanNetmask)) {
 -                if (NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)){
++                if (NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)) {
+                     return 3;
+                 }
+             }
+             return 0;
 -        }
 -        else if (newVlanGateway == null || newVlanGateway ==null){
 -            throw new InvalidParameterValueException("either both netmask and gateway should be passed or both should me omited.");
 -        }
 -        else {
++        } else if (newVlanGateway == null || newVlanGateway == null) {
++            throw new InvalidParameterValueException(
++                    "either both netmask and gateway should be passed or both should me omited.");
++        } else {
+             if (!NetUtils.sameSubnet(startIP, newVlanGateway, newVlanNetmask)) {
+                 throw new InvalidParameterValueException("The start ip and gateway do not belong to the same subnet");
+             }
+             if (!NetUtils.sameSubnet(endIP, newVlanGateway, newVlanNetmask)) {
+                 throw new InvalidParameterValueException("The end ip and gateway do not belong to the same subnet");
+             }
+         }
+         String cidrnew = NetUtils.getCidrFromGatewayAndNetmask(newVlanGateway, newVlanNetmask);
+         String existing_cidr = NetUtils.getCidrFromGatewayAndNetmask(vlan.getVlanGateway(), vlan.getVlanNetmask());
  
 -        return  (NetUtils.isNetowrkASubsetOrSupersetOfNetworkB(cidrnew, existing_cidr));
++        return (NetUtils.isNetowrkASubsetOrSupersetOfNetworkB(cidrnew, existing_cidr));
+     }
+ 
 -    public Pair<Boolean,Pair<String,String>> validateIpRange(String startIP, String endIP, String newVlanGateway, String newVlanNetmask, List<VlanVO> vlans, boolean ipv4, boolean ipv6, String ip6Gateway, String ip6Cidr, String startIPv6, String endIPv6, Network network) {
 -        String vlanGateway=null;
 -        String vlanNetmask=null;
++    public Pair<Boolean, Pair<String, String>> validateIpRange(String startIP, String endIP, String newVlanGateway,
++            String newVlanNetmask, List<VlanVO> vlans, boolean ipv4, boolean ipv6, String ip6Gateway, String ip6Cidr,
++            String startIPv6, String endIPv6, Network network) {
++        String vlanGateway = null;
++        String vlanNetmask = null;
+         boolean sameSubnet = false;
 -        if ( vlans != null && vlans.size() > 0 ) {
++        if (vlans != null && vlans.size() > 0) {
              for (VlanVO vlan : vlans) {
                  if (ipv4) {
                      vlanGateway = vlan.getVlanGateway();
                      vlanNetmask = vlan.getVlanNetmask();
-                     // Check if ip addresses are in network range
-                     if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) {
-                         if (!NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) {
-                                 // check if the the new subnet is not a superset of the existing subnets.
-                                 if (NetUtils.isNetworkAWithinNetworkB(NetUtils.getCidrFromGatewayAndNetmask(vlanGateway,vlanNetmask), NetUtils.ipAndNetMaskToCidr(startIP, newVlanNetmask))){
-                                     throw new InvalidParameterValueException ("The new subnet is a superset of the existing subnet");
-                                 }
-                                 // check if the new subnet is not a subset of the existing subnet.
-                                 if (NetUtils.isNetworkAWithinNetworkB(NetUtils.ipAndNetMaskToCidr(startIP, newVlanNetmask), NetUtils.getCidrFromGatewayAndNetmask(vlanGateway,vlanNetmask))){
-                                     throw  new InvalidParameterValueException("The new subnet is a subset of the existing subnet");
-                                 }
-                         }
-                     } else if (NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)){
-                         // trying to add to the same subnet.
 -                    //check if subset or super set or neither.
++                    // check if subset or super set or neither.
+                     int val = checkIfSubsetOrSuperset(newVlanGateway, newVlanNetmask, vlan, startIP, endIP);
+                     if (val == 1) {
 -                        // this means that new cidr is a superset of the existing subnet.
 -                        throw new InvalidParameterValueException("The subnet you are trying to add is a superset of the existing subnet having gateway"+vlan.getVlanGateway()+" and netmask  "+vlan.getVlanNetmask());
 -                    }
 -                    else if (val == 0) {
 -                        //this implies the user is trying to add a new subnet which is not a superset or subset of this subnet.
 -                        //checking with the other subnets.
++                        // this means that new cidr is a superset of the
++                        // existing subnet.
++                        throw new InvalidParameterValueException(
++                                "The subnet you are trying to add is a superset of the existing subnet having gateway"
++                                        + vlan.getVlanGateway() + " and netmask  " + vlan.getVlanNetmask());
++                    } else if (val == 0) {
++                        // this implies the user is trying to add a new subnet
++                        // which is not a superset or subset of this subnet.
++                        // checking with the other subnets.
+                         continue;
 -                    }
 -                    else if (val == 2) {
 -                        //this means he is trying to add to the same subnet.
 -                        throw new InvalidParameterValueException("The subnet you are trying to add is a subset of the existing subnet having gateway"+vlan.getVlanGateway()+" and netmask  "+vlan.getVlanNetmask());
 -                    }
 -                    else if (val == 3) {
 -                        sameSubnet =true;
++                    } else if (val == 2) {
++                        // this means he is trying to add to the same subnet.
++                        throw new InvalidParameterValueException(
++                                "The subnet you are trying to add is a subset of the existing subnet having gateway"
++                                        + vlan.getVlanGateway() + " and netmask  " + vlan.getVlanNetmask());
++                    } else if (val == 3) {
 +                        sameSubnet = true;
-                         if (newVlanGateway == null) {
-                             newVlanGateway = vlanGateway;
-                         }
-                         if (!newVlanGateway.equals(vlanGateway)){
-                             throw new InvalidParameterValueException("The gateway of the ip range is not same as the gateway of the subnet.");
-                         }
-                         break;
-                     }
-                     else {
-                         throw new InvalidParameterValueException("Start ip and End ip is not in vlan range!");
                      }
                  }
                  if (ipv6) {
                      if (ip6Gateway != null && !ip6Gateway.equals(network.getIp6Gateway())) {
--                       throw new InvalidParameterValueException("The input gateway " + ip6Gateway + " is not same as network gateway " + network.getIp6Gateway());
++                        throw new InvalidParameterValueException("The input gateway " + ip6Gateway
++                                + " is not same as network gateway " + network.getIp6Gateway());
                      }
                      if (ip6Cidr != null && !ip6Cidr.equals(network.getIp6Cidr())) {
--                       throw new InvalidParameterValueException("The input cidr " + ip6Cidr + " is not same as network ciddr " + network.getIp6Cidr());
++                        throw new InvalidParameterValueException("The input cidr " + ip6Cidr
++                                + " is not same as network ciddr " + network.getIp6Cidr());
                      }
                      ip6Gateway = network.getIp6Gateway();
                      ip6Cidr = network.getIp6Cidr();
                      _networkModel.checkIp6Parameters(startI

<TRUNCATED>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f41c800d/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f41c800d/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------