You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/24 01:57:37 UTC

[7/50] [abbrv] git commit: simulator: simulator maintenance mode and simulator latency per command

simulator: simulator maintenance mode and simulator latency per command

Detail:
To induce latency for a command you have to use an API call like so
http://localhost:8096/client/api?command=configureSimulator&zoneid=1&podid=1&name=CheckRouterCommand&value=wait:80|timeout:0

(This is a hidden API command just for the simulator)

You will see the configuration effected in the mockconfiguration table of
simulator db. You can introduce the latency at runtime without restarting
management server.

mysql> select * from mockconfiguration;
+----+----------------+--------+------------+---------+--------------------+-------------------+
| id | data_center_id | pod_id | cluster_id | host_id | name               | values            |
+----+----------------+--------+------------+---------+--------------------+-------------------+
|  1 |              1 |      1 |       NULL |    NULL | CheckRouterCommand | wait:80|timeout:0 |
+----+----------------+--------+------------+---------+--------------------+-------------------+
1 row in set (0.00 sec)

By providing the optional zoneid, podid, clusterid, hostid you can induce the
latency at various levels. This delay will happen before the command is
processed and post-execution return Command's Answer back to management
server.

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


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

Branch: refs/heads/api_refactoring
Commit: ed25ec050080867246b2af52a21328fb640699a5
Parents: beff1f4
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Sat Dec 22 13:57:13 2012 -0800
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Sat Dec 22 13:57:13 2012 -0800

----------------------------------------------------------------------
 .../com/cloud/agent/manager/MockAgentManager.java  |    2 -
 .../cloud/agent/manager/MockAgentManagerImpl.java  |    9 -----
 .../src/com/cloud/agent/manager/MockVmManager.java |    1 +
 .../com/cloud/agent/manager/MockVmManagerImpl.java |   29 ++++++++++++++-
 .../cloud/agent/manager/SimulatorManagerImpl.java  |   18 ++++-----
 5 files changed, 36 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ed25ec05/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
index 7db5b20..2bb1205 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
@@ -56,8 +56,6 @@ public interface MockAgentManager extends Manager {
 
 	Answer pingTest(PingTestCommand cmd);
 
-	Answer prepareForMigrate(PrepareForMigrationCommand cmd);
-
 	MockHost getHost(String guid);
 
 	Answer maintain(MaintainCommand cmd);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ed25ec05/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
index cb99297..f6bc8fc 100755
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
@@ -430,15 +430,6 @@ public class MockAgentManagerImpl implements MockAgentManager {
 	}
 
 	@Override
-	public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) {
-		VirtualMachineTO vm = cmd.getVirtualMachine();
-		if (s_logger.isDebugEnabled()) {
-			s_logger.debug("Preparing host for migrating " + vm);
-		}
-		return new PrepareForMigrationAnswer(cmd);
-	}
-
-	@Override
 	public boolean start() {
 		return true;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ed25ec05/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
index 82f600d..117e2f6 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
@@ -74,6 +74,7 @@ public interface MockVmManager extends Manager {
     HashMap<String, Pair<Long, Long>> syncNetworkGroups(SimulatorInfo info);
     SecurityGroupRuleAnswer AddSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info);
 	MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info);
+    PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd);
 	GetDomRVersionAnswer getDomRVersion(GetDomRVersionCmd cmd);
 	Map<String, MockVMVO> getVms(String hostGuid);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ed25ec05/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
