incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [5/7] more files changed
Date Thu, 10 Jan 2013 23:29:22 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/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 69c066d..63c04be 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
@@ -23,20 +23,56 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import com.cloud.agent.api.*;
-import com.cloud.agent.api.routing.*;
-import com.cloud.network.router.VirtualRouter;
 import org.apache.log4j.Logger;
 
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.BumpUpPriorityCommand;
+import com.cloud.agent.api.CheckRouterAnswer;
+import com.cloud.agent.api.CheckRouterCommand;
+import com.cloud.agent.api.CheckVirtualMachineAnswer;
+import com.cloud.agent.api.CheckVirtualMachineCommand;
+import com.cloud.agent.api.CleanupNetworkRulesCmd;
+import com.cloud.agent.api.GetDomRVersionAnswer;
+import com.cloud.agent.api.GetDomRVersionCmd;
+import com.cloud.agent.api.GetVmStatsAnswer;
+import com.cloud.agent.api.GetVmStatsCommand;
+import com.cloud.agent.api.GetVncPortAnswer;
+import com.cloud.agent.api.GetVncPortCommand;
+import com.cloud.agent.api.MigrateAnswer;
+import com.cloud.agent.api.MigrateCommand;
+import com.cloud.agent.api.NetworkUsageAnswer;
+import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.agent.api.PrepareForMigrationAnswer;
+import com.cloud.agent.api.PrepareForMigrationCommand;
+import com.cloud.agent.api.RebootAnswer;
+import com.cloud.agent.api.RebootCommand;
+import com.cloud.agent.api.SecurityGroupRuleAnswer;
+import com.cloud.agent.api.SecurityGroupRulesCmd;
+import com.cloud.agent.api.StartAnswer;
+import com.cloud.agent.api.StartCommand;
+import com.cloud.agent.api.StopAnswer;
+import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.VmStatsEntry;
 import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
 import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
+import com.cloud.agent.api.routing.DhcpEntryCommand;
+import com.cloud.agent.api.routing.IpAssocCommand;
+import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
+import com.cloud.agent.api.routing.NetworkElementCommand;
+import com.cloud.agent.api.routing.SavePasswordCommand;
+import com.cloud.agent.api.routing.SetFirewallRulesCommand;
+import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
+import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
+import com.cloud.agent.api.routing.VmDataCommand;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.router.VirtualRouter;
 import com.cloud.simulator.MockHost;
 import com.cloud.simulator.MockSecurityRulesVO;
 import com.cloud.simulator.MockVMVO;
@@ -46,7 +82,6 @@ import com.cloud.simulator.dao.MockSecurityRulesDao;
 import com.cloud.simulator.dao.MockVMDao;
 import com.cloud.utils.Pair;
 import com.cloud.utils.Ternary;
-
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine.State;
@@ -55,46 +90,46 @@ import com.cloud.vm.VirtualMachine.State;
 public class MockVmManagerImpl implements MockVmManager {
     private static final Logger s_logger = Logger.getLogger(MockVmManagerImpl.class);
 
-	@Inject MockVMDao _mockVmDao = null;
-	@Inject MockAgentManager _mockAgentMgr = null;
-	@Inject MockHostDao _mockHostDao = null;
-	@Inject MockSecurityRulesDao _mockSecurityDao = null;
-	private Map<String, Map<String, Ternary<String, Long, Long>>> _securityRules = new ConcurrentHashMap<String, Map<String, Ternary<String, Long, Long>>>();
+    @Inject MockVMDao _mockVmDao = null;
+    @Inject MockAgentManager _mockAgentMgr = null;
+    @Inject MockHostDao _mockHostDao = null;
+    @Inject MockSecurityRulesDao _mockSecurityDao = null;
+    private final Map<String, Map<String, Ternary<String, Long, Long>>> _securityRules = new ConcurrentHashMap<String, Map<String, Ternary<String, Long, Long>>>();
 
-	public MockVmManagerImpl() {
-	}
+    public MockVmManagerImpl() {
+    }
 
-	@Override
+    @Override
     public boolean configure(String name, Map<String, Object> params)
             throws ConfigurationException {
 
-	    return true;
-	}
+        return true;
+    }
 
     public String startVM(String vmName, NicTO[] nics,
-		int cpuHz, long ramSize,
-		String bootArgs, String hostGuid) {
-
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		MockHost host = null;
-		MockVm vm = null;
-		try {
-			txn.start();
-			host = _mockHostDao.findByGuid(hostGuid);
-			if (host == null) {
-				return "can't find host";
-			}
-
-			vm = _mockVmDao.findByVmName(vmName);
-			txn.commit();
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
-		} finally {
-			txn.close();
+            int cpuHz, long ramSize,
+            String bootArgs, String hostGuid) {
+
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        MockHost host = null;
+        MockVm vm = null;
+        try {
+            txn.start();
+            host = _mockHostDao.findByGuid(hostGuid);
+            if (host == null) {
+                return "can't find host";
+            }
+
+            vm = _mockVmDao.findByVmName(vmName);
+            txn.commit();
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
+        }
 
         if(vm == null) {
             int vncPort = 0;
@@ -109,43 +144,43 @@ public class MockVmManagerImpl implements MockVmManager {
             vm.setHostId(host.getId());
             vm.setBootargs(bootArgs);
             if(vmName.startsWith("s-")) {
-		vm.setType("SecondaryStorageVm");
+                vm.setType("SecondaryStorageVm");
             } else if (vmName.startsWith("v-")) {
-		vm.setType("ConsoleProxy");
+                vm.setType("ConsoleProxy");
             } else if (vmName.startsWith("r-")) {
-		vm.setType("DomainRouter");
+                vm.setType("DomainRouter");
             } else if (vmName.startsWith("i-")) {
-		vm.setType("User");
+                vm.setType("User");
             }
             txn = Transaction.open(Transaction.SIMULATOR_DB);
-			try {
-				txn.start();
-				vm = _mockVmDao.persist((MockVMVO) vm);
-				txn.commit();
-			} catch (Exception ex) {
-				txn.rollback();
-				throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
-			} finally {
-				txn.close();
+            try {
+                txn.start();
+                vm = _mockVmDao.persist((MockVMVO) vm);
+                txn.commit();
+            } catch (Exception ex) {
+                txn.rollback();
+                throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
+            } finally {
+                txn.close();
                 txn = Transaction.open(Transaction.CLOUD_DB);
                 txn.close();
-			}
+            }
         } else {
             if(vm.getState() == State.Stopped) {
                 vm.setState(State.Running);
                 txn = Transaction.open(Transaction.SIMULATOR_DB);
-			try {
-				txn.start();
-				_mockVmDao.update(vm.getId(), (MockVMVO)vm);
-				txn.commit();
-			} catch (Exception ex) {
-				txn.rollback();
-				throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
-			} finally {
-				txn.close();
+                try {
+                    txn.start();
+                    _mockVmDao.update(vm.getId(), (MockVMVO)vm);
+                    txn.commit();
+                } catch (Exception ex) {
+                    txn.rollback();
+                    throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
+                } finally {
+                    txn.close();
                     txn = Transaction.open(Transaction.CLOUD_DB);
                     txn.close();
-			}
+                }
             }
         }
 
@@ -192,49 +227,49 @@ public class MockVmManagerImpl implements MockVmManager {
         return null;
     }
 
-	public boolean rebootVM(String vmName) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			MockVm vm = _mockVmDao.findByVmName(vmName);
-			if (vm != null) {
-				vm.setState(State.Running);
-				_mockVmDao.update(vm.getId(), (MockVMVO) vm);
-
-			}
-			txn.commit();
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to reboot vm " + vmName, ex);
-		} finally {
-			txn.close();
+    public boolean rebootVM(String vmName) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            MockVm vm = _mockVmDao.findByVmName(vmName);
+            if (vm != null) {
+                vm.setState(State.Running);
+                _mockVmDao.update(vm.getId(), (MockVMVO) vm);
+
+            }
+            txn.commit();
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to reboot vm " + vmName, ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-		return true;
-	}
-
-	@Override
-	public Map<String, MockVMVO> getVms(String hostGuid) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
-			Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
-			for (MockVMVO vm : vms) {
-				vmMap.put(vm.getName(), vm);
-			}
-			txn.commit();
-			return vmMap;
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to fetch vms  from host " + hostGuid, ex);
-		} finally {
-			txn.close();
+        }
+        return true;
+    }
+
+    @Override
+    public Map<String, MockVMVO> getVms(String hostGuid) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
+            Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
+            for (MockVMVO vm : vms) {
+                vmMap.put(vm.getName(), vm);
+            }
+            txn.commit();
+            return vmMap;
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to fetch vms  from host " + hostGuid, ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-	}
+        }
+    }
 
     @Override
     public CheckRouterAnswer checkRouter(CheckRouterCommand cmd) {
@@ -267,30 +302,30 @@ public class MockVmManagerImpl implements MockVmManager {
     }
 
     @Override
-	public Map<String, State> getVmStates(String hostGuid) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			Map<String, State> states = new HashMap<String, State>();
-			List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
-			if (vms.isEmpty()) {
-				txn.commit();
-				return states;
-			}
-			for (MockVm vm : vms) {
-				states.put(vm.getName(), vm.getState());
-			}
-			txn.commit();
-			return states;
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to fetch vms  from host " + hostGuid, ex);
-		} finally {
-			txn.close();
+    public Map<String, State> getVmStates(String hostGuid) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            Map<String, State> states = new HashMap<String, State>();
+            List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
+            if (vms.isEmpty()) {
+                txn.commit();
+                return states;
+            }
+            for (MockVm vm : vms) {
+                states.put(vm.getName(), vm.getState());
+            }
+            txn.commit();
+            return states;
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to fetch vms  from host " + hostGuid, ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-	}
+        }
+    }
 
     @Override
     public boolean start() {
@@ -323,26 +358,26 @@ public class MockVmManagerImpl implements MockVmManager {
     }
 
     @Override
-	public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
-			if (vm == null) {
-				return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
-			}
+    public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
+            if (vm == null) {
+                return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
+            }
 
-			txn.commit();
-			return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
-		} finally {
-			txn.close();
+            txn.commit();
+            return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-	}
+        }
+    }
 
     @Override
     public Answer startVM(StartCommand cmd, SimulatorInfo info) {
@@ -372,7 +407,7 @@ public class MockVmManagerImpl implements MockVmManager {
 
     @Override
     public Answer SetFirewallRules(SetFirewallRulesCommand cmd) {
-	return new Answer(cmd);
+        return new Answer(cmd);
     }
 
 
@@ -382,38 +417,38 @@ public class MockVmManagerImpl implements MockVmManager {
     }
 
     @Override
-	public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			String vmName = cmd.getVmName();
-			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);
-			} else {
+    public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            String vmName = cmd.getVmName();
+            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);
+            } else {
                 if (vm.getState() == State.Migrating) {
                     vm.setState(State.Running);
                 }
             }
 
