Search in sources :

Example 1 with VmDynamic

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() {
        }
    });
}
Also used : EventSubscriber(org.ovirt.vdsm.jsonrpc.client.events.EventSubscriber) Guid(org.ovirt.engine.core.compat.Guid) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) List(java.util.List) Subscription(org.reactivestreams.Subscription) Map(java.util.Map) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 2 with VmDynamic

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;
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VmManager(org.ovirt.engine.core.vdsbroker.VmManager)

Example 3 with VmDynamic

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);
    }
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic)

Example 4 with VmDynamic

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());
    }
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic)

Example 5 with VmDynamic

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);
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic)

Aggregations

VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)54 Test (org.junit.Test)13 Guid (org.ovirt.engine.core.compat.Guid)12 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)8 VM (org.ovirt.engine.core.common.businessentities.VM)7 VmStatistics (org.ovirt.engine.core.common.businessentities.VmStatistics)6 Vm (org.ovirt.engine.api.model.Vm)4 Date (java.util.Date)3 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 VdsmVm (org.ovirt.engine.core.vdsbroker.monitoring.VdsmVm)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1