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