Search in sources :

Example 1 with DownloadAnswer

use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.

the class DownloadManagerImpl method handleDownloadProgressCmd.

private DownloadAnswer handleDownloadProgressCmd(final SecondaryStorageResource resource, final DownloadProgressCommand cmd) {
    final String jobId = cmd.getJobId();
    final DownloadAnswer answer;
    DownloadJob dj = null;
    if (jobId != null) {
        dj = this.jobs.get(jobId);
    }
    if (dj == null) {
        if (cmd.getRequest() == RequestType.GET_OR_RESTART) {
            final DownloadCommand dcmd = new DownloadCommand(cmd);
            return handleDownloadCommand(resource, dcmd);
        } else {
            return new DownloadAnswer("Cannot find job", VMTemplateStatus.UNKNOWN);
        }
    }
    final TemplateDownloader td = dj.getTemplateDownloader();
    switch(cmd.getRequest()) {
        case GET_STATUS:
            break;
        case ABORT:
            td.stopDownload();
            sleep();
            break;
        case RESTART:
            td.stopDownload();
            sleep();
            this.threadPool.execute(td);
            break;
        case PURGE:
            td.stopDownload();
            answer = new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
            this.jobs.remove(jobId);
            return answer;
        default:
            // TODO
            break;
    }
    return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
}
Also used : DownloadCommand(com.cloud.legacymodel.communication.command.DownloadCommand) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer)

Example 2 with DownloadAnswer

use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.

the class DownloadListener method processAnswers.

@Override
public boolean processAnswers(final long agentId, final long seq, final 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())) {
                // TODO
                return false;
            }
            transition(DownloadEvent.DOWNLOAD_ANSWER, answer);
            processed = true;
        }
    }
    return processed;
}
Also used : DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer)

Example 3 with DownloadAnswer

use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.

the class DownloadState method handleEvent.

public String handleEvent(final DownloadEvent event, final Object eventObj) {
    if (s_logger.isTraceEnabled()) {
        getDownloadListener().logTrace("handleEvent, event type=" + event + ", curr state=" + getName());
    }
    switch(event) {
        case DOWNLOAD_ANSWER:
            final DownloadAnswer answer = (DownloadAnswer) eventObj;
            return handleAnswer(answer);
        case ABANDON_DOWNLOAD:
            return handleAbort();
        case TIMEOUT_CHECK:
            final Date now = new Date();
            final long update = now.getTime() - dl.getLastUpdated().getTime();
            return handleTimeout(update);
        case DISCONNECT:
            return handleDisconnect();
    }
    return null;
}
Also used : DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer) Date(java.util.Date)

Example 4 with DownloadAnswer

use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.

the class DownloadManagerImpl method handleDownloadCommand.

@Override
public DownloadAnswer handleDownloadCommand(final SecondaryStorageResource resource, final DownloadCommand cmd) {
    final ResourceType resourceType = cmd.getResourceType();
    if (cmd instanceof DownloadProgressCommand) {
        return handleDownloadProgressCmd(resource, (DownloadProgressCommand) cmd);
    }
    if (cmd.getUrl() == null) {
        return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download", VMTemplateStatus.DOWNLOAD_ERROR);
    }
    if (cmd.getName() == null) {
        return new DownloadAnswer("Invalid Name", VMTemplateStatus.DOWNLOAD_ERROR);
    }
    final DataStoreTO dstore = cmd.getDataStore();
    String installPathPrefix = cmd.getInstallPath();
    // for NFS, we need to get mounted path
    if (dstore instanceof NfsTO) {
        installPathPrefix = resource.getRootDir(((NfsTO) dstore).getUrl()) + File.separator + installPathPrefix;
    }
    String user = null;
    String password = null;
    if (cmd.getAuth() != null) {
        user = cmd.getAuth().getUserName();
        password = cmd.getAuth().getPassword();
    }
    // TO DO - Define Volume max size as well
    final long maxDownloadSizeInBytes = cmd.getMaxDownloadSizeInBytes() == null ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : cmd.getMaxDownloadSizeInBytes();
    String jobId = null;
    jobId = downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, cmd.getInstallPath(), user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
    sleep();
    if (jobId == null) {
        return new DownloadAnswer("Internal Error", VMTemplateStatus.DOWNLOAD_ERROR);
    }
    return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) ResourceType(com.cloud.legacymodel.communication.command.DownloadCommand.ResourceType) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO) DownloadProgressCommand(com.cloud.legacymodel.communication.command.DownloadProgressCommand)

Example 5 with DownloadAnswer

use of com.cloud.legacymodel.communication.answer.DownloadAnswer in project cosmic by MissionCriticalCloud.

the class BaseImageStoreDriverImpl method createTemplateAsyncCallback.

protected Void createTemplateAsyncCallback(final AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, final CreateContext<CreateCmdResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing image store createTemplate async callback");
    }
    final DownloadAnswer answer = callback.getResult();
    final DataObject obj = context.data;
    final DataStore store = obj.getDataStore();
    final TemplateDataStoreVO tmpltStoreVO = this._templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
    if (tmpltStoreVO != null) {
        if (tmpltStoreVO.getDownloadState() == VMTemplateStatus.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        final TemplateDataStoreVO updateBuilder = this._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());
        this._templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
        // update size in vm_template table
        final VMTemplateVO tmlptUpdater = this._templateDao.createForUpdate();
        tmlptUpdater.setSize(answer.getTemplateSize());
        this._templateDao.update(obj.getId(), tmlptUpdater);
    }
    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 register template: " + obj.getUuid() + " with error: " + answer.getErrorString();
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStatus.DOWNLOADED) {
        if (answer.getCheckSum() != null) {
            final VMTemplateVO templateDaoBuilder = this._templateDao.createForUpdate();
            templateDaoBuilder.setChecksum(answer.getCheckSum());
            this._templateDao.update(obj.getId(), templateDaoBuilder);
        }
        final CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

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