Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3545F10EF1 for ; Fri, 14 Nov 2014 06:39:08 +0000 (UTC) Received: (qmail 5275 invoked by uid 500); 14 Nov 2014 06:39:08 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 5244 invoked by uid 500); 14 Nov 2014 06:39:08 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 5235 invoked by uid 99); 14 Nov 2014 06:39:07 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Nov 2014 06:39:07 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A358193AD24; Fri, 14 Nov 2014 06:39:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jayapal@apache.org To: commits@cloudstack.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/4.5 to 7e6ec2c Date: Fri, 14 Nov 2014 06:39:07 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/4.5 03505901b -> 7e6ec2ce8 CLOUDSTACK-7877: The NET.IPRELEASE events are not added to usage_event on IP range deletion from Physical Networks. Signed-off-by: Jayapal Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7e6ec2ce Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7e6ec2ce Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7e6ec2ce Branch: refs/heads/4.5 Commit: 7e6ec2ce826969aeb79ddb1113cdc45289bc89d3 Parents: 0350590 Author: Damodar Authored: Tue Nov 11 11:25:03 2014 +0530 Committer: Jayapal Committed: Fri Nov 14 10:31:46 2014 +0530 ---------------------------------------------------------------------- .../configuration/ConfigurationManagerImpl.java | 107 +++++++++---------- 1 file changed, 52 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7e6ec2ce/server/src/com/cloud/configuration/ConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 1f71c0f..628cbc7 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3159,69 +3159,66 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } // Check if the VLAN has any allocated public IPs - long allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId, true); List ips = _publicIpAddressDao.listByVlanId(vlanDbId); - boolean success = true; - if (allocIpCount > 0) { - if (isAccountSpecific) { - try { - vlanRange = _vlanDao.acquireInLockTable(vlanDbId, 30); - if (vlanRange == null) { - throw new CloudRuntimeException("Unable to acquire vlan configuration: " + vlanDbId); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("lock vlan " + vlanDbId + " is acquired"); - } - for (IPAddressVO ip : ips) { - if (ip.isOneToOneNat()) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip - + " belonging to the range is used for static nat purposes. Cleanup the rules first"); - } - - if (ip.isSourceNat()) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip - + " belonging to the range is a source nat ip for the network id=" + ip.getSourceNetworkId() - + ". IP range with the source nat ip address can be removed either as a part of Network, or account removal"); - } + if (isAccountSpecific) { + try { + vlanRange = _vlanDao.acquireInLockTable(vlanDbId, 30); + if (vlanRange == null) { + throw new CloudRuntimeException("Unable to acquire vlan configuration: " + vlanDbId); + } - if (_firewallDao.countRulesByIpId(ip.getId()) > 0) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip - + " belonging to the range has firewall rules applied. Cleanup the rules first"); - } - // release public ip address here - success = success && _ipAddrMgr.disassociatePublicIpAddress(ip.getId(), userId, caller); - } - if (!success) { - s_logger.warn("Some ip addresses failed to be released as a part of vlan " + vlanDbId + " removal"); - } else { - for (IPAddressVO ip : ips) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getId(), ip.getDataCenterId(), ip.getId(), - ip.getAddress().toString(), ip.isSourceNat(), vlanRange.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid()); - } - } - } finally { - _vlanDao.releaseFromLockTable(vlanDbId); - } - } else { // !isAccountSpecific - NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), vlanRange.getNetworkId(), NicIpAlias.state.active); - //check if the ipalias belongs to the vlan range being deleted. - if (ipAlias != null && vlanDbId == _publicIpAddressDao.findByIpAndSourceNetworkId(vlanRange.getNetworkId(), ipAlias.getIp4Address()).getVlanId()) { - throw new InvalidParameterValueException("Cannot delete vlan range " + vlanDbId + " as " + ipAlias.getIp4Address() - + "is being used for providing dhcp service in this subnet. Delete all VMs in this subnet and try again"); - } - allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId, true); - if (allocIpCount > 0) { - throw new InvalidParameterValueException(allocIpCount + " Ips are in use. Cannot delete this vlan"); - } + if (s_logger.isDebugEnabled()) { + s_logger.debug("lock vlan " + vlanDbId + " is acquired"); } + for (IPAddressVO ip : ips) { + boolean success = true; + if (ip.isOneToOneNat()) { + throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip + + " belonging to the range is used for static nat purposes. Cleanup the rules first"); + } + + if (ip.isSourceNat()) { + throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip + + " belonging to the range is a source nat ip for the network id=" + ip.getSourceNetworkId() + + ". IP range with the source nat ip address can be removed either as a part of Network, or account removal"); + } + + if (_firewallDao.countRulesByIpId(ip.getId()) > 0) { + throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip + + " belonging to the range has firewall rules applied. Cleanup the rules first"); + } + if(ip.getAllocatedTime() != null) {// This means IP is allocated + // release public ip address here + success = _ipAddrMgr.disassociatePublicIpAddress(ip.getId(), userId, caller); + } + if (!success) { + s_logger.warn("Some ip addresses failed to be released as a part of vlan " + vlanDbId + " removal"); + } else { + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getAccountId(), ip.getDataCenterId(), ip.getId(), + ip.getAddress().toString(), ip.isSourceNat(), vlanRange.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid()); + } + } + } finally { + _vlanDao.releaseFromLockTable(vlanDbId); + } + } else { // !isAccountSpecific + NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), vlanRange.getNetworkId(), NicIpAlias.state.active); + //check if the ipalias belongs to the vlan range being deleted. + if (ipAlias != null && vlanDbId == _publicIpAddressDao.findByIpAndSourceNetworkId(vlanRange.getNetworkId(), ipAlias.getIp4Address()).getVlanId()) { + throw new InvalidParameterValueException("Cannot delete vlan range " + vlanDbId + " as " + ipAlias.getIp4Address() + + "is being used for providing dhcp service in this subnet. Delete all VMs in this subnet and try again"); + } + long allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId, true); + if (allocIpCount > 0) { + throw new InvalidParameterValueException(allocIpCount + " Ips are in use. Cannot delete this vlan"); + } } Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - _publicIpAddressDao.deletePublicIPRange(vlanDbId); - _vlanDao.remove(vlanDbId); + _publicIpAddressDao.deletePublicIPRange(vlanDbId); + _vlanDao.remove(vlanDbId); } });