use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.
the class BaseImageStoreDriverImpl method createVolumeAsyncCallback.
protected Void createVolumeAsyncCallback(final AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, final CreateContext<CreateCmdResult> context) {
final DownloadAnswer answer = callback.getResult();
final DataObject obj = context.data;
final DataStore store = obj.getDataStore();
final VolumeDataStoreVO volStoreVO = this._volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
if (volStoreVO != null) {
if (volStoreVO.getDownloadState() == VMTemplateStatus.DOWNLOADED) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
}
return null;
}
final VolumeDataStoreVO updateBuilder = this._volumeStoreDao.createForUpdate();
updateBuilder.setDownloadPercent(answer.getDownloadPct());
updateBuilder.setDownloadState(answer.getDownloadStatus());
updateBuilder.setLastUpdated(new Date());
updateBuilder.setErrorString(answer.getErrorString());
updateBuilder.setJobId(answer.getJobId());
updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
updateBuilder.setInstallPath(answer.getInstallPath());
updateBuilder.setSize(answer.getTemplateSize());
updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
this._volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
// update size in volume table
final VolumeVO volUpdater = this.volumeDao.createForUpdate();
volUpdater.setSize(answer.getTemplateSize());
this.volumeDao.update(obj.getId(), volUpdater);
}
final AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
if (answer.getDownloadStatus() == VMTemplateStatus.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStatus.ABANDONED || answer.getDownloadStatus() == VMTemplateStatus.UNKNOWN) {
final CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(answer.getErrorString());
caller.complete(result);
final String msg = "Failed to upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString();
this._alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg);
s_logger.error(msg);
} else if (answer.getDownloadStatus() == VMTemplateStatus.DOWNLOADED) {
final CreateCmdResult result = new CreateCmdResult(null, null);
caller.complete(result);
}
return null;
}
use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.
the class VolumeObject method processDownloadAnswer.
private void processDownloadAnswer(Answer answer) {
// image store or imageCache store
if (answer instanceof DownloadAnswer) {
final DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
final VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
volStore.setInstallPath(dwdAnswer.getInstallPath());
volStore.setChecksum(dwdAnswer.getCheckSum());
volumeStoreDao.update(volStore.getId(), volStore);
} else if (answer instanceof CopyCmdAnswer) {
final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
final VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
volStore.setInstallPath(newVol.getPath());
if (newVol.getSize() != null) {
volStore.setSize(newVol.getSize());
}
volumeStoreDao.update(volStore.getId(), volStore);
}
}
use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.
the class DownloadAbandonedState method onEntry.
@Override
public void onEntry(final String prevState, final DownloadEvent event, final Object evtObj) {
super.onEntry(prevState, event, evtObj);
if (!prevState.equalsIgnoreCase(getName())) {
final DownloadAnswer answer = new DownloadAnswer("Download canceled", VMTemplateStatus.ABANDONED);
getDownloadListener().callback(answer);
getDownloadListener().cancelStatusTask();
getDownloadListener().cancelTimeoutTask();
getDownloadListener().sendCommand(RequestType.ABORT);
}
}
use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.
the class DownloadErrorState method onEntry.
@Override
public void onEntry(final String prevState, final DownloadEvent event, final Object evtObj) {
super.onEntry(prevState, event, evtObj);
if (event == DownloadEvent.DISCONNECT) {
getDownloadListener().logDisconnect();
getDownloadListener().cancelStatusTask();
getDownloadListener().cancelTimeoutTask();
final DownloadAnswer answer = new DownloadAnswer("Storage agent or storage VM disconnected", VMTemplateStatus.DOWNLOAD_ERROR);
getDownloadListener().callback(answer);
getDownloadListener().logWarn("Entering download error state because the storage host disconnected");
} else if (event == DownloadEvent.TIMEOUT_CHECK) {
final DownloadAnswer answer = new DownloadAnswer("Timeout waiting for response from storage host", VMTemplateStatus.DOWNLOAD_ERROR);
getDownloadListener().callback(answer);
getDownloadListener().logWarn("Entering download error state: timeout waiting for response from storage host");
}
getDownloadListener().setDownloadInactive(VMTemplateStatus.DOWNLOAD_ERROR);
}
use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.
the class DownloadMonitorImpl method downloadTemplateToStorage.
@Override
public void downloadTemplateToStorage(final DataObject template, final AsyncCompletionCallback<DownloadAnswer> callback) {
if (template != null) {
final long templateId = template.getId();
final DataStore store = template.getDataStore();
if (isTemplateUpdateable(templateId, store.getId())) {
if (template.getUri() != null) {
initiateTemplateDownload(template, callback);
} else {
s_logger.info("Template url is null, cannot download");
final DownloadAnswer ans = new DownloadAnswer("Template url is null", VMTemplateStatus.UNKNOWN);
callback.complete(ans);
}
} else {
s_logger.info("Template download is already in progress or already downloaded");
final DownloadAnswer ans = new DownloadAnswer("Template download is already in progress or already downloaded", VMTemplateStatus.UNKNOWN);
callback.complete(ans);
}
}
}
Aggregations