Search in sources :

Example 1 with ConsoleProxyVO

use of com.cloud.vm.ConsoleProxyVO in project cosmic by MissionCriticalCloud.

the class StoragePoolAutomationImpl method cancelMaintain.

@Override
public boolean cancelMaintain(final DataStore store) {
    // Change the storage state back to up
    final Long userId = CallContext.current().getCallingUserId();
    final User user = _userDao.findById(userId);
    final Account account = CallContext.current().getCallingAccount();
    final StoragePoolVO poolVO = primaryDataStoreDao.findById(store.getId());
    final StoragePool pool = (StoragePool) store;
    // Handeling the Zone wide and cluster wide primay storage
    List<HostVO> hosts = new ArrayList<>();
    // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
    if (poolVO.getScope().equals(ScopeType.ZONE)) {
        if (HypervisorType.Any.equals(pool.getHypervisor())) {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
        } else {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId());
        }
    } else {
        hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
    }
    if (hosts == null || hosts.size() == 0) {
        return true;
    }
    // add heartbeat
    for (final HostVO host : hosts) {
        final ModifyStoragePoolCommand msPoolCmd = new ModifyStoragePoolCommand(true, pool);
        final Answer answer = agentMgr.easySend(host.getId(), msPoolCmd);
        if (answer == null || !answer.getResult()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("ModifyStoragePool add failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
            }
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("ModifyStoragePool add secceeded");
            }
        }
    }
    // 2. Get a list of pending work for this queue
    final List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForCancelMaintenanceByPoolId(poolVO.getId());
    // 3. work through the queue
    for (final StoragePoolWorkVO work : pendingWork) {
        try {
            final VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
            if (vmInstance == null) {
                continue;
            }
            // proxy
            if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
                final ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
                vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
                // update work queue
                work.setStartedAfterMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // if the instance is of type ssvm, call the ssvm manager
            if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
                final SecondaryStorageVmVO ssVm = _secStrgDao.findById(vmInstance.getId());
                vmMgr.advanceStart(ssVm.getUuid(), null, null);
                // update work queue
                work.setStartedAfterMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // manager
            if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
                final DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
                vmMgr.advanceStart(domR.getUuid(), null, null);
                // update work queue
                work.setStartedAfterMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // if the instance is of type user vm, call the user vm manager
            if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
                // don't allow to start vm that doesn't have a root volume
                if (volumeDao.findByInstanceAndType(vmInstance.getId(), Volume.Type.ROOT).isEmpty()) {
                    _storagePoolWorkDao.remove(work.getId());
                } else {
                    final UserVmVO userVm = userVmDao.findById(vmInstance.getId());
                    vmMgr.advanceStart(userVm.getUuid(), null, null);
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
        } catch (final Exception e) {
            s_logger.debug("Failed start vm", e);
            throw new CloudRuntimeException(e.toString());
        }
    }
    return false;
}
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) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with ConsoleProxyVO

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

the class ConsoleProxyDaoImpl method remove.

@Override
public boolean remove(Long id) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    ConsoleProxyVO proxy = createForUpdate();
    proxy.setPublicIpAddress(null);
    proxy.setPrivateIpAddress(null);
    UpdateBuilder ub = getUpdateBuilder(proxy);
    ub.set(proxy, "state", State.Destroyed);
    ub.set(proxy, "privateIpAddress", null);
    update(id, ub, proxy);
    boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder)

Example 3 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method startProxy.

