bug 14076: Fix the exception scope

status 14076: resolved fixed
This commit is contained in:
Sheng Yang 2012-02-29 18:50:24 -08:00
parent 23a5cf2570
commit 178bd35143
1 changed files with 52 additions and 35 deletions

View File

@ -2100,6 +2100,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
List<VirtualRouter> connectedRouters = new ArrayList<VirtualRouter>();
List<VirtualRouter> disconnectedRouters = new ArrayList<VirtualRouter>();
Long podId = null;
if (isZoneBasic) {
podId = dest.getPod().getId();
}
boolean podLevelException = false;
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
if (isZoneBasic && podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
podLevelException = true;
}
for (DomainRouterVO router : routers) {
boolean sendDnsDhcpData = true;
@ -2110,8 +2120,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
//Stop pending only happened with
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!",
VirtualRouter.class, router.getId());
DataCenter.class, router.getDataCenterIdToDeployIn());
}
s_logger.warn("Unable to add virtual machine " + profile.getVirtualMachine() + " to the router " + router + " as the router is to be stopped");
continue;
@ -2120,9 +2131,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//for basic zone:
//1) send vm data/password information only to the dhcp in the same pod
//2) send dhcp/dns information to all routers in the cloudstack only when _dnsBasicZoneUpdates is set to "all" value
Long podId = null;
if (isZoneBasic) {
podId = dest.getPod().getId();
if (router.getPodIdToDeployIn().longValue() != podId.longValue()) {
if (_dnsBasicZoneUpdates.equalsIgnoreCase("pod")) {
sendDnsDhcpData = false;
@ -2157,11 +2166,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
if (cmds.size() > 0) {
boolean podLevelException = false;
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
if (isZoneBasic && podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
podLevelException = true;
}
try {
_agentMgr.send(router.getHostId(), cmds);
} catch (AgentUnavailableException e){
@ -2181,7 +2185,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (podLevelException) {
throw new ResourceUnavailableException("Unable to set dhcp entry for " + profile + " due to " + answer.getDetails(), Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to set dhcp entry for " + profile + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
throw new ResourceUnavailableException("Unable to set dhcp entry for " + profile + " due to " + answer.getDetails(), DataCenter.class, dc.getId());
}
}
@ -2191,14 +2195,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String msg = "Unable to apply dhcp entry for new VM into network on disconnected router ";
if (!connectedRouters.isEmpty()) {
// These disconnected ones are out of sync now, stop them for synchronization
handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
if (!isZoneBasic) {
handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
}
} else if (!disconnectedRouters.isEmpty()) {
for (VirtualRouter router : disconnectedRouters) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
}
throw new ResourceUnavailableException(msg, VirtualRouter.class, disconnectedRouters.get(0).getId());
if (podLevelException) {
throw new ResourceUnavailableException(msg, Pod.class, podId);
}
throw new ResourceUnavailableException(msg, DataCenter.class, dc.getId());
}
return rets;
@ -2242,6 +2251,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
List<VirtualRouter> connectedRouters = new ArrayList<VirtualRouter>();
List<VirtualRouter> disconnectedRouters = new ArrayList<VirtualRouter>();
Long podId = null;
if (isZoneBasic) {
podId = dest.getPod().getId();
}
boolean podLevelException = false;
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
if (isZoneBasic && podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
podLevelException = true;
}
for (DomainRouterVO router : routers) {
boolean sendPasswordAndVmData = true;
@ -2252,8 +2271,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
// Stop pending flag only used for advanced network
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!",
VirtualRouter.class, router.getId());
DataCenter.class, router.getDataCenterIdToDeployIn());
}
s_logger.warn("Unable to add virtual machine " + profile.getVirtualMachine() + " to the router " + router + " as the router is to be stopped");
continue;
@ -2262,9 +2282,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//for basic zone:
//1) send vm data/password information only to the dhcp in the same pod
//2) send dhcp/dns information to all routers in the cloudstack only when _dnsBasicZoneUpdates is set to "all" value
Long podId = null;
if (isZoneBasic) {
podId = dest.getPod().getId();
if (router.getPodIdToDeployIn().longValue() != podId.longValue()) {
sendPasswordAndVmData = false;
}
@ -2296,11 +2314,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
if (cmds.size() > 0) {
boolean podLevelException = false;
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
if (isZoneBasic && podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
podLevelException = true;
}
try {
_agentMgr.send(router.getHostId(), cmds);
} catch (AgentUnavailableException e){
@ -2320,7 +2333,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (podLevelException) {
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails(), Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails(), DataCenter.class, dc.getId());
}
answer = cmds.getAnswer("vmdata");
@ -2329,7 +2342,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (podLevelException) {
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails(), Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails(), DataCenter.class, dc.getId());
}
}
@ -2339,14 +2352,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String msg = "Unable to apply userdata for new VM into network on disconnected router ";
if (!connectedRouters.isEmpty()) {
// These disconnected ones are out of sync now, stop them for synchronization
handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
if (!isZoneBasic) {
handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
}
} else if (!disconnectedRouters.isEmpty()) {
for (VirtualRouter router : disconnectedRouters) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
}
throw new ResourceUnavailableException(msg, VirtualRouter.class, disconnectedRouters.get(0).getId());
if (podLevelException) {
throw new ResourceUnavailableException(msg, Pod.class, podId);
}
throw new ResourceUnavailableException(msg, DataCenter.class, dc.getId());
}
return rets;
@ -2800,11 +2818,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String msg = "Unable to associate ip addresses on disconnected router ";
for (VirtualRouter router : routers) {
if (router.getState() == State.Running) {
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!",
VirtualRouter.class, router.getId());
DataCenter.class, router.getDataCenterIdToDeployIn());
}
s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply firewall rules commands to the backend");
continue;
@ -2823,7 +2840,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//If ip fails to apply on one domR, no need to proceed with the rest
if (!result) {
throw new ResourceUnavailableException("Unable to associate ip addresses on router ", VirtualRouter.class, router.getId());
throw new ResourceUnavailableException("Unable to associate ip addresses on router ", DataCenter.class, router.getDataCenterIdToDeployIn());
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
@ -2844,7 +2861,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
}
throw new ResourceUnavailableException(msg, VirtualRouter.class, disconnectedRouters.get(0).getId());
throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterIdToDeployIn());
}
return result;
}
@ -2865,7 +2882,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!",
VirtualRouter.class, router.getId());
DataCenter.class, router.getDataCenterIdToDeployIn());
}
s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply firewall rules commands to the backend");
continue;
@ -2903,14 +2920,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//If rules fail to apply on one domR and not due to disconnection, no need to proceed with the rest
if (!result) {
throw new ResourceUnavailableException("Unable to apply firewall rules on router ", VirtualRouter.class, router.getId());
throw new ResourceUnavailableException("Unable to apply firewall rules on router ", DataCenter.class, router.getDataCenterIdToDeployIn());
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() +
", so not sending apply firewall rules commands to the backend");
} else {
s_logger.warn("Unable to apply firewall rules, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply firewall rules, virtual router is not in the right state", VirtualRouter.class, router.getId());
throw new ResourceUnavailableException("Unable to apply firewall rules, virtual router is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn());
}
}
@ -2923,7 +2940,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
}
throw new ResourceUnavailableException(msg, VirtualRouter.class, disconnectedRouters.get(0).getId());
throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterIdToDeployIn());
}
return true;
@ -3012,7 +3029,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!",
VirtualRouter.class, router.getId());
DataCenter.class, router.getDataCenterIdToDeployIn());
}
s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply firewall rules commands to the backend");
continue;
@ -3027,14 +3044,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//If rules fail to apply on one domR and not due to disconnection, no need to proceed with the rest
if (!result) {
throw new ResourceUnavailableException("Unable to apply static nat on router ", VirtualRouter.class, router.getId());
throw new ResourceUnavailableException("Unable to apply static nat on router ", DataCenter.class, router.getDataCenterIdToDeployIn());
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply static nat commands to the backend");
} else {
s_logger.warn("Unable to apply static nat, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply static nat, virtual router is not in the right state", VirtualRouter.class, router.getId());
throw new ResourceUnavailableException("Unable to apply static nat, virtual router is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn());
}
}
@ -3047,7 +3064,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
}
throw new ResourceUnavailableException(msg, VirtualRouter.class, disconnectedRouters.get(0).getId());
throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterIdToDeployIn());
}
return true;