-			MockHost destHost = _mockHostDao.findByGuid(destGuid);
-			if (destHost == null) {
-				return new MigrateAnswer(cmd, false, "can;t find host:" + info.getHostUuid(), null);
-			}
-			vm.setHostId(destHost.getId());
-			_mockVmDao.update(vm.getId(), vm);
-			txn.commit();
-			return new MigrateAnswer(cmd, true, null, 0);
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
-		} finally {
-			txn.close();
+            MockHost destHost = _mockHostDao.findByGuid(destGuid);
+            if (destHost == null) {
+                return new MigrateAnswer(cmd, false, "can;t find host:" + info.getHostUuid(), null);
+            }
+            vm.setHostId(destHost.getId());
+            _mockVmDao.update(vm.getId(), vm);
+            txn.commit();
+            return new MigrateAnswer(cmd, true, null, 0);
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-	}
+        }
+    }
 
     @Override
     public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) {
@@ -457,81 +492,81 @@ public class MockVmManagerImpl implements MockVmManager {
     }
 
     @Override
-	public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid());
-			for (MockSecurityRulesVO rule : rules) {
-				MockVMVO vm = _mockVmDao.findByVmNameAndHost(rule.getVmName(), info.getHostUuid());
-				if (vm == null) {
-					_mockSecurityDao.remove(rule.getId());
-				}
-			}
-			txn.commit();
-			return new Answer(cmd);
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to clean up rules", ex);
-		} finally {
-			txn.close();
+    public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid());
+            for (MockSecurityRulesVO rule : rules) {
+                MockVMVO vm = _mockVmDao.findByVmNameAndHost(rule.getVmName(), info.getHostUuid());
+                if (vm == null) {
+                    _mockSecurityDao.remove(rule.getId());
+                }
+            }
+            txn.commit();
+            return new Answer(cmd);
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to clean up rules", ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-	}
-
-    @Override
-	public Answer stopVM(StopCommand cmd) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			String vmName = cmd.getVmName();
-			MockVm vm = _mockVmDao.findByVmName(vmName);
-			if (vm != null) {
-				vm.setState(State.Stopped);
-				_mockVmDao.update(vm.getId(), (MockVMVO) vm);
-			}
-
-			if (vmName.startsWith("s-")) {
-				_mockAgentMgr.handleSystemVMStop(vm.getId());
-			}
-			txn.commit();
-			return new StopAnswer(cmd, null, new Integer(0), true);
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
-		} finally {
-			txn.close();
+        }
+    }
+
+    @Override
+    public Answer stopVM(StopCommand cmd) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            String vmName = cmd.getVmName();
+            MockVm vm = _mockVmDao.findByVmName(vmName);
+            if (vm != null) {
+                vm.setState(State.Stopped);
+                _mockVmDao.update(vm.getId(), (MockVMVO) vm);
+            }
+
+            if (vmName.startsWith("s-")) {
+                _mockAgentMgr.handleSystemVMStop(vm.getId());
+            }
+            txn.commit();
+            return new StopAnswer(cmd, null, new Integer(0), true);
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
+        } finally {
+            txn.close();
+            txn = Transaction.open(Transaction.CLOUD_DB);
+            txn.close();
+        }
+    }
+
+    @Override
+    public Answer rebootVM(RebootCommand cmd) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
+            if (vm != null) {
+                vm.setState(State.Running);
+                _mockVmDao.update(vm.getId(), (MockVMVO) vm);
+            }
+            txn.commit();
+            return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
+        } finally {
+            txn.close();
             txn = Transaction.open(Transaction.CLOUD_DB);
             txn.close();
-		}
-	}
-
-    @Override
-	public Answer rebootVM(RebootCommand cmd) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
-			if (vm != null) {
-				vm.setState(State.Running);
-				_mockVmDao.update(vm.getId(), (MockVMVO) vm);
-			}
-			txn.commit();
-			return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
-		} finally {
-			txn.close();
-			txn = Transaction.open(Transaction.CLOUD_DB);
-			txn.close();
-		}
-	}
+        }
+    }
 
     @Override
     public Answer getVncPort(GetVncPortCommand cmd) {
-          return new GetVncPortAnswer(cmd, 0);
+        return new GetVncPortAnswer(cmd, 0);
     }
 
     @Override
