bug 9330: ensure that console proxies are always created from the same hypervisor type

This commit is contained in:
Chiradeep Vittal 2011-04-12 15:15:01 -07:00
parent 2a45327a89
commit b56c82e3b6
3 changed files with 21 additions and 4 deletions

View File

@ -74,6 +74,8 @@ import com.cloud.exception.StorageUnavailableException;
import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.info.ConsoleProxyConnectionInfo;
import com.cloud.info.ConsoleProxyInfo;
import com.cloud.info.ConsoleProxyLoadInfo;
@ -528,8 +530,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
s_logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit");
return null;
}
Map<String, Object> context = createProxyInstance(dataCenterId);
HypervisorType currentHyp = currentHypervisorType(dataCenterId);
Map<String, Object> context = createProxyInstance(dataCenterId, currentHyp);
long proxyVmId = (Long) context.get("proxyVmId");
if (proxyVmId == 0) {
@ -558,7 +561,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
return null;
}
protected Map<String, Object> createProxyInstance(long dataCenterId) throws ConcurrentOperationException {
protected Map<String, Object> createProxyInstance(long dataCenterId, HypervisorType desiredHyp) throws ConcurrentOperationException {
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
String name = VirtualMachineName.getConsoleProxyName(id, _instance);
@ -582,7 +585,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null));
}
VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId);
VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId, desiredHyp);
if (template == null) {
s_logger.debug("Can't find a template to start");
throw new CloudRuntimeException("Insufficient capacity exception");
@ -868,6 +871,14 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
int launchLimit = NumbersUtil.parseInt(value, 10);
return l.size() < launchLimit;
}
private HypervisorType currentHypervisorType(long dcId) {
List<ConsoleProxyVO> l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting,
VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped,
VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown);
return l.size() > 0? l.get(0).getHypervisorType():HypervisorType.Any;
}
private boolean checkCapacity(ConsoleProxyLoadInfo proxyCountInfo, ConsoleProxyLoadInfo vmCountInfo) {

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Set;
import com.cloud.domain.DomainVO;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.VMTemplateVO;
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
@ -67,6 +68,8 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
public List<VMTemplateVO> listByHypervisorType(HypervisorType hyperType);
public List<VMTemplateVO> publicIsoSearch();
VMTemplateVO findSystemVMTemplate(long zoneId);
VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType);
VMTemplateVO findRoutingTemplate(HypervisorType type);
}

View File

@ -475,6 +475,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
return tmplt;
}
}
if (tmplts.size() > 0 && hType == HypervisorType.Any) {
return tmplts.get(0);
}
return null;
}