use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.
the class VMSnapshotStrategyTest method testRevertSnapshot.
@Test
public void testRevertSnapshot() throws AgentUnavailableException, OperationTimedoutException {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
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);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
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);
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);
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.revertVMSnapshot(vmSnapshot);
} catch (CloudRuntimeException e1) {
e = e1;
}
assertNotNull(e);
RevertToVMSnapshotAnswer answer = Mockito.mock(RevertToVMSnapshotAnswer.class);
Mockito.when(answer.getResult()).thenReturn(Boolean.TRUE);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
boolean result = vmSnapshotStrategy.revertVMSnapshot(vmSnapshot);
assertTrue(result);
}
use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.
the class VMSnapshotStrategyTest method testCreateVMSnapshot.
@Test
public void testCreateVMSnapshot() throws AgentUnavailableException, OperationTimedoutException {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
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);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
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);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
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.takeVMSnapshot(vmSnapshot);
} catch (CloudRuntimeException e1) {
e = e1;
}
assertNotNull(e);
CreateVMSnapshotAnswer answer = Mockito.mock(CreateVMSnapshotAnswer.class);
Mockito.when(answer.getResult()).thenReturn(true);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
VMSnapshot snapshot = null;
snapshot = vmSnapshotStrategy.takeVMSnapshot(vmSnapshot);
assertNotNull(snapshot);
}
use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.
the class VMSnapshotStrategyTest method testDeleteVMSnapshot.
@Test
public void testDeleteVMSnapshot() throws AgentUnavailableException, OperationTimedoutException {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
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);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
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);
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);
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 (CloudRuntimeException e1) {
e = e1;
}
assertNotNull(e);
DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class);
Mockito.when(answer.getResult()).thenReturn(true);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
assertTrue(result);
}
use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.
the class QueryManagerImpl method searchForServersInternal.
public Pair<List<HostJoinVO>, Integer> searchForServersInternal(ListHostsCmd cmd) {
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object name = cmd.getHostName();
Object type = cmd.getType();
Object state = cmd.getState();
Object pod = cmd.getPodId();
Object cluster = cmd.getClusterId();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Object outOfBandManagementEnabled = cmd.isOutOfBandManagementEnabled();
Object powerState = cmd.getHostOutOfBandManagementPowerState();
Object resourceState = cmd.getResourceState();
Object haHosts = cmd.getHaHost();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
SearchBuilder<HostJoinVO> sb = _hostJoinDao.createSearchBuilder();
// select distinct
sb.select(null, Func.DISTINCT, sb.entity().getId());
// ids
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("oobmEnabled", sb.entity().isOutOfBandManagementEnabled(), SearchCriteria.Op.EQ);
sb.and("powerState", sb.entity().getOutOfBandManagementPowerState(), SearchCriteria.Op.EQ);
sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
sb.and("hypervisor_type", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
String haTag = _haMgr.getHaTag();
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
if ((Boolean) haHosts) {
sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ);
} else {
sb.and().op("tag", sb.entity().getTag(), SearchCriteria.Op.NEQ);
sb.or("tagNull", sb.entity().getTag(), SearchCriteria.Op.NULL);
sb.cp();
}
}
SearchCriteria<HostJoinVO> sc = sb.create();
if (keyword != null) {
SearchCriteria<HostJoinVO> ssc = _hostJoinDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("status", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (id != null) {
sc.setParameters("id", id);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");
}
if (type != null) {
sc.setParameters("type", "%" + type);
}
if (state != null) {
sc.setParameters("status", state);
}
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (pod != null) {
sc.setParameters("podId", pod);
}
if (cluster != null) {
sc.setParameters("clusterId", cluster);
}
if (outOfBandManagementEnabled != null) {
sc.setParameters("oobmEnabled", outOfBandManagementEnabled);
}
if (powerState != null) {
sc.setParameters("powerState", powerState);
}
if (resourceState != null) {
sc.setParameters("resourceState", resourceState);
}
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
sc.setParameters("tag", haTag);
}
if (hypervisorType != HypervisorType.None && hypervisorType != HypervisorType.Any) {
sc.setParameters("hypervisor_type", hypervisorType);
}
// search host details by ids
Pair<List<HostJoinVO>, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter);
Integer count = uniqueHostPair.second();
if (count.intValue() == 0) {
// handle empty result cases
return uniqueHostPair;
}
List<HostJoinVO> uniqueHosts = uniqueHostPair.first();
Long[] hostIds = new Long[uniqueHosts.size()];
int i = 0;
for (HostJoinVO v : uniqueHosts) {
hostIds[i++] = v.getId();
}
List<HostJoinVO> hosts = _hostJoinDao.searchByIds(hostIds);
return new Pair<List<HostJoinVO>, Integer>(hosts, count);
}
use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.
the class NetworkHelperImpl method getHypervisors.
protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition) throws InsufficientServerCapacityException {
final DeployDestination dest = routerDeploymentDefinition.getDest();
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
if (dest.getCluster() != null) {
if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) {
hypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId()));
} else {
hypervisors.add(dest.getCluster().getHypervisorType());
}
} else {
final HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
if (defaults != HypervisorType.None) {
hypervisors.add(defaults);
} else {
// if there is no default hypervisor, get it from the cluster
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, routerDeploymentDefinition.getPlan().getPodId());
}
}
filterSupportedHypervisors(hypervisors);
if (hypervisors.isEmpty()) {
if (routerDeploymentDefinition.getPodId() != null) {
throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the pod." + getNoHypervisorsErrMsgDetails(), Pod.class, routerDeploymentDefinition.getPodId());
}
throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the zone." + getNoHypervisorsErrMsgDetails(), DataCenter.class, dest.getDataCenter().getId());
}
return hypervisors;
}
Aggregations