use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class KVMFencerTest method testWithSingleHost.
@Test
public void testWithSingleHost() {
final HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getId()).thenReturn(1l);
final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Collections.singletonList(host));
Assert.assertFalse(fencer.fenceOff(virtualMachine, host));
}
use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class KVMFencerTest method testWithSingleNotKVM.
@Test
public void testWithSingleNotKVM() {
final HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.Any);
Mockito.when(host.getStatus()).thenReturn(Status.Down);
Mockito.when(host.getId()).thenReturn(1l);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Collections.singletonList(host));
Assert.assertNull(fencer.fenceOff(virtualMachine, host));
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class HostDaoImpl method listHostsWithActiveVMs.
@Override
public List<HostVO> listHostsWithActiveVMs(long offeringId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<HostVO> result = new ArrayList<>();
StringBuilder sql = new StringBuilder(GET_HOSTS_OF_ACTIVE_VMS);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, offeringId);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(toEntityBean(rs, false));
}
return result;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleVolumeMigrationForXenServer.
private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
VirtualMachine vm = srcVolumeInfo.getAttachedVM();
if (vm == null || vm.getState() != VirtualMachine.State.Running) {
throw new CloudRuntimeException("Currently, a volume to migrate from non-managed storage to managed storage on XenServer must be attached to " + "a VM in the Running state.");
}
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
HostVO hostVO = _hostDao.findById(vm.getHostId());
_volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
String value = _configDao.getValue(Config.MigrateWait.key());
int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destVolumeInfo.getDataStore().getId(), DataStoreRole.Primary);
MigrateVolumeCommand command = new MigrateVolumeCommand(srcVolumeInfo.getId(), srcVolumeInfo.getPath(), destPool, srcVolumeInfo.getAttachedVmName(), srcVolumeInfo.getVolumeType(), waitInterval, null);
Map<String, String> details = new HashMap<>();
details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
details.put(DiskTO.IQN, destVolumeInfo.get_iScsiName());
details.put(DiskTO.STORAGE_HOST, destPool.getHostAddress());
details.put(DiskTO.PROTOCOL_TYPE, (destPool.getPoolType() != null) ? destPool.getPoolType().toString() : null);
command.setDestDetails(details);
EndPoint ep = selector.select(srcVolumeInfo, StorageAction.MIGRATEVOLUME);
Answer answer;
if (ep == null) {
String errMsg = "No remote endpoint to send command to; check if host or SSVM is down";
LOGGER.error(errMsg);
answer = new Answer(command, false, errMsg);
} else {
answer = ep.sendMessage(command);
}
handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
if (answer == null || !answer.getResult()) {
handleFailedVolumeMigration(srcVolumeInfo, destVolumeInfo, hostVO);
throw new CloudRuntimeException("Failed to migrate volume with ID " + srcVolumeInfo.getId() + " to storage pool with ID " + destPool.getId());
} else {
handleSuccessfulVolumeMigration(srcVolumeInfo, destPool, (MigrateVolumeAnswer) answer);
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class EndpointSelectorTest method createHost.
public HostVO createHost(Hypervisor.HypervisorType hypervisorType) {
String uuid = UUID.randomUUID().toString();
HostVO host = new HostVO(uuid);
host.setName("devcloud xenserver host");
host.setType(Host.Type.Routing);
host.setPrivateIpAddress(uuid);
host.setDataCenterId(dcId);
host.setVersion("6.0.1");
host.setAvailable(true);
host.setSetup(true);
host.setPodId(podId);
host.setLastPinged(0);
host.setResourceState(ResourceState.Enabled);
host.setHypervisorType(hypervisorType);
host.setClusterId(clusterId);
host = hostDao.persist(host);
agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, 1L);
host = hostDao.findById(host.getId());
agentMgr.agentStatusTransitTo(host, Status.Event.Ready, 1L);
return hostDao.findById(host.getId());
}
Aggregations