use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class VMSnapshotStrategyTest method testDeleteVMSnapshot.
@Test
public void testDeleteVMSnapshot() throws AgentUnavailableException, OperationTimedoutException {
final Long hostId = 1L;
final Long vmId = 1L;
final Long guestOsId = 1L;
final HypervisorType hypervisorType = HypervisorType.Any;
final String hypervisorVersion = "default";
final String guestOsName = "Other";
final List<VolumeObjectTO> volumeObjectTOs = new ArrayList<>();
final VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
final UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId);
Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId);
Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId);
Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs);
Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
final GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
final GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
final VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class);
Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO);
Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
Mockito.when(vmSnapshot.getId()).thenReturn(1L);
Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date());
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
final HostVO hostVO = Mockito.mock(HostVO.class);
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
Exception e = null;
try {
vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
} catch (final CloudRuntimeException e1) {
e = e1;
}
assertNotNull(e);
final DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class);
Mockito.when(answer.getResult()).thenReturn(true);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
final boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
assertTrue(result);
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class ConsoleProxyManagerImpl method startNew.
public ConsoleProxyVO startNew(final long dataCenterId) throws ConcurrentOperationException {
logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
if (!allowToLaunchNew(dataCenterId)) {
logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit");
return null;
}
final HypervisorType availableHypervisor = this._resourceMgr.getAvailableHypervisor(dataCenterId);
final String templateName = retrieveTemplateName(dataCenterId);
final VMTemplateVO template = this._templateDao.findRoutingTemplate(availableHypervisor, templateName, dataCenterId);
if (template == null) {
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
}
final Map<String, Object> context = createProxyInstance(dataCenterId, template);
final long proxyVmId = (Long) context.get("proxyVmId");
if (proxyVmId == 0) {
logger.trace("Creating proxy instance failed, data center id : " + dataCenterId);
return null;
}
final ConsoleProxyVO proxy = this._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 {
logger.debug("Unable to allocate console proxy storage, remove the console proxy record from DB, proxy id: " + proxyVmId);
}
return null;
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class CapacityManagerImpl method checkIfHostReachMaxGuestLimit.
@Override
public boolean checkIfHostReachMaxGuestLimit(final Host host) {
final Long vmCount = this._vmDao.countActiveByHostId(host.getId());
final HypervisorType hypervisorType = host.getHypervisorType();
final String hypervisorVersion = host.getHypervisorVersion();
final Long maxGuestLimit = this._hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
if (vmCount >= maxGuestLimit) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " already reached max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + ",Running VM counts is: " + vmCount);
}
return true;
}
return false;
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class ClusterDaoImpl method getAvailableHypervisorInZone.
@Override
public List<HypervisorType> getAvailableHypervisorInZone(final Long zoneId) {
final SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);
}
final List<ClusterVO> clusters = listBy(sc);
final List<HypervisorType> hypers = new ArrayList<>(4);
for (final ClusterVO cluster : clusters) {
hypers.add(cluster.getHypervisorType());
}
return hypers;
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method downloadBootstrapSysTemplate.
@Override
public void downloadBootstrapSysTemplate(final DataStore store) {
final Set<VMTemplateVO> toBeDownloaded = new HashSet();
final List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
for (final VMTemplateVO rtngTmplt : rtngTmplts) {
toBeDownloaded.add(rtngTmplt);
}
final List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(store.getScope().getScopeId());
if (availHypers.isEmpty()) {
/*
* This is for cloudzone, local secondary storage resource started
* before cluster created
*/
availHypers.add(HypervisorType.KVM);
}
// bug 9809: resume ISO
availHypers.add(HypervisorType.None);
for (final VMTemplateVO template : toBeDownloaded) {
if (availHypers.contains(template.getHypervisorType())) {
// only download sys template applicable for current hypervisor
final TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) {
final TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
createTemplateAsync(tmplt, store, null);
}
}
}
}
Aggregations