Search in sources :

Example 6 with DownloadAnswer

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;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Example 7 with DownloadAnswer

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);
    }
}
Also used : VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 8 with DownloadAnswer

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);
    }
}
Also used : DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer)

Example 9 with DownloadAnswer

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);
}
Also used : DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer)

Example 10 with DownloadAnswer

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);
        }
    }
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer)

Aggregations

DownloadAnswer (com.cloud.legacymodel.communication.answer.DownloadAnswer)10 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 Date (java.util.Date)3 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)2 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)2 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)2 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)1 DownloadCommand (com.cloud.legacymodel.communication.command.DownloadCommand)1 ResourceType (com.cloud.legacymodel.communication.command.DownloadCommand.ResourceType)1 DownloadProgressCommand (com.cloud.legacymodel.communication.command.DownloadProgressCommand)1 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)1 NfsTO (com.cloud.legacymodel.to.NfsTO)1 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)1