Search in sources :

Example 21 with DownloadAnswer

use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.

the class BaseImageStoreDriverImpl method createTemplateAsyncCallback.

protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, CreateContext<CreateCmdResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing image store createTemplate async callback");
    }
    DownloadAnswer answer = callback.getResult();
    DataObject obj = context.data;
    DataStore store = obj.getDataStore();
    TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
    if (tmpltStoreVO != null) {
        if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        TemplateDataStoreVO updateBuilder = _templateStoreDao.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());
        _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
        // update size in vm_template table
        VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
        tmlptUpdater.setSize(answer.getTemplateSize());
        _templateDao.update(obj.getId(), tmlptUpdater);
    }
    AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
    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);
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Aggregations

DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)5 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)4 NfsTO (com.cloud.agent.api.to.NfsTO)4 MockVolumeVO (com.cloud.simulator.MockVolumeVO)4 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 DownloadCommand (org.apache.cloudstack.storage.command.DownloadCommand)4 VolumeVO (com.cloud.storage.VolumeVO)3 Date (java.util.Date)3 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)3 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 SwiftTO (com.cloud.agent.api.to.SwiftTO)2 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)2 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ConfigurationException (javax.naming.ConfigurationException)2