@Override public Answer executeRequest(Command cmd) { if (cmd instanceof DownloadProgressCommand) { return new DownloadAnswer(null, 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, "dummyFS", "/dummy"); } else if (cmd instanceof DownloadCommand) { return new DownloadAnswer(null, 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, "dummyFS", "/dummy"); } else if (cmd instanceof GetStorageStatsCommand) { return execute((GetStorageStatsCommand)cmd); } else if (cmd instanceof CheckHealthCommand) { return new CheckHealthAnswer((CheckHealthCommand)cmd, true); } else if (cmd instanceof ReadyCommand) { return new ReadyAnswer((ReadyCommand)cmd); } else { return Answer.createUnsupportedCommandAnswer(cmd); } }
@Override public boolean processAnswers(long agentId, long seq, Answer[] answers) { boolean processed = false; if (answers != null & answers.length > 0) { if (answers[0] instanceof DownloadAnswer) { final DownloadAnswer answer = (DownloadAnswer)answers[0]; if (getJobId() == null) { setJobId(answer.getJobId()); } else if (!getJobId().equalsIgnoreCase(answer.getJobId())) { return false;//TODO } transition(DownloadEvent.DOWNLOAD_ANSWER, answer); processed = true; } } return processed; }
public void setInstallPath(String installPath) { this.installPath = fixPath(installPath); }
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()); _volumeStoreDao.update(volStoreVO.getId(), updateBuilder); volUpdater.setSize(answer.getTemplateSize()); volumeDao.update(obj.getId(), volUpdater); if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) { CreateCmdResult result = new CreateCmdResult(null, null); result.setSuccess(false); result.setResult(answer.getErrorString()); caller.complete(result); String msg = "Failed to upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString(); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg); s_logger.error(msg); } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { CreateCmdResult result = new CreateCmdResult(null, null); caller.complete(result);
DownloadAnswer dwdAnswer = (DownloadAnswer)answer; 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) {
@Override public String handleAnswer(DownloadAnswer answer) { if (s_logger.isTraceEnabled()) { s_logger.trace("handleAnswer, answer status=" + answer.getDownloadStatus() + ", curr state=" + getName()); } switch (answer.getDownloadStatus()) { case DOWNLOAD_IN_PROGRESS: getDownloadListener().scheduleStatusCheck(RequestType.GET_STATUS); return Status.DOWNLOAD_IN_PROGRESS.toString(); case DOWNLOADED: getDownloadListener().cancelTimeoutTask(); return Status.DOWNLOADED.toString(); case NOT_DOWNLOADED: getDownloadListener().scheduleStatusCheck(RequestType.GET_STATUS); return Status.NOT_DOWNLOADED.toString(); case DOWNLOAD_ERROR: getDownloadListener().cancelStatusTask(); getDownloadListener().cancelTimeoutTask(); return Status.DOWNLOAD_ERROR.toString(); case UNKNOWN: getDownloadListener().cancelStatusTask(); getDownloadListener().cancelTimeoutTask(); return Status.DOWNLOAD_ERROR.toString(); default: return null; } }
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()); _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder); tmlptUpdater.setSize(answer.getTemplateSize()); _templateDao.update(obj.getId(), tmlptUpdater); if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) { CreateCmdResult result = new CreateCmdResult(null, null); result.setSuccess(false); result.setResult(answer.getErrorString()); caller.complete(result); String msg = "Failed to register template: " + obj.getUuid() + " with error: " + answer.getErrorString(); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, _vmTemplateZoneDao.listByTemplateId(obj.getId()).get(0).getZoneId(), null, msg, msg); s_logger.error(msg); } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { if (answer.getCheckSum() != null) { VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate(); templateDaoBuilder.setChecksum(answer.getCheckSum()); _templateDao.update(obj.getId(), templateDaoBuilder);
DownloadAnswer dwdAnswer = (DownloadAnswer)answer; 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) {
@Override public String handleAnswer(DownloadAnswer answer) { switch (answer.getDownloadStatus()) { case DOWNLOAD_IN_PROGRESS: getDownloadListener().scheduleStatusCheck(RequestType.GET_STATUS); return Status.DOWNLOAD_IN_PROGRESS.toString(); case DOWNLOADED: getDownloadListener().scheduleImmediateStatusCheck(RequestType.PURGE); getDownloadListener().cancelTimeoutTask(); return Status.DOWNLOADED.toString(); case NOT_DOWNLOADED: getDownloadListener().scheduleStatusCheck(RequestType.GET_STATUS); return Status.NOT_DOWNLOADED.toString(); case DOWNLOAD_ERROR: getDownloadListener().cancelStatusTask(); getDownloadListener().cancelTimeoutTask(); return Status.DOWNLOAD_ERROR.toString(); case UNKNOWN: getDownloadListener().cancelStatusTask(); getDownloadListener().cancelTimeoutTask(); return Status.DOWNLOAD_ERROR.toString(); default: return null; } }
@Override public void downloadTemplateToStorage(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) { if(template != null) { long templateId = template.getId(); 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"); DownloadAnswer ans = new DownloadAnswer("Template url is null", Status.UNKNOWN); callback.complete(ans); } } else { s_logger.info("Template download is already in progress or already downloaded"); DownloadAnswer ans = new DownloadAnswer("Template download is already in progress or already downloaded", Status.UNKNOWN); callback.complete(ans); } } }
public DownloadAnswer(String jobId, int downloadPct, String errorString, Status downloadStatus, String fileSystemPath, String installPath, long templateSize, long templatePhySicalSize, String checkSum) { super(); this.jobId = jobId; this.downloadPct = downloadPct; this.errorString = errorString; this.details = errorString; this.downloadStatus = downloadStatus; this.downloadPath = fileSystemPath; this.installPath = fixPath(installPath); this.templateSize = templateSize; this.templatePhySicalSize = templatePhySicalSize; this.checkSum = checkSum; }
public DownloadListener(EndPoint ssAgent, DataStore store, DataObject object, Timer timer, DownloadMonitorImpl downloadMonitor, DownloadCommand cmd, AsyncCompletionCallback<DownloadAnswer> callback) { _ssAgent = ssAgent; this.object = object; _downloadMonitor = downloadMonitor; _cmd = cmd; initStateMachine(); _currState = getState(Status.NOT_DOWNLOADED.toString()); this._timer = timer; _timeoutTask = new TimeoutTask(this); this._timer.schedule(_timeoutTask, 3 * STATUS_POLL_INTERVAL); _callback = callback; DownloadAnswer answer = new DownloadAnswer("", Status.NOT_DOWNLOADED); callback(answer); }
DataStoreTO cacheStore = cmd.getCacheStore(); if (cacheStore == null || !(cacheStore instanceof NfsTO)) { return new DownloadAnswer("cache store can't be null", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, swiftPath, swiftPath, virtualSize, file.length(), md5sum); return answer; } catch (IOException e) { s_logger.debug("Failed to register template into swift", e); return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); } finally { if (file != null) {
@Override public void onEntry(String prevState, DownloadEvent event, Object evtObj) { super.onEntry(prevState, event, evtObj); if (!prevState.equalsIgnoreCase(getName())) { DownloadAnswer answer = new DownloadAnswer("Download canceled", Status.ABANDONED); getDownloadListener().callback(answer); getDownloadListener().cancelStatusTask(); getDownloadListener().cancelTimeoutTask(); getDownloadListener().sendCommand(RequestType.ABORT); } }
@Override public void onEntry(String prevState, DownloadEvent event, Object evtObj) { super.onEntry(prevState, event, evtObj); if (event == DownloadEvent.DISCONNECT) { getDownloadListener().logDisconnect(); getDownloadListener().cancelStatusTask(); getDownloadListener().cancelTimeoutTask(); DownloadAnswer answer = new DownloadAnswer("Storage agent or storage VM disconnected", Status.DOWNLOAD_ERROR); getDownloadListener().callback(answer); getDownloadListener().log("Entering download error state because the storage host disconnected", Level.WARN); } else if (event == DownloadEvent.TIMEOUT_CHECK) { DownloadAnswer answer = new DownloadAnswer("Timeout waiting for response from storage host", Status.DOWNLOAD_ERROR); getDownloadListener().callback(answer); getDownloadListener().log("Entering download error state: timeout waiting for response from storage host", Level.WARN); } getDownloadListener().setDownloadInactive(Status.DOWNLOAD_ERROR); }
return handleDownloadCommand(resource, dcmd); } else { return new DownloadAnswer("Cannot find job", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.UNKNOWN); td.stopDownload(); answer = new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId)); jobs.remove(jobId); break; // TODO return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); return new DownloadAnswer("invalid algorithm: " + cmd.getChecksum(), VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED); return new DownloadAnswer("Internal Error", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));