use of org.ovirt.engine.core.vdsbroker.VmManager in project ovirt-engine by oVirt.
the class HostMonitoring method refreshCommitedMemory.
/**
* calculate the memory and cpus used by vms based on the number of the running VMs. only DB vms counted currently as
* we know their provisioned memory value.
* only vms we know their memory definition are calculated, thus
* external VMs are added to db on the 1st cycle they appear, and then being added to this calculation
*/
public static boolean refreshCommitedMemory(VDS host, List<VmDynamic> vms, ResourceManager resourceManager) {
boolean memoryUpdated = false;
int memCommited = host.getGuestOverhead();
int vmsCoresCount = 0;
for (VmDynamic vm : vms) {
// we shouldn't include them as committed.
if (vm != null && vm.getStatus() != VMStatus.WaitForLaunch && vm.getStatus() != VMStatus.Down) {
final VmManager vmManager = resourceManager.getVmManager(vm.getId());
memCommited += vmManager.getVmMemoryWithOverheadInMB();
vmsCoresCount += vmManager.getNumOfCpus();
}
}
if (memCommited != host.getMemCommited()) {
host.setMemCommited(memCommited);
memoryUpdated = true;
}
if (vmsCoresCount != host.getVmsCoresCount()) {
host.setVmsCoresCount(vmsCoresCount);
memoryUpdated = true;
}
return memoryUpdated;
}
use of org.ovirt.engine.core.vdsbroker.VmManager in project ovirt-engine by oVirt.
the class VmsMonitoring method unlockVms.
private void unlockVms(List<VmAnalyzer> vmAnalyzers) {
vmAnalyzers.stream().map(VmAnalyzer::getVmId).forEach(vmId -> {
VmManager vmManager = getVmManager(vmId);
vmManager.updateVmDataChangedTime();
vmManager.unlock();
});
}
use of org.ovirt.engine.core.vdsbroker.VmManager in project ovirt-engine by oVirt.
the class SetVmTicketCommand method perform.
@Override
protected void perform() {
// a ticket):
if (StringUtils.isEmpty(ticket)) {
ticket = Ticketing.generateOTP();
}
VmManager vmManager = resourceManager.getVmManager(getParameters().getVmId());
vmManager.lock();
try {
// Update the dynamic information of the virtual machine in memory (we need it
// to update the database later):
final VM vm = getVm();
final DbUser user = getCurrentUser();
vm.setConsoleUserId(user.getId());
vm.setConsoleCurrentUserName(getConsoleUserName());
// the console of the same virtual machine simultaneously.
if (vm.getAllowConsoleReconnect() || neededPermissions) {
vmManager.update(vm.getDynamicData());
sendTicket();
} else {
final boolean saved = vmDynamicDao.updateConsoleUserWithOptimisticLocking(vm.getDynamicData());
if (saved) {
sendTicket();
} else {
dontSendTicket();
}
}
} finally {
vmManager.unlock();
}
}
use of org.ovirt.engine.core.vdsbroker.VmManager in project ovirt-engine by oVirt.
the class VmHandler method updateOperationProgress.
public void updateOperationProgress(final VM vm) {
VmManager vmManager = resourceManager.getVmManager(vm.getId(), false);
if (vmManager != null) {
vm.setBackgroundOperationDescription(vmManager.getConvertOperationDescription());
vm.setBackgroundOperationProgress(vmManager.getConvertOperationProgress());
} else {
vm.setBackgroundOperationDescription(null);
vm.setBackgroundOperationProgress(-1);
}
}
use of org.ovirt.engine.core.vdsbroker.VmManager in project ovirt-engine by oVirt.
the class VmsMonitoring method shouldAnalyzeVm.
private boolean shouldAnalyzeVm(Pair<VmDynamic, VdsmVm> pair, long fetchTime, Guid vdsId) {
Guid vmId = getVmId(pair.getFirst(), pair.getSecond());
VmManager vmManager = getVmManager(vmId);
if (!vmManager.trylock()) {
log.debug("skipping VM '{}' from this monitoring cycle" + " - the VM is locked by its VmManager ", vmId);
return false;
}
if (!vmManager.isLatestData(pair.getSecond(), vdsId)) {
log.warn("skipping VM '{}' from this monitoring cycle" + " - newer VM data was already processed", vmId);
vmManager.unlock();
return false;
}
if (vmManager.getVmDataChangedTime() != null && fetchTime - vmManager.getVmDataChangedTime() <= 0) {
log.warn("skipping VM '{}' from this monitoring cycle" + " - the VM data has changed since fetching the data", vmId);
vmManager.unlock();
return false;
}
return true;
}
Aggregations