@@ -546,13 +581,13 @@ public class MockVmManagerImpl implements MockVmManager {
 
     @Override
     public GetDomRVersionAnswer getDomRVersion(GetDomRVersionCmd cmd) {
-	return new GetDomRVersionAnswer(cmd, null, null, null);
+        return new GetDomRVersionAnswer(cmd, null, null, null);
     }
 
     @Override
     public SecurityGroupRuleAnswer AddSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info) {
         if (!info.isEnabled()) {
-		return new SecurityGroupRuleAnswer(cmd, false, "Disabled", SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL);
+            return new SecurityGroupRuleAnswer(cmd, false, "Disabled", SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL);
         }
 
         Map<String, Ternary<String,Long, Long>> rules = _securityRules.get(info.getHostUuid());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/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 25e7d48..b0bc703 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -16,30 +16,84 @@
 // under the License.
 package com.cloud.agent.manager;
 
-import com.cloud.agent.api.*;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.AttachIsoCommand;
+import com.cloud.agent.api.AttachVolumeCommand;
+import com.cloud.agent.api.BackupSnapshotCommand;
+import com.cloud.agent.api.BumpUpPriorityCommand;
+import com.cloud.agent.api.CheckHealthCommand;
+import com.cloud.agent.api.CheckNetworkCommand;
+import com.cloud.agent.api.CheckRouterCommand;
+import com.cloud.agent.api.CheckVirtualMachineCommand;
+import com.cloud.agent.api.CleanupNetworkRulesCmd;
+import com.cloud.agent.api.ClusterSyncCommand;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.ComputeChecksumCommand;
+import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
+import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
+import com.cloud.agent.api.CreateStoragePoolCommand;
+import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
+import com.cloud.agent.api.DeleteSnapshotBackupCommand;
+import com.cloud.agent.api.DeleteStoragePoolCommand;
+import com.cloud.agent.api.GetDomRVersionCmd;
+import com.cloud.agent.api.GetHostStatsCommand;
+import com.cloud.agent.api.GetStorageStatsCommand;
+import com.cloud.agent.api.GetVmStatsCommand;
+import com.cloud.agent.api.GetVncPortCommand;
+import com.cloud.agent.api.MaintainCommand;
+import com.cloud.agent.api.ManageSnapshotCommand;
+import com.cloud.agent.api.MigrateCommand;
+import com.cloud.agent.api.ModifyStoragePoolCommand;
+import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.agent.api.PingTestCommand;
+import com.cloud.agent.api.PrepareForMigrationCommand;
+import com.cloud.agent.api.RebootCommand;
+import com.cloud.agent.api.SecStorageSetupCommand;
+import com.cloud.agent.api.SecStorageVMSetupCommand;
+import com.cloud.agent.api.SecurityGroupRulesCmd;
+import com.cloud.agent.api.StartCommand;
+import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.StoragePoolInfo;
 import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
 import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
-import com.cloud.agent.api.routing.*;
-import com.cloud.agent.api.storage.*;
+import com.cloud.agent.api.routing.DhcpEntryCommand;
+import com.cloud.agent.api.routing.IpAssocCommand;
+import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
+import com.cloud.agent.api.routing.SavePasswordCommand;
+import com.cloud.agent.api.routing.SetFirewallRulesCommand;
+import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
+import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
+import com.cloud.agent.api.routing.VmDataCommand;
+import com.cloud.agent.api.storage.CopyVolumeCommand;
+import com.cloud.agent.api.storage.CreateCommand;
+import com.cloud.agent.api.storage.DeleteTemplateCommand;
+import com.cloud.agent.api.storage.DestroyCommand;
+import com.cloud.agent.api.storage.DownloadCommand;
+import com.cloud.agent.api.storage.DownloadProgressCommand;
+import com.cloud.agent.api.storage.ListTemplateCommand;
+import com.cloud.agent.api.storage.ListVolumeCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.simulator.MockConfigurationVO;
 import com.cloud.simulator.MockHost;
 import com.cloud.simulator.MockVMVO;
 import com.cloud.simulator.dao.MockConfigurationDao;
 import com.cloud.simulator.dao.MockHostDao;
 import com.cloud.utils.Pair;
-
 import com.cloud.utils.db.ConnectionConcierge;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine.State;
-import org.apache.log4j.Logger;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-import java.util.HashMap;
-import java.util.Map;
 
 @Local(value = { SimulatorManager.class })
 public class SimulatorManagerImpl implements SimulatorManager {
@@ -57,7 +111,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
     private ConnectionConcierge _concierge;
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-    /*
+        /*
         try {
             Connection conn = Transaction.getStandaloneSimulatorConnection();
             conn.setAutoCommit(true);
@@ -65,7 +119,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
         } catch (SQLException e) {
             throw new CloudRuntimeException("Unable to get a db connection to simulator", e);
         }
-	*/
+         */
         return true;
     }
 
@@ -146,7 +200,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
             } else if (cmd instanceof PingTestCommand) {
                 return _mockAgentMgr.pingTest((PingTestCommand) cmd);
             } else if (cmd instanceof PrepareForMigrationCommand) {
-			return _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
+                return _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
             } else if (cmd instanceof MigrateCommand) {
                 return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
             } else if (cmd instanceof StartCommand) {
@@ -154,11 +208,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) {
@@ -174,7 +228,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) {
@@ -244,11 +298,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 Answer(cmd);
             } else if (cmd instanceof CopyVolumeCommand) {
-	        	return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
+                return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
             } else {
                 return Answer.createUnsupportedCommandAnswer(cmd);
             }
@@ -270,49 +324,49 @@ public class SimulatorManagerImpl implements SimulatorManager {
 
     @Override
     public Map<String, State> getVmStates(String hostGuid) {
-	return _mockVmMgr.getVmStates(hostGuid);
+        return _mockVmMgr.getVmStates(hostGuid);
     }
 
     @Override
     public Map<String, MockVMVO> getVms(String hostGuid) {
-	return _mockVmMgr.getVms(hostGuid);
+        return _mockVmMgr.getVms(hostGuid);
     }
 
     @Override
     public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid) {
-	SimulatorInfo info = new SimulatorInfo();
-	info.setHostUuid(hostGuid);
-	return _mockVmMgr.syncNetworkGroups(info);
+        SimulatorInfo info = new SimulatorInfo();
+        info.setHostUuid(hostGuid);
+        return _mockVmMgr.syncNetworkGroups(info);
     }
 
     @Override
