Search in sources :

Example 51 with SecondaryStorageVmVO

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

the class PremiumSecondaryStorageManagerImpl method scanPool.

@Override
public Pair<AfterScanAction, Object> scanPool(Long pool) {
    long dataCenterId = pool.longValue();
    if (!isSecondaryStorageVmRequired(dataCenterId)) {
        return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
    }
    Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _maxExecutionTimeMs);
    _cmdExecLogDao.expungeExpiredRecords(cutTime);
    boolean suspendAutoLoading = !reserveStandbyCapacity();
    if (!suspendAutoLoading) {
        // this is a hacking, has nothing to do with console proxy, it is just a flag that primary storage is being under maintenance mode
        String restart = _configDao.getValue("consoleproxy.restart");
        if (restart != null && restart.equalsIgnoreCase("false")) {
            s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode");
            suspendAutoLoading = true;
        }
    }
    List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting);
    if (alreadyRunning.size() == 0) {
        s_logger.info("No running secondary storage vms found in datacenter id=" + dataCenterId + ", starting one");
        List<SecondaryStorageVmVO> stopped = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, State.Stopping);
        if (stopped.size() == 0 || !suspendAutoLoading) {
            List<SecondaryStorageVmVO> stopping = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, State.Stopping);
            if (stopping.size() > 0) {
                s_logger.info("Found SSVMs that are currently at stopping state, wait until they are settled");
                return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
            }
            expandPool(pool, SecondaryStorageVm.Role.templateProcessor);
        }
    }
    if (!suspendAutoLoading) {
        // this is to avoid surprises that people may accidently see two SSVMs being launched, capacity expanding only happens when we have at least the primary SSVM is up
        if (alreadyRunning.size() == 0) {
            s_logger.info("Primary secondary storage is not even started, wait until next turn");
            return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
        }
        alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, dataCenterId, State.Running, State.Migrating, State.Starting);
        List<CommandExecLogVO> activeCmds = findActiveCommands(dataCenterId, cutTime);
        List<CommandExecLogVO> copyCmdsInPipeline = findAllActiveCopyCommands(dataCenterId, cutTime);
        return scaleSSVMOnLoad(alreadyRunning, activeCmds, copyCmdsInPipeline, dataCenterId);
    }
    return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) Date(java.util.Date) Pair(com.cloud.utils.Pair)

Example 52 with SecondaryStorageVmVO

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

the class StoragePoolAutomationImpl method maintain.

