try {
txn.start();
String volumeId = cmd.getJobId();
MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
if (volume == null) {
return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
}
long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
volume.setSize(size);
double volumeSize = volume.getSize();
double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
if (pct >= 1.0) {
volume.setStatus(Status.DOWNLOADED);
_mockVolumeDao.update(volume.getId(), volume);
txn.commit();
return new DownloadAnswer(cmd.getJobId(), 100, cmd,
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(),
volume.getName());
} else {
_mockVolumeDao.update(volume.getId(), volume);
txn.commit();
return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd,
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(),
volume.getName());
}
} catch (Exception ex) {
txn.rollback();