From 513adab51b53ba1acdea908225cfffab90ca1595 Mon Sep 17 00:00:00 2001 From: Koushik Das Date: Mon, 1 Dec 2014 16:18:06 +0530 Subject: [PATCH] CLOUDSTACK-7994: Network rules are not configured in VR after out-of-band movement due to host crash Ensure that VR is re-booted when it is moved to another host out-of-band. This is necessary to re-program all network rules --- .../VirtualNetworkApplianceManagerImpl.java | 20 ++++++++++++++++--- ...VpcVirtualNetworkApplianceManagerImpl.java | 7 +++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index fcaf3bc3a7a..df8d1794e12 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -244,6 +244,7 @@ import com.cloud.vm.dao.NicIpAliasVO; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; + import org.apache.cloudstack.alert.AlertService; import org.apache.cloudstack.alert.AlertService.AlertType; import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd; @@ -266,6 +267,7 @@ import org.apache.log4j.Logger; import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -4459,10 +4461,22 @@ VirtualMachineGuru, Listener, Configurable, StateListener) { + Pair pair = (Pair)opaque; + Object first = pair.first(); + Object second = pair.second(); + if (first != null && second != null && first instanceof Long && second instanceof Long) { + Long hostId = (Long)first; + Long powerHostId = (Long)second; + // If VM host known to CS is different from 'PowerOn' report host, then it is out-of-band movement + if (hostId.longValue() != powerHostId.longValue()) { + s_logger.info("Schedule a router reboot task as router " + vo.getId() + " is powered-on out-of-band. we need to reboot to refresh network rules"); + _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); + } + } + } } } return true; diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index cc673d96b4a..15c4f085282 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -1481,4 +1481,11 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return true; } + + @Override + public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) { + // Without this VirtualNetworkApplianceManagerImpl.postStateTransitionEvent() gets called twice as part of listeners - + // once from VpcVirtualNetworkApplianceManagerImpl and once from VirtualNetworkApplianceManagerImpl itself + return true; + } }