You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by wi...@apache.org on 2012/06/23 11:40:28 UTC
[2/7] agent: Replace tabs by 4 spaces
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/DummyResource.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/DummyResource.java b/agent/src/com/cloud/agent/resource/DummyResource.java
index 26256d2..573f639 100755
--- a/agent/src/com/cloud/agent/resource/DummyResource.java
+++ b/agent/src/com/cloud/agent/resource/DummyResource.java
@@ -45,183 +45,183 @@ import com.cloud.storage.Storage.StoragePoolType;
@Local(value = { ServerResource.class })
public class DummyResource implements ServerResource {
- String _name;
- Host.Type _type;
- boolean _negative;
- IAgentControl _agentControl;
- private Map<String, Object> _params;
-
- @Override
- public void disconnected() {
- }
-
- @Override
- public Answer executeRequest(Command cmd) {
- if (cmd instanceof CheckNetworkCommand) {
- return new CheckNetworkAnswer((CheckNetworkCommand) cmd, true, null);
- }
- System.out.println("Received Command: " + cmd.toString());
- Answer answer = new Answer(cmd, !_negative, "response");
- System.out.println("Replying with: " + answer.toString());
- return answer;
- }
-
- @Override
- public PingCommand getCurrentStatus(long id) {
- return new PingCommand(_type, id);
- }
-
- @Override
- public Type getType() {
- return _type;
- }
-
- protected String getConfiguredProperty(String key, String defaultValue) {
- String val = (String) _params.get(key);
- return val == null ? defaultValue : val;
- }
-
- protected Long getConfiguredProperty(String key, Long defaultValue) {
- String val = (String) _params.get(key);
-
- if (val != null) {
- Long result = Long.parseLong(val);
- return result;
- }
- return defaultValue;
- }
-
- protected List<Object> getHostInfo() {
- final ArrayList<Object> info = new ArrayList<Object>();
- long speed = getConfiguredProperty("cpuspeed", 4000L);
- long cpus = getConfiguredProperty("cpus", 4L);
- long ram = getConfiguredProperty("memory", 16000L * 1024L * 1024L);
- long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
-
- String cap = getConfiguredProperty("capabilities", "hvm");
- info.add((int) cpus);
- info.add(speed);
- info.add(ram);
- info.add(cap);
- info.add(dom0ram);
- return info;
-
- }
-
- protected void fillNetworkInformation(final StartupCommand cmd) {
-
- cmd.setPrivateIpAddress((String) getConfiguredProperty(
- "private.ip.address", "127.0.0.1"));
- cmd.setPrivateMacAddress((String) getConfiguredProperty(
- "private.mac.address", "8A:D2:54:3F:7C:C3"));
- cmd.setPrivateNetmask((String) getConfiguredProperty(
- "private.ip.netmask", "255.255.255.0"));
-
- cmd.setStorageIpAddress((String) getConfiguredProperty(
- "private.ip.address", "127.0.0.1"));
- cmd.setStorageMacAddress((String) getConfiguredProperty(
- "private.mac.address", "8A:D2:54:3F:7C:C3"));
- cmd.setStorageNetmask((String) getConfiguredProperty(
- "private.ip.netmask", "255.255.255.0"));
- cmd.setGatewayIpAddress((String) getConfiguredProperty(
- "gateway.ip.address", "127.0.0.1"));
-
- }
-
- private Map<String, String> getVersionStrings() {
- Map<String, String> result = new HashMap<String, String>();
- String hostOs = (String) _params.get("Host.OS");
- String hostOsVer = (String) _params.get("Host.OS.Version");
- String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
- result.put("Host.OS", hostOs == null ? "Fedora" : hostOs);
- result.put("Host.OS.Version", hostOsVer == null ? "14" : hostOsVer);
- result.put("Host.OS.Kernel.Version",
- hostOsKernVer == null ? "2.6.35.6-45.fc14.x86_64"
- : hostOsKernVer);
- return result;
- }
-
- protected StoragePoolInfo initializeLocalStorage() {
- String hostIp = (String) getConfiguredProperty("private.ip.address",
- "127.0.0.1");
- String localStoragePath = (String) getConfiguredProperty(
- "local.storage.path", "/mnt");
- String lh = hostIp + localStoragePath;
- String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
-
- String capacity = (String) getConfiguredProperty(
- "local.storage.capacity", "1000000000");
- String available = (String) getConfiguredProperty(
- "local.storage.avail", "10000000");
-
- return new StoragePoolInfo(uuid, hostIp, localStoragePath,
- localStoragePath, StoragePoolType.Filesystem,
- Long.parseLong(capacity), Long.parseLong(available));
-
- }
-
- @Override
- public StartupCommand[] initialize() {
- Map<String, VmState> changes = null;
-
- final List<Object> info = getHostInfo();
-
- final StartupRoutingCommand cmd = new StartupRoutingCommand(
- (Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
- (Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
- RouterPrivateIpStrategy.HostLocal, changes);
- fillNetworkInformation(cmd);
- cmd.getHostDetails().putAll(getVersionStrings());
- cmd.setCluster(getConfiguredProperty("cluster", "1"));
- StoragePoolInfo pi = initializeLocalStorage();
- StartupStorageCommand sscmd = new StartupStorageCommand();
- sscmd.setPoolInfo(pi);
- sscmd.setGuid(pi.getUuid());
- sscmd.setDataCenter((String) _params.get("zone"));
- sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
-
- return new StartupCommand[] { cmd, sscmd };
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params) {
- _name = name;
-
- String value = (String) params.get("type");
- _type = Host.Type.valueOf(value);
-
- value = (String) params.get("negative.reply");
- _negative = Boolean.parseBoolean(value);
- setParams(params);
- return true;
- }
-
- public void setParams(Map<String, Object> _params) {
- this._params = _params;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- @Override
- public boolean start() {
- return true;
- }
-
- @Override
- public boolean stop() {
- return true;
- }
-
- @Override
- public IAgentControl getAgentControl() {
- return _agentControl;
- }
-
- @Override
- public void setAgentControl(IAgentControl agentControl) {
- _agentControl = agentControl;
- }
+ String _name;
+ Host.Type _type;
+ boolean _negative;
+ IAgentControl _agentControl;
+ private Map<String, Object> _params;
+
+ @Override
+ public void disconnected() {
+ }
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ if (cmd instanceof CheckNetworkCommand) {
+ return new CheckNetworkAnswer((CheckNetworkCommand) cmd, true, null);
+ }
+ System.out.println("Received Command: " + cmd.toString());
+ Answer answer = new Answer(cmd, !_negative, "response");
+ System.out.println("Replying with: " + answer.toString());
+ return answer;
+ }
+
+ @Override
+ public PingCommand getCurrentStatus(long id) {
+ return new PingCommand(_type, id);
+ }
+
+ @Override
+ public Type getType() {
+ return _type;
+ }
+
+ protected String getConfiguredProperty(String key, String defaultValue) {
+ String val = (String) _params.get(key);
+ return val == null ? defaultValue : val;
+ }
+
+ protected Long getConfiguredProperty(String key, Long defaultValue) {
+ String val = (String) _params.get(key);
+
+ if (val != null) {
+ Long result = Long.parseLong(val);
+ return result;
+ }
+ return defaultValue;
+ }
+
+ protected List<Object> getHostInfo() {
+ final ArrayList<Object> info = new ArrayList<Object>();
+ long speed = getConfiguredProperty("cpuspeed", 4000L);
+ long cpus = getConfiguredProperty("cpus", 4L);
+ long ram = getConfiguredProperty("memory", 16000L * 1024L * 1024L);
+ long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
+
+ String cap = getConfiguredProperty("capabilities", "hvm");
+ info.add((int) cpus);
+ info.add(speed);
+ info.add(ram);
+ info.add(cap);
+ info.add(dom0ram);
+ return info;
+
+ }
+
+ protected void fillNetworkInformation(final StartupCommand cmd) {
+
+ cmd.setPrivateIpAddress((String) getConfiguredProperty(
+ "private.ip.address", "127.0.0.1"));
+ cmd.setPrivateMacAddress((String) getConfiguredProperty(
+ "private.mac.address", "8A:D2:54:3F:7C:C3"));
+ cmd.setPrivateNetmask((String) getConfiguredProperty(
+ "private.ip.netmask", "255.255.255.0"));
+
+ cmd.setStorageIpAddress((String) getConfiguredProperty(
+ "private.ip.address", "127.0.0.1"));
+ cmd.setStorageMacAddress((String) getConfiguredProperty(
+ "private.mac.address", "8A:D2:54:3F:7C:C3"));
+ cmd.setStorageNetmask((String) getConfiguredProperty(
+ "private.ip.netmask", "255.255.255.0"));
+ cmd.setGatewayIpAddress((String) getConfiguredProperty(
+ "gateway.ip.address", "127.0.0.1"));
+
+ }
+
+ private Map<String, String> getVersionStrings() {
+ Map<String, String> result = new HashMap<String, String>();
+ String hostOs = (String) _params.get("Host.OS");
+ String hostOsVer = (String) _params.get("Host.OS.Version");
+ String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
+ result.put("Host.OS", hostOs == null ? "Fedora" : hostOs);
+ result.put("Host.OS.Version", hostOsVer == null ? "14" : hostOsVer);
+ result.put("Host.OS.Kernel.Version",
+ hostOsKernVer == null ? "2.6.35.6-45.fc14.x86_64"
+ : hostOsKernVer);
+ return result;
+ }
+
+ protected StoragePoolInfo initializeLocalStorage() {
+ String hostIp = (String) getConfiguredProperty("private.ip.address",
+ "127.0.0.1");
+ String localStoragePath = (String) getConfiguredProperty(
+ "local.storage.path", "/mnt");
+ String lh = hostIp + localStoragePath;
+ String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
+
+ String capacity = (String) getConfiguredProperty(
+ "local.storage.capacity", "1000000000");
+ String available = (String) getConfiguredProperty(
+ "local.storage.avail", "10000000");
+
+ return new StoragePoolInfo(uuid, hostIp, localStoragePath,
+ localStoragePath, StoragePoolType.Filesystem,
+ Long.parseLong(capacity), Long.parseLong(available));
+
+ }
+
+ @Override
+ public StartupCommand[] initialize() {
+ Map<String, VmState> changes = null;
+
+ final List<Object> info = getHostInfo();
+
+ final StartupRoutingCommand cmd = new StartupRoutingCommand(
+ (Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
+ (Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
+ RouterPrivateIpStrategy.HostLocal, changes);
+ fillNetworkInformation(cmd);
+ cmd.getHostDetails().putAll(getVersionStrings());
+ cmd.setCluster(getConfiguredProperty("cluster", "1"));
+ StoragePoolInfo pi = initializeLocalStorage();
+ StartupStorageCommand sscmd = new StartupStorageCommand();
+ sscmd.setPoolInfo(pi);
+ sscmd.setGuid(pi.getUuid());
+ sscmd.setDataCenter((String) _params.get("zone"));
+ sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
+
+ return new StartupCommand[] { cmd, sscmd };
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) {
+ _name = name;
+
+ String value = (String) params.get("type");
+ _type = Host.Type.valueOf(value);
+
+ value = (String) params.get("negative.reply");
+ _negative = Boolean.parseBoolean(value);
+ setParams(params);
+ return true;
+ }
+
+ public void setParams(Map<String, Object> _params) {
+ this._params = _params;
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ @Override
+ public boolean start() {
+ return true;
+ }
+
+ @Override
+ public boolean stop() {
+ return true;
+ }
+
+ @Override
+ public IAgentControl getAgentControl() {
+ return _agentControl;
+ }
+
+ @Override
+ public void setAgentControl(IAgentControl agentControl) {
+ _agentControl = agentControl;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/FakeComputingResource.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/FakeComputingResource.java b/agent/src/com/cloud/agent/resource/computing/FakeComputingResource.java
index b7e9cb0..d9b5d94 100644
--- a/agent/src/com/cloud/agent/resource/computing/FakeComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/FakeComputingResource.java
@@ -110,536 +110,536 @@ import com.cloud.vm.VirtualMachine.State;
*/
@Local(value = { ServerResource.class })
public class FakeComputingResource extends ServerResourceBase implements
- ServerResource {
- private static final Logger s_logger = Logger
- .getLogger(FakeComputingResource.class);
- private Map<String, Object> _params;
- private VmMgr _vmManager = new MockVmMgr();
- protected HashMap<String, State> _vms = new HashMap<String, State>(20);
- protected DhcpSnooper _dhcpSnooper = new FakeDhcpSnooper();
- protected VmDataServer _vmDataServer = new JettyVmDataServer();
-
- @Override
- public Type getType() {
- return Type.Routing;
- }
-
- @Override
- public StartupCommand[] initialize() {
- Map<String, VmState> changes = null;
-
- final List<Object> info = getHostInfo();
-
- final StartupRoutingCommand cmd = new StartupRoutingCommand(
- (Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
- (Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
- RouterPrivateIpStrategy.HostLocal, changes);
- fillNetworkInformation(cmd);
- cmd.getHostDetails().putAll(getVersionStrings());
- cmd.setCluster(getConfiguredProperty("cluster", "1"));
- StoragePoolInfo pi = initializeLocalStorage();
- StartupStorageCommand sscmd = new StartupStorageCommand();
- sscmd.setPoolInfo(pi);
- sscmd.setGuid(pi.getUuid());
- sscmd.setDataCenter((String) _params.get("zone"));
- sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
-
- return new StartupCommand[] { cmd, sscmd };
-
- }
-
- private Map<String, String> getVersionStrings() {
- Map<String, String> result = new HashMap<String, String>();
- String hostOs = (String) _params.get("Host.OS");
- String hostOsVer = (String) _params.get("Host.OS.Version");
- String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
- result.put("Host.OS", hostOs == null ? "Fedora" : hostOs);
- result.put("Host.OS.Version", hostOsVer == null ? "14" : hostOsVer);
- result.put("Host.OS.Kernel.Version",
- hostOsKernVer == null ? "2.6.35.6-45.fc14.x86_64"
- : hostOsKernVer);
- return result;
- }
-
- protected void fillNetworkInformation(final StartupCommand cmd) {
-
- cmd.setPrivateIpAddress((String) _params.get("private.ip.address"));
- cmd.setPrivateMacAddress((String) _params.get("private.mac.address"));
- cmd.setPrivateNetmask((String) _params.get("private.ip.netmask"));
-
- cmd.setStorageIpAddress((String) _params.get("private.ip.address"));
- cmd.setStorageMacAddress((String) _params.get("private.mac.address"));
- cmd.setStorageNetmask((String) _params.get("private.ip.netmask"));
- cmd.setGatewayIpAddress((String) _params.get("gateway.ip.address"));
-
- }
-
- protected StoragePoolInfo initializeLocalStorage() {
- String hostIp = (String) _params.get("private.ip.address");
- String localStoragePath = (String) _params.get("local.storage.path");
- String lh = hostIp + localStoragePath;
- String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
-
- String capacity = (String) _params.get("local.storage.capacity");
- String available = (String) _params.get("local.storage.avail");
-
- return new StoragePoolInfo(uuid, hostIp, localStoragePath,
- localStoragePath, StoragePoolType.Filesystem,
- Long.parseLong(capacity), Long.parseLong(available));
-
- }
-
- @Override
- public PingCommand getCurrentStatus(long id) {
- final HashMap<String, State> newStates = new HashMap<String, State>();
- _dhcpSnooper.syncIpAddr();
- return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id,
- newStates);
- }
-
- @Override
- public Answer executeRequest(Command cmd) {
- try {
- if (cmd instanceof ReadyCommand) {
- return execute((ReadyCommand) cmd);
- } else if (cmd instanceof ModifySshKeysCommand) {
- return execute((ModifySshKeysCommand) cmd);// TODO: remove
- } else if (cmd instanceof GetHostStatsCommand) {
- return execute((GetHostStatsCommand) cmd);
- } else if (cmd instanceof PrimaryStorageDownloadCommand) {
- return execute((PrimaryStorageDownloadCommand) cmd);
-
- } else if (cmd instanceof StopCommand) {
- return execute((StopCommand) cmd);
- } else if (cmd instanceof GetVmStatsCommand) {
- return execute((GetVmStatsCommand) cmd);
- } else if (cmd instanceof RebootCommand) {
- return execute((RebootCommand) cmd);
- } else if (cmd instanceof CheckStateCommand) {
- return executeRequest(cmd);
- } else if (cmd instanceof CheckHealthCommand) {
- return execute((CheckHealthCommand) cmd);
- } else if (cmd instanceof PingTestCommand) {
- return execute((PingTestCommand) cmd);
- } else if (cmd instanceof CheckVirtualMachineCommand) {
- return execute((CheckVirtualMachineCommand) cmd);
- } else if (cmd instanceof ReadyCommand) {
- return execute((ReadyCommand) cmd);
- } else if (cmd instanceof StopCommand) {
- return execute((StopCommand) cmd);
- } else if (cmd instanceof CreateCommand) {
- return execute((CreateCommand) cmd);
- } else if (cmd instanceof DestroyCommand) {
- return execute((DestroyCommand) cmd);
- } else if (cmd instanceof PrimaryStorageDownloadCommand) {
- return execute((PrimaryStorageDownloadCommand) cmd);
- } else if (cmd instanceof GetStorageStatsCommand) {
- return execute((GetStorageStatsCommand) cmd);
- } else if (cmd instanceof ModifyStoragePoolCommand) {
- return execute((ModifyStoragePoolCommand) cmd);
- } else if (cmd instanceof SecurityGroupRulesCmd) {
- return execute((SecurityGroupRulesCmd) cmd);
- } else if (cmd instanceof StartCommand) {
- return execute((StartCommand) cmd);
- } else if (cmd instanceof CleanupNetworkRulesCmd) {
- return execute((CleanupNetworkRulesCmd) cmd);
- } else if (cmd instanceof SavePasswordCommand) {
- return execute((SavePasswordCommand) cmd);
- } else if (cmd instanceof VmDataCommand) {
- return execute((VmDataCommand) cmd);
- } else {
- s_logger.warn("Unsupported command ");
- return Answer.createUnsupportedCommandAnswer(cmd);
- }
- } catch (final IllegalArgumentException e) {
- return new Answer(cmd, false, e.getMessage());
- }
- }
-
- private Answer execute(CleanupNetworkRulesCmd cmd) {
- return new Answer(cmd);
- }
-
- private Answer execute(SecurityGroupRulesCmd cmd) {
- s_logger.info("Programmed network rules for vm " + cmd.getVmName()
- + " guestIp=" + cmd.getGuestIp() + ",ingress numrules="
- + cmd.getIngressRuleSet().length + ",egress numrules="
- + cmd.getEgressRuleSet().length);
- return new SecurityGroupRuleAnswer(cmd);
- }
-
- private Answer execute(ModifyStoragePoolCommand cmd) {
- long capacity = getConfiguredProperty("local.storage.capacity",
- 10000000000L);
- long used = 10000000L;
- long available = capacity - used;
- if (cmd.getAdd()) {
-
- ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd,
- capacity, used, new HashMap<String, TemplateInfo>());
-
- if (s_logger.isInfoEnabled())
- s_logger.info("Sending ModifyStoragePoolCommand answer with capacity: "
- + capacity
- + ", used: "
- + used
- + ", available: "
- + available);
- return answer;
- } else {
- if (s_logger.isInfoEnabled())
- s_logger.info("ModifyNetfsStoragePoolCmd is not add command, cmd: "
- + cmd.toString());
- return new Answer(cmd);
- }
- }
-
- private Answer execute(GetStorageStatsCommand cmd) {
- return new GetStorageStatsAnswer(cmd, getConfiguredProperty(
- "local.storage.capacity", 100000000000L), 0L);
- }
-
- protected synchronized ReadyAnswer execute(ReadyCommand cmd) {
- return new ReadyAnswer(cmd);
- }
-
- private Answer execute(PrimaryStorageDownloadCommand cmd) {
- return new PrimaryStorageDownloadAnswer(cmd.getLocalPath(), 16000000L);
- }
-
- private Answer execute(ModifySshKeysCommand cmd) {
- return new Answer(cmd, true, null);
- }
-
- @Override
- protected String getDefaultScriptsDir() {
- return null;
- }
-
- protected String getConfiguredProperty(String key, String defaultValue) {
- String val = (String) _params.get(key);
- return val == null ? defaultValue : val;
- }
-
- protected Long getConfiguredProperty(String key, Long defaultValue) {
- String val = (String) _params.get(key);
-
- if (val != null) {
- Long result = Long.parseLong(val);
- return result;
- }
- return defaultValue;
- }
-
- protected List<Object> getHostInfo() {
- final ArrayList<Object> info = new ArrayList<Object>();
- long speed = getConfiguredProperty("cpuspeed", 4000L);
- long cpus = getConfiguredProperty("cpus", 4L);
- long ram = getConfiguredProperty("memory", 16000L * 1024L * 1024L);
- long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
-
- String cap = getConfiguredProperty("capabilities", "hvm");
- info.add((int) cpus);
- info.add(speed);
- info.add(ram);
- info.add(cap);
- info.add(dom0ram);
- return info;
-
- }
-
- private Map<String, Object> getSimulatorProperties()
- throws ConfigurationException {
- final File file = PropertiesUtil.findConfigFile("simulator.properties");
- if (file == null) {
- throw new ConfigurationException(
- "Unable to find simulator.properties.");
- }
-
- s_logger.info("simulator.properties found at " + file.getAbsolutePath());
- Properties properties = new Properties();
- try {
- properties.load(new FileInputStream(file));
-
- final Map<String, Object> params = PropertiesUtil.toMap(properties);
-
- return params;
- } catch (final FileNotFoundException ex) {
- throw new CloudRuntimeException("Cannot find the file: "
- + file.getAbsolutePath(), ex);
- } catch (final IOException ex) {
- throw new CloudRuntimeException("IOException in reading "
- + file.getAbsolutePath(), ex);
- }
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params)
- throws ConfigurationException {
- Map<String, Object> simProps = getSimulatorProperties();
- params.putAll(simProps);
- setParams(params);
- _vmManager.configure(params);
- _dhcpSnooper.configure(name, params);
- _vmDataServer.configure(name, params);
- return true;
- }
-
- public void setParams(Map<String, Object> _params) {
- this._params = _params;
- }
-
- public Map<String, Object> getParams() {
- return _params;
- }
-
- protected synchronized StartAnswer execute(StartCommand cmd) {
- VmMgr vmMgr = getVmManager();
-
- VirtualMachineTO vmSpec = cmd.getVirtualMachine();
- String vmName = vmSpec.getName();
- State state = State.Stopped;
-
- try {
- if (!_vms.containsKey(vmName)) {
- synchronized (_vms) {
- _vms.put(vmName, State.Starting);
- }
-
- MockVm vm = vmMgr.createVmFromSpec(vmSpec);
- vmMgr.createVbd(vmSpec, vmName, vm);
- vmMgr.createVif(vmSpec, vmName, vm);
-
- state = State.Running;
- for (NicTO nic : cmd.getVirtualMachine().getNics()) {
- if (nic.getType() == TrafficType.Guest) {
- InetAddress addr = _dhcpSnooper.getIPAddr(nic.getMac(),
- vmName);
- nic.setIp(addr.getHostAddress());
- }
- }
- _vmDataServer.handleVmStarted(cmd.getVirtualMachine());
- return new StartAnswer(cmd);
- } else {
- String msg = "There is already a VM having the same name "
- + vmName;
- s_logger.warn(msg);
- return new StartAnswer(cmd, msg);
- }
- } catch (Exception ex) {
-
- } finally {
- synchronized (_vms) {
- _vms.put(vmName, state);
- }
- }
- return new StartAnswer(cmd);
- }
-
- protected synchronized StopAnswer execute(StopCommand cmd) {
- VmMgr vmMgr = getVmManager();
-
- StopAnswer answer = null;
- String vmName = cmd.getVmName();
-
- Integer port = vmMgr.getVncPort(vmName);
- Long bytesReceived = null;
- Long bytesSent = null;
-
- State state = null;
- synchronized (_vms) {
- state = _vms.get(vmName);
- _vms.put(vmName, State.Stopping);
- }
- try {
- String result = vmMgr.stopVM(vmName, false);
- if (result != null) {
- s_logger.info("Trying destroy on " + vmName);
- if (result == Script.ERR_TIMEOUT) {
- result = vmMgr.stopVM(vmName, true);
- }
-
- s_logger.warn("Couldn't stop " + vmName);
-
- if (result != null) {
- return new StopAnswer(cmd, result);
- }
- }
-
- answer = new StopAnswer(cmd, null, port, bytesSent, bytesReceived);
-
- String result2 = vmMgr.cleanupVnet(cmd.getVnet());
- if (result2 != null) {
- result = result2 + (result != null ? ("\n" + result) : "");
- answer = new StopAnswer(cmd, result, port, bytesSent,
- bytesReceived);
- }
-
- _dhcpSnooper.cleanup(vmName, null);
-
- return answer;
- } finally {
- if (answer == null || !answer.getResult()) {
- synchronized (_vms) {
- _vms.put(vmName, state);
- }
- }
- }
- }
-
- protected Answer execute(final VmDataCommand cmd) {
- return _vmDataServer.handleVmDataCommand(cmd);
- }
-
- protected Answer execute(final SavePasswordCommand cmd) {
- return new Answer(cmd);
- }
-
- protected Answer execute(RebootCommand cmd) {
- VmMgr vmMgr = getVmManager();
- vmMgr.rebootVM(cmd.getVmName());
- return new RebootAnswer(cmd, "success", 0L, 0L);
- }
-
- private Answer execute(PingTestCommand cmd) {
- return new Answer(cmd);
- }
-
- protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
- return null;
- }
-
- private VmMgr getVmManager() {
- return _vmManager;
- }
-
- protected Answer execute(GetHostStatsCommand cmd) {
- VmMgr vmMgr = getVmManager();
- return new GetHostStatsAnswer(cmd, vmMgr.getHostCpuUtilization(),
- vmMgr.getHostFreeMemory(), vmMgr.getHostTotalMemory(), 0, 0,
- "SimulatedHost");
- }
-
- protected CheckStateAnswer execute(CheckStateCommand cmd) {
- State state = getVmManager().checkVmState(cmd.getVmName());
- return new CheckStateAnswer(cmd, state);
- }
-
- protected CheckHealthAnswer execute(CheckHealthCommand cmd) {
- return new CheckHealthAnswer(cmd, true);
- }
-
- protected CheckVirtualMachineAnswer execute(
- final CheckVirtualMachineCommand cmd) {
- VmMgr vmMgr = getVmManager();
- final String vmName = cmd.getVmName();
-
- final State state = vmMgr.checkVmState(vmName);
- Integer vncPort = null;
- if (state == State.Running) {
- vncPort = vmMgr.getVncPort(vmName);
- synchronized (_vms) {
- _vms.put(vmName, State.Running);
- }
- }
- return new CheckVirtualMachineAnswer(cmd, state, vncPort);
- }
-
- protected Answer execute(final AttachVolumeCommand cmd) {
- return new Answer(cmd);
- }
-
- protected Answer execute(final AttachIsoCommand cmd) {
- return new Answer(cmd);
- }
-
- protected CreateAnswer execute(final CreateCommand cmd) {
- try {
-
- VolumeTO vol = new VolumeTO(cmd.getVolumeId(), Volume.Type.ROOT,
- com.cloud.storage.Storage.StoragePoolType.LVM, cmd
- .getPool().getUuid(), "dummy", "/mountpoint",
- "dummyPath", 1000L, null);
- return new CreateAnswer(cmd, vol);
- } catch (Throwable th) {
- return new CreateAnswer(cmd, new Exception("Unexpected exception"));
- }
- }
-
- protected HashMap<String, State> sync() {
- Map<String, State> newStates;
- Map<String, State> oldStates = null;
-
- HashMap<String, State> changes = new HashMap<String, State>();
-
- synchronized (_vms) {
- newStates = getVmManager().getVmStates();
- oldStates = new HashMap<String, State>(_vms.size());
- oldStates.putAll(_vms);
-
- for (Map.Entry<String, State> entry : newStates.entrySet()) {
- String vm = entry.getKey();
-
- State newState = entry.getValue();
- State oldState = oldStates.remove(vm);
-
- if (s_logger.isTraceEnabled()) {
- s_logger.trace("VM " + vm + ": xen has state " + newState
- + " and we have state "
- + (oldState != null ? oldState.toString() : "null"));
- }
-
- if (oldState == null) {
- _vms.put(vm, newState);
- changes.put(vm, newState);
- } else if (oldState == State.Starting) {
- if (newState == State.Running) {
- _vms.put(vm, newState);
- } else if (newState == State.Stopped) {
- s_logger.debug("Ignoring vm " + vm
- + " because of a lag in starting the vm.");
- }
- } else if (oldState == State.Stopping) {
- if (newState == State.Stopped) {
- _vms.put(vm, newState);
- } else if (newState == State.Running) {
- s_logger.debug("Ignoring vm " + vm
- + " because of a lag in stopping the vm. ");
- }
- } else if (oldState != newState) {
- _vms.put(vm, newState);
- changes.put(vm, newState);
- }
- }
-
- for (Map.Entry<String, State> entry : oldStates.entrySet()) {
- String vm = entry.getKey();
- State oldState = entry.getValue();
-
- if (s_logger.isTraceEnabled()) {
- s_logger.trace("VM " + vm
- + " is now missing from xen so reporting stopped");
- }
-
- if (oldState == State.Stopping) {
- s_logger.debug("Ignoring VM " + vm
- + " in transition state stopping.");
- _vms.remove(vm);
- } else if (oldState == State.Starting) {
- s_logger.debug("Ignoring VM " + vm
- + " in transition state starting.");
- } else if (oldState == State.Stopped) {
- _vms.remove(vm);
- } else {
- changes.put(entry.getKey(), State.Stopped);
- }
- }
- }
-
- return changes;
- }
-
- protected Answer execute(DestroyCommand cmd) {
- return new Answer(cmd, true, null);
- }
+ ServerResource {
+ private static final Logger s_logger = Logger
+ .getLogger(FakeComputingResource.class);
+ private Map<String, Object> _params;
+ private VmMgr _vmManager = new MockVmMgr();
+ protected HashMap<String, State> _vms = new HashMap<String, State>(20);
+ protected DhcpSnooper _dhcpSnooper = new FakeDhcpSnooper();
+ protected VmDataServer _vmDataServer = new JettyVmDataServer();
+
+ @Override
+ public Type getType() {
+ return Type.Routing;
+ }
+
+ @Override
+ public StartupCommand[] initialize() {
+ Map<String, VmState> changes = null;
+
+ final List<Object> info = getHostInfo();
+
+ final StartupRoutingCommand cmd = new StartupRoutingCommand(
+ (Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
+ (Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
+ RouterPrivateIpStrategy.HostLocal, changes);
+ fillNetworkInformation(cmd);
+ cmd.getHostDetails().putAll(getVersionStrings());
+ cmd.setCluster(getConfiguredProperty("cluster", "1"));
+ StoragePoolInfo pi = initializeLocalStorage();
+ StartupStorageCommand sscmd = new StartupStorageCommand();
+ sscmd.setPoolInfo(pi);
+ sscmd.setGuid(pi.getUuid());
+ sscmd.setDataCenter((String) _params.get("zone"));
+ sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
+
+ return new StartupCommand[] { cmd, sscmd };
+
+ }
+
+ private Map<String, String> getVersionStrings() {
+ Map<String, String> result = new HashMap<String, String>();
+ String hostOs = (String) _params.get("Host.OS");
+ String hostOsVer = (String) _params.get("Host.OS.Version");
+ String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
+ result.put("Host.OS", hostOs == null ? "Fedora" : hostOs);
+ result.put("Host.OS.Version", hostOsVer == null ? "14" : hostOsVer);
+ result.put("Host.OS.Kernel.Version",
+ hostOsKernVer == null ? "2.6.35.6-45.fc14.x86_64"
+ : hostOsKernVer);
+ return result;
+ }
+
+ protected void fillNetworkInformation(final StartupCommand cmd) {
+
+ cmd.setPrivateIpAddress((String) _params.get("private.ip.address"));
+ cmd.setPrivateMacAddress((String) _params.get("private.mac.address"));
+ cmd.setPrivateNetmask((String) _params.get("private.ip.netmask"));
+
+ cmd.setStorageIpAddress((String) _params.get("private.ip.address"));
+ cmd.setStorageMacAddress((String) _params.get("private.mac.address"));
+ cmd.setStorageNetmask((String) _params.get("private.ip.netmask"));
+ cmd.setGatewayIpAddress((String) _params.get("gateway.ip.address"));
+
+ }
+
+ protected StoragePoolInfo initializeLocalStorage() {
+ String hostIp = (String) _params.get("private.ip.address");
+ String localStoragePath = (String) _params.get("local.storage.path");
+ String lh = hostIp + localStoragePath;
+ String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
+
+ String capacity = (String) _params.get("local.storage.capacity");
+ String available = (String) _params.get("local.storage.avail");
+
+ return new StoragePoolInfo(uuid, hostIp, localStoragePath,
+ localStoragePath, StoragePoolType.Filesystem,
+ Long.parseLong(capacity), Long.parseLong(available));
+
+ }
+
+ @Override
+ public PingCommand getCurrentStatus(long id) {
+ final HashMap<String, State> newStates = new HashMap<String, State>();
+ _dhcpSnooper.syncIpAddr();
+ return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id,
+ newStates);
+ }
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ try {
+ if (cmd instanceof ReadyCommand) {
+ return execute((ReadyCommand) cmd);
+ } else if (cmd instanceof ModifySshKeysCommand) {
+ return execute((ModifySshKeysCommand) cmd);// TODO: remove
+ } else if (cmd instanceof GetHostStatsCommand) {
+ return execute((GetHostStatsCommand) cmd);
+ } else if (cmd instanceof PrimaryStorageDownloadCommand) {
+ return execute((PrimaryStorageDownloadCommand) cmd);
+
+ } else if (cmd instanceof StopCommand) {
+ return execute((StopCommand) cmd);
+ } else if (cmd instanceof GetVmStatsCommand) {
+ return execute((GetVmStatsCommand) cmd);
+ } else if (cmd instanceof RebootCommand) {
+ return execute((RebootCommand) cmd);
+ } else if (cmd instanceof CheckStateCommand) {
+ return executeRequest(cmd);
+ } else if (cmd instanceof CheckHealthCommand) {
+ return execute((CheckHealthCommand) cmd);
+ } else if (cmd instanceof PingTestCommand) {
+ return execute((PingTestCommand) cmd);
+ } else if (cmd instanceof CheckVirtualMachineCommand) {
+ return execute((CheckVirtualMachineCommand) cmd);
+ } else if (cmd instanceof ReadyCommand) {
+ return execute((ReadyCommand) cmd);
+ } else if (cmd instanceof StopCommand) {
+ return execute((StopCommand) cmd);
+ } else if (cmd instanceof CreateCommand) {
+ return execute((CreateCommand) cmd);
+ } else if (cmd instanceof DestroyCommand) {
+ return execute((DestroyCommand) cmd);
+ } else if (cmd instanceof PrimaryStorageDownloadCommand) {
+ return execute((PrimaryStorageDownloadCommand) cmd);
+ } else if (cmd instanceof GetStorageStatsCommand) {
+ return execute((GetStorageStatsCommand) cmd);
+ } else if (cmd instanceof ModifyStoragePoolCommand) {
+ return execute((ModifyStoragePoolCommand) cmd);
+ } else if (cmd instanceof SecurityGroupRulesCmd) {
+ return execute((SecurityGroupRulesCmd) cmd);
+ } else if (cmd instanceof StartCommand) {
+ return execute((StartCommand) cmd);
+ } else if (cmd instanceof CleanupNetworkRulesCmd) {
+ return execute((CleanupNetworkRulesCmd) cmd);
+ } else if (cmd instanceof SavePasswordCommand) {
+ return execute((SavePasswordCommand) cmd);
+ } else if (cmd instanceof VmDataCommand) {
+ return execute((VmDataCommand) cmd);
+ } else {
+ s_logger.warn("Unsupported command ");
+ return Answer.createUnsupportedCommandAnswer(cmd);
+ }
+ } catch (final IllegalArgumentException e) {
+ return new Answer(cmd, false, e.getMessage());
+ }
+ }
+
+ private Answer execute(CleanupNetworkRulesCmd cmd) {
+ return new Answer(cmd);
+ }
+
+ private Answer execute(SecurityGroupRulesCmd cmd) {
+ s_logger.info("Programmed network rules for vm " + cmd.getVmName()
+ + " guestIp=" + cmd.getGuestIp() + ",ingress numrules="
+ + cmd.getIngressRuleSet().length + ",egress numrules="
+ + cmd.getEgressRuleSet().length);
+ return new SecurityGroupRuleAnswer(cmd);
+ }
+
+ private Answer execute(ModifyStoragePoolCommand cmd) {
+ long capacity = getConfiguredProperty("local.storage.capacity",
+ 10000000000L);
+ long used = 10000000L;
+ long available = capacity - used;
+ if (cmd.getAdd()) {
+
+ ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd,
+ capacity, used, new HashMap<String, TemplateInfo>());
+
+ if (s_logger.isInfoEnabled())
+ s_logger.info("Sending ModifyStoragePoolCommand answer with capacity: "
+ + capacity
+ + ", used: "
+ + used
+ + ", available: "
+ + available);
+ return answer;
+ } else {
+ if (s_logger.isInfoEnabled())
+ s_logger.info("ModifyNetfsStoragePoolCmd is not add command, cmd: "
+ + cmd.toString());
+ return new Answer(cmd);
+ }
+ }
+
+ private Answer execute(GetStorageStatsCommand cmd) {
+ return new GetStorageStatsAnswer(cmd, getConfiguredProperty(
+ "local.storage.capacity", 100000000000L), 0L);
+ }
+
+ protected synchronized ReadyAnswer execute(ReadyCommand cmd) {
+ return new ReadyAnswer(cmd);
+ }
+
+ private Answer execute(PrimaryStorageDownloadCommand cmd) {
+ return new PrimaryStorageDownloadAnswer(cmd.getLocalPath(), 16000000L);
+ }
+
+ private Answer execute(ModifySshKeysCommand cmd) {
+ return new Answer(cmd, true, null);
+ }
+
+ @Override
+ protected String getDefaultScriptsDir() {
+ return null;
+ }
+
+ protected String getConfiguredProperty(String key, String defaultValue) {
+ String val = (String) _params.get(key);
+ return val == null ? defaultValue : val;
+ }
+
+ protected Long getConfiguredProperty(String key, Long defaultValue) {
+ String val = (String) _params.get(key);
+
+ if (val != null) {
+ Long result = Long.parseLong(val);
+ return result;
+ }
+ return defaultValue;
+ }
+
+ protected List<Object> getHostInfo() {
+ final ArrayList<Object> info = new ArrayList<Object>();
+ long speed = getConfiguredProperty("cpuspeed", 4000L);
+ long cpus = getConfiguredProperty("cpus", 4L);
+ long ram = getConfiguredProperty("memory", 16000L * 1024L * 1024L);
+ long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
+
+ String cap = getConfiguredProperty("capabilities", "hvm");
+ info.add((int) cpus);
+ info.add(speed);
+ info.add(ram);
+ info.add(cap);
+ info.add(dom0ram);
+ return info;
+
+ }
+
+ private Map<String, Object> getSimulatorProperties()
+ throws ConfigurationException {
+ final File file = PropertiesUtil.findConfigFile("simulator.properties");
+ if (file == null) {
+ throw new ConfigurationException(
+ "Unable to find simulator.properties.");
+ }
+
+ s_logger.info("simulator.properties found at " + file.getAbsolutePath());
+ Properties properties = new Properties();
+ try {
+ properties.load(new FileInputStream(file));
+
+ final Map<String, Object> params = PropertiesUtil.toMap(properties);
+
+ return params;
+ } catch (final FileNotFoundException ex) {
+ throw new CloudRuntimeException("Cannot find the file: "
+ + file.getAbsolutePath(), ex);
+ } catch (final IOException ex) {
+ throw new CloudRuntimeException("IOException in reading "
+ + file.getAbsolutePath(), ex);
+ }
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params)
+ throws ConfigurationException {
+ Map<String, Object> simProps = getSimulatorProperties();
+ params.putAll(simProps);
+ setParams(params);
+ _vmManager.configure(params);
+ _dhcpSnooper.configure(name, params);
+ _vmDataServer.configure(name, params);
+ return true;
+ }
+
+ public void setParams(Map<String, Object> _params) {
+ this._params = _params;
+ }
+
+ public Map<String, Object> getParams() {
+ return _params;
+ }
+
+ protected synchronized StartAnswer execute(StartCommand cmd) {
+ VmMgr vmMgr = getVmManager();
+
+ VirtualMachineTO vmSpec = cmd.getVirtualMachine();
+ String vmName = vmSpec.getName();
+ State state = State.Stopped;
+
+ try {
+ if (!_vms.containsKey(vmName)) {
+ synchronized (_vms) {
+ _vms.put(vmName, State.Starting);
+ }
+
+ MockVm vm = vmMgr.createVmFromSpec(vmSpec);
+ vmMgr.createVbd(vmSpec, vmName, vm);
+ vmMgr.createVif(vmSpec, vmName, vm);
+
+ state = State.Running;
+ for (NicTO nic : cmd.getVirtualMachine().getNics()) {
+ if (nic.getType() == TrafficType.Guest) {
+ InetAddress addr = _dhcpSnooper.getIPAddr(nic.getMac(),
+ vmName);
+ nic.setIp(addr.getHostAddress());
+ }
+ }
+ _vmDataServer.handleVmStarted(cmd.getVirtualMachine());
+ return new StartAnswer(cmd);
+ } else {
+ String msg = "There is already a VM having the same name "
+ + vmName;
+ s_logger.warn(msg);
+ return new StartAnswer(cmd, msg);
+ }
+ } catch (Exception ex) {
+
+ } finally {
+ synchronized (_vms) {
+ _vms.put(vmName, state);
+ }
+ }
+ return new StartAnswer(cmd);
+ }
+
+ protected synchronized StopAnswer execute(StopCommand cmd) {
+ VmMgr vmMgr = getVmManager();
+
+ StopAnswer answer = null;
+ String vmName = cmd.getVmName();
+
+ Integer port = vmMgr.getVncPort(vmName);
+ Long bytesReceived = null;
+ Long bytesSent = null;
+
+ State state = null;
+ synchronized (_vms) {
+ state = _vms.get(vmName);
+ _vms.put(vmName, State.Stopping);
+ }
+ try {
+ String result = vmMgr.stopVM(vmName, false);
+ if (result != null) {
+ s_logger.info("Trying destroy on " + vmName);
+ if (result == Script.ERR_TIMEOUT) {
+ result = vmMgr.stopVM(vmName, true);
+ }
+
+ s_logger.warn("Couldn't stop " + vmName);
+
+ if (result != null) {
+ return new StopAnswer(cmd, result);
+ }
+ }
+
+ answer = new StopAnswer(cmd, null, port, bytesSent, bytesReceived);
+
+ String result2 = vmMgr.cleanupVnet(cmd.getVnet());
+ if (result2 != null) {
+ result = result2 + (result != null ? ("\n" + result) : "");
+ answer = new StopAnswer(cmd, result, port, bytesSent,
+ bytesReceived);
+ }
+
+ _dhcpSnooper.cleanup(vmName, null);
+
+ return answer;
+ } finally {
+ if (answer == null || !answer.getResult()) {
+ synchronized (_vms) {
+ _vms.put(vmName, state);
+ }
+ }
+ }
+ }
+
+ protected Answer execute(final VmDataCommand cmd) {
+ return _vmDataServer.handleVmDataCommand(cmd);
+ }
+
+ protected Answer execute(final SavePasswordCommand cmd) {
+ return new Answer(cmd);
+ }
+
+ protected Answer execute(RebootCommand cmd) {
+ VmMgr vmMgr = getVmManager();
+ vmMgr.rebootVM(cmd.getVmName());
+ return new RebootAnswer(cmd, "success", 0L, 0L);
+ }
+
+ private Answer execute(PingTestCommand cmd) {
+ return new Answer(cmd);
+ }
+
+ protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
+ return null;
+ }
+
+ private VmMgr getVmManager() {
+ return _vmManager;
+ }
+
+ protected Answer execute(GetHostStatsCommand cmd) {
+ VmMgr vmMgr = getVmManager();
+ return new GetHostStatsAnswer(cmd, vmMgr.getHostCpuUtilization(),
+ vmMgr.getHostFreeMemory(), vmMgr.getHostTotalMemory(), 0, 0,
+ "SimulatedHost");
+ }
+
+ protected CheckStateAnswer execute(CheckStateCommand cmd) {
+ State state = getVmManager().checkVmState(cmd.getVmName());
+ return new CheckStateAnswer(cmd, state);
+ }
+
+ protected CheckHealthAnswer execute(CheckHealthCommand cmd) {
+ return new CheckHealthAnswer(cmd, true);
+ }
+
+ protected CheckVirtualMachineAnswer execute(
+ final CheckVirtualMachineCommand cmd) {
+ VmMgr vmMgr = getVmManager();
+ final String vmName = cmd.getVmName();
+
+ final State state = vmMgr.checkVmState(vmName);
+ Integer vncPort = null;
+ if (state == State.Running) {
+ vncPort = vmMgr.getVncPort(vmName);
+ synchronized (_vms) {
+ _vms.put(vmName, State.Running);
+ }
+ }
+ return new CheckVirtualMachineAnswer(cmd, state, vncPort);
+ }
+
+ protected Answer execute(final AttachVolumeCommand cmd) {
+ return new Answer(cmd);
+ }
+
+ protected Answer execute(final AttachIsoCommand cmd) {
+ return new Answer(cmd);
+ }
+
+ protected CreateAnswer execute(final CreateCommand cmd) {
+ try {
+
+ VolumeTO vol = new VolumeTO(cmd.getVolumeId(), Volume.Type.ROOT,
+ com.cloud.storage.Storage.StoragePoolType.LVM, cmd
+ .getPool().getUuid(), "dummy", "/mountpoint",
+ "dummyPath", 1000L, null);
+ return new CreateAnswer(cmd, vol);
+ } catch (Throwable th) {
+ return new CreateAnswer(cmd, new Exception("Unexpected exception"));
+ }
+ }
+
+ protected HashMap<String, State> sync() {
+ Map<String, State> newStates;
+ Map<String, State> oldStates = null;
+
+ HashMap<String, State> changes = new HashMap<String, State>();
+
+ synchronized (_vms) {
+ newStates = getVmManager().getVmStates();
+ oldStates = new HashMap<String, State>(_vms.size());
+ oldStates.putAll(_vms);
+
+ for (Map.Entry<String, State> entry : newStates.entrySet()) {
+ String vm = entry.getKey();
+
+ State newState = entry.getValue();
+ State oldState = oldStates.remove(vm);
+
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace("VM " + vm + ": xen has state " + newState
+ + " and we have state "
+ + (oldState != null ? oldState.toString() : "null"));
+ }
+
+ if (oldState == null) {
+ _vms.put(vm, newState);
+ changes.put(vm, newState);
+ } else if (oldState == State.Starting) {
+ if (newState == State.Running) {
+ _vms.put(vm, newState);
+ } else if (newState == State.Stopped) {
+ s_logger.debug("Ignoring vm " + vm
+ + " because of a lag in starting the vm.");
+ }
+ } else if (oldState == State.Stopping) {
+ if (newState == State.Stopped) {
+ _vms.put(vm, newState);
+ } else if (newState == State.Running) {
+ s_logger.debug("Ignoring vm " + vm
+ + " because of a lag in stopping the vm. ");
+ }
+ } else if (oldState != newState) {
+ _vms.put(vm, newState);
+ changes.put(vm, newState);
+ }
+ }
+
+ for (Map.Entry<String, State> entry : oldStates.entrySet()) {
+ String vm = entry.getKey();
+ State oldState = entry.getValue();
+
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace("VM " + vm
+ + " is now missing from xen so reporting stopped");
+ }
+
+ if (oldState == State.Stopping) {
+ s_logger.debug("Ignoring VM " + vm
+ + " in transition state stopping.");
+ _vms.remove(vm);
+ } else if (oldState == State.Starting) {
+ s_logger.debug("Ignoring VM " + vm
+ + " in transition state starting.");
+ } else if (oldState == State.Stopped) {
+ _vms.remove(vm);
+ } else {
+ changes.put(entry.getKey(), State.Stopped);
+ }
+ }
+ }
+
+ return changes;
+ }
+
+ protected Answer execute(DestroyCommand cmd) {
+ return new Answer(cmd, true, null);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java b/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java
index fceece4..22f3935 100644
--- a/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java
+++ b/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java
@@ -22,148 +22,148 @@ import java.util.Map;
import org.apache.log4j.Logger;
public class KVMGuestOsMapper {
- private static final Logger s_logger = Logger
- .getLogger(KVMGuestOsMapper.class);
- private static Map<String, String> s_mapper = new HashMap<String, String>();
- static {
- s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5");
- s_mapper.put("CentOS 4.6 (32-bit)", "CentOS 4.6");
- s_mapper.put("CentOS 4.7 (32-bit)", "CentOS 4.7");
- s_mapper.put("CentOS 4.8 (32-bit)", "CentOS 4.8");
- s_mapper.put("CentOS 5.0 (32-bit)", "CentOS 5.0");
- s_mapper.put("CentOS 5.0 (64-bit)", "CentOS 5.0");
- s_mapper.put("CentOS 5.1 (32-bit)", "CentOS 5.1");
- s_mapper.put("CentOS 5.1 (64-bit)", "CentOS 5.1");
- s_mapper.put("CentOS 5.2 (32-bit)", "CentOS 5.2");
- s_mapper.put("CentOS 5.2 (64-bit)", "CentOS 5.2");
- s_mapper.put("CentOS 5.3 (32-bit)", "CentOS 5.3");
- s_mapper.put("CentOS 5.3 (64-bit)", "CentOS 5.3");
- s_mapper.put("CentOS 5.4 (32-bit)", "CentOS 5.4");
- s_mapper.put("CentOS 5.4 (64-bit)", "CentOS 5.4");
- s_mapper.put("CentOS 5.5 (32-bit)", "CentOS 5.5");
- s_mapper.put("CentOS 5.5 (64-bit)", "CentOS 5.5");
- s_mapper.put("Red Hat Enterprise Linux 2", "Red Hat Enterprise Linux 2");
- s_mapper.put("Red Hat Enterprise Linux 3 (32-bit)",
- "Red Hat Enterprise Linux 3");
- s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)",
- "Red Hat Enterprise Linux 3");
- s_mapper.put("Red Hat Enterprise Linux 4(64-bit)",
- "Red Hat Enterprise Linux 4");
- s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)",
- "Red Hat Enterprise Linux 4.5");
- s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)",
- "Red Hat Enterprise Linux 4.6");
- s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)",
- "Red Hat Enterprise Linux 4.7");
- s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)",
- "Red Hat Enterprise Linux 4.8");
- s_mapper.put("Red Hat Enterprise Linux 5.0 (32-bit)",
- "Red Hat Enterprise Linux 5.0");
- s_mapper.put("Red Hat Enterprise Linux 5.0 (64-bit)",
- "Red Hat Enterprise Linux 5.0");
- s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
- "Red Hat Enterprise Linux 5.1");
- s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
- "Red Hat Enterprise Linux 5.1");
- s_mapper.put("Red Hat Enterprise Linux 5.2 (32-bit)",
- "Red Hat Enterprise Linux 5.2");
- s_mapper.put("Red Hat Enterprise Linux 5.2 (64-bit)",
- "Red Hat Enterprise Linux 5.2");
- s_mapper.put("Red Hat Enterprise Linux 5.3 (32-bit)",
- "Red Hat Enterprise Linux 5.3");
- s_mapper.put("Red Hat Enterprise Linux 5.3 (64-bit)",
- "Red Hat Enterprise Linux 5.3");
- s_mapper.put("Red Hat Enterprise Linux 5.4 (32-bit)",
- "Red Hat Enterprise Linux 5.4");
- s_mapper.put("Red Hat Enterprise Linux 5.4 (64-bit)",
- "Red Hat Enterprise Linux 5.4");
- s_mapper.put("Red Hat Enterprise Linux 5.5 (32-bit)",
- "Red Hat Enterprise Linux 5.5");
- s_mapper.put("Red Hat Enterprise Linux 5.5 (64-bit)",
- "Red Hat Enterprise Linux 5.5");
- s_mapper.put("Red Hat Enterprise Linux 6.0 (32-bit)",
- "Red Hat Enterprise Linux 6.0");
- s_mapper.put("Red Hat Enterprise Linux 6.0 (64-bit)",
- "Red Hat Enterprise Linux 6.0");
- s_mapper.put("Fedora 13", "Fedora 13");
- s_mapper.put("Fedora 12", "Fedora 12");
- s_mapper.put("Fedora 11", "Fedora 11");
- s_mapper.put("Fedora 10", "Fedora 10");
- s_mapper.put("Fedora 9", "Fedora 9");
- s_mapper.put("Fedora 8", "Fedora 8");
- s_mapper.put("Ubuntu 10.04 (32-bit)", "Ubuntu 10.04");
- s_mapper.put("Ubuntu 10.04 (64-bit)", "Ubuntu 10.04");
- s_mapper.put("Ubuntu 10.10 (32-bit)", "Ubuntu 10.10");
- s_mapper.put("Ubuntu 10.10 (64-bit)", "Ubuntu 10.10");
- s_mapper.put("Ubuntu 9.10 (32-bit)", "Ubuntu 9.10");
- s_mapper.put("Ubuntu 9.10 (64-bit)", "Ubuntu 9.10");
- s_mapper.put("Ubuntu 9.04 (32-bit)", "Ubuntu 9.04");
- s_mapper.put("Ubuntu 9.04 (64-bit)", "Ubuntu 9.04");
- s_mapper.put("Ubuntu 8.10 (32-bit)", "Ubuntu 8.10");
- s_mapper.put("Ubuntu 8.10 (64-bit)", "Ubuntu 8.10");
- s_mapper.put("Ubuntu 8.04 (32-bit)", "Other Linux");
- s_mapper.put("Ubuntu 8.04 (64-bit)", "Other Linux");
- s_mapper.put("Debian GNU/Linux 5(32-bit)", "Debian GNU/Linux 5");
- s_mapper.put("Debian GNU/Linux 5(64-bit)", "Debian GNU/Linux 5");
- s_mapper.put("Debian GNU/Linux 4(32-bit)", "Debian GNU/Linux 4");
- s_mapper.put("Debian GNU/Linux 4(64-bit)", "Debian GNU/Linux 4");
- s_mapper.put("Debian GNU/Linux 6(64-bit)", "Debian GNU/Linux 6");
- s_mapper.put("Debian GNU/Linux 6(32-bit)", "Debian GNU/Linux 6");
- s_mapper.put("Other 2.6x Linux (32-bit)", "Other 2.6x Linux");
- s_mapper.put("Other 2.6x Linux (64-bit)", "Other 2.6x Linux");
- s_mapper.put("Other Linux (32-bit)", "Other Linux");
- s_mapper.put("Other Linux (64-bit)", "Other Linux");
- s_mapper.put("Other Ubuntu (32-bit)", "Other Linux");
- s_mapper.put("Other Ubuntu (64-bit)", "Other Linux");
- s_mapper.put("Asianux 3(32-bit)", "Other Linux");
- s_mapper.put("Asianux 3(64-bit)", "Other Linux");
- s_mapper.put("Windows 7 (32-bit)", "Windows 7");
- s_mapper.put("Windows 7 (64-bit)", "Windows 7");
- s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2003 Standard Edition(32-bit)",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2003 Standard Edition(64-bit)",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2003 Web Edition", "Windows Server 2003");
- s_mapper.put("Microsoft Small Bussiness Server 2003",
- "Windows Server 2003");
- s_mapper.put("Windows Server 2008 (32-bit)", "Windows Server 2008");
- s_mapper.put("Windows Server 2008 (64-bit)", "Windows Server 2008");
- s_mapper.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008");
- s_mapper.put("Windows 2000 Server SP4 (32-bit)", "Windows 2000");
- s_mapper.put("Windows 2000 Server", "Windows 2000");
- s_mapper.put("Windows 2000 Advanced Server", "Windows 2000");
- s_mapper.put("Windows 2000 Professional", "Windows 2000");
- s_mapper.put("Windows Vista (32-bit)", "Windows Vista");
- s_mapper.put("Windows Vista (64-bit)", "Windows Vista");
- s_mapper.put("Windows XP SP2 (32-bit)", "Windows XP");
- s_mapper.put("Windows XP SP3 (32-bit)", "Windows XP");
- s_mapper.put("Windows XP (32-bit)", "Windows XP");
- s_mapper.put("Windows XP (64-bit)", "Windows XP");
- s_mapper.put("Windows 98", "Windows 98");
- s_mapper.put("Windows 95", "Windows 95");
- s_mapper.put("Windows NT 4", "Windows NT");
- s_mapper.put("Windows 3.1", "Windows 3.1");
- s_mapper.put("Windows PV", "Other PV");
- s_mapper.put("Other PV (32-bit)", "Other PV");
- s_mapper.put("Other PV (64-bit)", "Other PV");
+ private static final Logger s_logger = Logger
+ .getLogger(KVMGuestOsMapper.class);
+ private static Map<String, String> s_mapper = new HashMap<String, String>();
+ static {
+ s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5");
+ s_mapper.put("CentOS 4.6 (32-bit)", "CentOS 4.6");
+ s_mapper.put("CentOS 4.7 (32-bit)", "CentOS 4.7");
+ s_mapper.put("CentOS 4.8 (32-bit)", "CentOS 4.8");
+ s_mapper.put("CentOS 5.0 (32-bit)", "CentOS 5.0");
+ s_mapper.put("CentOS 5.0 (64-bit)", "CentOS 5.0");
+ s_mapper.put("CentOS 5.1 (32-bit)", "CentOS 5.1");
+ s_mapper.put("CentOS 5.1 (64-bit)", "CentOS 5.1");
+ s_mapper.put("CentOS 5.2 (32-bit)", "CentOS 5.2");
+ s_mapper.put("CentOS 5.2 (64-bit)", "CentOS 5.2");
+ s_mapper.put("CentOS 5.3 (32-bit)", "CentOS 5.3");
+ s_mapper.put("CentOS 5.3 (64-bit)", "CentOS 5.3");
+ s_mapper.put("CentOS 5.4 (32-bit)", "CentOS 5.4");
+ s_mapper.put("CentOS 5.4 (64-bit)", "CentOS 5.4");
+ s_mapper.put("CentOS 5.5 (32-bit)", "CentOS 5.5");
+ s_mapper.put("CentOS 5.5 (64-bit)", "CentOS 5.5");
+ s_mapper.put("Red Hat Enterprise Linux 2", "Red Hat Enterprise Linux 2");
+ s_mapper.put("Red Hat Enterprise Linux 3 (32-bit)",
+ "Red Hat Enterprise Linux 3");
+ s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)",
+ "Red Hat Enterprise Linux 3");
+ s_mapper.put("Red Hat Enterprise Linux 4(64-bit)",
+ "Red Hat Enterprise Linux 4");
+ s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)",
+ "Red Hat Enterprise Linux 4.5");
+ s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)",
+ "Red Hat Enterprise Linux 4.6");
+ s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)",
+ "Red Hat Enterprise Linux 4.7");
+ s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)",
+ "Red Hat Enterprise Linux 4.8");
+ s_mapper.put("Red Hat Enterprise Linux 5.0 (32-bit)",
+ "Red Hat Enterprise Linux 5.0");
+ s_mapper.put("Red Hat Enterprise Linux 5.0 (64-bit)",
+ "Red Hat Enterprise Linux 5.0");
+ s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
+ "Red Hat Enterprise Linux 5.1");
+ s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
+ "Red Hat Enterprise Linux 5.1");
+ s_mapper.put("Red Hat Enterprise Linux 5.2 (32-bit)",
+ "Red Hat Enterprise Linux 5.2");
+ s_mapper.put("Red Hat Enterprise Linux 5.2 (64-bit)",
+ "Red Hat Enterprise Linux 5.2");
+ s_mapper.put("Red Hat Enterprise Linux 5.3 (32-bit)",
+ "Red Hat Enterprise Linux 5.3");
+ s_mapper.put("Red Hat Enterprise Linux 5.3 (64-bit)",
+ "Red Hat Enterprise Linux 5.3");
+ s_mapper.put("Red Hat Enterprise Linux 5.4 (32-bit)",
+ "Red Hat Enterprise Linux 5.4");
+ s_mapper.put("Red Hat Enterprise Linux 5.4 (64-bit)",
+ "Red Hat Enterprise Linux 5.4");
+ s_mapper.put("Red Hat Enterprise Linux 5.5 (32-bit)",
+ "Red Hat Enterprise Linux 5.5");
+ s_mapper.put("Red Hat Enterprise Linux 5.5 (64-bit)",
+ "Red Hat Enterprise Linux 5.5");
+ s_mapper.put("Red Hat Enterprise Linux 6.0 (32-bit)",
+ "Red Hat Enterprise Linux 6.0");
+ s_mapper.put("Red Hat Enterprise Linux 6.0 (64-bit)",
+ "Red Hat Enterprise Linux 6.0");
+ s_mapper.put("Fedora 13", "Fedora 13");
+ s_mapper.put("Fedora 12", "Fedora 12");
+ s_mapper.put("Fedora 11", "Fedora 11");
+ s_mapper.put("Fedora 10", "Fedora 10");
+ s_mapper.put("Fedora 9", "Fedora 9");
+ s_mapper.put("Fedora 8", "Fedora 8");
+ s_mapper.put("Ubuntu 10.04 (32-bit)", "Ubuntu 10.04");
+ s_mapper.put("Ubuntu 10.04 (64-bit)", "Ubuntu 10.04");
+ s_mapper.put("Ubuntu 10.10 (32-bit)", "Ubuntu 10.10");
+ s_mapper.put("Ubuntu 10.10 (64-bit)", "Ubuntu 10.10");
+ s_mapper.put("Ubuntu 9.10 (32-bit)", "Ubuntu 9.10");
+ s_mapper.put("Ubuntu 9.10 (64-bit)", "Ubuntu 9.10");
+ s_mapper.put("Ubuntu 9.04 (32-bit)", "Ubuntu 9.04");
+ s_mapper.put("Ubuntu 9.04 (64-bit)", "Ubuntu 9.04");
+ s_mapper.put("Ubuntu 8.10 (32-bit)", "Ubuntu 8.10");
+ s_mapper.put("Ubuntu 8.10 (64-bit)", "Ubuntu 8.10");
+ s_mapper.put("Ubuntu 8.04 (32-bit)", "Other Linux");
+ s_mapper.put("Ubuntu 8.04 (64-bit)", "Other Linux");
+ s_mapper.put("Debian GNU/Linux 5(32-bit)", "Debian GNU/Linux 5");
+ s_mapper.put("Debian GNU/Linux 5(64-bit)", "Debian GNU/Linux 5");
+ s_mapper.put("Debian GNU/Linux 4(32-bit)", "Debian GNU/Linux 4");
+ s_mapper.put("Debian GNU/Linux 4(64-bit)", "Debian GNU/Linux 4");
+ s_mapper.put("Debian GNU/Linux 6(64-bit)", "Debian GNU/Linux 6");
+ s_mapper.put("Debian GNU/Linux 6(32-bit)", "Debian GNU/Linux 6");
+ s_mapper.put("Other 2.6x Linux (32-bit)", "Other 2.6x Linux");
+ s_mapper.put("Other 2.6x Linux (64-bit)", "Other 2.6x Linux");
+ s_mapper.put("Other Linux (32-bit)", "Other Linux");
+ s_mapper.put("Other Linux (64-bit)", "Other Linux");
+ s_mapper.put("Other Ubuntu (32-bit)", "Other Linux");
+ s_mapper.put("Other Ubuntu (64-bit)", "Other Linux");
+ s_mapper.put("Asianux 3(32-bit)", "Other Linux");
+ s_mapper.put("Asianux 3(64-bit)", "Other Linux");
+ s_mapper.put("Windows 7 (32-bit)", "Windows 7");
+ s_mapper.put("Windows 7 (64-bit)", "Windows 7");
+ s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2003 Standard Edition(32-bit)",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2003 Standard Edition(64-bit)",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2003 Web Edition", "Windows Server 2003");
+ s_mapper.put("Microsoft Small Bussiness Server 2003",
+ "Windows Server 2003");
+ s_mapper.put("Windows Server 2008 (32-bit)", "Windows Server 2008");
+ s_mapper.put("Windows Server 2008 (64-bit)", "Windows Server 2008");
+ s_mapper.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008");
+ s_mapper.put("Windows 2000 Server SP4 (32-bit)", "Windows 2000");
+ s_mapper.put("Windows 2000 Server", "Windows 2000");
+ s_mapper.put("Windows 2000 Advanced Server", "Windows 2000");
+ s_mapper.put("Windows 2000 Professional", "Windows 2000");
+ s_mapper.put("Windows Vista (32-bit)", "Windows Vista");
+ s_mapper.put("Windows Vista (64-bit)", "Windows Vista");
+ s_mapper.put("Windows XP SP2 (32-bit)", "Windows XP");
+ s_mapper.put("Windows XP SP3 (32-bit)", "Windows XP");
+ s_mapper.put("Windows XP (32-bit)", "Windows XP");
+ s_mapper.put("Windows XP (64-bit)", "Windows XP");
+ s_mapper.put("Windows 98", "Windows 98");
+ s_mapper.put("Windows 95", "Windows 95");
+ s_mapper.put("Windows NT 4", "Windows NT");
+ s_mapper.put("Windows 3.1", "Windows 3.1");
+ s_mapper.put("Windows PV", "Other PV");
+ s_mapper.put("Other PV (32-bit)", "Other PV");
+ s_mapper.put("Other PV (64-bit)", "Other PV");
- }
+ }
- public static String getGuestOsName(String guestOsName) {
- String guestOS = s_mapper.get(guestOsName);
- if (guestOS == null) {
- s_logger.debug("Can't find the mapping of guest os: " + guestOsName);
- return "Other";
- } else {
- return guestOS;
- }
- }
+ public static String getGuestOsName(String guestOsName) {
+ String guestOS = s_mapper.get(guestOsName);
+ if (guestOS == null) {
+ s_logger.debug("Can't find the mapping of guest os: " + guestOsName);
+ return "Other";
+ } else {
+ return guestOS;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/KVMHABase.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/KVMHABase.java b/agent/src/com/cloud/agent/resource/computing/KVMHABase.java
index 0377efc..ed29a62 100644
--- a/agent/src/com/cloud/agent/resource/computing/KVMHABase.java
+++ b/agent/src/com/cloud/agent/resource/computing/KVMHABase.java
@@ -34,187 +34,187 @@ import com.cloud.utils.script.OutputInterpreter.AllLinesParser;
import com.cloud.utils.script.Script;
public class KVMHABase {
- private long _timeout = 60000; /* 1 minutes */
- protected static String _heartBeatPath;
- protected long _heartBeatUpdateTimeout = 60000;
- protected long _heartBeatUpdateFreq = 60000;
- protected long _heartBeatUpdateMaxRetry = 3;
-
- public static enum PoolType {
- PrimaryStorage, SecondaryStorage
- }
-
- public static class NfsStoragePool {
- String _poolUUID;
- String _poolIp;
- String _poolMountSourcePath;
- String _mountDestPath;
- PoolType _type;
-
- public NfsStoragePool(String poolUUID, String poolIp,
- String poolSourcePath, String mountDestPath, PoolType type) {
- this._poolUUID = poolUUID;
- this._poolIp = poolIp;
- this._poolMountSourcePath = poolSourcePath;
- this._mountDestPath = mountDestPath;
- this._type = type;
- }
- }
-
- protected String checkingMountPoint(NfsStoragePool pool, String poolName) {
- String mountSource = pool._poolIp + ":" + pool._poolMountSourcePath;
- String mountPaths = Script
- .runSimpleBashScript("cat /proc/mounts | grep " + mountSource);
- String destPath = pool._mountDestPath;
-
- if (mountPaths != null) {
- String token[] = mountPaths.split(" ");
- String mountType = token[2];
- String mountDestPath = token[1];
- if (mountType.equalsIgnoreCase("nfs")) {
- if (poolName != null && !mountDestPath.startsWith(destPath)) {
- /* we need to mount it under poolName */
- Script mount = new Script("/bin/bash", 60000);
- mount.add("-c");
- mount.add("mount " + mountSource + " " + destPath);
- String result = mount.execute();
- if (result != null) {
- destPath = null;
- }
- destroyVMs(destPath);
- } else if (poolName == null) {
- destPath = mountDestPath;
- }
- }
- } else {
- /* Can't find the mount point? */
- /* we need to mount it under poolName */
- if (poolName != null) {
- Script mount = new Script("/bin/bash", 60000);
- mount.add("-c");
- mount.add("mount " + mountSource + " " + destPath);
- String result = mount.execute();
- if (result != null) {
- destPath = null;
- }
-
- destroyVMs(destPath);
- }
- }
-
- return destPath;
- }
-
- protected String getMountPoint(NfsStoragePool storagePool) {
-
- StoragePool pool = null;
- String poolName = null;
- try {
- pool = LibvirtConnection.getConnection()
- .storagePoolLookupByUUIDString(storagePool._poolUUID);
- if (pool != null) {
- StoragePoolInfo spi = pool.getInfo();
- if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
- pool.create(0);
- } else {
- /*
- * Sometimes, the mount point is lost, even libvirt thinks
- * the storage pool still running
- */
- }
- }
- poolName = pool.getName();
- } catch (LibvirtException e) {
-
- } finally {
- try {
- if (pool != null) {
- pool.free();
- }
- } catch (LibvirtException e) {
-
- }
- }
-
- return checkingMountPoint(storagePool, poolName);
- }
-
- protected void destroyVMs(String mountPath) {
- /* if there are VMs using disks under this mount path, destroy them */
- Script cmd = new Script("/bin/bash", _timeout);
- cmd.add("-c");
- cmd.add("ps axu|grep qemu|grep " + mountPath + "* |awk '{print $2}'");
- AllLinesParser parser = new OutputInterpreter.AllLinesParser();
- String result = cmd.execute(parser);
-
- if (result != null) {
- return;
- }
-
- String pids[] = parser.getLines().split("\n");
- for (String pid : pids) {
- Script.runSimpleBashScript("kill -9 " + pid);
- }
- }
-
- protected String getHBFile(String mountPoint, String hostIP) {
- return mountPoint + File.separator + "KVMHA" + File.separator + "hb-"
- + hostIP;
- }
-
- protected String getHBFolder(String mountPoint) {
- return mountPoint + File.separator + "KVMHA" + File.separator;
- }
-
- protected String runScriptRetry(String cmdString,
- OutputInterpreter interpreter) {
- String result = null;
- for (int i = 0; i < 3; i++) {
- Script cmd = new Script("/bin/bash", _timeout);
- cmd.add("-c");
- cmd.add(cmdString);
- if (interpreter != null)
- result = cmd.execute(interpreter);
- else {
- result = cmd.execute();
- }
- if (result == Script.ERR_TIMEOUT) {
- continue;
- } else if (result == null) {
- break;
- }
- }
-
- return result;
- }
-
- public static void main(String[] args) {
-
- NfsStoragePool pool = new KVMHAMonitor.NfsStoragePool(null, null, null,
- null, PoolType.PrimaryStorage);
-
- KVMHAMonitor haWritter = new KVMHAMonitor(pool, "192.168.1.163", null);
- Thread ha = new Thread(haWritter);
- ha.start();
-
- KVMHAChecker haChecker = new KVMHAChecker(haWritter.getStoragePools(),
- "192.168.1.163");
-
- ExecutorService exe = Executors.newFixedThreadPool(1);
- Future<Boolean> future = exe.submit((Callable<Boolean>) haChecker);
- try {
- for (int i = 0; i < 10; i++) {
- System.out.println(future.get());
- future = exe.submit((Callable<Boolean>) haChecker);
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ExecutionException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
+ private long _timeout = 60000; /* 1 minutes */
+ protected static String _heartBeatPath;
+ protected long _heartBeatUpdateTimeout = 60000;
+ protected long _heartBeatUpdateFreq = 60000;
+ protected long _heartBeatUpdateMaxRetry = 3;
+
+ public static enum PoolType {
+ PrimaryStorage, SecondaryStorage
+ }
+
+ public static class NfsStoragePool {
+ String _poolUUID;
+ String _poolIp;
+ String _poolMountSourcePath;
+ String _mountDestPath;
+ PoolType _type;
+
+ public NfsStoragePool(String poolUUID, String poolIp,
+ String poolSourcePath, String mountDestPath, PoolType type) {
+ this._poolUUID = poolUUID;
+ this._poolIp = poolIp;
+ this._poolMountSourcePath = poolSourcePath;
+ this._mountDestPath = mountDestPath;
+ this._type = type;
+ }
+ }
+
+ protected String checkingMountPoint(NfsStoragePool pool, String poolName) {
+ String mountSource = pool._poolIp + ":" + pool._poolMountSourcePath;
+ String mountPaths = Script
+ .runSimpleBashScript("cat /proc/mounts | grep " + mountSource);
+ String destPath = pool._mountDestPath;
+
+ if (mountPaths != null) {
+ String token[] = mountPaths.split(" ");
+ String mountType = token[2];
+ String mountDestPath = token[1];
+ if (mountType.equalsIgnoreCase("nfs")) {
+ if (poolName != null && !mountDestPath.startsWith(destPath)) {
+ /* we need to mount it under poolName */
+ Script mount = new Script("/bin/bash", 60000);
+ mount.add("-c");
+ mount.add("mount " + mountSource + " " + destPath);
+ String result = mount.execute();
+ if (result != null) {
+ destPath = null;
+ }
+ destroyVMs(destPath);
+ } else if (poolName == null) {
+ destPath = mountDestPath;
+ }
+ }
+ } else {
+ /* Can't find the mount point? */
+ /* we need to mount it under poolName */
+ if (poolName != null) {
+ Script mount = new Script("/bin/bash", 60000);
+ mount.add("-c");
+ mount.add("mount " + mountSource + " " + destPath);
+ String result = mount.execute();
+ if (result != null) {
+ destPath = null;
+ }
+
+ destroyVMs(destPath);
+ }
+ }
+
+ return destPath;
+ }
+
+ protected String getMountPoint(NfsStoragePool storagePool) {
+
+ StoragePool pool = null;
+ String poolName = null;
+ try {
+ pool = LibvirtConnection.getConnection()
+ .storagePoolLookupByUUIDString(storagePool._poolUUID);
+ if (pool != null) {
+ StoragePoolInfo spi = pool.getInfo();
+ if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
+ pool.create(0);
+ } else {
+ /*
+ * Sometimes, the mount point is lost, even libvirt thinks
+ * the storage pool still running
+ */
+ }
+ }
+ poolName = pool.getName();
+ } catch (LibvirtException e) {
+
+ } finally {
+ try {
+ if (pool != null) {
+ pool.free();
+ }
+ } catch (LibvirtException e) {
+
+ }
+ }
+
+ return checkingMountPoint(storagePool, poolName);
+ }
+
+ protected void destroyVMs(String mountPath) {
+ /* if there are VMs using disks under this mount path, destroy them */
+ Script cmd = new Script("/bin/bash", _timeout);
+ cmd.add("-c");
+ cmd.add("ps axu|grep qemu|grep " + mountPath + "* |awk '{print $2}'");
+ AllLinesParser parser = new OutputInterpreter.AllLinesParser();
+ String result = cmd.execute(parser);
+
+ if (result != null) {
+ return;
+ }
+
+ String pids[] = parser.getLines().split("\n");
+ for (String pid : pids) {
+ Script.runSimpleBashScript("kill -9 " + pid);
+ }
+ }
+
+ protected String getHBFile(String mountPoint, String hostIP) {
+ return mountPoint + File.separator + "KVMHA" + File.separator + "hb-"
+ + hostIP;
+ }
+
+ protected String getHBFolder(String mountPoint) {
+ return mountPoint + File.separator + "KVMHA" + File.separator;
+ }
+
+ protected String runScriptRetry(String cmdString,
+ OutputInterpreter interpreter) {
+ String result = null;
+ for (int i = 0; i < 3; i++) {
+ Script cmd = new Script("/bin/bash", _timeout);
+ cmd.add("-c");
+ cmd.add(cmdString);
+ if (interpreter != null)
+ result = cmd.execute(interpreter);
+ else {
+ result = cmd.execute();
+ }
+ if (result == Script.ERR_TIMEOUT) {
+ continue;
+ } else if (result == null) {
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ public static void main(String[] args) {
+
+ NfsStoragePool pool = new KVMHAMonitor.NfsStoragePool(null, null, null,
+ null, PoolType.PrimaryStorage);
+
+ KVMHAMonitor haWritter = new KVMHAMonitor(pool, "192.168.1.163", null);
+ Thread ha = new Thread(haWritter);
+ ha.start();
+
+ KVMHAChecker haChecker = new KVMHAChecker(haWritter.getStoragePools(),
+ "192.168.1.163");
+
+ ExecutorService exe = Executors.newFixedThreadPool(1);
+ Future<Boolean> future = exe.submit((Callable<Boolean>) haChecker);
+ try {
+ for (int i = 0; i < 10; i++) {
+ System.out.println(future.get());
+ future = exe.submit((Callable<Boolean>) haChecker);
+ }
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/KVMHAChecker.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/KVMHAChecker.java b/agent/src/com/cloud/agent/resource/computing/KVMHAChecker.java
index d9b4692..b2df8c1 100644
--- a/agent/src/com/cloud/agent/resource/computing/KVMHAChecker.java
+++ b/agent/src/com/cloud/agent/resource/computing/KVMHAChecker.java
@@ -27,59 +27,59 @@ import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
public class KVMHAChecker extends KVMHABase implements Callable<Boolean> {
- private static final Logger s_logger = Logger.getLogger(KVMHAChecker.class);
- private List<NfsStoragePool> _pools;
- private String _hostIP;
- private long _heartBeatCheckerTimeout = 360000; /* 6 minutes */
+ private static final Logger s_logger = Logger.getLogger(KVMHAChecker.class);
+ private List<NfsStoragePool> _pools;
+ private String _hostIP;
+ private long _heartBeatCheckerTimeout = 360000; /* 6 minutes */
- public KVMHAChecker(List<NfsStoragePool> pools, String host) {
- this._pools = pools;
- this._hostIP = host;
- }
+ public KVMHAChecker(List<NfsStoragePool> pools, String host) {
+ this._pools = pools;
+ this._hostIP = host;
+ }
- /*
- * True means heartbeaing is on going, or we can't get it's status. False
- * means heartbeating is stopped definitely
- */
- private Boolean checkingHB() {
- List<Boolean> results = new ArrayList<Boolean>();
- for (NfsStoragePool pool : _pools) {
+ /*
+ * True means heartbeaing is on going, or we can't get it's status. False
+ * means heartbeating is stopped definitely
+ */
+ private Boolean checkingHB() {
+ List<Boolean> results = new ArrayList<Boolean>();
+ for (NfsStoragePool pool : _pools) {
- Script cmd = new Script(_heartBeatPath, _heartBeatCheckerTimeout,
- s_logger);
- cmd.add("-i", pool._poolIp);
- cmd.add("-p", pool._poolMountSourcePath);
- cmd.add("-m", pool._mountDestPath);
- cmd.add("-h", _hostIP);
- cmd.add("-r");
- cmd.add("-t",
- String.valueOf((_heartBeatUpdateFreq + _heartBeatUpdateTimeout) / 1000 * 2));
- OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
- String result = cmd.execute(parser);
- s_logger.debug("pool: " + pool._poolIp);
- s_logger.debug("reture: " + result);
- s_logger.debug("parser: " + parser.getLine());
- if (result == null && parser.getLine().contains("> DEAD <")) {
- s_logger.debug("read heartbeat failed: " + result);
- results.add(false);
- } else {
- results.add(true);
- }
- }
+ Script cmd = new Script(_heartBeatPath, _heartBeatCheckerTimeout,
+ s_logger);
+ cmd.add("-i", pool._poolIp);
+ cmd.add("-p", pool._poolMountSourcePath);
+ cmd.add("-m", pool._mountDestPath);
+ cmd.add("-h", _hostIP);
+ cmd.add("-r");
+ cmd.add("-t",
+ String.valueOf((_heartBeatUpdateFreq + _heartBeatUpdateTimeout) / 1000 * 2));
+ OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
+ String result = cmd.execute(parser);
+ s_logger.debug("pool: " + pool._poolIp);
+ s_logger.debug("reture: " + result);
+ s_logger.debug("parser: " + parser.getLine());
+ if (result == null && parser.getLine().contains("> DEAD <")) {
+ s_logger.debug("read heartbeat failed: " + result);
+ results.add(false);
+ } else {
+ results.add(true);
+ }
+ }
- for (Boolean r : results) {
- if (r) {
- return true;
- }
- }
+ for (Boolean r : results) {
+ if (r) {
+ return true;
+ }
+ }
- return false;
- }
+ return false;
+ }
- @Override
- public Boolean call() throws Exception {
- // s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
- // org.apache.log4j.PatternLayout(), "System.out"));
- return checkingHB();
- }
+ @Override
+ public Boolean call() throws Exception {
+ // s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
+ // org.apache.log4j.PatternLayout(), "System.out"));
+ return checkingHB();
+ }
}