Search in sources :

Example 1 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadListener method updateDatabase.

public synchronized void updateDatabase(UploadAnswer answer) {
    if (answer.getErrorString().startsWith("553")) {
        answer.setErrorString(answer.getErrorString().concat("Please check if the file name already exists."));
    }
    resultObj.setResultString(answer.getErrorString());
    resultObj.setState(answer.getUploadStatus().toString());
    resultObj.setUploadPercent(answer.getUploadPct());
    if (answer.getUploadStatus() == Status.UPLOAD_IN_PROGRESS) {
        asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L);
        asyncMgr.updateAsyncJobStatus(asyncJobId, JobInfo.Status.IN_PROGRESS.ordinal(), ApiSerializerHelper.toSerializedString(resultObj));
    } else if (answer.getUploadStatus() == Status.UPLOADED) {
        resultObj.setResultString("Success");
        asyncMgr.completeAsyncJob(asyncJobId, JobInfo.Status.SUCCEEDED, 1, ApiSerializerHelper.toSerializedString(resultObj));
    } else {
        asyncMgr.completeAsyncJob(asyncJobId, JobInfo.Status.FAILED, 2, ApiSerializerHelper.toSerializedString(resultObj));
    }
    UploadVO updateBuilder = uploadDao.createForUpdate();
    updateBuilder.setUploadPercent(answer.getUploadPct());
    updateBuilder.setUploadState(answer.getUploadStatus());
    updateBuilder.setLastUpdated(new Date());
    updateBuilder.setErrorString(answer.getErrorString());
    updateBuilder.setJobId(answer.getJobId());
    uploadDao.update(getUploadId(), updateBuilder);
}
Also used : UploadVO(com.cloud.storage.UploadVO) Date(java.util.Date)

Example 2 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadListener method updateDatabase.

public void updateDatabase(Status state, String uploadErrorString) {
    resultObj.setResultString(uploadErrorString);
    resultObj.setState(state.toString());
    asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L);
    asyncMgr.updateAsyncJobStatus(asyncJobId, JobInfo.Status.IN_PROGRESS.ordinal(), ApiSerializerHelper.toSerializedString(resultObj));
    UploadVO vo = uploadDao.createForUpdate();
    vo.setUploadState(state);
    vo.setLastUpdated(new Date());
    vo.setErrorString(uploadErrorString);
    uploadDao.update(getUploadId(), vo);
}
Also used : UploadVO(com.cloud.storage.UploadVO) Date(java.util.Date)

Example 3 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadMonitorImpl method cleanupStorage.

public void cleanupStorage() {
    final int EXTRACT_URL_LIFE_LIMIT_IN_SECONDS = _urlExpirationInterval;
    List<UploadVO> extractJobs = _uploadDao.listByModeAndStatus(Mode.HTTP_DOWNLOAD, Status.DOWNLOAD_URL_CREATED);
    for (UploadVO extractJob : extractJobs) {
        if (getTimeDiff(extractJob.getLastUpdated()) > EXTRACT_URL_LIFE_LIMIT_IN_SECONDS) {
            String path = extractJob.getInstallPath();
            DataStore secStore = storeMgr.getDataStore(extractJob.getDataStoreId(), DataStoreRole.Image);
            // Would delete the symlink for the Type and if Type == VOLUME then also the volume
            DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(path, extractJob.getType(), extractJob.getUploadUrl(), ((ImageStoreVO) secStore).getParent());
            EndPoint ep = _epSelector.select(secStore);
            if (ep == null) {
                s_logger.warn("UploadMonitor cleanup: There is no secondary storage VM for secondary storage host " + extractJob.getDataStoreId());
                //TODO: why continue? why not break?
                continue;
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("UploadMonitor cleanup: Sending deletion of extract URL " + extractJob.getUploadUrl() + " to ssvm " + ep.getHostAddr());
            }
            Answer ans = ep.sendMessage(cmd);
            if (ans != null && ans.getResult()) {
                _uploadDao.remove(extractJob.getId());
            } else {
                s_logger.warn("UploadMonitor cleanup: Unable to delete the link for " + extractJob.getType() + " id=" + extractJob.getTypeId() + " url=" + extractJob.getUploadUrl() + " on ssvm " + ep.getHostAddr());
            }
        }
    }
}
Also used : Answer(com.cloud.agent.api.Answer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) UploadVO(com.cloud.storage.UploadVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) DeleteEntityDownloadURLCommand(com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand)

Example 4 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadMonitorImpl method extractTemplate.

