cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [11/33] git commit: updated refs/heads/master to 90262a8
Date Fri, 28 Feb 2014 23:37:31 GMT
reboot VR if a out-of-band power-on event is detected


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ee2adab7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ee2adab7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ee2adab7

Branch: refs/heads/master
Commit: ee2adab7c7c9cf42eaf93c7eedb6dd32ebd8b501
Parents: fed8581
Author: Kelven Yang <kelveny@gmail.com>
Authored: Mon Feb 10 16:58:49 2014 -0800
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Fri Feb 28 15:35:58 2014 -0800

----------------------------------------------------------------------
 .../VirtualNetworkApplianceManagerImpl.java     | 45 ++++++++++++++++++--
 1 file changed, 41 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ee2adab7/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index c241aac..a64f15c 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -251,6 +251,7 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.TransactionCallbackNoReturn;
 import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.fsm.StateListener;
 import com.cloud.utils.net.Ip;
 import com.cloud.utils.net.MacAddress;
 import com.cloud.utils.net.NetUtils;
@@ -281,9 +282,9 @@ import com.cloud.vm.dao.VMInstanceDao;
 /**
  * VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances
available in the Cloud Stack.
  */
-@Local(value = {VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class})
-public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager,
VirtualNetworkApplianceService, VirtualMachineGuru,
-Listener, Configurable {
+@Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class
})
+public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager,
VirtualNetworkApplianceService,
+        VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.Event,
VirtualMachine> {
     private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
 
     @Inject
@@ -675,6 +676,8 @@ Listener, Configurable {
         _checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor"));
         _networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater"));
 
+        VirtualMachine.State.getStateMachine().registerListener(this);
+
         final Map<String, String> configs = _configDao.getConfiguration("AgentManager",
params);
 
         _routerRamSize = NumbersUtil.parseInt(configs.get("router.ram.size"), DEFAULT_ROUTER_VM_RAMSIZE);
@@ -3435,7 +3438,6 @@ Listener, Configurable {
                 "vmdata",
                 generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering,
zoneName, nic.getIp4Address(), vm.getHostName(), vm.getInstanceName(),
                         vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId()));
-
     }
 
     private void createVmDataCommandForVMs(final DomainRouterVO router, final Commands cmds,
final long guestNetworkId) {
@@ -4228,4 +4230,39 @@ Listener, Configurable {
     public ConfigKey<?>[] getConfigKeys() {
         return new ConfigKey<?>[] {UseExternalDnsServers, routerVersionCheckEnabled,
SetServiceMonitor};
     }
+
+    @Override
+    public boolean preStateTransitionEvent(State oldState, VirtualMachine.Event event, State
newState, VirtualMachine vo, boolean status, Object opaque) {
+        return true;
+    }
+
+    @Override
+    public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State
newState, VirtualMachine vo, boolean status, Object opaque) {
+        if (oldState == State.Stopped && event == VirtualMachine.Event.FollowAgentPowerOnReport
&& newState == State.Running) {
+            if (vo.getType() == VirtualMachine.Type.DomainRouter) {
+                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;
+    }
+
+    protected class RebootTask extends ManagedContextRunnable {
+
+        long _routerId;
+
+        public RebootTask(long routerId) {
+            _routerId = routerId;
+        }
+
+        @Override
+        protected void runInContext() {
+            try {
+                s_logger.info("Reboot router " + _routerId + " to refresh network rules");
+                rebootRouter(_routerId, true);
+            } catch (Exception e) {
+                s_logger.warn("Error while rebooting the router", e);
+            }
+        }
+    }
 }


Mime
View raw message