@Override
public ConsoleProxyVO startProxy(long proxyVmId, boolean ignoreRestartSetting) {
    try {
        ConsoleProxyVO proxy = consoleProxyDao.findById(proxyVmId);
        if (proxy.getState() == VirtualMachine.State.Running) {
            return proxy;
        }
        String restart = configurationDao.getValue(Config.ConsoleProxyRestart.key());
        if (!ignoreRestartSetting && restart != null && restart.equalsIgnoreCase("false")) {
            return null;
        }
        if (proxy.getState() == VirtualMachine.State.Stopped) {
            virtualMachineManager.advanceStart(proxy.getUuid(), null, null);
            proxy = consoleProxyDao.findById(proxy.getId());
            return proxy;
        }
        s_logger.warn(String.format("Console proxy [%s] must be in \"Stopped\" state to start proxy. Current state [%s].", proxy.toString(), proxy.getState()));
    } catch (ConcurrentOperationException | InsufficientCapacityException | OperationTimedoutException | ResourceUnavailableException ex) {
        s_logger.warn(String.format("Unable to start proxy [%s] due to [%s].", proxyVmId, ex.getMessage()), ex);
    }
    return null;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 4 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method handleResetSuspending.

private void handleResetSuspending() {
    List<ConsoleProxyVO> runningProxies = consoleProxyDao.getProxyListInStates(State.Running);
    for (ConsoleProxyVO proxy : runningProxies) {
        s_logger.info("Stop console proxy " + proxy.getId() + " because of we are currently in ResetSuspending management mode");
        stopProxy(proxy.getId());
    }
    List<ConsoleProxyVO> proxiesInTransition = consoleProxyDao.getProxyListInStates(State.Running, State.Starting, State.Stopping);
    if (CollectionUtils.isEmpty(proxiesInTransition)) {
        s_logger.info("All previous console proxy VMs in transition mode ceased the mode, we will now resume to last management state");
        resumeLastManagementState();
    }
}
Also used : ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Example 5 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method doAssignProxy.

public ConsoleProxyVO doAssignProxy(long dataCenterId, long vmId) {
    ConsoleProxyVO proxy = null;
    VMInstanceVO vm = vmInstanceDao.findById(vmId);
    if (vm == null) {
        s_logger.warn("VM " + vmId + " no longer exists, return a null proxy for vm:" + vmId);
        return null;
    }
    if (!availableVmStateOnAssignProxy.contains(vm.getState())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info(String.format("Detected that %s is not currently in \"Starting\", \"Running\", \"Stopping\" or \"Migrating\" state, it will fail the proxy assignment.", vm.toString()));
        }
        return null;
    }
    if (allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC_IN_SECONDS)) {
        try {
            if (vm.getProxyId() != null) {
                proxy = consoleProxyDao.findById(vm.getProxyId());
                if (proxy != null) {
                    if (!isInAssignableState(proxy)) {
                        if (s_logger.isInfoEnabled()) {
                            s_logger.info("A previous assigned proxy is not assignable now, reassign console proxy for user vm : " + vmId);
                        }
                        proxy = null;
                    } else {
                        if (consoleProxyDao.getProxyActiveLoad(proxy.getId()) < capacityPerProxy || hasPreviousSession(proxy, vm)) {
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("Assign previous allocated console proxy for user vm : " + vmId);
                            }
                            if (proxy.getActiveSession() >= capacityPerProxy) {
                                s_logger.warn("Assign overloaded proxy to user VM as previous session exists, user vm : " + vmId);
                            }
                        } else {
                            proxy = null;
                        }
                    }
                }
            }
            if (proxy == null) {
                proxy = assignProxyFromRunningPool(dataCenterId);
            }
        } finally {
            allocProxyLock.unlock();
        }
    } else {
        s_logger.error("Unable to acquire synchronization lock to get/allocate proxy resource for vm :" + vmId + ". Previous console proxy allocation is taking too long");
    }
    if (proxy == null) {
        s_logger.warn("Unable to find or allocate console proxy resource");
        return null;
    }
    if (vm.getProxyId() == null || vm.getProxyId() != proxy.getId()) {
        vmInstanceDao.updateProxyId(vmId, proxy.getId(), DateUtil.currentGMTTime());
    }
    proxy.setSslEnabled(sslEnabled);
    if (sslEnabled) {
        proxy.setPort(443);
    } else {
        proxy.setPort(80);
    }
    return proxy;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Aggregations

ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 NicProfile (com.cloud.vm.NicProfile)9 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 HostVO (com.cloud.host.HostVO)8 Answer (com.cloud.agent.api.Answer)7 Account (com.cloud.user.Account)7 VMInstanceVO (com.cloud.vm.VMInstanceVO)7 ArrayList (java.util.ArrayList)7 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)5 HostPodVO (com.cloud.dc.HostPodVO)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 Network (com.cloud.network.Network)5 NetworkOffering (com.cloud.offering.NetworkOffering)5 VMTemplateVO (com.cloud.storage.VMTemplateVO)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 Zone (com.cloud.db.model.Zone)4 DataCenter (com.cloud.dc.DataCenter)4