-	public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
-			String values) {
-		Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-		try {
-			txn.start();
-			MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
-			if (config == null) {
-				config = new MockConfigurationVO();
-				config.setClusterId(clusterId);
-				config.setDataCenterId(zoneId);
-				config.setPodId(podId);
-				config.setHostId(hostId);
-				config.setName(command);
-				config.setValues(values);
-				_mockConfigDao.persist(config);
-				txn.commit();
-			} else {
-				config.setValues(values);
-				_mockConfigDao.update(config.getId(), config);
-				txn.commit();
-			}
-		} catch (Exception ex) {
-			txn.rollback();
-			throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
-		} finally {
-			txn.close();
-		}
-		return true;
-	}
+    public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
+            String values) {
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        try {
+            txn.start();
+            MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
+            if (config == null) {
+                config = new MockConfigurationVO();
+                config.setClusterId(clusterId);
+                config.setDataCenterId(zoneId);
+                config.setPodId(podId);
+                config.setHostId(hostId);
+                config.setName(command);
+                config.setValues(values);
+                _mockConfigDao.persist(config);
+                txn.commit();
+            } else {
+                config.setValues(values);
+                _mockConfigDao.update(config.getId(), config);
+                txn.commit();
+            }
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
+        } finally {
+            txn.close();
+        }
+        return true;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java b/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java
index e4e76bb..205484d 100755
--- a/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java
@@ -16,20 +16,21 @@
 // under the License.
 package com.cloud.api.commands;
 
-import org.apache.log4j.Logger;
+import javax.inject.Inject;
 
-import com.cloud.agent.manager.SimulatorManager;
+import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.manager.SimulatorManager;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.server.ManagementService;
 import com.cloud.user.Account;
 
 
@@ -38,6 +39,8 @@ public class ConfigureSimulator extends BaseCmd {
     public static final Logger s_logger = Logger.getLogger(ConfigureSimulator.class.getName());
     private static final String s_name = "configuresimulatorresponse";
 
+    @Inject SimulatorManager _simMgr;
+
     @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="configure range: in a zone")
     private Long zoneId;
 
@@ -58,8 +61,6 @@ public class ConfigureSimulator extends BaseCmd {
 
     @Override
     public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
-        ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
-        SimulatorManager _simMgr = locator.getManager(SimulatorManager.class);
         boolean result = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values);
         if (!result) {
             throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure simulator");

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/hypervisors/simulator/src/com/cloud/resource/AgentResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentResourceBase.java b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentResourceBase.java
index ee6d8a3..de3bfd9 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentResourceBase.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentResourceBase.java
@@ -26,6 +26,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
@@ -46,239 +47,237 @@ import com.cloud.simulator.MockHost;
 
 
 public class AgentResourceBase implements ServerResource {
-	private static final Logger s_logger = Logger
-			.getLogger(AgentResourceBase.class);
+    private static final Logger s_logger = Logger.getLogger(AgentResourceBase.class);
 
-	protected String _name;
-	private List<String> _warnings = new LinkedList<String>();
-	private List<String> _errors = new LinkedList<String>();
+    protected String _name;
+    private List<String> _warnings = new LinkedList<String>();
+    private List<String> _errors = new LinkedList<String>();
 
-	private transient IAgentControl _agentControl;
+    private transient IAgentControl _agentControl;
 
-	protected long _instanceId;
+    protected long _instanceId;
 
-	private Type _type;
+    private Type _type;
 
-	private transient ComponentLocator _locator = null;
-	protected transient SimulatorManager _simMgr;
-	protected MockHost agentHost = null;
-	protected boolean stopped = false;
-	protected String hostGuid = null;
+    @Inject protected SimulatorManager _simMgr;
+    protected MockHost agentHost = null;
+    protected boolean stopped = false;
+    protected String hostGuid = null;
 
 
-	public AgentResourceBase(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
-	    _instanceId = instanceId;
+    public AgentResourceBase(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
+        _instanceId = instanceId;
 
-		if(s_logger.isDebugEnabled()) {
-			s_logger.info("New Routing host instantiated with guid:" + hostGuid);
-		}
+        if(s_logger.isDebugEnabled()) {
+            s_logger.info("New Routing host instantiated with guid:" + hostGuid);
+        }
 
-		if (agentType == AgentType.Routing) {
-			_type = Host.Type.Routing;
-		} else {
-			_type = Host.Type.Storage;
-		}
+        if (agentType == AgentType.Routing) {
+            _type = Host.Type.Routing;
+        } else {
+            _type = Host.Type.Storage;
+        }
 
-		this.hostGuid = hostGuid;
-	}
+        this.hostGuid = hostGuid;
+    }
 
-	protected MockVmManager getVmMgr() {
-	    return _simMgr.getVmMgr();
-	}
+    protected MockVmManager getVmMgr() {
+        return _simMgr.getVmMgr();
+    }
 
-	protected MockStorageManager getStorageMgr() {
-	    return _simMgr.getStorageMgr();
-	}
+    protected MockStorageManager getStorageMgr() {
+        return _simMgr.getStorageMgr();
+    }
 
-	protected MockAgentManager getAgentMgr() {
-	    return _simMgr.getAgentMgr();
-	}
+    protected MockAgentManager getAgentMgr() {
+        return _simMgr.getAgentMgr();
+    }
 
-	protected long getInstanceId() {
-	    return _instanceId;
-	}
+    protected long getInstanceId() {
+        return _instanceId;
+    }
 
-	public AgentResourceBase() {
-		if(s_logger.isDebugEnabled()) {
-			s_logger.debug("Deserializing simulated agent on reconnect");
-		}
+    public AgentResourceBase() {
+        if(s_logger.isDebugEnabled()) {
+            s_logger.debug("Deserializing simulated agent on reconnect");
+        }
 
-	}
+    }
 
-	@Override
-	public String getName() {
-		return _name;
-	}
+    @Override
+    public String getName() {
+        return _name;
+    }
 
-	public void setName(String name) {
-		_name = name;
-	}
+    public void setName(String name) {
+        _name = name;
+    }
 
-	@Override
-	public boolean configure(String name, Map<String, Object> params)
-			throws ConfigurationException {
-	    hostGuid = (String)params.get("guid");
-	    _locator = ComponentLocator.getLocator("management-server");
+    @Override
+    public boolean configure(String name, Map<String, Object> params)
+            throws ConfigurationException {
+        hostGuid = (String)params.get("guid");
+        _locator = ComponentLocator.getLocator("management-server");
         _simMgr = _locator.getManager(SimulatorManager.class);
 
-	    agentHost = getAgentMgr().getHost(hostGuid);
-	    return true;
-	}
-
-
-	private void reconnect(MockHost host) {
-		if(s_logger.isDebugEnabled()) {
-			s_logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid());
-		}
-		this.agentHost = host;
-	}
-
-
-	@Override
-	public void disconnected() {
-	    this.stopped = true;
-	}
-
-	protected void recordWarning(String msg, Throwable th) {
-		String str = getLogStr(msg, th);
-		synchronized (_warnings) {
-			_warnings.add(str);
-		}
-	}
-
-	protected void recordWarning(String msg) {
-		recordWarning(msg, null);
-	}
-
-	protected List<String> getWarnings() {
-		synchronized (this) {
-			List<String> results = _warnings;
-			_warnings = new ArrayList<String>();
-			return results;
-		}
-	}
-
-	protected List<String> getErrors() {
-		synchronized (this) {
-			List<String> result = _errors;
-			_errors = new ArrayList<String>();
-			return result;
-		}
-	}
-
-	protected void recordError(String msg, Throwable th) {
-		String str = getLogStr(msg, th);
-		synchronized (_errors) {
-			_errors.add(str);
-		}
-	}
-
-	protected void recordError(String msg) {
-		recordError(msg, null);
-	}
-
-	protected Answer createErrorAnswer(Command cmd, String msg, Throwable th) {
-		StringWriter writer = new StringWriter();
-		if (msg != null) {
-			writer.append(msg);
-		}
-		writer.append("===>Stack<===");
-		th.printStackTrace(new PrintWriter(writer));
-		return new Answer(cmd, false, writer.toString());
-	}
-
-	protected String createErrorDetail(String msg, Throwable th) {
-		StringWriter writer = new StringWriter();
-		if (msg != null) {
-			writer.append(msg);
-		}
-		writer.append("===>Stack<===");
-		th.printStackTrace(new PrintWriter(writer));
-		return writer.toString();
-	}
-
-	protected String getLogStr(String msg, Throwable th) {
-		StringWriter writer = new StringWriter();
-		writer.append(new Date().toString()).append(": ").append(msg);
-		if (th != null) {
-			writer.append("\n  Exception: ");
-			th.printStackTrace(new PrintWriter(writer));
-		}
-		return writer.toString();
-	}
-
-	@Override
-	public boolean start() {
-		return true;
-	}
-
-	@Override
-	public boolean stop() {
-	    this.stopped = true;
-		return true;
-	}
-
-	@Override
-	public IAgentControl getAgentControl() {
-		return _agentControl;
-	}
-
-	@Override
-	public void setAgentControl(IAgentControl agentControl) {
-		_agentControl = agentControl;
-	}
-
-	protected String findScript(String script) {
-		s_logger.debug("Looking for " + script + " in the classpath");
-		URL url = ClassLoader.getSystemResource(script);
-		File file = null;
-		if (url == null) {
-			file = new File("./" + script);
-			s_logger.debug("Looking for " + script + " in "
-					+ file.getAbsolutePath());
-			if (!file.exists()) {
-				return null;
-			}
-		} else {
-			file = new File(url.getFile());
-		}
-		return file.getAbsolutePath();
-	}
-
-
-	@Override
-	public Answer executeRequest(Command cmd) {
-		return null;
-	}
-
-	@Override
-	public PingCommand getCurrentStatus(long id) {
-		return null;
-	}
-
-	@Override
-	public Type getType() {
-		return _type;
-	}
-
-	public void setType(Host.Type _type) {
-		this._type = _type;
-	}
-
-	@Override
-	public StartupCommand[] initialize() {
-		return null;
-	}
-
-	public SimulatorManager getSimulatorManager() {
-		return _simMgr;
-	}
-
-	public void setSimulatorManager(SimulatorManager simMgr) {
-		_simMgr = simMgr;
-	}
-
-	public boolean isStopped() {
-	    return this.stopped;
-	}
+        agentHost = getAgentMgr().getHost(hostGuid);
+        return true;
+    }
+
+
+    private void reconnect(MockHost host) {
+        if(s_logger.isDebugEnabled()) {
+            s_logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid());
+        }
+        this.agentHost = host;
+    }
+
+
+    @Override
+    public void disconnected() {
+        this.stopped = true;
+    }
+
+    protected void recordWarning(String msg, Throwable th) {
+        String str = getLogStr(msg, th);
+        synchronized (_warnings) {
+            _warnings.add(str);
+        }
+    }
+
+    protected void recordWarning(String msg) {
+        recordWarning(msg, null);
+    }
+
+    protected List<String> getWarnings() {
+        synchronized (this) {
+            List<String> results = _warnings;
+            _warnings = new ArrayList<String>();
+            return results;
+        }
+    }
+
+    protected List<String> getErrors() {
+        synchronized (this) {
+            List<String> result = _errors;
+            _errors = new ArrayList<String>();
+            return result;
+        }
+    }
+
+    protected void recordError(String msg, Throwable th) {
+        String str = getLogStr(msg, th);
+        synchronized (_errors) {
+            _errors.add(str);
+        }
+    }
+
+    protected void recordError(String msg) {
+        recordError(msg, null);
+    }
+
+    protected Answer createErrorAnswer(Command cmd, String msg, Throwable th) {
+        StringWriter writer = new StringWriter();
+        if (msg != null) {
+            writer.append(msg);
+        }
+        writer.append("===>Stack<===");
+        th.printStackTrace(new PrintWriter(writer));
+        return new Answer(cmd, false, writer.toString());
+    }
+
+    protected String createErrorDetail(String msg, Throwable th) {
+        StringWriter writer = new StringWriter();
+        if (msg != null) {
+            writer.append(msg);
+        }
+        writer.append("===>Stack<===");
+        th.printStackTrace(new PrintWriter(writer));
+        return writer.toString();
+    }
+
+    protected String getLogStr(String msg, Throwable th) {
+        StringWriter writer = new StringWriter();
+        writer.append(new Date().toString()).append(": ").append(msg);
+        if (th != null) {
+            writer.append("\n  Exception: ");
+            th.printStackTrace(new PrintWriter(writer));
+        }
+        return writer.toString();
+    }
+
+    @Override
+    public boolean start() {
+        return true;
+    }
+
+    @Override
+    public boolean stop() {
+        this.stopped = true;
+        return true;
+    }
+
+    @Override
+    public IAgentControl getAgentControl() {
+        return _agentControl;
+    }
+
+    @Override
+    public void setAgentControl(IAgentControl agentControl) {
+        _agentControl = agentControl;
+    }
+
+    protected String findScript(String script) {
+        s_logger.debug("Looking for " + script + " in the classpath");
+        URL url = ClassLoader.getSystemResource(script);
+        File file = null;
+        if (url == null) {
+            file = new File("./" + script);
+            s_logger.debug("Looking for " + script + " in "
+                    + file.getAbsolutePath());
+            if (!file.exists()) {
+                return null;
+            }
+        } else {
+            file = new File(url.getFile());
+        }
+        return file.getAbsolutePath();
+    }
+
+
+    @Override
+    public Answer executeRequest(Command cmd) {
+        return null;
+    }
+
+    @Override
+    public PingCommand getCurrentStatus(long id) {
+        return null;
+    }
+
+    @Override
+    public Type getType() {
+        return _type;
+    }
+
+    public void setType(Host.Type _type) {
+        this._type = _type;
+    }
+
+    @Override
+    public StartupCommand[] initialize() {
+        return null;
+    }
+
+    public SimulatorManager getSimulatorManager() {
+        return _simMgr;
+    }
+
+    public void setSimulatorManager(SimulatorManager simMgr) {
+        _simMgr = simMgr;
+    }
+
+    public boolean isStopped() {
+        return this.stopped;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorDiscoverer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorDiscoverer.java b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorDiscoverer.java
index 69ada14..5cb0941 100755
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorDiscoverer.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorDiscoverer.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.UUID;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
@@ -43,12 +44,10 @@ import com.cloud.dc.ClusterVO;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.exception.ConnectionException;
 import com.cloud.exception.DiscoveryException;
-import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.storage.VMTemplateHostVO;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VMTemplateZoneVO;
 import com.cloud.storage.dao.VMTemplateDao;
@@ -58,11 +57,11 @@ import com.cloud.storage.dao.VMTemplateZoneDao;
 
 @Local(value = Discoverer.class)
 public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
-	private static final Logger s_logger = Logger
-			.getLogger(SimulatorDiscoverer.class);
+    private static final Logger s_logger = Logger
+            .getLogger(SimulatorDiscoverer.class);
 
-	@Inject HostDao _hostDao;
-	@Inject VMTemplateDao _vmTemplateDao;
+    @Inject HostDao _hostDao;
+    @Inject VMTemplateDao _vmTemplateDao;
     @Inject VMTemplateHostDao _vmTemplateHostDao;
     @Inject VMTemplateZoneDao _vmTemplateZoneDao;
     @Inject ClusterDao _clusterDao;
@@ -71,166 +70,166 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L
     @Inject MockStorageManager _mockStorageMgr = null;
     @Inject ResourceManager _resourceMgr;
 
-	/**
-	 * Finds ServerResources of an in-process simulator
-	 *
-	 * @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
-	 *      java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
-	 */
-	@Override
-	public Map<? extends ServerResource, Map<String, String>> find(long dcId,
-			Long podId, Long clusterId, URI uri, String username,
-			String password, List<String> hostTags) throws DiscoveryException {
-		Map<AgentResourceBase, Map<String, String>> resources;
-
-		try {
-		    //http://sim/count=$count, it will add $count number of hosts into the cluster
-		    String scheme = uri.getScheme();
-		    String host = uri.getAuthority();
-		    String commands = URLDecoder.decode(uri.getPath());
-
-		    long cpuSpeed = _mockAgentMgr.DEFAULT_HOST_SPEED_MHZ;
-		    long cpuCores = _mockAgentMgr.DEFAULT_HOST_CPU_CORES;
-		    long memory = _mockAgentMgr.DEFAULT_HOST_MEM_SIZE;
-		    long localstorageSize = _mockStorageMgr.DEFAULT_HOST_STORAGE_SIZE;
-			if (scheme.equals("http")) {
-				if (host == null || !host.startsWith("sim")) {
-					String msg = "uri is not of simulator type so we're not taking care of the discovery for this: "
-							+ uri;
-					if(s_logger.isDebugEnabled()) {
-						s_logger.debug(msg);
-					}
-					return null;
-				}
-				if (commands != null) {
-				    int index = commands.lastIndexOf("/");
-				    if (index != -1) {
-				        commands = commands.substring(index+1);
-
-				        String[] cmds = commands.split("&");
-				        for (String cmd : cmds) {
-				            String[] parameter = cmd.split("=");
-				            if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
-				                cpuSpeed = Long.parseLong(parameter[1]);
-				            } else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
-				                cpuCores = Long.parseLong(parameter[1]);
-				            } else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
-				                memory = Long.parseLong(parameter[1]);
-				            } else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
-				                localstorageSize = Long.parseLong(parameter[1]);
-				            }
-				        }
-				    }
-				}
-			} else {
-				String msg = "uriString is not http so we're not taking care of the discovery for this: "
-						+ uri;
-				if(s_logger.isDebugEnabled()) {
-					s_logger.debug(msg);
-				}
-				return null;
-			}
-
-			String cluster = null;
-			if (clusterId == null) {
-				String msg = "must specify cluster Id when adding host";
-				if(s_logger.isDebugEnabled()) {
-					s_logger.debug(msg);
-				}
-				throw new RuntimeException(msg);
-			} else {
-				ClusterVO clu = _clusterDao.findById(clusterId);
-				if (clu == null
-						|| (clu.getHypervisorType() != HypervisorType.Simulator)) {
-					if (s_logger.isInfoEnabled())
-						s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
-					return null;
-				}
-				cluster = Long.toString(clusterId);
-				if(clu.getGuid() == null) {
-					clu.setGuid(UUID.randomUUID().toString());
-				}
-				_clusterDao.update(clusterId, clu);
-			}
-
-			String pod;
-			if (podId == null) {
-				String msg = "must specify pod Id when adding host";
-				if(s_logger.isDebugEnabled()) {
-					s_logger.debug(msg);
-				}
-				throw new RuntimeException(msg);
-			} else {
-				pod = Long.toString(podId);
-			}
-
-			Map<String, String> details = new HashMap<String, String>();
-			Map<String, Object> params = new HashMap<String, Object>();
-			details.put("username", username);
-			params.put("username", username);
-			details.put("password", password);
-			params.put("password", password);
-			params.put("zone", Long.toString(dcId));
-			params.put("pod", pod);
-			params.put("cluster", cluster);
-			params.put("cpuspeed", Long.toString(cpuSpeed));
-			params.put("cpucore", Long.toString(cpuCores));
-			params.put("memory", Long.toString(memory));
-			params.put("localstorage", Long.toString(localstorageSize));
-
-			resources = createAgentResources(params);
-			return resources;
-		} catch (Exception ex) {
-			s_logger.error("Exception when discovering simulator hosts: "
-					+ ex.getMessage());
-		}
-		return null;
-	}
-
-	private Map<AgentResourceBase, Map<String, String>> createAgentResources(
-			Map<String, Object> params) {
-		try {
-			s_logger.info("Creating Simulator Resources");
-			return _mockAgentMgr.createServerResources(params);
-		} catch (Exception ex) {
-			s_logger.warn("Caught exception at agent resource creation: "
-					+ ex.getMessage(), ex);
-		}
-		return null;
-	}
-
-	@Override
-	public void postDiscovery(List<HostVO> hosts, long msId) {
-
-		for (HostVO h : hosts) {
-			associateTemplatesToZone(h.getId(), h.getDataCenterId());
-		}
-	}
+    /**
+     * Finds ServerResources of an in-process simulator
+     *
+     * @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
+     *      java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
+     */
+    @Override
+    public Map<? extends ServerResource, Map<String, String>> find(long dcId,
+            Long podId, Long clusterId, URI uri, String username,
+            String password, List<String> hostTags) throws DiscoveryException {
+        Map<AgentResourceBase, Map<String, String>> resources;
+
+        try {
+            //http://sim/count=$count, it will add $count number of hosts into the cluster
+            String scheme = uri.getScheme();
+            String host = uri.getAuthority();
+            String commands = URLDecoder.decode(uri.getPath());
+
+            long cpuSpeed = _mockAgentMgr.DEFAULT_HOST_SPEED_MHZ;
+            long cpuCores = _mockAgentMgr.DEFAULT_HOST_CPU_CORES;
+            long memory = _mockAgentMgr.DEFAULT_HOST_MEM_SIZE;
+            long localstorageSize = _mockStorageMgr.DEFAULT_HOST_STORAGE_SIZE;
+            if (scheme.equals("http")) {
+                if (host == null || !host.startsWith("sim")) {
+                    String msg = "uri is not of simulator type so we're not taking care of the discovery for this: "
+                            + uri;
+                    if(s_logger.isDebugEnabled()) {
+                        s_logger.debug(msg);
+                    }
+                    return null;
+                }
+                if (commands != null) {
+                    int index = commands.lastIndexOf("/");
+                    if (index != -1) {
+                        commands = commands.substring(index+1);
+
+                        String[] cmds = commands.split("&");
+                        for (String cmd : cmds) {
+                            String[] parameter = cmd.split("=");
+                            if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
+                                cpuSpeed = Long.parseLong(parameter[1]);
+                            } else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
+                                cpuCores = Long.parseLong(parameter[1]);
+                            } else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
+                                memory = Long.parseLong(parameter[1]);
+                            } else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
+                                localstorageSize = Long.parseLong(parameter[1]);
+                            }
+                        }
+                    }
+                }
+            } else {
+                String msg = "uriString is not http so we're not taking care of the discovery for this: "
+                        + uri;
+                if(s_logger.isDebugEnabled()) {
+                    s_logger.debug(msg);
+                }
+                return null;
+            }
+
+            String cluster = null;
+            if (clusterId == null) {
+                String msg = "must specify cluster Id when adding host";
+                if(s_logger.isDebugEnabled()) {
+                    s_logger.debug(msg);
+                }
+                throw new RuntimeException(msg);
+            } else {
+                ClusterVO clu = _clusterDao.findById(clusterId);
+                if (clu == null
+                        || (clu.getHypervisorType() != HypervisorType.Simulator)) {
+                    if (s_logger.isInfoEnabled())
+                        s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
+                    return null;
+                }
+                cluster = Long.toString(clusterId);
+                if(clu.getGuid() == null) {
+                    clu.setGuid(UUID.randomUUID().toString());
+                }
+                _clusterDao.update(clusterId, clu);
+            }
+
+            String pod;
+            if (podId == null) {
+                String msg = "must specify pod Id when adding host";
+                if(s_logger.isDebugEnabled()) {
+                    s_logger.debug(msg);
+                }
+                throw new RuntimeException(msg);
+            } else {
+                pod = Long.toString(podId);
+            }
+
+            Map<String, String> details = new HashMap<String, String>();
+            Map<String, Object> params = new HashMap<String, Object>();
+            details.put("username", username);
+            params.put("username", username);
+            details.put("password", password);
+            params.put("password", password);
+            params.put("zone", Long.toString(dcId));
+            params.put("pod", pod);
+            params.put("cluster", cluster);
+            params.put("cpuspeed", Long.toString(cpuSpeed));
+            params.put("cpucore", Long.toString(cpuCores));
+            params.put("memory", Long.toString(memory));
+            params.put("localstorage", Long.toString(localstorageSize));
+
+            resources = createAgentResources(params);
+            return resources;
+        } catch (Exception ex) {
+            s_logger.error("Exception when discovering simulator hosts: "
+                    + ex.getMessage());
+        }
+        return null;
+    }
+
+    private Map<AgentResourceBase, Map<String, String>> createAgentResources(
+            Map<String, Object> params) {
+        try {
+            s_logger.info("Creating Simulator Resources");
+            return _mockAgentMgr.createServerResources(params);
+        } catch (Exception ex) {
+            s_logger.warn("Caught exception at agent resource creation: "
+                    + ex.getMessage(), ex);
+        }
+        return null;
+    }
+
+    @Override
+    public void postDiscovery(List<HostVO> hosts, long msId) {
+
+        for (HostVO h : hosts) {
+            associateTemplatesToZone(h.getId(), h.getDataCenterId());
+        }
+    }
 
     private void associateTemplatesToZone(long hostId, long dcId){
-	VMTemplateZoneVO tmpltZone;
-
-	List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
-	for (VMTemplateVO vt: allTemplates){
-		if (vt.isCrossZones()) {
-			tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
-			if (tmpltZone == null) {
-				VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
-				_vmTemplateZoneDao.persist(vmTemplateZone);
-			}
-		}
-	}
+        VMTemplateZoneVO tmpltZone;
+
+        List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
+        for (VMTemplateVO vt: allTemplates){
+            if (vt.isCrossZones()) {
+                tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
+                if (tmpltZone == null) {
+                    VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
+                    _vmTemplateZoneDao.persist(vmTemplateZone);
+                }
+            }
+        }
     }
 
