diff --git a/api/src/com/cloud/exception/InsufficientCapacityException.java b/api/src/com/cloud/exception/InsufficientCapacityException.java index 343742847be..06477acdad8 100755 --- a/api/src/com/cloud/exception/InsufficientCapacityException.java +++ b/api/src/com/cloud/exception/InsufficientCapacityException.java @@ -25,20 +25,20 @@ import com.cloud.utils.SerialVersionUID; */ public abstract class InsufficientCapacityException extends Exception { private static final long serialVersionUID = SerialVersionUID.InsufficientCapacityException; - + Long id; Class scope; protected InsufficientCapacityException() { super(); } - + public InsufficientCapacityException(String msg, Class scope, Long id) { super(msg); this.scope = scope; this.id = id; } - + /** * @return scope where we are insufficient. The possible classes are * Host, StoragePool, Cluster, Pod, DataCenter, NetworkConfiguration. @@ -46,7 +46,7 @@ public abstract class InsufficientCapacityException extends Exception { public Class getScope() { return scope; } - + /** * @return the id of the object that it is insufficient in. Note that this method is * marked such that if the id is not set, then it will throw NullPointerException. @@ -56,4 +56,9 @@ public abstract class InsufficientCapacityException extends Exception { public long getId() { return id; } + + @Override public String toString() { + String str = super.toString(); + return str + "Scope=" + scope + "; id=" + id; + } } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index e52f1d55e90..e98dbc8c16a 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -941,7 +941,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (tableName.equals("host_pod_ref") || tableName.equals("host") || tableName.equals("volumes")) { selectSql += " AND removed is NULL"; } - + if (tableName.equals("vm_instance")) { selectSql += " AND state != '" + VirtualMachine.State.Expunging.toString() + "'"; } @@ -1474,7 +1474,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Please specify a valid domain id"); } } - + boolean localStorageRequired = false; String storageType = cmd.getStorageType(); if (storageType == null) { @@ -1512,7 +1512,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura vm_type = VirtualMachine.Type.DomainRouter; } } - + return createServiceOffering(userId, cmd.getIsSystem(), vm_type, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), localStorageRequired, offerHA, limitCpuUse, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag()); } @@ -1546,7 +1546,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura // Verify input parameters ServiceOffering offeringHandle = getServiceOffering(id); - + if (offeringHandle == null) { throw new InvalidParameterValueException("unable to find service offering " + id); } @@ -1741,7 +1741,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (offering == null) { throw new InvalidParameterValueException("unable to find service offering " + offeringId); } - + if(offering.getDefaultUse()){ throw new InvalidParameterValueException("Default service offerings cannot be deleted"); } @@ -2086,9 +2086,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() + " has the same subnet. Please specify a different gateway/netmask."); } - + boolean vlansUntaggedAndVirtual = (vlanId.equals(Vlan.UNTAGGED) && vlanId.equals(vlan.getVlanTag()) && forVirtualNetwork && vlan.getVlanType() == VlanType.VirtualNetwork); - + if (vlansUntaggedAndVirtual && !newVlanSubnet.equals(otherVlanSubnet)) { throw new InvalidParameterValueException("The Untagged ip range with different subnet already exists in zone " + zone.getId()); } @@ -2304,9 +2304,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Transaction txn = Transaction.currentTxn(); txn.start(); IPRangeConfig config = new IPRangeConfig(); - config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkid); + List problemIps = config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkid); txn.commit(); - return true; + return problemIps != null && problemIps.size() == 0; } @DB @@ -3052,7 +3052,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (offering != null && offering.getRemoved() == null) { return offering; } - + return null; } @@ -3085,14 +3085,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return networkRate; } - + @Override public DiskOffering getDiskOffering(long diskOfferingId) { DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId); if (offering != null && offering.getRemoved() == null) { return offering; } - + return null; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 88255453463..75d1d0cfd63 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -55,13 +55,13 @@ import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterVO; +import com.cloud.dc.Pod; import com.cloud.dc.PodVlanMapVO; import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; -import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; import com.cloud.deploy.DataCenterDeployment; @@ -207,7 +207,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkDomainDao _networkDomainDao; @Inject VMInstanceDao _vmDao; - + @Inject DomainRouterDao _routerDao; private final HashMap _systemNetworks = new HashMap(5); @@ -227,7 +227,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean _allowSubdomainNetworkAccess; private Map _configs; - + HashMap _lastNetworkIdsToFree = new HashMap(); @@ -238,7 +238,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @DB public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign) - throws InsufficientAddressCapacityException { + throws InsufficientAddressCapacityException { Transaction txn = Transaction.currentTxn(); txn.start(); SearchCriteria sc = null; @@ -267,7 +267,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (addrs.size() == 0) { if (podId != null) { - throw new InsufficientAddressCapacityException("Insufficient address capacity", HostPodDao.class, podId); + throw new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId); } throw new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId); } @@ -789,7 +789,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NicForTrafficTypeSearch.done(); _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Network-Scavenger")); - + _allowSubdomainNetworkAccess = Boolean.valueOf(_configs.get(Config.SubDomainNetworkAccess.key())); s_logger.info("Network Manager is configured."); @@ -835,7 +835,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared, boolean isDefault) - throws ConcurrentOperationException { + throws ConcurrentOperationException { return setupNetwork(owner, offering, null, plan, name, displayText, isShared, isDefault, false, null, null); } @@ -1469,7 +1469,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Account caller = UserContext.current().getCaller(); List tags = cmd.getTags(); boolean isDomainSpecific = false; - + if (tags != null && tags.size() > 1) { throw new InvalidParameterException("Only one tag can be specified for a network at this time"); } @@ -1676,7 +1676,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!NetUtils.verifyDomainName(networkDomain)) { throw new InvalidParameterValueException( "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " - + "and the hyphen ('-'); can't start or end with \"-\""); + + "and the hyphen ('-'); can't start or end with \"-\""); } } } @@ -1756,7 +1756,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Long accountId = null; String path = null; Long sharedNetworkDomainId = null; - + //1) default is system to false if not specified //2) reset parameter to false if it's specified by the regular user if ((isSystem == null || caller.getType() == Account.ACCOUNT_TYPE_NORMAL) && id == null) { @@ -1791,7 +1791,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { accountId = caller.getId(); } - + if ((isSystem == null || !isSystem) && (isShared == null || isShared)) { sharedNetworkDomainId = domainId; } @@ -1810,7 +1810,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag SearchBuilder zoneSearch = _dcDao.createSearchBuilder(); zoneSearch.and("networkType", zoneSearch.entity().getNetworkType(), SearchCriteria.Op.EQ); sb.join("zoneSearch", zoneSearch, sb.entity().getDataCenterId(), zoneSearch.entity().getId(), JoinBuilder.JoinType.INNER); - + //domain level networks if (sharedNetworkDomainId != null) { SearchBuilder domainNetworkSearch = _networkDomainDao.createSearchBuilder(); @@ -1820,9 +1820,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sb.and("removed", sb.entity().getRemoved(), Op.NULL); if (isSystem == null || !isSystem) { - //Get domain level + account/zone level networks + //Get domain level + account/zone level networks List networksToReturn = new ArrayList(); - + if (sharedNetworkDomainId != null) { networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, type, isDefault, trafficType, isShared), searchFilter, sharedNetworkDomainId)); } else { @@ -1831,22 +1831,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER); networksToReturn.addAll(listDomainSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, type, isDefault, trafficType, isShared), searchFilter, path)); } - + //if domain id is specified - list only domain level networks if (accountId != null || (domainId == null && accountName == null)) { networksToReturn.addAll(listAccountSpecificAndZoneLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, type, isDefault, trafficType, isShared), searchFilter, accountId, path)); } - + return networksToReturn; - + } else { return _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, type, isDefault, trafficType, isShared), searchFilter); } } - + private SearchCriteria buildNetworkSearchCriteria(SearchBuilder sb, String keyword, Long id, Boolean isSystem, Long zoneId, String type, Boolean isDefault, String trafficType, Boolean isShared) { SearchCriteria sc = sb.create(); - + if (isSystem != null) { sc.setJoinParameters("networkOfferingSearch", "systemOnly", isSystem); } @@ -1871,21 +1871,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (isDefault != null) { sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); } - + if (trafficType != null) { sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType); } - + if (isShared != null) { sc.addAnd("isShared", SearchCriteria.Op.EQ, isShared); } - + return sc; } - + private List listDomainLevelNetworks(SearchCriteria sc, Filter searchFilter, long domainId) { - + Set allowedDomains = new HashSet(); if (_allowSubdomainNetworkAccess) { allowedDomains = _accountMgr.getDomainParentIds(domainId); @@ -1896,46 +1896,46 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sc.addJoinAnd("domainNetworkSearch", "domainId", SearchCriteria.Op.IN, allowedDomains.toArray()); return _networksDao.search(sc, searchFilter); } - + private List listAccountSpecificAndZoneLevelNetworks(SearchCriteria sc, Filter searchFilter, Long accountId, String path) { - + SearchCriteria ssc = _networksDao.createSearchCriteria(); - + //account level networks SearchCriteria accountSC = _networksDao.createSearchCriteria(); if (accountId != null) { accountSC.addAnd("accountId", SearchCriteria.Op.EQ, accountId); } - + accountSC.addAnd("isShared", SearchCriteria.Op.EQ, false); if (path != null) { Set allowedDomains = _accountMgr.getDomainChildrenIds(path); accountSC.addAnd("domainId", SearchCriteria.Op.IN, allowedDomains.toArray()); } - + ssc.addOr("id", SearchCriteria.Op.SC, accountSC); - + //zone level networks SearchCriteria zoneSC = _networksDao.createSearchCriteria(); zoneSC.addAnd("isDomainSpecific", SearchCriteria.Op.EQ, false); zoneSC.addAnd("isShared", SearchCriteria.Op.EQ, true); ssc.addOr("id", SearchCriteria.Op.SC, zoneSC); - + sc.addAnd("id", SearchCriteria.Op.SC, ssc); - + return _networksDao.search(sc, searchFilter); } - - + + private List listDomainSpecificNetworks(SearchCriteria sc, Filter searchFilter, String path) { - + if (path != null) { sc.addAnd("isShared", SearchCriteria.Op.EQ, true); sc.addAnd("isDomainSpecific", SearchCriteria.Op.EQ, true); sc.setJoinParameters("domainSearch", "path", path + "%"); } - + return _networksDao.search(sc, searchFilter); } @@ -1950,7 +1950,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (network == null) { throw new InvalidParameterValueException("unable to find network " + networkId); } - + //don't allow to delete system network NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId()); if (offering.isSystemOnly()) { @@ -2436,11 +2436,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public Map getServiceCapabilities(long zoneId, Long networkOfferingId, Service service) { - + if (!isServiceSupported(networkOfferingId, service)) { throw new UnsupportedServiceException("Service " + service.getName() + " is not by the network offering id=" + networkOfferingId); } - + Map> networkCapabilities = getZoneCapabilities(zoneId); if (networkCapabilities.get(service) == null) { throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in zone id=" + zoneId); @@ -2764,7 +2764,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Transaction txn = Transaction.currentTxn(); IPAddressVO ip = _ipAddressDao.findById(addrId); - + if (ip.getAllocatedToAccountId() == null && ip.getAllocatedTime() == null) { s_logger.trace("Ip address id=" + addrId + " is already released"); return ip; @@ -2807,8 +2807,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public boolean isNetworkAvailableInDomain(long networkId, long domainId) { - - + + Long networkDomainId = null; Network network = getNetwork(networkId); if (!network.getIsShared()) { @@ -2823,19 +2823,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { networkDomainId = networkDomainMap.get(0).getDomainId(); } - + if (domainId == networkDomainId.longValue()) { return true; } - + if (_allowSubdomainNetworkAccess) { Set parentDomains = _accountMgr.getDomainParentIds(domainId); - + if (parentDomains.contains(domainId)) { return true; } } - + return false; } @@ -2858,39 +2858,39 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (network == null) { throw new InvalidParameterValueException("Network id=" + networkId + "doesn't exist in the system"); } - + if (tags != null && tags.size() > 1) { throw new InvalidParameterException("Unable to support more than one tag on network yet"); } - + // Don't allow to update system network - make an exception for the Guest network in Basic zone NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId()); if (offering.isSystemOnly() && network.getTrafficType() != TrafficType.Guest) { throw new InvalidParameterValueException("Can't update system networks"); } - + //don't allow to modify network domain if the service is not supported if (domainSuffix != null) { // validate network domain if (!NetUtils.verifyDomainName(domainSuffix)) { throw new InvalidParameterValueException( "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " - + "and the hyphen ('-'); can't start or end with \"-\""); + + "and the hyphen ('-'); can't start or end with \"-\""); } - - + + Map dnsCapabilities = getServiceCapabilities(network.getDataCenterId(), network.getNetworkOfferingId(), Service.Dns); String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification); if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) { throw new InvalidParameterValueException("Domain name change is not supported for network id=" + network.getNetworkOfferingId() + " in zone id=" + network.getDataCenterId()); } - + List routers = _routerDao.listActive(networkId); if (!routers.isEmpty()) { throw new CloudRuntimeException("Unable to update network id=" + networkId + " with new network domain as the network has running network elements"); } - - + + network.setNetworkDomain(domainSuffix); } @@ -2903,7 +2903,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (displayText != null) { network.setDisplayText(displayText); } - + if (tags != null) { network.setTags(tags); }