index 8177cda..d04e166 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
@@ -388,8 +388,12 @@ public class MockVmManagerImpl implements MockVmManager {
 			String destGuid = cmd.getHostGuid();
 			MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
 			if (vm == null) {
-				return new MigrateAnswer(cmd, false, "can;t find vm:" + vmName + " on host:" + info.getHostUuid(), null);
-			}
+				return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:" + info.getHostUuid(), null);
+			} else {
+                if (vm.getState() == State.Migrating) {
+                    vm.setState(State.Running);
+                }
+            }
 
 			MockHost destHost = _mockHostDao.findByGuid(destGuid);
 			if (destHost == null) {
@@ -410,6 +414,27 @@ public class MockVmManagerImpl implements MockVmManager {
 	}
 
     @Override
+    public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        VirtualMachineTO vmTo = cmd.getVirtualMachine();
+        try {
+            txn.start();
+            MockVMVO vm = _mockVmDao.findById(vmTo.getId());
+            vm.setState(State.Migrating);
+            _mockVmDao.update(vm.getId(), vm);
+            txn.commit();
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to find vm " + vmTo.getName(), ex);
+        } finally {
+            txn.close();
+            txn = Transaction.open(Transaction.CLOUD_DB);
+            txn.close();
+            return new PrepareForMigrationAnswer(cmd);
+        }
+    }
+
+    @Override
     public Answer IpAssoc(IpAssocCommand cmd) {
         return new Answer(cmd);
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ed25ec05/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
index a32da34..3d572ff 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -16,8 +16,6 @@
 // under the License.
 package com.cloud.agent.manager;
 
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -58,6 +56,7 @@ import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine.State;
+
 @Local(value = { SimulatorManager.class })
 public class SimulatorManagerImpl implements SimulatorManager {
     private static final Logger s_logger = Logger.getLogger(SimulatorManagerImpl.class);
@@ -165,7 +164,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
             } else if (cmd instanceof PingTestCommand) {
                 return _mockAgentMgr.pingTest((PingTestCommand)cmd);
             } else if (cmd instanceof PrepareForMigrationCommand) {
-		return _mockAgentMgr.prepareForMigrate((PrepareForMigrationCommand)cmd);
+        		return _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand)cmd);
             } else if (cmd instanceof MigrateCommand) {
                 return _mockVmMgr.Migrate((MigrateCommand)cmd, info);
             } else if (cmd instanceof StartCommand) {
@@ -173,11 +172,11 @@ public class SimulatorManagerImpl implements SimulatorManager {
             } else if (cmd instanceof CheckSshCommand) {
                 return _mockVmMgr.checkSshCommand((CheckSshCommand)cmd);
             } else if (cmd instanceof CheckVirtualMachineCommand) {
-		return _mockVmMgr.checkVmState((CheckVirtualMachineCommand)cmd);
+        		return _mockVmMgr.checkVmState((CheckVirtualMachineCommand)cmd);
             } else if (cmd instanceof SetStaticNatRulesCommand) {
                 return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand)cmd);
             } else if (cmd instanceof SetFirewallRulesCommand) {
-		return _mockVmMgr.SetFirewallRules((SetFirewallRulesCommand)cmd);
+	        	return _mockVmMgr.SetFirewallRules((SetFirewallRulesCommand)cmd);
             } else if (cmd instanceof SetPortForwardingRulesCommand) {
                 return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand)cmd);
             } else if (cmd instanceof NetworkUsageCommand) {
@@ -193,7 +192,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
             } else if (cmd instanceof CleanupNetworkRulesCmd) {
                 return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd)cmd, info);
             } else if (cmd instanceof CheckNetworkCommand) {
-		return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
+        		return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
             }else if (cmd instanceof StopCommand) {
                 return _mockVmMgr.stopVM((StopCommand)cmd);
             } else if (cmd instanceof RebootCommand) {
@@ -261,12 +260,11 @@ public class SimulatorManagerImpl implements SimulatorManager {
             } else if (cmd instanceof BumpUpPriorityCommand) {
                 return _mockVmMgr.bumpPriority((BumpUpPriorityCommand) cmd);
             } else if (cmd instanceof GetDomRVersionCmd) {
-		return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
+		        return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
             } else if (cmd instanceof ClusterSyncCommand) {
-		return new Answer(cmd);
-		//return new ClusterSyncAnswer(((ClusterSyncCommand) cmd).getClusterId(), this.getVmStates(hostGuid));
+        		return new Answer(cmd);
             } else if (cmd instanceof CopyVolumeCommand) {
-		return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
+	        	return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
             } else {
                 return Answer.createUnsupportedCommandAnswer(cmd);
             }