@Override
public boolean maintain(DataStore store) {
    Long userId = CallContext.current().getCallingUserId();
    User user = _userDao.findById(userId);
    Account account = CallContext.current().getCallingAccount();
    StoragePoolVO pool = primaryDataStoreDao.findById(store.getId());
    try {
        List<StoragePoolVO> spes = null;
        // if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS
        if (pool.getScope() == ScopeType.ZONE) {
            spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), null, null, ScopeType.ZONE);
        } else {
            spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), pool.getPodId(), pool.getClusterId(), ScopeType.CLUSTER);
        }
        for (StoragePoolVO sp : spes) {
            if (sp.getParent() != pool.getParent() && sp.getId() != pool.getParent()) {
                // If Datastore cluster is tried to prepare for maintenance then child storage pools are also kept in PrepareForMaintenance mode
                if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
                    throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId() + " is already in  PrepareForMaintenance mode ");
                }
            }
        }
        StoragePool storagePool = (StoragePool) store;
        // Handeling the Zone wide and cluster wide primay storage
        List<HostVO> hosts = new ArrayList<HostVO>();
        // TODO: if it's zone wide, this code will list a lot of hosts in the zone, which may cause performance/OOM issue.
        if (pool.getScope().equals(ScopeType.ZONE)) {
            if (HypervisorType.Any.equals(pool.getHypervisor())) {
                hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
            } else {
                hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId());
            }
        } else {
            hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
        }
        if (hosts == null || hosts.size() == 0) {
            pool.setStatus(StoragePoolStatus.Maintenance);
            primaryDataStoreDao.update(pool.getId(), pool);
            return true;
        } else {
            // set the pool state to prepare for maintenance
            pool.setStatus(StoragePoolStatus.PrepareForMaintenance);
            primaryDataStoreDao.update(pool.getId(), pool);
        }
        // remove heartbeat
        for (HostVO host : hosts) {
            ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(false, storagePool);
            final Answer answer = agentMgr.easySend(host.getId(), cmd);
            if (answer == null || !answer.getResult()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("ModifyStoragePool false failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
                }
            } else {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("ModifyStoragePool false succeeded");
                }
                if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
                    s_logger.debug(String.format("Started synchronising datastore cluster storage pool %s with vCenter", pool.getUuid()));
                    storageManager.syncDatastoreClusterStoragePool(pool.getId(), ((ModifyStoragePoolAnswer) answer).getDatastoreClusterChildren(), host.getId());
                }
            }
        }
        // check to see if other ps exist
        // if they do, then we can migrate over the system vms to them
        // if they dont, then just stop all vms on this one
        List<StoragePoolVO> upPools = primaryDataStoreDao.listByStatusInZone(pool.getDataCenterId(), StoragePoolStatus.Up);
        boolean restart = true;
        if (upPools == null || upPools.size() == 0) {
            restart = false;
        }
        // 2. Get a list of all the ROOT volumes within this storage pool
        List<VolumeVO> allVolumes = volumeDao.findByPoolId(pool.getId());
        // 3. Enqueue to the work queue
        for (VolumeVO volume : allVolumes) {
            VMInstanceVO vmInstance = vmDao.findById(volume.getInstanceId());
            if (vmInstance == null) {
                continue;
            }
            // enqueue sp work
            if (vmInstance.getState().equals(State.Running) || vmInstance.getState().equals(State.Starting) || vmInstance.getState().equals(State.Stopping)) {
                try {
                    StoragePoolWorkVO work = new StoragePoolWorkVO(vmInstance.getId(), pool.getId(), false, false, server.getId());
                    _storagePoolWorkDao.persist(work);
                } catch (Exception e) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Work record already exists, re-using by re-setting values");
                    }
                    StoragePoolWorkVO work = _storagePoolWorkDao.findByPoolIdAndVmId(pool.getId(), vmInstance.getId());
                    work.setStartedAfterMaintenance(false);
                    work.setStoppedForMaintenance(false);
                    work.setManagementServerId(server.getId());
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
        }
        // 4. Process the queue
        List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForPrepareForMaintenanceByPoolId(pool.getId());
        for (StoragePoolWorkVO work : pendingWork) {
            // shut down the running vms
            VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
            if (vmInstance == null) {
                continue;
            }
            // proxy
            if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
                // call the consoleproxymanager
                ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
                vmMgr.advanceStop(consoleProxy.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
                if (restart) {
                    vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
                    // update work status
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
            // if the instance is of type uservm, call the user vm manager
            if (vmInstance.getType() == VirtualMachine.Type.User) {
                UserVmVO userVm = userVmDao.findById(vmInstance.getId());
                vmMgr.advanceStop(userVm.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // secondary storage vm manager
            if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
                SecondaryStorageVmVO secStrgVm = _secStrgDao.findById(vmInstance.getId());
                vmMgr.advanceStop(secStrgVm.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
                if (restart) {
                    vmMgr.advanceStart(secStrgVm.getUuid(), null, null);
                    // update work status
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
            // manager
            if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
                DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
                vmMgr.advanceStop(domR.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
                if (restart) {
                    vmMgr.advanceStart(domR.getUuid(), null, null);
                    // update work status
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
        }
    } catch (Exception e) {
        s_logger.error("Exception in enabling primary storage maintenance:", e);
        pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
        primaryDataStoreDao.update(pool.getId(), pool);
        throw new CloudRuntimeException(e.getMessage());
    }
    return true;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UserVmVO(com.cloud.vm.UserVmVO) User(com.cloud.user.User) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 53 with SecondaryStorageVmVO

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

the class ManagementServerImpl method uploadCertificate.

@Override
@DB
public String uploadCertificate(final UploadCustomCertificateCmd cmd) {
    if (cmd.getPrivateKey() != null && cmd.getAlias() != null) {
        throw new InvalidParameterValueException("Can't change the alias for private key certification");
    }
    if (cmd.getPrivateKey() == null) {
        if (cmd.getAlias() == null) {
            throw new InvalidParameterValueException("alias can't be empty, if it's a certification chain");
        }
        if (cmd.getCertIndex() == null) {
            throw new InvalidParameterValueException("index can't be empty, if it's a certifciation chain");
        }
    }
    final String certificate = cmd.getCertificate();
    final String key = cmd.getPrivateKey();
    if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(certificate, key, cmd.getDomainSuffix())) {
        throw new InvalidParameterValueException("Failed to pass certificate validation check");
    }
    if (cmd.getPrivateKey() != null) {
        _ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, certificate, key, cmd.getDomainSuffix());
        // Reboot ssvm here since private key is present - meaning server cert being passed
        final List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, State.Running, State.Migrating, State.Starting);
        for (final SecondaryStorageVmVO ssVmVm : alreadyRunning) {
            _secStorageVmMgr.rebootSecStorageVm(ssVmVm.getId());
        }
    } else {
        _ksMgr.saveCertificate(cmd.getAlias(), certificate, cmd.getCertIndex(), cmd.getDomainSuffix());
    }
    _consoleProxyMgr.setManagementState(ConsoleProxyManagementState.ResetSuspending);
    return "Certificate has been successfully updated, if its the server certificate we would reboot all " + "running console proxy VMs and secondary storage VMs to propagate the new certificate, " + "please give a few minutes for console access and storage services service to be up and working again";
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DB(com.cloud.utils.db.DB)

Aggregations

SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)53 HostVO (com.cloud.host.HostVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 Answer (com.cloud.agent.api.Answer)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)11 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)9 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)8 ArrayList (java.util.ArrayList)8 Account (com.cloud.user.Account)7 DB (com.cloud.utils.db.DB)6 NicProfile (com.cloud.vm.NicProfile)6 ConfigurationException (javax.naming.ConfigurationException)6 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)6 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)5 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)5 Pair (com.cloud.utils.Pair)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)4