add new configuration parameter: cmd.wait, for heavy timing-consuming commands, such as backupsnapshotcommand

This commit is contained in:
Edison Su 2011-02-03 18:57:32 -05:00
parent 6f55c4dd7e
commit 3cc5ce8642
5 changed files with 43 additions and 10 deletions

View File

@ -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<DomainInfo.DomainState, State> 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);

View File

@ -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;
}

View File

@ -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),

View File

@ -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<VolumeVO> 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<Long, Answer[]>(hostId, _agentMgr.send(hostId, cmds));
List<Answer> answers = new ArrayList<Answer>();
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<Long, Answer[]>(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) {

View File

@ -408,6 +408,23 @@ public class Script implements Callable<String> {
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");