@Override public void onPublishMessage(String senderAddress, String subject, Object obj) { VMInstanceVO vm = ((VMInstanceVO)obj); s_logger.debug("MessageBus message: host reserved capacity released for VM: " + vm.getLastHostId() + ", checking if host reservation can be released for host:" + vm.getLastHostId()); Long hostId = vm.getLastHostId(); checkHostReservationRelease(hostId); } });
@Override public Long getHostIdForSnapshotOperation(Volume vol) { VMInstanceVO vm = _vmDao.findById(vol.getInstanceId()); if (vm != null) { if (vm.getHostId() != null) { return vm.getHostId(); } else if (vm.getLastHostId() != null) { return vm.getLastHostId(); } } return null; }
private List<Map<String, String>> getTargets(long clusterId, long storagePoolId) { List<Map<String, String>> targets = new ArrayList<>(); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); // If you do not pass in null for the second parameter, you only get back applicable ROOT disks. List<VolumeVO> volumes = volumeDao.findByPoolId(storagePoolId, null); if (volumes != null) { for (VolumeVO volume : volumes) { Long instanceId = volume.getInstanceId(); if (instanceId != null) { VMInstanceVO vmInstance = vmDao.findById(instanceId); Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId(); if (hostIdForVm != null) { HostVO hostForVm = hostDao.findById(hostIdForVm); if (hostForVm.getClusterId().equals(clusterId)) { Map<String, String> details = new HashMap<>(); details.put(ModifyTargetsCommand.IQN, volume.get_iScsiName()); details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress()); details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort())); targets.add(details); } } } } } return targets; }
private List<String> getStoragePaths(long clusterId, long storagePoolId) { List<String> storagePaths = new ArrayList<>(); // If you do not pass in null for the second parameter, you only get back applicable ROOT disks. List<VolumeVO> volumes = volumeDao.findByPoolId(storagePoolId, null); if (volumes != null) { for (VolumeVO volume : volumes) { Long instanceId = volume.getInstanceId(); if (instanceId != null) { VMInstanceVO vmInstance = vmDao.findById(instanceId); Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId(); if (hostIdForVm != null) { HostVO hostForVm = hostDao.findById(hostIdForVm); if (hostForVm != null && hostForVm.getClusterId().equals(clusterId)) { storagePaths.add(volume.get_iScsiName()); } } } } } return storagePaths; }
private Answer[] attemptHypervisorMigration(StoragePool destPool, VMInstanceVO vm) { final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); // OfflineVmwareMigration: in case of vmware call vcenter to do it for us. // OfflineVmwareMigration: should we check the proximity of source and destination // OfflineVmwareMigration: if we are in the same cluster/datacentre/pool or whatever? // OfflineVmwareMigration: we are checking on success to optionally delete an old vm if we are not List<Command> commandsToSend = hvGuru.finalizeMigrate(vm, destPool); Long hostId = vm.getHostId(); // OfflineVmwareMigration: probably this is null when vm is stopped if(hostId == null) { hostId = vm.getLastHostId(); if (s_logger.isDebugEnabled()) { s_logger.debug(String.format("host id is null, using last host id %d", hostId) ); } } if(CollectionUtils.isNotEmpty(commandsToSend)) { Commands commandsContainer = new Commands(Command.OnError.Stop); commandsContainer.addCommands(commandsToSend); try { // OfflineVmwareMigration: change to the call back variety? // OfflineVmwareMigration: getting a Long seq to be filled with _agentMgr.send(hostId, commandsContainer, this) return _agentMgr.send(hostId, commandsContainer); } catch (AgentUnavailableException | OperationTimedoutException e) { throw new CloudRuntimeException(String.format("Failed to migrate VM: %s", vm.getUuid()),e); } } return null; }
s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host"); } else if (VirtualMachine.State.Stopped.equals(groupVM.getState()) && groupVM.getLastHostId() != null) { long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000; if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) { avoid.addHost(groupVM.getLastHostId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host, in Stopped state but has reserved capacity");
private HostVO getHost(long volumeId) { VolumeVO volumeVO = volumeDao.findById(volumeId); Long vmInstanceId = volumeVO.getInstanceId(); VMInstanceVO vmInstanceVO = vmInstanceDao.findById(vmInstanceId); Long hostId = null; // if the volume to snapshot is associated with a VM if (vmInstanceVO != null) { hostId = vmInstanceVO.getHostId(); // if the VM is not associated with a host if (hostId == null) { hostId = vmInstanceVO.getLastHostId(); } } return getHost(volumeVO.getDataCenterId(), hostId); }
@Override public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); VMInstanceVO vo = _vmDao.findById(vm.getId()); if (vo.getLastHostId() == null) { to.setBootArgs(BaremetalManager.DO_PXE); } Map<String, String> details = new HashMap<String, String>(); details.put("template", vm.getTemplate().getUrl()); to.setDetails(details); // Determine the VM's OS description GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId()); to.setOs(guestOS.getDisplayName()); return to; }
private void migrateThroughHypervisorOrStorage(StoragePool destPool, VMInstanceVO vm) throws StorageUnavailableException, InsufficientCapacityException { final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); final Long srchostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId(); final HostVO srcHost = _hostDao.findById(srchostId); final Long srcClusterId = srcHost.getClusterId(); Answer[] hypervisorMigrationResults = attemptHypervisorMigration(destPool, vm); boolean migrationResult = false; if (hypervisorMigrationResults == null) { // OfflineVmwareMigration: if the HypervisorGuru can't do it, let the volume manager take care of it. migrationResult = volumeMgr.storageMigration(profile, destPool); if (migrationResult) { afterStorageMigrationCleanup(destPool, vm, srcHost, srcClusterId); } else { s_logger.debug("Storage migration failed"); } } else { afterHypervisorMigrationCleanup(destPool, vm, srcHost, srcClusterId, hypervisorMigrationResults); } }
vmHostId = vmInstanceVO.getLastHostId();
VMInstanceVO vmvo = q.find(); if (vmvo.getLastHostId() == null) {
@Override public void cleanupVMReservations() { List<VMReservationVO> reservations = _reservationDao.listAll(); for (VMReservationVO reserv : reservations) { VMInstanceVO vm = _vmInstanceDao.findById(reserv.getVmId()); if (vm != null) { if (vm.getState() == State.Starting || (vm.getState() == State.Stopped && vm.getLastHostId() == null)) { continue; } else { // delete reservation _reservationDao.remove(reserv.getId()); } } else { // delete reservation _reservationDao.remove(reserv.getId()); } } }
host = _hostDao.findById(vm.getLastHostId());
final Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
hostId = vmInstanceVO.getLastHostId();
hostId = vm.getLastHostId();
@Override @DB public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) { return false; } VMInstanceVO vo = _vmDao.findById(vm.getId()); assert vo != null : "Where ths nic " + nic.getId() + " going???"; if (vo.getLastHostId() == null) { nic.setMacAddress(dest.getHost().getPrivateMacAddress()); NicVO nicVo = _nicDao.findById(nic.getId()); nicVo.setMacAddress(nic.getMacAddress()); _nicDao.update(nicVo.getId(), nicVo); /*This vm is just being created */ if (!_pxeMgr.prepare(vm, nic, network, dest, context)) { throw new CloudRuntimeException("Cannot prepare pxe server"); } } if (dest.getDataCenter().getNetworkType() == DataCenter.NetworkType.Advanced){ prepareVlan(network, dest); } return true; }
VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId); Long lastHostId = vmInstanceVO.getLastHostId();
hostId = vm.getLastHostId(); HostVO host = _hostDao.findById(hostId);
LHVMClusterSearch.join("hostSearch1", hostSearch1, hostSearch1.entity().getId(), LHVMClusterSearch.entity().getLastHostId(), JoinType.INNER); LHVMClusterSearch.and("hostid", LHVMClusterSearch.entity().getHostId(), Op.NULL); hostSearch1.and("clusterId", hostSearch1.entity().getClusterId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ); AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); AllFieldsSearch.and("zone", AllFieldsSearch.entity().getDataCenterId(), Op.EQ); NotMigratingSearch.and("lastHost", NotMigratingSearch.entity().getLastHostId(), Op.EQ); NotMigratingSearch.and("state", NotMigratingSearch.entity().getState(), Op.NEQ); NotMigratingSearch.done();