made taking snapshots more resilient with retries

This commit is contained in:
David Ribeiro Alves 2012-03-15 03:24:53 +00:00
parent b1333b1f2c
commit 04f72a67d7
2 changed files with 29 additions and 17 deletions

View File

@ -99,6 +99,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
.getVBox()
.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(),
vmSpec.isForceOverwrite());
List<CloneOptions> options = new ArrayList<CloneOptions>();
if (isLinkedClone)
options.add(CloneOptions.Link);

View File

@ -40,7 +40,6 @@ import com.google.common.base.Throwables;
*/
public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISnapshot> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@ -49,7 +48,6 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISna
private String snapshotName;
private String snapshotDesc;
public TakeSnapshotIfNotAlreadyAttached(Supplier<VirtualBoxManager> manager, String snapshotName, String snapshotDesc) {
this.manager = manager;
this.snapshotName = snapshotName;
@ -61,22 +59,35 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISna
// Snapshot a machine
ISession session = null;
if (machine.getCurrentSnapshot() == null) {
int retries = 10;
while (true) {
try {
session = manager.get().openMachineSession(machine);
IProgress progress = session.getConsole().takeSnapshot(snapshotName, snapshotDesc);
progress.waitForCompletion(-1);
if (progress.getCompleted())
logger.debug("Snapshot %s (description: %s) taken from %s", snapshotName, snapshotDesc, machine.getName());
logger.debug("Snapshot %s (description: %s) taken from %s", snapshotName, snapshotDesc,
machine.getName());
break;
} catch (Exception e) {
logger.error(e, "Problem creating snapshot %s (descripton: %s) from machine %s", snapshotName, snapshotDesc, machine.getName());
Throwables.propagate(e);
assert false;
if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
retries--;
if (retries == 0) {
logger.error(e,
"Problem creating snapshot (too many retries) %s (descripton: %s) from machine %s",
snapshotName, snapshotDesc, machine.getName());
throw Throwables.propagate(e);
}
}
logger.error(e, "Problem creating snapshot %s (descripton: %s) from machine %s", snapshotName,
snapshotDesc, machine.getName());
throw Throwables.propagate(e);
} finally {
if (session != null) {
session.unlockMachine();
}
}
}
}
return machine.getCurrentSnapshot();
}