Search in sources :

Example 6 with Guid

use of org.ovirt.engine.core.compat.Guid 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 7 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class VmDevicesMonitoring method processVmDevices.

/**
 * Actually process the VM device update and store individual device additions/updates/removals
 * in the <code>change</code>.
 */
private void processVmDevices(Change change, Map<String, Object> vmInfo) {
    Guid vmId = getVmId(vmInfo);
    Set<Guid> processedDeviceIds = new HashSet<>();
    List<VmDevice> dbDevices = getVmDeviceDao().getVmDeviceByVmId(vmId);
    Map<VmDeviceId, VmDevice> dbDeviceMap = Entities.businessEntitiesById(dbDevices);
    for (Object o : (Object[]) vmInfo.get(VdsProperties.Devices)) {
        Map<String, Object> vdsmDevice = (Map<String, Object>) o;
        if (vdsmDevice.get(VdsProperties.Address) == null) {
            logDeviceInformation(vmId, vdsmDevice);
            continue;
        }
        Guid deviceId = getDeviceId(vdsmDevice);
        VmDevice dbDevice = dbDeviceMap.get(new VmDeviceId(deviceId, vmId));
        if (dbDevice == null) {
            dbDevice = getByDeviceType((String) vdsmDevice.get(VdsProperties.Device), dbDeviceMap);
            deviceId = dbDevice != null ? dbDevice.getDeviceId() : deviceId;
        }
        String logicalName = getDeviceLogicalName(vmInfo, vdsmDevice);
        if (deviceId == null || dbDevice == null) {
            VmDevice newDevice = buildNewVmDevice(vmId, vdsmDevice, logicalName);
            if (newDevice != null) {
                change.addDeviceToAdd(newDevice);
                processedDeviceIds.add(newDevice.getDeviceId());
            }
        } else {
            dbDevice.setPlugged(Boolean.TRUE);
            dbDevice.setAddress(vdsmDevice.get(VdsProperties.Address).toString());
            dbDevice.setAlias(StringUtils.defaultString((String) vdsmDevice.get(VdsProperties.Alias)));
            dbDevice.setLogicalName(logicalName);
            dbDevice.setHostDevice(StringUtils.defaultString((String) vdsmDevice.get(VdsProperties.HostDev)));
            change.addDeviceToUpdate(dbDevice);
            processedDeviceIds.add(deviceId);
        }
    }
    handleRemovedDevices(change, vmId, processedDeviceIds, dbDevices);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) HashSet(java.util.HashSet)

Example 8 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class VmDevicesMonitoring method buildNewVmDevice.

/**
 * Builds a new device structure for the device recognized by libvirt.
 */
private VmDevice buildNewVmDevice(Guid vmId, Map device, String logicalName) {
    String typeName = (String) device.get(VdsProperties.Type);
    String deviceName = (String) device.get(VdsProperties.Device);
    // do not allow null or empty device or type values
    if (StringUtils.isEmpty(typeName) || StringUtils.isEmpty(deviceName)) {
        log.error("Empty or NULL values were passed for a VM '{}' device, Device is skipped", vmId);
        return null;
    }
    String address = device.get(VdsProperties.Address).toString();
    String alias = StringUtils.defaultString((String) device.get(VdsProperties.Alias));
    Map<String, Object> specParams = (Map<String, Object>) device.get(VdsProperties.SpecParams);
    specParams = specParams != null ? specParams : new HashMap<>();
    Guid newDeviceId = Guid.newGuid();
    VmDeviceId id = new VmDeviceId(newDeviceId, vmId);
    Object deviceReadonlyValue = device.get(VdsProperties.ReadOnly);
    boolean isReadOnly = deviceReadonlyValue != null && Boolean.getBoolean(deviceReadonlyValue.toString());
    VmDevice newDevice = new VmDevice(id, VmDeviceGeneralType.forValue(typeName), deviceName, address, specParams, false, true, isReadOnly, alias, null, null, logicalName);
    if (VmDeviceCommonUtils.isMemory(newDevice)) {
        fixMemorySpecParamsTypes(newDevice);
    }
    log.debug("New device was marked for adding to VM '{}' Device : '{}'", vmId, newDevice);
    return newDevice;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 9 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class VmMigrationProgressMonitoring method onNext.

@Override
public void onNext(Map<String, Object> map) {
    try {
        map.remove(VdsProperties.notify_time);
        map.entrySet().forEach(vmInfo -> {
            Guid vmId = new Guid(vmInfo.getKey());
            Map<?, ?> properties = (Map<?, ?>) vmInfo.getValue();
            int progress = Integer.valueOf(properties.get(VdsProperties.vm_migration_progress).toString());
            VmStatistics vmStatistics = resourceManager.getVmManager(vmId).getStatistics();
            vmStatistics.setMigrationProgressPercent(progress);
            Integer actualDowntime = (Integer) properties.get(VdsProperties.MIGRATION_DOWNTIME);
            if (actualDowntime != null) {
                resourceManager.getEventListener().actualDowntimeReported(vmId, actualDowntime);
            }
        });
    } finally {
        subscription.request(1);
    }
}
Also used : VmStatistics(org.ovirt.engine.core.common.businessentities.VmStatistics) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map)

Example 10 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class VmsListFetcher method fetch.

@SuppressWarnings("unchecked")
public boolean fetch() {
    VDSReturnValue pollReturnValue = poll();
    if (pollReturnValue.getSucceeded()) {
        vdsmVms = (Map<Guid, VdsmVm>) pollReturnValue.getReturnValue();
        onFetchVms();
        return true;
    } else {
        onError();
        return false;
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

Guid (org.ovirt.engine.core.compat.Guid)1431 ArrayList (java.util.ArrayList)330 Test (org.junit.Test)322 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)219 HashMap (java.util.HashMap)211 List (java.util.List)167 VM (org.ovirt.engine.core.common.businessentities.VM)144 Map (java.util.Map)118 VDS (org.ovirt.engine.core.common.businessentities.VDS)117 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)106 HashSet (java.util.HashSet)102 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)89 Pair (org.ovirt.engine.core.common.utils.Pair)79 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)77 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)72 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)70 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)69 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)57 ActionType (org.ovirt.engine.core.common.action.ActionType)56 Set (java.util.Set)52