Search in sources :

Example 11 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