Search in sources :

Example 6 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method generateSetupCommand.

@Override
public boolean generateSetupCommand(Long ssHostId) {
    HostVO cssHost = _hostDao.findById(ssHostId);
    Long zoneId = cssHost.getDataCenterId();
    if (cssHost.getType() == Host.Type.SecondaryStorageVM) {
        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(cssHost.getName());
        if (secStorageVm == null) {
            s_logger.warn("secondary storage VM " + cssHost.getName() + " doesn't exist");
            return false;
        }
        List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
        for (DataStore ssStore : ssStores) {
            if (!(ssStore.getTO() instanceof NfsTO)) {
                // only do this for Nfs
                continue;
            }
            String secUrl = ssStore.getUri();
            SecStorageSetupCommand setupCmd = null;
            if (!_useSSlCopy) {
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
            } else {
                KeystoreManager.Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
            }
            Integer nfsVersion = imageStoreDetailsUtil.getNfsVersion(ssStore.getId());
            setupCmd.setNfsVersion(nfsVersion);
            //template/volume file upload key
            String postUploadKey = _configDao.getValue(Config.SSVMPSK.key());
            setupCmd.setPostUploadKey(postUploadKey);
            Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
            if (answer != null && answer.getResult()) {
                SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
                if (an.get_dir() != null) {
                    // update the parent path in image_store table for this image store
                    ImageStoreVO svo = _imageStoreDao.findById(ssStore.getId());
                    svo.setParent(an.get_dir());
                    _imageStoreDao.update(ssStore.getId(), svo);
                }
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
                }
            } else {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
                }
                return false;
            }
        }
    }
    /* After removing SecondaryStorage entries from host table, control should never come here!!
        else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
            List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
            String secUrl = cssHost.getStorageUrl();
            SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
            for ( SecondaryStorageVmVO ssVm : alreadyRunning ) {
                HostVO host = _resourceMgr.findHostByName(ssVm.getInstanceName());
                Answer answer = _agentMgr.easySend(host.getId(), setupCmd);
                if (answer != null && answer.getResult()) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Successfully programmed secondary storage " + host.getName() + " in secondary storage VM " + ssVm.getInstanceName());
                    }
                } else {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Successfully programmed secondary storage " + host.getName() + " in secondary storage VM " + ssVm.getInstanceName());
                    }
                    return false;
                }
            }
        }
         */
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) KeystoreManager(org.apache.cloudstack.framework.security.keystore.KeystoreManager) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) HostVO(com.cloud.host.HostVO) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 7 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class PremiumSecondaryStorageManagerImpl method assignSecStorageVm.

@Override
public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd) {
    // TODO, need performance optimization
    List<Long> vms = _secStorageVmDao.listRunningSecStorageOrderByLoad(null, zoneId);
    for (Long vmId : vms) {
        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(vmId);
        HostVO host;
        host = _resourceMgr.findHostByName(secStorageVm.getHostName());
        if (host != null && host.getStatus() == Status.Up)
            return new Pair<HostVO, SecondaryStorageVmVO>(host, secStorageVm);
    }
    return null;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) HostVO(com.cloud.host.HostVO)

Example 8 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO 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);
        if (answer != null && answer.getResult()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getHostName());
            }
            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null));
            return true;
        } else {
            String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getHostName();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            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 9 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method stopSecStorageVm.

@Override
public boolean stopSecStorageVm(long secStorageVmId) {
    SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
    if (secStorageVm == null) {
        String msg = "Stopping secondary storage vm failed: secondary storage vm " + secStorageVmId + " no longer exists";
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(msg);
        }
        return false;
    }
    try {
        if (secStorageVm.getHostId() != null) {
            GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId()));
            try {
                if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
                    try {
                        _itMgr.stop(secStorageVm.getUuid());
                        return true;
                    } finally {
                        secStorageVmLock.unlock();
                    }
                } else {
                    String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString();
                    s_logger.debug(msg);
                    return false;
                }
            } finally {
                secStorageVmLock.releaseRef();
            }
        }
        // vm was already stopped, return true
        return true;
    } catch (ResourceUnavailableException e) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Stopping secondary storage vm " + secStorageVm.getHostName() + " faled : exception " + e.toString());
        }
        return false;
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 10 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method assignSecStorageVmFromRunningPool.

public SecondaryStorageVmVO assignSecStorageVmFromRunningPool(long dataCenterId, SecondaryStorageVm.Role role) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Assign  secondary storage vm from running pool for request from data center : " + dataCenterId);
    }
    SecondaryStorageVmAllocator allocator = getCurrentAllocator();
    assert (allocator != null);
    List<SecondaryStorageVmVO> runningList = _secStorageVmDao.getSecStorageVmListInStates(role, dataCenterId, State.Running);
    if (runningList != null && runningList.size() > 0) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Running secondary storage vm pool size : " + runningList.size());
            for (SecondaryStorageVmVO secStorageVm : runningList) {
                s_logger.trace("Running secStorageVm instance : " + secStorageVm.getHostName());
            }
        }
        Map<Long, Integer> loadInfo = new HashMap<Long, Integer>();
        return allocator.allocSecondaryStorageVm(runningList, loadInfo, dataCenterId);
    } else {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Empty running secStorageVm pool for now in data center : " + dataCenterId);
        }
    }
    return null;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) SecondaryStorageVmAllocator(com.cloud.storage.secondary.SecondaryStorageVmAllocator)

Aggregations

SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)27 HostVO (com.cloud.host.HostVO)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 Answer (com.cloud.agent.api.Answer)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)6 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)5 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)5 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)4 ArrayList (java.util.ArrayList)4 ConfigurationException (javax.naming.ConfigurationException)4 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)3 SecStorageVmAlertEventArgs (com.cloud.storage.secondary.SecStorageVmAlertEventArgs)3 Account (com.cloud.user.Account)3 Pair (com.cloud.utils.Pair)3 DB (com.cloud.utils.db.DB)3 NicProfile (com.cloud.vm.NicProfile)3 URISyntaxException (java.net.URISyntaxException)3