From 3cc5ce864281e9cf31337d222beb0ca1643d3c43 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Thu, 3 Feb 2011 18:57:32 -0500 Subject: [PATCH] add new configuration parameter: cmd.wait, for heavy timing-consuming commands, such as backupsnapshotcommand --- .../computing/LibvirtComputingResource.java | 17 ++++++++++------- .../computing/LibvirtStorageResource.java | 4 ++-- server/src/com/cloud/configuration/Config.java | 1 + .../com/cloud/storage/StorageManagerImpl.java | 14 +++++++++++++- utils/src/com/cloud/utils/script/Script.java | 17 +++++++++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index c7dff6ccf91..d121aad24c1 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -294,6 +294,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected boolean _disconnected = true; protected int _timeout; + protected int _cmdsTimeout; protected int _stopTimeout; protected static HashMap s_statesTable; static { @@ -544,11 +545,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } value = (String)params.get("scripts.timeout"); - _timeout = NumbersUtil.parseInt(value, 120) * 1000; + _timeout = NumbersUtil.parseInt(value, 30*60) * 1000; value = (String)params.get("stop.script.timeout"); _stopTimeout = NumbersUtil.parseInt(value, 120) * 1000; + value = (String)params.get("cmds.timeout"); + _cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000; value = (String)params.get("host.reserved.mem.mb"); _dom0MinMem = NumbersUtil.parseInt(value, 0)*1024*1024; @@ -1004,7 +1007,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } else { /*VM is not running, create a snapshot by ourself*/ - final Script command = new Script(_manageSnapshotPath, _timeout, s_logger); + final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); if (cmd.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) { command.add("-c", VolPath); } else { @@ -1041,7 +1044,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv LibvirtStoragePoolDef spd = _storageResource.getStoragePoolDef(conn, secondaryStoragePool); String ssPmountPath = spd.getTargetPath(); snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId; - Script command = new Script(_manageSnapshotPath, 1800000, s_logger); + Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); command.add("-b", snapshotPath); command.add("-n", snapshotName); command.add("-p", snapshotDestPath); @@ -1079,7 +1082,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv vm.resume(); } } else { - command = new Script(_manageSnapshotPath, _timeout, s_logger); + command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); command.add("-d", snapshotPath); command.add("-n", snapshotName); result = command.execute(); @@ -1107,7 +1110,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String ssPmountPath = spd.getTargetPath(); String snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId; - final Script command = new Script(_manageSnapshotPath, _timeout, s_logger); + final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); command.add("-d", snapshotDestPath); command.add("-n", cmd.getSnapshotName()); @@ -1131,7 +1134,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String ssPmountPath = spd.getTargetPath(); String snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId; - final Script command = new Script(_manageSnapshotPath, _timeout, s_logger); + final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); command.add("-d", snapshotDestPath); command.add("-n", cmd.getSnapshotName()); command.add("-f"); @@ -1338,7 +1341,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv primaryPool = _storageResource.getStoragePool(conn, cmd.getPoolUuid()); LibvirtStorageVolumeDef vol = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, null, null); s_logger.debug(vol.toString()); - primaryVol = _storageResource.copyVolume(primaryPool, vol, tmplVol); + primaryVol = _storageResource.copyVolume(primaryPool, vol, tmplVol, _cmdsTimeout); StorageVolInfo priVolInfo = primaryVol.getInfo(); return new PrimaryStorageDownloadAnswer(primaryVol.getKey(), priVolInfo.allocation); diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java index 72add3f68d5..b71aa40a294 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageResource.java @@ -335,11 +335,11 @@ public class LibvirtStorageResource { return sp; } - public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol) throws LibvirtException { + public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException { StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0); String srcPath = srcVol.getKey(); String destPath = vol.getKey(); - Script.runSimpleBashScript("cp " + srcPath + " " + destPath ); + Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout); return vol; } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index b5dbead5ee2..9ae1274079b 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -130,6 +130,7 @@ public enum Config { StorageCleanupEnabled("Advanced", StorageManager.class, Boolean.class, "storage.cleanup.enabled", "true", "Enables/disables the storage cleanup thread.", null), UpdateWait("Advanced", AgentManager.class, Integer.class, "update.wait", "600", "Time to wait before alerting on a updating agent", null), Wait("Advanced", AgentManager.class, Integer.class, "wait", "1800", "Time to wait for control commands to return", null), + CmdsWait("Advanced", AgentManager.class, Integer.class, "cmd.wait", "7200", "Time to wait for some heavy time-consuming commands", null), Workers("Advanced", AgentManager.class, Integer.class, "workers", "5", "Number of worker threads.", null), MountParent("Advanced", ManagementServer.class, String.class, "mount.parent", "/var/lib/cloud/mnt", "The mount point on the Management Server for Secondary Storage.", null), // UpgradeURL("Advanced", ManagementServer.class, String.class, "upgrade.url", "http://example.com:8080/client/agent/update.zip", "The upgrade URL is the URL of the management server that agents will connect to in order to automatically upgrade.", null), diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index da9b31e15d7..13a7d3704b8 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -253,6 +253,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag private int _maxVolumeSizeInGb; private long _serverId; + private int _snapshotTimeout; + public boolean share(VMInstanceVO vm, List vols, HostVO host, boolean cancelPreviousShare) throws StorageUnavailableException { // if pool is in maintenance and it is the ONLY pool available; reject @@ -712,6 +714,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag _retry = NumbersUtil.parseInt(configs.get(Config.StartRetry.key()), 10); _pingInterval = NumbersUtil.parseInt(configs.get("ping.interval"), 60); _hostRetry = NumbersUtil.parseInt(configs.get("host.retry"), 2); + _snapshotTimeout = NumbersUtil.parseInt(Config.CmdsWait.key(), 2*60*60*1000); _storagePoolAcquisitionWaitSeconds = NumbersUtil.parseInt(configs.get("pool.acquisition.wait.seconds"), 1800); s_logger.info("pool.acquisition.wait.seconds is configured as " + _storagePoolAcquisitionWaitSeconds + " seconds"); @@ -1636,7 +1639,16 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag for (Long hostId : hostIds) { try { - return new Pair(hostId, _agentMgr.send(hostId, cmds)); + List answers = new ArrayList(); + Command[] cmdArray = cmds.toCommands(); + for (Command cmd : cmdArray) { + if (cmd instanceof BackupSnapshotCommand) { + answers.add(_agentMgr.send(hostId, cmd, _snapshotTimeout)); + } else { + answers.add(_agentMgr.send(hostId, cmd)); + } + } + return new Pair(hostId, answers.toArray(new Answer[answers.size()])); } catch (AgentUnavailableException e) { s_logger.debug("Unable to send storage pool command to " + pool, e); } catch (OperationTimedoutException e) { diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java index 4c94817f644..614be735e1c 100755 --- a/utils/src/com/cloud/utils/script/Script.java +++ b/utils/src/com/cloud/utils/script/Script.java @@ -408,6 +408,23 @@ public class Script implements Callable { else return result.trim(); } + + public static String runSimpleBashScript(String command, int timeout) { + + Script s = new Script("/bin/bash", timeout); + s.add("-c"); + s.add(command); + + OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); + if (s.execute(parser) != null) + return null; + + String result = parser.getLine(); + if (result == null || result.trim().isEmpty()) + return null; + else + return result.trim(); + } public static void main(String[] args) { String path = findScript(".", "try.sh");