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