-	@Override
-	public HypervisorType getHypervisorType() {
-		return HypervisorType.Simulator;
-	}
+    @Override
+    public HypervisorType getHypervisorType() {
+        return HypervisorType.Simulator;
+    }
 
-	@Override
-	public boolean matchHypervisor(String hypervisor) {
-		return hypervisor.equalsIgnoreCase(HypervisorType.Simulator.toString());
-	}
+    @Override
+    public boolean matchHypervisor(String hypervisor) {
+        return hypervisor.equalsIgnoreCase(HypervisorType.Simulator.toString());
+    }
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@@ -298,38 +297,38 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L
         return false;
     }
 
-	@Override
-	public HostVO createHostVOForConnectedAgent(HostVO host,
-			StartupCommand[] cmd) {
-		return null;
-	}
-
-	@Override
-	public HostVO createHostVOForDirectConnectAgent(HostVO host,
-			StartupCommand[] startup, ServerResource resource,
-			Map<String, String> details, List<String> hostTags) {
-		StartupCommand firstCmd = startup[0];
-		if (!(firstCmd instanceof StartupRoutingCommand)) {
-			return null;
-		}
-
-		StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
-		if (ssCmd.getHypervisorType() != HypervisorType.Simulator) {
-			return null;
-		}
-
-		return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Simulator, details, hostTags);
-	}
-
-	@Override
-	public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
-			boolean isForceDeleteStorage) throws UnableDeleteHostException {
-		return null;
-	}
+    @Override
+    public HostVO createHostVOForConnectedAgent(HostVO host,
+            StartupCommand[] cmd) {
+        return null;
+    }
+
+    @Override
+    public HostVO createHostVOForDirectConnectAgent(HostVO host,
+            StartupCommand[] startup, ServerResource resource,
+            Map<String, String> details, List<String> hostTags) {
+        StartupCommand firstCmd = startup[0];
+        if (!(firstCmd instanceof StartupRoutingCommand)) {
+            return null;
+        }
+
+        StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
+        if (ssCmd.getHypervisorType() != HypervisorType.Simulator) {
+            return null;
+        }
+
+        return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Simulator, details, hostTags);
+    }
+
+    @Override
+    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
+            boolean isForceDeleteStorage) throws UnableDeleteHostException {
+        return null;
+    }
 
     @Override
     public boolean stop() {
-	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
+        _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
         return super.stop();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
index 3b22ad5..cd0cd27 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
@@ -21,8 +21,11 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.log4j.Logger;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
 import com.cloud.agent.api.AgentControlAnswer;
@@ -38,9 +41,7 @@ import com.cloud.host.Status;
 import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.secondary.SecondaryStorageDiscoverer;
-
 import com.cloud.utils.exception.CloudRuntimeException;
-import org.apache.log4j.Logger;
 
 @Local(value=Discoverer.class)
 public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer implements ResourceStateAdapter, Listener {
@@ -52,7 +53,7 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-	_agentMgr.registerForHostEvents(this, true, false, false);
+        _agentMgr.registerForHostEvents(this, true, false, false);
         _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
         return super.configure(name, params);
     }
@@ -88,40 +89,40 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
         }
     }
 
