Search in sources :

Example 6 with VdsIdAndVdsVDSCommandParametersBase

use of org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase in project ovirt-engine by oVirt.

the class RefreshHostDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    VDSReturnValue vdsReturnValue = resourceManager.runVdsCommand(VDSCommandType.HostDevListByCaps, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
    if (!vdsReturnValue.getSucceeded()) {
        return;
    }
    List<HostDevice> fetchedDevices = (List<HostDevice>) vdsReturnValue.getReturnValue();
    List<HostDevice> oldDevices = hostDeviceDao.getHostDevicesByHostId(getVdsId());
    Map<String, HostDevice> oldMap = Entities.entitiesByName(oldDevices);
    fetchedMap = filterOrphanedDevices(Entities.entitiesByName(fetchedDevices));
    final List<HostDevice> newDevices = new ArrayList<>();
    final List<HostDevice> changedDevices = new ArrayList<>();
    for (Map.Entry<String, HostDevice> entry : fetchedMap.entrySet()) {
        HostDevice device = entry.getValue();
        if (oldMap.containsKey(entry.getKey())) {
            if (!oldMap.get(entry.getKey()).equals(device)) {
                changedDevices.add(device);
            }
        } else {
            newDevices.add(device);
        }
    }
    final List<HostDevice> removedDevices = new ArrayList<>();
    final List<VmDevice> removedVmDevices = new ArrayList<>();
    for (Map.Entry<String, HostDevice> entry : oldMap.entrySet()) {
        final String deviceName = entry.getKey();
        if (!fetchedMap.containsKey(deviceName)) {
            removedDevices.add(entry.getValue());
            if (getAttachedVmDevicesMap().containsKey(deviceName)) {
                List<VmDevice> vmDevices = getAttachedVmDevicesMap().get(deviceName);
                for (VmDevice vmDevice : vmDevices) {
                    log.warn("Removing VM[{}]'s hostDevice[{}] because it no longer exists on host {}", vmDevice.getVmId(), deviceName, getVds());
                    removedVmDevices.add(vmDevice);
                }
            }
        }
    }
    try {
        hostLocking.acquireHostDevicesLock(getVdsId());
        TransactionSupport.executeInNewTransaction(() -> {
            hostDeviceDao.saveAllInBatch(newDevices);
            hostDeviceDao.updateAllInBatch(changedDevices);
            hostDeviceDao.removeAllInBatch(removedDevices);
            handleHostNicVfsConfigUpdate();
            vmDeviceDao.removeAllInBatch(removedVmDevices);
            return null;
        });
    } finally {
        hostLocking.releaseHostDevicesLock(getVdsId());
    }
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

VdsIdAndVdsVDSCommandParametersBase (org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase)6 ArrayList (java.util.ArrayList)3 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)3 List (java.util.List)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1 StorageDomainPoolParametersBase (org.ovirt.engine.core.common.action.StorageDomainPoolParametersBase)1 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)1 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)1 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)1 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)1 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 Guid (org.ovirt.engine.core.compat.Guid)1 Version (org.ovirt.engine.core.compat.Version)1 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)1