use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method releasePublicIpRange.
@DB
public boolean releasePublicIpRange(final long vlanDbId, final long userId, final Account caller) {
VlanVO vlan = _vlanDao.findById(vlanDbId);
// Verify range is dedicated
boolean isAccountSpecific = false;
final List<AccountVlanMapVO> acctVln = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanDbId);
// Verify range is dedicated
if (acctVln != null && !acctVln.isEmpty()) {
isAccountSpecific = true;
}
boolean isDomainSpecific = false;
final List<DomainVlanMapVO> domainVln = _domainVlanMapDao.listDomainVlanMapsByVlan(vlanDbId);
// Check for domain wide pool. It will have an entry for domain_vlan_map.
if (domainVln != null && !domainVln.isEmpty()) {
isDomainSpecific = true;
}
if (!isAccountSpecific && !isDomainSpecific) {
throw new InvalidParameterValueException("Can't release Public IP range " + vlanDbId + " as it not dedicated to any domain and any account");
}
// Check if range has any allocated public IPs
final long allocIpCount = _publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true);
final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlanDbId);
boolean success = true;
final List<IPAddressVO> ipsInUse = new ArrayList<>();
if (allocIpCount > 0) {
try {
vlan = _vlanDao.acquireInLockTable(vlanDbId, 30);
if (vlan == null) {
throw new CloudRuntimeException("Unable to acquire vlan configuration: " + vlanDbId);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("lock vlan " + vlanDbId + " is acquired");
}
for (final IPAddressVO ip : ips) {
// Disassociate allocated IP's that are not in use
if (!ip.isOneToOneNat() && !ip.isSourceNat() && !(_firewallDao.countRulesByIpId(ip.getId()) > 0)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Releasing Public IP addresses" + ip + " of vlan " + vlanDbId + " as part of Public IP" + " range release to the system pool");
}
success = success && _ipAddrMgr.disassociatePublicIpAddress(ip.getId(), userId, caller);
} else {
ipsInUse.add(ip);
}
}
if (!success) {
s_logger.warn("Some Public IP addresses that were not in use failed to be released as a part of" + " vlan " + vlanDbId + "release to the system pool");
}
} finally {
_vlanDao.releaseFromLockTable(vlanDbId);
}
}
// A Public IP range can only be dedicated to one account at a time
if (isAccountSpecific && _accountVlanMapDao.remove(acctVln.get(0).getId())) {
// decrement resource count for dedicated public ip's
_resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), ResourceType.public_ip, new Long(ips.size()));
return true;
} else if (isDomainSpecific && _domainVlanMapDao.remove(domainVln.get(0).getId())) {
s_logger.debug("Remove the vlan from domain_vlan_map successfully.");
return true;
} else {
return false;
}
}
use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method runReleasePublicIpRangePostiveTest2.
void runReleasePublicIpRangePostiveTest2() throws Exception {
final TransactionLegacy txn = TransactionLegacy.open("runReleasePublicIpRangePostiveTest2");
when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
final List<AccountVlanMapVO> accountVlanMaps = new ArrayList<>();
final AccountVlanMapVO accountVlanMap = new AccountVlanMapVO(1, 1);
accountVlanMaps.add(accountVlanMap);
when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByVlan(anyLong())).thenReturn(accountVlanMaps);
when(configurationMgr._publicIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(1);
final List<IPAddressVO> ipAddressList = new ArrayList<>();
final IPAddressVO ipAddress = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
ipAddressList.add(ipAddress);
when(configurationMgr._publicIpAddressDao.listByVlanId(anyLong())).thenReturn(ipAddressList);
when(configurationMgr._firewallDao.countRulesByIpId(anyLong())).thenReturn(0L);
when(configurationMgr._ipAddrMgr.disassociatePublicIpAddress(anyLong(), anyLong(), any(Account.class))).thenReturn(true);
when(configurationMgr._vlanDao.releaseFromLockTable(anyLong())).thenReturn(true);
when(configurationMgr._accountVlanMapDao.remove(anyLong())).thenReturn(true);
try {
final Boolean result = configurationMgr.releasePublicIpRange(releasePublicIpRangesCmd);
Assert.assertTrue(result);
} catch (final Exception e) {
s_logger.info("exception in testing runReleasePublicIpRangePostiveTest2 message: " + e.toString());
} finally {
txn.close("runReleasePublicIpRangePostiveTest2");
}
}
use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method runReleasePublicIpRangePostiveTest1.
void runReleasePublicIpRangePostiveTest1() throws Exception {
final TransactionLegacy txn = TransactionLegacy.open("runReleasePublicIpRangePostiveTest1");
when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
final List<AccountVlanMapVO> accountVlanMaps = new ArrayList<>();
final AccountVlanMapVO accountVlanMap = new AccountVlanMapVO(1, 1);
accountVlanMaps.add(accountVlanMap);
when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByVlan(anyLong())).thenReturn(accountVlanMaps);
// no allocated ip's
when(configurationMgr._publicIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(0);
when(configurationMgr._accountVlanMapDao.remove(anyLong())).thenReturn(true);
try {
final Boolean result = configurationMgr.releasePublicIpRange(releasePublicIpRangesCmd);
Assert.assertTrue(result);
} catch (final Exception e) {
s_logger.info("exception in testing runReleasePublicIpRangePostiveTest1 message: " + e.toString());
} finally {
txn.close("runReleasePublicIpRangePostiveTest1");
}
}
Aggregations