Issue #: 5775

Release vnet and private IP allocation when domR fails to start
This commit is contained in:
kishan 2010-08-18 19:43:16 +05:30
parent f508bd7715
commit d4682d4c90
1 changed files with 27 additions and 26 deletions

View File

@ -770,6 +770,9 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
if(s_logger.isDebugEnabled())
s_logger.debug("Lock on router " + routerId + " is acquired");
boolean started = false;
String vnet = null;
boolean vnetAllocated = false;
try {
final State state = router.getState();
if (state == State.Running) {
@ -816,10 +819,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
throw new ConcurrentOperationException("Someone else is starting the router: " + router.toString());
}
String vnet = null;
boolean vnetAllocated = false;
final boolean mirroredVols = router.isMirroredVols();
boolean started = false;
try {
event = new EventVO();
event.setUserId(1L);
@ -832,6 +832,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
for (final UserVmVO vm : vms) {
if (vm.getVnet() != null) {
vnet = vm.getVnet();
break;
}
}
}
@ -969,28 +970,6 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
return _routerDao.findById(routerId);
} catch (final Throwable th) {
Transaction txn = Transaction.currentTxn();
if (!started) {
txn.start();
if (vnetAllocated == true && vnet != null) {
_dcDao.releaseVnet(vnet, router.getDataCenterId(), router.getAccountId());
}
router.setVnet(null);
String privateIpAddress = router.getPrivateIpAddress();
router.setPrivateIpAddress(null);
if (privateIpAddress != null) {
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
}
if (_routerDao.updateIf(router, Event.OperationFailed, null)) {
txn.commit();
}
}
if (th instanceof ExecutionException) {
s_logger.error("Error while starting router due to " + th.getMessage());
} else if (th instanceof ConcurrentOperationException) {
@ -1003,8 +982,30 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
return null;
}
} finally {
if (!started){
Transaction txn = Transaction.currentTxn();
txn.start();
if (vnetAllocated == true && vnet != null) {
_dcDao.releaseVnet(vnet, router.getDataCenterId(), router.getAccountId());
}
router.setVnet(null);
String privateIpAddress = router.getPrivateIpAddress();
router.setPrivateIpAddress(null);
if (privateIpAddress != null) {
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
}
if (_routerDao.updateIf(router, Event.OperationFailed, null)) {
txn.commit();
}
}
if (router != null) {
if(s_logger.isDebugEnabled())
s_logger.debug("Releasing lock on router " + routerId);
_routerDao.release(routerId);