mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 19:14:40 +01:00
Fix resource count discrepancy while associating IP address to a network or vpc (#9563)
This commit is contained in:
parent
89482a2583
commit
e16a971511
@ -35,6 +35,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import com.cloud.network.dao.PublicIpQuarantineDao;
|
import com.cloud.network.dao.PublicIpQuarantineDao;
|
||||||
import com.cloud.network.vo.PublicIpQuarantineVO;
|
import com.cloud.network.vo.PublicIpQuarantineVO;
|
||||||
|
import com.cloud.resourcelimit.CheckedReservation;
|
||||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||||
import org.apache.cloudstack.annotation.AnnotationService;
|
import org.apache.cloudstack.annotation.AnnotationService;
|
||||||
@ -53,6 +54,7 @@ import org.apache.cloudstack.region.PortableIp;
|
|||||||
import org.apache.cloudstack.region.PortableIpDao;
|
import org.apache.cloudstack.region.PortableIpDao;
|
||||||
import org.apache.cloudstack.region.PortableIpVO;
|
import org.apache.cloudstack.region.PortableIpVO;
|
||||||
import org.apache.cloudstack.region.Region;
|
import org.apache.cloudstack.region.Region;
|
||||||
|
import org.apache.cloudstack.reservation.dao.ReservationDao;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@ -261,6 +263,8 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||||||
@Inject
|
@Inject
|
||||||
ResourceLimitService _resourceLimitMgr;
|
ResourceLimitService _resourceLimitMgr;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ReservationDao reservationDao;
|
||||||
@Inject
|
@Inject
|
||||||
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
|
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
|
||||||
@Inject
|
@Inject
|
||||||
@ -1556,14 +1560,15 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||||||
|
|
||||||
s_logger.debug("Associating ip " + ipToAssoc + " to network " + network);
|
s_logger.debug("Associating ip " + ipToAssoc + " to network " + network);
|
||||||
|
|
||||||
IPAddressVO ip = _ipAddressDao.findById(ipId);
|
boolean success = false;
|
||||||
|
IPAddressVO ip = null;
|
||||||
|
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) {
|
||||||
|
ip = _ipAddressDao.findById(ipId);
|
||||||
//update ip address with networkId
|
//update ip address with networkId
|
||||||
ip.setAssociatedWithNetworkId(networkId);
|
ip.setAssociatedWithNetworkId(networkId);
|
||||||
ip.setSourceNat(isSourceNat);
|
ip.setSourceNat(isSourceNat);
|
||||||
_ipAddressDao.update(ipId, ip);
|
_ipAddressDao.update(ipId, ip);
|
||||||
|
|
||||||
boolean success = false;
|
|
||||||
try {
|
|
||||||
success = applyIpAssociations(network, false);
|
success = applyIpAssociations(network, false);
|
||||||
if (success) {
|
if (success) {
|
||||||
s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network);
|
s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network);
|
||||||
@ -1571,6 +1576,9 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||||||
s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network);
|
s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network);
|
||||||
}
|
}
|
||||||
return _ipAddressDao.findById(ipId);
|
return _ipAddressDao.findById(ipId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
s_logger.error(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e);
|
||||||
|
throw new CloudRuntimeException(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (!success && releaseOnFailure) {
|
if (!success && releaseOnFailure) {
|
||||||
if (ip != null) {
|
if (ip != null) {
|
||||||
|
|||||||
@ -42,6 +42,7 @@ import javax.annotation.PostConstruct;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import com.cloud.resourcelimit.CheckedReservation;
|
||||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||||
import org.apache.cloudstack.alert.AlertService;
|
import org.apache.cloudstack.alert.AlertService;
|
||||||
import org.apache.cloudstack.annotation.AnnotationService;
|
import org.apache.cloudstack.annotation.AnnotationService;
|
||||||
@ -63,6 +64,7 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationSe
|
|||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||||
import org.apache.cloudstack.query.QueryService;
|
import org.apache.cloudstack.query.QueryService;
|
||||||
|
import org.apache.cloudstack.reservation.dao.ReservationDao;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -237,6 +239,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||||||
@Inject
|
@Inject
|
||||||
ResourceLimitService _resourceLimitMgr;
|
ResourceLimitService _resourceLimitMgr;
|
||||||
@Inject
|
@Inject
|
||||||
|
ReservationDao reservationDao;
|
||||||
|
@Inject
|
||||||
VpcServiceMapDao _vpcSrvcDao;
|
VpcServiceMapDao _vpcSrvcDao;
|
||||||
@Inject
|
@Inject
|
||||||
DataCenterDao _dcDao;
|
DataCenterDao _dcDao;
|
||||||
@ -2927,6 +2931,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||||||
s_logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);
|
s_logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);
|
||||||
|
|
||||||
final boolean isSourceNatFinal = isSrcNatIpRequired(vpc.getVpcOfferingId()) && getExistingSourceNatInVpc(vpc.getAccountId(), vpcId) == null;
|
final boolean isSourceNatFinal = isSrcNatIpRequired(vpc.getVpcOfferingId()) && getExistingSourceNatInVpc(vpc.getAccountId(), vpcId) == null;
|
||||||
|
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) {
|
||||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||||
@Override
|
@Override
|
||||||
public void doInTransactionWithoutResult(final TransactionStatus status) {
|
public void doInTransactionWithoutResult(final TransactionStatus status) {
|
||||||
@ -2941,6 +2946,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||||||
_ipAddrMgr.markPublicIpAsAllocated(ip);
|
_ipAddrMgr.markPublicIpAsAllocated(ip);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
s_logger.error("Failed to associate ip " + ipToAssoc + " to vpc " + vpc, e);
|
||||||
|
throw new CloudRuntimeException("Failed to associate ip " + ipToAssoc + " to vpc " + vpc, e);
|
||||||
|
}
|
||||||
|
|
||||||
s_logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
|
s_logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
|
||||||
CallContext.current().putContextParameter(IpAddress.class, ipToAssoc.getUuid());
|
CallContext.current().putContextParameter(IpAddress.class, ipToAssoc.getUuid());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user