@Override
public Long extractTemplate(VMTemplateVO template, String url, TemplateDataStoreVO vmTemplateHost, Long dataCenterId, long eventId, long asyncJobId, AsyncJobManager asyncMgr) {
    Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
    DataStore secStore = storeMgr.getImageStore(dataCenterId);
    UploadVO uploadTemplateObj = new UploadVO(secStore.getId(), template.getId(), new Date(), Upload.Status.NOT_UPLOADED, type, url, Mode.FTP_UPLOAD);
    _uploadDao.persist(uploadTemplateObj);
    if (vmTemplateHost != null) {
        start();
        UploadCommand ucmd = new UploadCommand(template, url, vmTemplateHost.getInstallPath(), vmTemplateHost.getSize());
        UploadListener ul = new UploadListener(secStore, _timer, _uploadDao, uploadTemplateObj, this, ucmd, template.getAccountId(), template.getName(), type, eventId, asyncJobId, asyncMgr);
        _listenerMap.put(uploadTemplateObj, ul);
        try {
            EndPoint ep = _epSelector.select(secStore);
            if (ep == null) {
                String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                s_logger.error(errMsg);
                return null;
            }
            ep.sendMessageAsync(ucmd, new UploadListener.Callback(ep.getId(), ul));
        } catch (Exception e) {
            s_logger.warn("Unable to start upload of " + template.getUniqueName() + " from " + secStore.getName() + " to " + url, e);
            ul.setDisconnected();
            ul.scheduleStatusCheck(RequestType.GET_OR_RESTART);
        }
        return uploadTemplateObj.getId();
    }
    return null;
}
Also used : Type(com.cloud.storage.Upload.Type) RequestType(com.cloud.agent.api.storage.UploadProgressCommand.RequestType) UploadCommand(com.cloud.agent.api.storage.UploadCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) UploadVO(com.cloud.storage.UploadVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) Date(java.util.Date) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method allocCapacity.

private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Allocate secondary storage vm standby capacity for data center : " + dataCenterId);
    }
    if (!isSecondaryStorageVmRequired(dataCenterId)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " according to zone config");
        }
        return;
    }
    SecondaryStorageVmVO secStorageVm = null;
    String errorString = null;
    try {
        boolean secStorageVmFromStoppedPool = false;
        secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
        if (secStorageVm == null) {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("No stopped secondary storage vm is available, need to allocate a new secondary storage vm");
            }
            if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
                try {
                    secStorageVm = startNew(dataCenterId, role);
                    for (UploadVO upload : _uploadDao.listAll()) {
                        _uploadDao.expunge(upload.getId());
                    }
                } finally {
                    _allocLock.unlock();
                }
            } else {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Unable to acquire synchronization lock for secondary storage vm allocation, wait for next scan");
                }
                return;
            }
        } else {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Found a stopped secondary storage vm, starting it. Vm id : " + secStorageVm.getId());
            }
            secStorageVmFromStoppedPool = true;
        }
        if (secStorageVm != null) {
            long secStorageVmId = secStorageVm.getId();
            GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVmId));
            try {
                if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
                    try {
                        secStorageVm = startSecStorageVm(secStorageVmId);
                    } finally {
                        secStorageVmLock.unlock();
                    }
                } else {
                    if (s_logger.isInfoEnabled()) {
                        s_logger.info("Unable to acquire synchronization lock for starting secondary storage vm id : " + secStorageVm.getId());
                    }
                    return;
                }
            } finally {
                secStorageVmLock.releaseRef();
            }
            if (secStorageVm == null) {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Unable to start secondary storage vm for standby capacity, vm id : " + secStorageVmId + ", will recycle it and start a new one");
                }
                if (secStorageVmFromStoppedPool) {
                    destroySecStorageVm(secStorageVmId);
                }
            } else {
                SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_UP, dataCenterId, secStorageVmId, secStorageVm, null));
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
                }
            }
        }
    } catch (Exception e) {
        errorString = e.getMessage();
        throw e;
    } finally {
        // Also add failure reason since startvm masks some of them.
        if (secStorageVm == null || secStorageVm.getState() != State.Running)
            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, 0l, null, errorString));
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UploadVO(com.cloud.storage.UploadVO) SecStorageVmAlertEventArgs(com.cloud.storage.secondary.SecStorageVmAlertEventArgs) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URISyntaxException(java.net.URISyntaxException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Aggregations

UploadVO (com.cloud.storage.UploadVO)11 Date (java.util.Date)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 Answer (com.cloud.agent.api.Answer)3 CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)2 RequestType (com.cloud.agent.api.storage.UploadProgressCommand.RequestType)2 HostVO (com.cloud.host.HostVO)2 Type (com.cloud.storage.Upload.Type)2 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)2 ConfigurationException (javax.naming.ConfigurationException)2 DeleteEntityDownloadURLCommand (com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand)1 UploadCommand (com.cloud.agent.api.storage.UploadCommand)1 DataCenter (com.cloud.dc.DataCenter)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 ProjectAccount (com.cloud.projects.ProjectAccount)1