-	@Override
-	public HostVO createHostVOForConnectedAgent(HostVO host,
-			StartupCommand[] cmd) {
-		return null;
-	}
-
-	@Override
-	public HostVO createHostVOForDirectConnectAgent(HostVO host,
-			StartupCommand[] startup, ServerResource resource,
-			Map<String, String> details, List<String> hostTags) {
-		//for detecting SSVM dispatch
-		StartupCommand firstCmd = startup[0];
-	    if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
-		return null;
-	    }
-
-		host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
-		return host;
-	}
-
-	@Override
-	public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
-			boolean isForceDeleteStorage) throws UnableDeleteHostException {
-		long hostId = host.getId();
-		List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
-		if (snapshots != null && !snapshots.isEmpty()) {
-			throw new CloudRuntimeException("Cannot delete this secondary storage because there are still snapshots on it ");
-		}
-		_vmTemplateHostDao.deleteByHost(hostId);
-		host.setGuid(null);
-		_hostDao.update(hostId, host);
-		_hostDao.remove(hostId);
-		return new DeleteHostAnswer(true);
-	}
+    @Override
+    public HostVO createHostVOForConnectedAgent(HostVO host,
+            StartupCommand[] cmd) {
+        return null;
+    }
+
+    @Override
+    public HostVO createHostVOForDirectConnectAgent(HostVO host,
+            StartupCommand[] startup, ServerResource resource,
+            Map<String, String> details, List<String> hostTags) {
+        //for detecting SSVM dispatch
+        StartupCommand firstCmd = startup[0];
+        if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
+            return null;
+        }
+
+        host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
+        return host;
+    }
+
+    @Override
+    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
+            boolean isForceDeleteStorage) throws UnableDeleteHostException {
+        long hostId = host.getId();
+        List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
+        if (snapshots != null && !snapshots.isEmpty()) {
+            throw new CloudRuntimeException("Cannot delete this secondary storage because there are still snapshots on it ");
+        }
+        _vmTemplateHostDao.deleteByHost(hostId);
+        host.setGuid(null);
+        _hostDao.update(hostId, host);
+        _hostDao.remove(hostId);
+        return new DeleteHostAnswer(true);
+    }
 
     @Override
     public boolean start() {
@@ -130,49 +131,49 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
 
     @Override
     public boolean stop() {
-	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
+        _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
         return true;
     }
 
-	@Override
-	public int getTimeout() {
-		return 0;
-	}
+    @Override
+    public int getTimeout() {
+        return 0;
+    }
 
-	@Override
-	public boolean isRecurring() {
-		return false;
-	}
+    @Override
+    public boolean isRecurring() {
+        return false;
+    }
 
-	@Override
-	public boolean processAnswers(long agentId, long seq, Answer[] answers) {
-		return false;
-	}
+    @Override
+    public boolean processAnswers(long agentId, long seq, Answer[] answers) {
+        return false;
+    }
 
-	@Override
-	public boolean processCommands(long agentId, long seq, Command[] commands) {
-		return false;
-	}
+    @Override
+    public boolean processCommands(long agentId, long seq, Command[] commands) {
+        return false;
+    }
 
-	@Override
-	public void processConnect(HostVO host, StartupCommand cmd,
-			boolean forRebalance) throws ConnectionException {
+    @Override
+    public void processConnect(HostVO host, StartupCommand cmd,
+            boolean forRebalance) throws ConnectionException {
 
-	}
+    }
 
-	@Override
-	public AgentControlAnswer processControlCommand(long agentId,
-			AgentControlCommand cmd) {
-		return null;
-	}
+    @Override
+    public AgentControlAnswer processControlCommand(long agentId,
+            AgentControlCommand cmd) {
+        return null;
+    }
 
-	@Override
-	public boolean processDisconnect(long agentId, Status state) {
-		return false;
-	}
+    @Override
+    public boolean processDisconnect(long agentId, Status state) {
+        return false;
+    }
 
-	@Override
-	public boolean processTimeout(long agentId, long seq) {
-		return false;
-	}
+    @Override
+    public boolean processTimeout(long agentId, long seq) {
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java
index 102ce4e..c9d3080 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java
@@ -17,14 +17,14 @@
 package com.cloud.simulator;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 
 import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.HypervisorGuru;
 import com.cloud.hypervisor.HypervisorGuruBase;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.GuestOSVO;
 import com.cloud.storage.dao.GuestOSDao;
-
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 
@@ -52,8 +52,8 @@ public class SimulatorGuru extends HypervisorGuruBase implements HypervisorGuru
         return to;
     }
 
-	@Override
-	public boolean trackVmHostChange() {
-		return false;
-	}
+    @Override
+    public boolean trackVmHostChange() {
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
index e5b30f0..be7a988 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
@@ -21,11 +21,11 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import com.cloud.simulator.MockHostVO;
 import com.cloud.simulator.MockVMVO;
-
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/plugins/user-authenticators/sha256salted/src/com/cloud/server/auth/SHA256SaltedUserAuthenticator.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/sha256salted/src/com/cloud/server/auth/SHA256SaltedUserAuthenticator.java b/plugins/user-authenticators/sha256salted/src/com/cloud/server/auth/SHA256SaltedUserAuthenticator.java
index 28ed92d..1b29f69 100644
--- a/plugins/user-authenticators/sha256salted/src/com/cloud/server/auth/SHA256SaltedUserAuthenticator.java
+++ b/plugins/user-authenticators/sha256salted/src/com/cloud/server/auth/SHA256SaltedUserAuthenticator.java
@@ -23,40 +23,38 @@ import java.security.SecureRandom;
 import java.util.Map;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.bouncycastle.util.encoders.Base64;
 
-import com.cloud.server.ManagementServer;
-import com.cloud.servlet.CloudStartupServlet;
 import com.cloud.user.UserAccount;
 import com.cloud.user.dao.UserAccountDao;
-
-
 import com.cloud.utils.exception.CloudRuntimeException;
 
 @Local(value={UserAuthenticator.class})
 public class SHA256SaltedUserAuthenticator extends DefaultUserAuthenticator {
-	public static final Logger s_logger = Logger.getLogger(SHA256SaltedUserAuthenticator.class);
-	
-	@Inject
-	private UserAccountDao _userAccountDao;
-	private static int s_saltlen = 20;
-
-	public boolean configure(String name, Map<String, Object> params)
-			throws ConfigurationException {
-		super.configure(name, params);
-		return true;
-	}
-	
-	/* (non-Javadoc)
-	 * @see com.cloud.server.auth.UserAuthenticator#authenticate(java.lang.String, java.lang.String, java.lang.Long, java.util.Map)
-	 */
-	@Override
-	public boolean authenticate(String username, String password,
-			Long domainId, Map<String, Object[]> requestParameters) {
-		if (s_logger.isDebugEnabled()) {
+    public static final Logger s_logger = Logger.getLogger(SHA256SaltedUserAuthenticator.class);
+
+    @Inject
+    private UserAccountDao _userAccountDao;
+    private static int s_saltlen = 20;
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params)
+            throws ConfigurationException {
+        super.configure(name, params);
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see com.cloud.server.auth.UserAuthenticator#authenticate(java.lang.String, java.lang.String, java.lang.Long, java.util.Map)
+     */
+    @Override
+    public boolean authenticate(String username, String password,
+            Long domainId, Map<String, Object[]> requestParameters) {
+        if (s_logger.isDebugEnabled()) {
             s_logger.debug("Retrieving user: " + username);
         }
         UserAccount user = _userAccountDao.getUserAccount(username, domainId);
@@ -64,59 +62,59 @@ public class SHA256SaltedUserAuthenticator extends DefaultUserAuthenticator {
             s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
             return false;
         }
-        
+
+        try {
+            String storedPassword[] = user.getPassword().split(":");
+            if (storedPassword.length != 2) {
+                s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator");
+                return false;
+            }
+            byte salt[] = Base64.decode(storedPassword[0]);
+            String hashedPassword = encode(password, salt);
+            return storedPassword[1].equals(hashedPassword);
+        } catch (NoSuchAlgorithmException e) {
+            throw new CloudRuntimeException("Unable to hash password", e);
+        } catch (UnsupportedEncodingException e) {
+            throw new CloudRuntimeException("Unable to hash password", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see com.cloud.server.auth.UserAuthenticator#encode(java.lang.String)
+     */
+    @Override
+    public String encode(String password) {
+        // 1. Generate the salt
+        SecureRandom randomGen;
         try {
-	        String storedPassword[] = user.getPassword().split(":");
-	        if (storedPassword.length != 2) {
-	        	s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator");
-	        	return false;
-	        }
-	        byte salt[] = Base64.decode(storedPassword[0]);
-	        String hashedPassword = encode(password, salt);
-	        return storedPassword[1].equals(hashedPassword);
-		} catch (NoSuchAlgorithmException e) {
-			throw new CloudRuntimeException("Unable to hash password", e);
-		} catch (UnsupportedEncodingException e) {
-			throw new CloudRuntimeException("Unable to hash password", e);
-		}
-	}
-
-	/* (non-Javadoc)
-	 * @see com.cloud.server.auth.UserAuthenticator#encode(java.lang.String)
-	 */
-	@Override
-	public String encode(String password) {
-		// 1. Generate the salt
-		SecureRandom randomGen;
-		try {
-			randomGen = SecureRandom.getInstance("SHA1PRNG");
-		
-			byte salt[] = new byte[s_saltlen];
-			randomGen.nextBytes(salt);
-			
-			String saltString = new String(Base64.encode(salt));
-			String hashString = encode(password, salt);
-			
-			// 3. concatenate the two and return
-			return saltString + ":" + hashString;
-		} catch (NoSuchAlgorithmException e) {
-			throw new CloudRuntimeException("Unable to hash password", e);
-		} catch (UnsupportedEncodingException e) {
-			throw new CloudRuntimeException("Unable to hash password", e);
-		}
-	}
-
-	public String encode(String password, byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException {
-		byte[] passwordBytes = password.getBytes("UTF-8");
-		byte[] hashSource = new byte[passwordBytes.length + s_saltlen];
-		System.arraycopy(passwordBytes, 0, hashSource, 0, passwordBytes.length);
-		System.arraycopy(salt, 0, hashSource, passwordBytes.length, s_saltlen);
-		
-		// 2. Hash the password with the salt
-		MessageDigest md = MessageDigest.getInstance("SHA-256");
-		md.update(hashSource);
-		byte[] digest = md.digest();
-		
-		return new String(Base64.encode(digest));
-	}
+            randomGen = SecureRandom.getInstance("SHA1PRNG");
+
+            byte salt[] = new byte[s_saltlen];
+            randomGen.nextBytes(salt);
+
+            String saltString = new String(Base64.encode(salt));
+            String hashString = encode(password, salt);
+
+            // 3. concatenate the two and return
+            return saltString + ":" + hashString;
+        } catch (NoSuchAlgorithmException e) {
+            throw new CloudRuntimeException("Unable to hash password", e);
+        } catch (UnsupportedEncodingException e) {
+            throw new CloudRuntimeException("Unable to hash password", e);
+        }
+    }
+
+    public String encode(String password, byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException {
+        byte[] passwordBytes = password.getBytes("UTF-8");
+        byte[] hashSource = new byte[passwordBytes.length + s_saltlen];
+        System.arraycopy(passwordBytes, 0, hashSource, 0, passwordBytes.length);
+        System.arraycopy(salt, 0, hashSource, passwordBytes.length, s_saltlen);
+
+        // 2. Hash the password with the salt
+        MessageDigest md = MessageDigest.getInstance("SHA-256");
+        md.update(hashSource);
+        byte[] digest = md.digest();
+
+        return new String(Base64.encode(digest));
+    }
 }


Mime
View raw message