use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class VolumeApiServiceImpl method getMaxDataVolumesSupported.
private int getMaxDataVolumesSupported(final UserVmVO vm) {
Long hostId = vm.getHostId();
if (hostId == null) {
hostId = vm.getLastHostId();
}
final HostVO host = _hostDao.findById(hostId);
Integer maxDataVolumesSupported = null;
if (host != null) {
_hostDao.loadDetails(host);
maxDataVolumesSupported = _hypervisorCapabilitiesDao.getMaxDataVolumesLimit(host.getHypervisorType(), host.getDetail("product_version"));
}
if (maxDataVolumesSupported == null) {
// 6 data disks by default if nothing
maxDataVolumesSupported = 6;
// is specified in
// 'hypervisor_capabilities' table
}
return maxDataVolumesSupported.intValue();
}
use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class VolumeApiServiceImpl method sendAttachVolumeCommand.
private VolumeVO sendAttachVolumeCommand(final UserVmVO vm, VolumeVO volumeToAttach, Long deviceId) {
String errorMsg = "Failed to attach volume " + volumeToAttach.getName() + " to VM " + vm.getHostName();
boolean sendCommand = vm.getState() == State.Running;
AttachAnswer answer = null;
final Long hostId = vm.getHostId();
HostVO host = null;
final StoragePoolVO volumeToAttachStoragePool = _storagePoolDao.findById(volumeToAttach.getPoolId());
if (hostId != null) {
host = _hostDao.findById(hostId);
if (host != null && host.getHypervisorType() == HypervisorType.XenServer && volumeToAttachStoragePool != null && volumeToAttachStoragePool.isManaged()) {
sendCommand = true;
}
}
// volumeToAttachStoragePool should be null if the VM we are attaching the disk to has never been started before
final DataStore dataStore = volumeToAttachStoragePool != null ? dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), DataStoreRole.Primary) : null;
// if we don't have a host, the VM we are attaching the disk to has never been started before
if (host != null) {
try {
volService.grantAccess(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
} catch (final Exception e) {
volService.revokeAccess(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
throw new CloudRuntimeException(e.getMessage());
}
}
if (sendCommand) {
if (host != null && host.getHypervisorType() == HypervisorType.KVM && volumeToAttachStoragePool.isManaged() && volumeToAttach.getPath() == null) {
volumeToAttach.setPath(volumeToAttach.get_iScsiName());
_volsDao.update(volumeToAttach.getId(), volumeToAttach);
}
final DataTO volTO = volFactory.getVolume(volumeToAttach.getId()).getTO();
deviceId = getDeviceId(vm, deviceId);
final DiskTO disk = new DiskTO(volTO, deviceId, volumeToAttach.getPath(), volumeToAttach.getVolumeType());
final AttachCommand cmd = new AttachCommand(disk, vm.getInstanceName());
final ChapInfo chapInfo = volService.getChapInfo(volFactory.getVolume(volumeToAttach.getId()), dataStore);
final Map<String, String> details = new HashMap<>();
disk.setDetails(details);
details.put(DiskTO.MANAGED, String.valueOf(volumeToAttachStoragePool.isManaged()));
details.put(DiskTO.STORAGE_HOST, volumeToAttachStoragePool.getHostAddress());
details.put(DiskTO.STORAGE_PORT, String.valueOf(volumeToAttachStoragePool.getPort()));
details.put(DiskTO.VOLUME_SIZE, String.valueOf(volumeToAttach.getSize()));
details.put(DiskTO.IQN, volumeToAttach.get_iScsiName());
details.put(DiskTO.MOUNT_POINT, volumeToAttach.get_iScsiName());
details.put(DiskTO.PROTOCOL_TYPE, volumeToAttach.getPoolType() != null ? volumeToAttach.getPoolType().toString() : null);
if (chapInfo != null) {
details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
details.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
details.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
}
_userVmDao.loadDetails(vm);
final Map<String, String> controllerInfo = new HashMap<>();
controllerInfo.put(VmDetailConstants.ROOT_DISK_CONTROLLER, vm.getDetail(VmDetailConstants.ROOT_DISK_CONTROLLER));
controllerInfo.put(VmDetailConstants.DATA_DISK_CONTROLLER, vm.getDetail(VmDetailConstants.DATA_DISK_CONTROLLER));
cmd.setControllerInfo(controllerInfo);
try {
answer = (AttachAnswer) _agentMgr.send(hostId, cmd);
} catch (final Exception e) {
if (host != null) {
volService.revokeAccess(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
}
throw new CloudRuntimeException(errorMsg + " due to: " + e.getMessage());
}
}
if (!sendCommand || answer != null && answer.getResult()) {
// Mark the volume as attached
if (sendCommand) {
final DiskTO disk = answer.getDisk();
_volsDao.attachVolume(volumeToAttach.getId(), vm.getId(), disk.getDiskSeq());
volumeToAttach = _volsDao.findById(volumeToAttach.getId());
if (volumeToAttachStoragePool.isManaged() && volumeToAttach.getPath() == null) {
volumeToAttach.setPath(answer.getDisk().getPath());
_volsDao.update(volumeToAttach.getId(), volumeToAttach);
}
} else {
deviceId = getDeviceId(vm, deviceId);
_volsDao.attachVolume(volumeToAttach.getId(), vm.getId(), deviceId);
}
// insert record for disk I/O statistics
VmDiskStatisticsVO diskstats = _vmDiskStatsDao.findBy(vm.getAccountId(), vm.getDataCenterId(), vm.getId(), volumeToAttach.getId());
if (diskstats == null) {
diskstats = new VmDiskStatisticsVO(vm.getAccountId(), vm.getDataCenterId(), vm.getId(), volumeToAttach.getId());
_vmDiskStatsDao.persist(diskstats);
}
return _volsDao.findById(volumeToAttach.getId());
} else {
if (answer != null) {
final String details = answer.getDetails();
if (details != null && !details.isEmpty()) {
errorMsg += "; " + details;
}
}
if (host != null) {
volService.revokeAccess(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
}
throw new CloudRuntimeException(errorMsg);
}
}
use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method checkIfZoneIsDeletableFailureOnHostTest.
@Test(expected = CloudRuntimeException.class)
public void checkIfZoneIsDeletableFailureOnHostTest() {
final HostVO hostVO = Mockito.mock(HostVO.class);
final ArrayList<HostVO> arrayList = new ArrayList<>();
arrayList.add(hostVO);
Mockito.when(_hostDao.listByDataCenterId(anyLong())).thenReturn(arrayList);
Mockito.when(_podDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
Mockito.when(_publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<>());
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
}
use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class KVMFencerTest method testWithTimeoutingFence.
@Test
public void testWithTimeoutingFence() throws AgentUnavailableException, OperationTimedoutException {
final HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);
final HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);
final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost));
Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenThrow(new OperationTimedoutException(null, 2l, 0l, 0, false));
Assert.assertFalse(fencer.fenceOff(virtualMachine, host));
}
use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.
the class KVMFencerTest method testWithFailingFence.
@Test
public void testWithFailingFence() throws AgentUnavailableException, OperationTimedoutException {
final HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);
final HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);
final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost));
Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenThrow(new AgentUnavailableException(2l));
Assert.assertFalse(fencer.fenceOff(virtualMachine, host));
}
Aggregations