use of org.ovirt.engine.core.common.businessentities.VmDynamic in project ovirt-engine by oVirt.
the class EventVmStatsRefresher method startMonitoring.
@Override
public void startMonitoring() {
allVmStatsOnlyRefresher.startMonitoring();
final String hostname = vdsManager.getVdsHostname();
resourceManager.subscribe(new EventSubscriber(hostname + "|*|VM_status|*") {
@Override
public void onSubscribe(Subscription sub) {
subscription = sub;
subscription.request(1);
}
@Override
public void onNext(Map<String, Object> map) {
try {
long fetchTime = System.nanoTime();
printEventInDebug(map);
List<Pair<VmDynamic, VdsmVm>> vms = convertEvent(map);
if (!vms.isEmpty()) {
getVmsMonitoring().perform(vms, fetchTime, vdsManager, false);
processDevices(vms.stream().map(Pair::getSecond), fetchTime);
}
} finally {
subscription.request(1);
}
}
private void printEventInDebug(Map<String, Object> map) {
if (!log.isDebugEnabled()) {
return;
}
StringBuilder sb = new StringBuilder();
ObjectDescriptor.toStringBuilder(map, sb);
log.debug("processing event for host {} data:\n{}", vdsManager.getVdsName(), sb);
}
@SuppressWarnings("unchecked")
private List<Pair<VmDynamic, VdsmVm>> convertEvent(Map<String, Object> map) {
Double notifyTime = VdsBrokerObjectsBuilder.removeNotifyTimeFromVmStatusEvent(map);
return map.entrySet().stream().map(idToMap -> toMonitoredVm(new Guid(idToMap.getKey()), (Map<String, Object>) idToMap.getValue(), notifyTime)).collect(Collectors.toList());
}
private Pair<VmDynamic, VdsmVm> toMonitoredVm(Guid vmId, Map<String, Object> vmMap, Double notifyTime) {
VmDynamic dbVm = vmDynamicDao.get(vmId);
VdsmVm vdsmVm = dbVm == null ? createVdsmVm(vmId, vmMap, notifyTime) : createVdsmVm(dbVm, vmMap, notifyTime);
return new Pair<>(dbVm, vdsmVm);
}
private VdsmVm createVdsmVm(Guid vmId, Map<String, Object> struct, Double notifyTime) {
VmDynamic fakeVm = new VmDynamic();
fakeVm.setId(vmId);
return createVdsmVm(fakeVm, struct, notifyTime);
}
private VdsmVm createVdsmVm(VmDynamic dbVmDynamic, Map<String, Object> struct, Double notifyTime) {
// send a clone of vm dynamic to be overridden with new data
VmDynamic clonedVmDynamic = new VmDynamic(dbVmDynamic);
VdsBrokerObjectsBuilder.updateVMDynamicData(clonedVmDynamic, struct, vdsManager.getCopyVds());
return new VdsmVm(notifyTime).setVmDynamic(clonedVmDynamic).setDevicesHash(VdsBrokerObjectsBuilder.getVmDevicesHash(struct));
}
@Override
public void onError(Throwable t) {
// communication issue is delivered as a message so we need to request for more
subscription.request(1);
}
@Override
public void onComplete() {
}
});
}
use of org.ovirt.engine.core.common.businessentities.VmDynamic 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.common.businessentities.VmDynamic in project ovirt-engine by oVirt.
the class VmsListFetcher method filterVms.
protected void filterVms() {
for (VdsmVm vdsmVm : vdsmVms.values()) {
VmDynamic dbVm = dbVms.get(vdsmVm.getVmDynamic().getId());
gatherChangedVms(dbVm, vdsmVm);
}
}
use of org.ovirt.engine.core.common.businessentities.VmDynamic in project ovirt-engine by oVirt.
the class VmAnalyzer method proceedVmReportedOnTheSameHost.
private void proceedVmReportedOnTheSameHost() {
if (vdsmVm.getVmDynamic().getStatus() == VMStatus.MigratingTo) {
log.info("VM '{}' is migrating to VDS '{}'({}) ignoring it in the refresh until migration is done", vdsmVm.getVmDynamic().getId(), vdsManager.getVdsId(), vdsManager.getVdsName());
return;
}
VmDynamic vdsmVmDynamic = vdsmVm.getVmDynamic();
if (!Objects.equals(vdsmVmDynamic.getClientIp(), dbVm.getClientIp())) {
auditClientIpChange();
}
logVmStatusTransition();
if (dbVm.getStatus() == VMStatus.Unknown && vdsmVmDynamic.getStatus() != VMStatus.Unknown) {
auditVmRestoredFromUnknown();
if (!EnumSet.of(VMStatus.WaitForLaunch, VMStatus.MigratingTo).contains(vdsmVmDynamic.getStatus())) {
resourceManager.removeAsyncRunningVm(dbVm.getId());
}
}
if (dbVm.getStatus() != VMStatus.Up && vdsmVmDynamic.getStatus() == VMStatus.Up || dbVm.getStatus() != VMStatus.PoweringUp && vdsmVmDynamic.getStatus() == VMStatus.PoweringUp) {
poweringUp = true;
}
// "Up" as this means that the power down operation failed:
if (dbVm.getStatus() == VMStatus.PoweringDown && vdsmVmDynamic.getStatus() == VMStatus.Up) {
auditVmPowerDownFailed();
}
// log vm recovered from error
if (dbVm.getStatus() == VMStatus.Paused && dbVm.getPauseStatus().isError() && vdsmVmDynamic.getStatus() == VMStatus.Up) {
auditVmRecoveredFromError();
}
if (isRunSucceeded() || isMigrationSucceeded()) {
// Vm moved to Up status - remove its record from Async
// reportedAndUnchangedVms handling
log.debug("removing VM '{}' from successful run VMs list", dbVm.getId());
succeededToRun = true;
}
// is not MigratingFrom, it means the migration failed
if (dbVm.getStatus() == VMStatus.MigratingFrom && vdsmVmDynamic.getStatus() != VMStatus.MigratingFrom && vdsmVmDynamic.getStatus().isRunning()) {
rerun = true;
log.info("Adding VM '{}'({}) to re-run list", dbVm.getId(), getVmManager().getName());
dbVm.setMigratingToVds(null);
getVmManager().getStatistics().setMigrationProgressPercent(0);
}
if (dbVm.getStatus() != VMStatus.NotResponding && vdsmVmDynamic.getStatus() == VMStatus.NotResponding) {
auditVmNotResponding();
}
if (vdsmVmDynamic.getStatus() == VMStatus.Paused) {
if (vdsmVmDynamic.getPauseStatus() == VmPauseStatus.POSTCOPY) {
handOverVm();
// no need to do anything else besides the hand-over
return;
}
switch(dbVm.getStatus()) {
case Paused:
break;
default:
// otherwise, remove the vm from async list
removeFromAsync = true;
auditVmPaused();
// check exit message to determine why the VM is paused
if (vdsmVmDynamic.getPauseStatus().isError()) {
auditVmPausedError(vdsmVmDynamic);
}
}
}
updateVmDynamicData();
updateStatistics();
prepareGuestAgentNetworkDevicesForUpdate();
if (!vdsManager.isInitialized()) {
resourceManager.removeVmFromDownVms(vdsManager.getVdsId(), vdsmVm.getVmDynamic().getId());
}
}
use of org.ovirt.engine.core.common.businessentities.VmDynamic in project ovirt-engine by oVirt.
the class VmAnalyzer method auditVmSuspended.
private void auditVmSuspended() {
VmDynamic vm = vdsmVm.getVmDynamic();
AuditLogType type = vm.getExitStatus() == VmExitStatus.Normal ? AuditLogType.USER_SUSPEND_VM_OK : AuditLogType.USER_FAILED_SUSPEND_VM;
AuditLogableBase logable = Injector.injectMembers(new AuditLogableBase(vdsManager.getVdsId(), vm.getId()));
auditLog(logable, type);
}
Aggregations