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);
}
Aggregations