Search in sources :

Example 11 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method assignProxyFromRunningPool.

public ConsoleProxyVO assignProxyFromRunningPool(long dataCenterId) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Assign console proxy from running pool for request from data center : " + dataCenterId);
    }
    ConsoleProxyAllocator allocator = getCurrentAllocator();
    assert (allocator != null);
    List<ConsoleProxyVO> runningList = _consoleProxyDao.getProxyListInStates(dataCenterId, State.Running);
    if (runningList != null && runningList.size() > 0) {
        Iterator<ConsoleProxyVO> it = runningList.iterator();
        while (it.hasNext()) {
            ConsoleProxyVO proxy = it.next();
            if (proxy.getActiveSession() >= _capacityPerProxy) {
                it.remove();
            }
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Running proxy pool size : " + runningList.size());
            for (ConsoleProxyVO proxy : runningList) {
                s_logger.trace("Running proxy instance : " + proxy.getHostName());
            }
        }
        List<Pair<Long, Integer>> l = _consoleProxyDao.getProxyLoadMatrix();
        Map<Long, Integer> loadInfo = new HashMap<Long, Integer>();
        if (l != null) {
            for (Pair<Long, Integer> p : l) {
                loadInfo.put(p.first(), p.second());
                if (s_logger.isTraceEnabled()) {
                    s_logger.trace("Running proxy instance allocation load { proxy id : " + p.first() + ", load : " + p.second() + "}");
                }
            }
        }
        Long allocated = allocator.allocProxy(runningList, loadInfo, dataCenterId);
        if (allocated == null) {
            s_logger.debug("Unable to find a console proxy ");
            return null;
        }
        return _consoleProxyDao.findById(allocated);
    } else {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Empty running proxy pool for now in data center : " + dataCenterId);
        }
    }
    return null;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) Pair(com.cloud.utils.Pair)

Example 12 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method finalizeDeployment.

@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    finalizeCommandsOnStart(cmds, profile);
    ConsoleProxyVO proxy = _consoleProxyDao.findById(profile.getId());
    DataCenter dc = dest.getDataCenter();
    List<NicProfile> nics = profile.getNics();
    for (NicProfile nic : nics) {
        if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
            proxy.setPublicIpAddress(nic.getIPv4Address());
            proxy.setPublicNetmask(nic.getIPv4Netmask());
            proxy.setPublicMacAddress(nic.getMacAddress());
        } else if (nic.getTrafficType() == TrafficType.Management) {
            proxy.setPrivateIpAddress(nic.getIPv4Address());
            proxy.setPrivateMacAddress(nic.getMacAddress());
        }
    }
    _consoleProxyDao.update(proxy.getId(), proxy);
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) NicProfile(com.cloud.vm.NicProfile)

Example 13 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method allocCapacity.

private void allocCapacity(long dataCenterId) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Allocate console proxy standby capacity for data center : " + dataCenterId);
    }
    ConsoleProxyVO proxy = null;
    String errorString = null;
    try {
        boolean consoleProxyVmFromStoppedPool = false;
        proxy = assignProxyFromStoppedPool(dataCenterId);
        if (proxy == null) {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("No stopped console proxy is available, need to allocate a new console proxy");
            }
            if (_allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
                try {
                    proxy = startNew(dataCenterId);
                } catch (ConcurrentOperationException e) {
                    s_logger.info("Concurrent operation exception caught " + e);
                } finally {
                    _allocProxyLock.unlock();
                }
            } else {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Unable to acquire synchronization lock for console proxy vm allocation, wait for next scan");
                }
            }
        } else {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Found a stopped console proxy, starting it. Vm id : " + proxy.getId());
            }
            consoleProxyVmFromStoppedPool = true;
        }
        if (proxy != null) {
            long proxyVmId = proxy.getId();
            proxy = startProxy(proxyVmId, false);
            if (proxy != null) {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Console proxy " + proxy.getHostName() + " is started");
                }
                SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_UP, dataCenterId, proxy.getId(), proxy, null));
            } else {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Unable to start console proxy vm for standby capacity, vm id : " + proxyVmId + ", will recycle it and start a new one");
                }
                if (consoleProxyVmFromStoppedPool) {
                    destroyProxy(proxyVmId);
                }
            }
        }
    } catch (Exception e) {
        errorString = e.getMessage();
        throw e;
    } finally {
        // Also add failure reason since startvm masks some of them.
        if (proxy == null || proxy.getState() != State.Running)
            SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE, dataCenterId, 0l, null, errorString));
    }
}
Also used : ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Example 14 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method assignProxy.

@Override
public ConsoleProxyInfo assignProxy(final long dataCenterId, final long vmId) {
    ConsoleProxyVO proxy = doAssignProxy(dataCenterId, vmId);
    if (proxy == null) {
        return null;
    }
    if (proxy.getPublicIpAddress() == null) {
        s_logger.warn("Assigned console proxy does not have a valid public IP address");
        return null;
    }
    KeystoreVO ksVo = _ksDao.findByName(ConsoleProxyManager.CERTIFICATE_NAME);
    if (proxy.isSslEnabled() && ksVo == null) {
        s_logger.warn("SSL enabled for console proxy but no server certificate found in database");
    }
    if (_staticPublicIp == null) {
        return new ConsoleProxyInfo(proxy.isSslEnabled(), proxy.getPublicIpAddress(), _consoleProxyPort, proxy.getPort(), _consoleProxyUrlDomain);
    } else {
        return new ConsoleProxyInfo(proxy.isSslEnabled(), _staticPublicIp, _consoleProxyPort, _staticPort, _consoleProxyUrlDomain);
    }
}
Also used : ConsoleProxyInfo(com.cloud.info.ConsoleProxyInfo) KeystoreVO(org.apache.cloudstack.framework.security.keystore.KeystoreVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Example 15 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method startNew.

public ConsoleProxyVO startNew(long dataCenterId) throws ConcurrentOperationException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
    }
    if (!allowToLaunchNew(dataCenterId)) {
        s_logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit");
        return null;
    }
    VMTemplateVO template = null;
    HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
    template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
    if (template == null) {
        throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
    }
    Map<String, Object> context = createProxyInstance(dataCenterId, template);
    long proxyVmId = (Long) context.get("proxyVmId");
    if (proxyVmId == 0) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Creating proxy instance failed, data center id : " + dataCenterId);
        }
        return null;
    }
    ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
    if (proxy != null) {
        SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATED, dataCenterId, proxy.getId(), proxy, null));
        return proxy;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Unable to allocate console proxy storage, remove the console proxy record from DB, proxy id: " + proxyVmId);
        }
    }
    return null;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateVO(com.cloud.storage.VMTemplateVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Aggregations

ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 HostVO (com.cloud.host.HostVO)4 NicProfile (com.cloud.vm.NicProfile)4 Answer (com.cloud.agent.api.Answer)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 Account (com.cloud.user.Account)3 VMInstanceVO (com.cloud.vm.VMInstanceVO)3 ArrayList (java.util.ArrayList)3 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)2 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)2 DataCenter (com.cloud.dc.DataCenter)2 HostPodVO (com.cloud.dc.HostPodVO)2 Network (com.cloud.network.Network)2 NetworkOffering (com.cloud.offering.NetworkOffering)2