Search in sources :

Example 1 with SecStorageVmAlertEventArgs

use of com.cloud.storage.secondary.SecStorageVmAlertEventArgs in project cloudstack by apache.

the class SecondaryStorageManagerImpl method rebootSecStorageVm.

@Override
public boolean rebootSecStorageVm(long secStorageVmId) {
    final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
    if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) {
        return false;
    }
    if (secStorageVm.getState() == State.Running && secStorageVm.getHostId() != null) {
        final RebootCommand cmd = new RebootCommand(secStorageVm.getInstanceName(), _itMgr.getExecuteInSequence(secStorageVm.getHypervisorType()));
        final Answer answer = _agentMgr.easySend(secStorageVm.getHostId(), cmd);
        String secondaryStorageVmName = secStorageVm.getHostName();
        if (answer != null && answer.getResult()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(String.format("Successfully reboot secondary storage VM [%s].", secondaryStorageVmName));
            }
            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null));
            return true;
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(String.format("Unable to reboot secondary storage VM [%s] due to [%s].", secondaryStorageVmName, answer == null ? "answer null" : answer.getDetails()));
            }
            return false;
        }
    } else {
        return startSecStorageVm(secStorageVmId) != null;
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) RebootCommand(com.cloud.agent.api.RebootCommand) SecStorageVmAlertEventArgs(com.cloud.storage.secondary.SecStorageVmAlertEventArgs)

Example 2 with SecStorageVmAlertEventArgs

use of com.cloud.storage.secondary.SecStorageVmAlertEventArgs in project cloudstack by apache.

the class SecondaryStorageManagerImpl method startNew.

public SecondaryStorageVmVO startNew(long dataCenterId, SecondaryStorageVm.Role role) {
    if (!isSecondaryStorageVmRequired(dataCenterId)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(String.format("Secondary storage VM not required in zone [%s] account to zone config.", dataCenterId));
        }
        return null;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(String.format("Assign secondary storage VM from a newly started instance for request from data center [%s].", dataCenterId));
    }
    Map<String, Object> context = createSecStorageVmInstance(dataCenterId, role);
    long secStorageVmId = (Long) context.get("secStorageVmId");
    if (secStorageVmId == 0) {
        s_logger.debug(String.format("Creating secondary storage VM instance failed on data center [%s].", dataCenterId));
        return null;
    }
    SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
    if (secStorageVm != null) {
        SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATED, dataCenterId, secStorageVmId, secStorageVm, null));
        return secStorageVm;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(String.format("Unable to allocate secondary storage VM [%s] due to it was not found on database.", secStorageVmId));
        }
        SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, "Unable to allocate storage"));
    }
    return null;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) SecStorageVmAlertEventArgs(com.cloud.storage.secondary.SecStorageVmAlertEventArgs)

Example 3 with SecStorageVmAlertEventArgs

use of com.cloud.storage.secondary.SecStorageVmAlertEventArgs in project cloudstack by apache.

the class SecondaryStorageManagerImpl method allocCapacity.

public void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
    s_logger.debug(String.format("Allocate secondary storage VM standby capacity for zone [%s].", dataCenterId));
    if (!isSecondaryStorageVmRequired(dataCenterId)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(String.format("Secondary storage VM not required in zone [%s] according to zone config.", dataCenterId));
        }
        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_IN_SECONDS)) {
                try {
                    secStorageVm = startNew(dataCenterId, role);
                } 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(String.format("Found a stopped secondary storage %s, starting it.", secStorageVm.toString()));
            }
            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_IN_SECONDS)) {
                    try {
                        secStorageVm = startSecStorageVm(secStorageVmId);
                    } finally {
                        secStorageVmLock.unlock();
                    }
                } else {
                    if (s_logger.isInfoEnabled()) {
                        s_logger.info(String.format("Unable to acquire synchronization lock for starting secondary storage %s.", secStorageVm.toString()));
                    }
                    return;
                }
            } finally {
                secStorageVmLock.releaseRef();
            }
            if (secStorageVm == null) {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info(String.format("Unable to start secondary storage VM [%s] for standby capacity, it will be recycled and will start a new one.", secStorageVmId));
                }
                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(String.format("Secondary storage %s was started.", secStorageVm.toString()));
                }
            }
        }
    } catch (Exception e) {
        errorString = String.format("Unable to allocate capacity on zone [%s] due to [%s].", dataCenterId, errorString);
        throw e;
    } finally {
        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) SecStorageVmAlertEventArgs(com.cloud.storage.secondary.SecStorageVmAlertEventArgs) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) 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

SecStorageVmAlertEventArgs (com.cloud.storage.secondary.SecStorageVmAlertEventArgs)3 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)3 Answer (com.cloud.agent.api.Answer)1 RebootCommand (com.cloud.agent.api.RebootCommand)1 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)1 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)1 GlobalLock (com.cloud.utils.db.GlobalLock)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 URISyntaxException (java.net.URISyntaxException)1 ConfigurationException (javax.naming.ConfigurationException)1