Adam Litke has uploaded a new change for review. Change subject: engine: Track the time a VM was last stopped ......................................................................
engine: Track the time a VM was last stopped Today, ovirt provides information on how long a VM has been up. Users have requested the ability to see how long a VM has been down. This could be useful for determining which VMs need to be powered on for maintenance (eg. package updates). As a first step, just track this information and make it available via the REST API. In the future, it could be displayed in the UI in the 'Uptime' column or similar. This patch makes the following specific changes: - Add new column last_stop_time to the vm_dynamic table and update views - When a new VM is created, initialize stop time to the current time - Catch VM state changes in ResourceManager and update last_stop_time - Add "stop_time" to the REST API and always show it in the VM resource Signed-off-by: Adam Litke <ali...@redhat.com> Change-Id: I0f94a56e0c82246a932fc1800a2c9ef8c5205e13 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1042854 --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/ResourceManager.java M packaging/dbscripts/create_views.sql A packaging/dbscripts/upgrade/03_04_0250_add_last_stop_time_to_vm_dynamic.sql M packaging/dbscripts/vms_sp.sql 11 files changed, 39 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/22429/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java index dfbe541..5b54bb8 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java @@ -750,6 +750,7 @@ tempVar.setVmIp(""); tempVar.setVmFQDN(""); tempVar.setDisplayType(getParameters().getVmStaticData().getDefaultDisplayType()); + tempVar.setLastStopTime(new Date()); VmDynamic vmDynamic = tempVar; DbFacade.getInstance().getVmDynamicDao().save(vmDynamic); getCompensationContext().snapshotNewEntity(vmDynamic); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java index 4e139e2..b916263 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java @@ -487,6 +487,14 @@ this.vmDynamic.setLastStartTime(value); } + public Date getLastStopTime() { + return this.vmDynamic.getLastStopTime(); + } + + public void setLastStopTime(Date value) { + this.vmDynamic.setLastStopTime(value); + } + public String getConsoleCurentUserName() { return this.vmDynamic.getConsoleCurrentUserName(); } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java index 3bcd19a..111a545 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java @@ -17,6 +17,7 @@ private String vmHost; private Integer vmPid; private Date lastStartTime; + private Date lastStopTime; private String guestCurUserName; private String consoleCurUserName; private Guid consoleUserId; @@ -88,6 +89,7 @@ result = prime * result + ((vmIp == null) ? 0 : vmIp.hashCode()); result = prime * result + ((vmFQDN == null) ? 0 : vmFQDN.hashCode()); result = prime * result + ((lastStartTime == null) ? 0 : lastStartTime.hashCode()); + result = prime * result + ((lastStopTime == null) ? 0 : lastStopTime.hashCode()); result = prime * result + ((vmPid == null) ? 0 : vmPid.hashCode()); result = prime * result + (lastWatchdogEvent == null ? 0 : lastWatchdogEvent.hashCode()); result = prime * result + (lastWatchdogAction == null ? 0 : lastWatchdogAction.hashCode()); @@ -141,6 +143,7 @@ && ObjectUtils.objectsEqual(vmIp, other.vmIp) && ObjectUtils.objectsEqual(vmFQDN, other.vmFQDN) && ObjectUtils.objectsEqual(lastStartTime, other.lastStartTime) + && ObjectUtils.objectsEqual(lastStopTime, other.lastStopTime) && ObjectUtils.objectsEqual(vmPid, other.vmPid) && ObjectUtils.objectsEqual(lastWatchdogEvent, other.lastWatchdogEvent) && ObjectUtils.objectsEqual(lastWatchdogAction, other.lastWatchdogAction) @@ -333,6 +336,14 @@ this.lastStartTime = value; } + public Date getLastStopTime() { + return this.lastStopTime; + } + + public void setLastStopTime(Date value) { + this.lastStopTime = value; + } + public Integer getVmPid() { return this.vmPid; } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java index 30b7f91..28ff9ef 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java @@ -291,6 +291,7 @@ entity.setVmPid((Integer) rs.getObject("vm_pid")); entity.setDbGeneration(rs.getLong("db_generation")); entity.setLastStartTime(DbFacadeUtils.fromDate(rs.getTimestamp("last_start_time"))); + entity.setLastStopTime(DbFacadeUtils.fromDate(rs.getTimestamp("last_stop_time"))); entity.setGuestCurrentUserName(rs.getString("guest_cur_user_name")); entity.setConsoleCurrentUserName(rs.getString("console_cur_user_name")); entity.setGuestLastLoginTime(DbFacadeUtils.fromDate(rs.getTimestamp("guest_last_login_time"))); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java index 4950bb3..7f2b52e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java @@ -89,6 +89,7 @@ .addValue("vm_ip", vm.getVmIp()) .addValue("vm_fqdn", vm.getVmFQDN()) .addValue("last_start_time", vm.getLastStartTime()) + .addValue("last_stop_time", vm.getLastStopTime()) .addValue("vm_pid", vm.getVmPid()) .addValue("display", vm.getDisplay()) .addValue("acpi_enable", vm.getAcpiEnable()) @@ -143,6 +144,8 @@ entity.setVmFQDN(rs.getString("vm_fqdn")); entity.setLastStartTime(DbFacadeUtils.fromDate(rs .getTimestamp("last_start_time"))); + entity.setLastStopTime(DbFacadeUtils.fromDate(rs + .getTimestamp("last_stop_time"))); entity.setVmPid((Integer) rs.getObject("vm_pid")); entity.setDisplay((Integer) rs.getObject("display")); entity.setAcpiEnable((Boolean) rs.getObject("acpi_enable")); @@ -199,6 +202,7 @@ .addValue("vm_host", entity.getVmHost()) .addValue("vm_ip", entity.getVmIp()) .addValue("last_start_time", entity.getLastStartTime()) + .addValue("last_stop_time", entity.getLastStopTime()) .addValue("vm_pid", entity.getVmPid()) .addValue("vm_fqdn", entity.getVmFQDN()) .addValue("app_list", entity.getAppList()) diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 3f000b4..5e7a04f 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -2503,6 +2503,7 @@ <xs:element ref="template" minOccurs="0" maxOccurs="1"/> <xs:element ref="storage_domain" minOccurs="0" maxOccurs="1"/> <xs:element name="start_time" type="xs:dateTime" minOccurs="0"/> + <xs:element name="stop_time" type="xs:dateTime" minOccurs="0"/> <xs:element name="creation_time" type="xs:dateTime" minOccurs="0"/> <xs:element name="origin" type="xs:string" minOccurs="0"/> <xs:element name="stateless" type="xs:boolean" minOccurs="0"/> diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java index ccd5f5b..412d10b 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java @@ -422,6 +422,9 @@ model.getDisplay().setType(map(entity.getDefaultDisplayType(), null)); } } + if (entity.getLastStopTime() != null) { + model.setStopTime(DateMapper.map(entity.getLastStopTime(), null)); + } if (model.getDisplay() != null) { model.getDisplay().setMonitors(entity.getNumOfMonitors()); model.getDisplay().setSingleQxlPci(entity.getSingleQxlPci()); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/ResourceManager.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/ResourceManager.java index c30756c..2d16868 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/ResourceManager.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/ResourceManager.java @@ -2,6 +2,7 @@ import java.lang.reflect.Constructor; import java.util.ArrayList; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -289,6 +290,7 @@ if (isVmNotRunning) { vm.setRunOnVds(null); vm.setVmPauseStatus(VmPauseStatus.NONE); + vm.setLastStopTime(new Date()); } } } diff --git a/packaging/dbscripts/create_views.sql b/packaging/dbscripts/create_views.sql index ebcc883..beead60 100644 --- a/packaging/dbscripts/create_views.sql +++ b/packaging/dbscripts/create_views.sql @@ -598,7 +598,7 @@ vm_static.initrd_url as initrd_url, vm_static.kernel_url as kernel_url, vm_static.kernel_params as kernel_params, vm_dynamic.pause_status as pause_status, vm_dynamic.exit_message as exit_message, vm_dynamic.exit_status as exit_status,vm_static.migration_support as migration_support,vm_static.predefined_properties as predefined_properties,vm_static.userdefined_properties as userdefined_properties,vm_static.min_allocated_mem as min_allocated_mem, vm_dynamic.hash as hash, vm_static.cpu_pinning as cpu_pinning, vm_static.db_generation as db_generation, vm_static.host_cpu_flags as host_cpu_flags, vm_static.tunnel_migration as tunnel_migration, vm_static.vnc_keyboard_layout as vnc_keyboard_layout, vm_static.is_run_and_pause as is_run_and_pause, vm_static.created_by_user_id as created_by_user_id, vm_dynamic.last_watchdog_event as last_watchdog_event, vm_dynamic.last_watchdog_action as last_watchdog_action, vm_dynamic.is_run_once as is_run_once, vm_dynamic.vm_fqdn as vm_fqdn, vm_dynamic.cpu_name as cpu_name, - vm_static.instance_type_id as instance_type_id, vm_static.image_type_id as image_type_id, vds_groups.architecture as architecture + vm_static.instance_type_id as instance_type_id, vm_static.image_type_id as image_type_id, vds_groups.architecture as architecture, vm_dynamic.last_stop_time as last_stop_time FROM vm_static INNER JOIN vm_dynamic ON vm_static.vm_guid = vm_dynamic.vm_guid INNER JOIN vm_static AS vm_templates ON vm_static.vmt_guid = vm_templates.vm_guid INNER JOIN @@ -622,7 +622,7 @@ vms.vds_group_description, vms.vmt_name, vms.vmt_mem_size_mb, vms.vmt_os, vms.vmt_creation_date, vms.vmt_child_count, vms.vmt_num_of_sockets, vms.vmt_cpu_per_socket, vms.vmt_description, vms.status, vms.vm_ip, vms.vm_host, vms.vmt_num_of_sockets * vms.vmt_cpu_per_socket AS vmt_num_of_cpus, vms.vm_pid, - vms.last_start_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.console_user_id, + vms.last_start_time, vms.last_stop_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.console_user_id, vms.guest_last_logout_time, vms.guest_os, vms.run_on_vds, vms.migrating_to_vds, vms.app_list, vms.display, vms.hibernation_vol_handle, vms.vm_pool_name, vms.vm_pool_id, vms.vm_guid, vms.num_of_monitors, vms.single_qxl_pci, vms.allow_console_reconnect, diff --git a/packaging/dbscripts/upgrade/03_04_0250_add_last_stop_time_to_vm_dynamic.sql b/packaging/dbscripts/upgrade/03_04_0250_add_last_stop_time_to_vm_dynamic.sql new file mode 100644 index 0000000..e7120b6 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_04_0250_add_last_stop_time_to_vm_dynamic.sql @@ -0,0 +1 @@ +select fn_db_add_column('vm_dynamic', 'last_stop_time', 'timestamp with time zone'); diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql index 741ab41..d7f3321 100644 --- a/packaging/dbscripts/vms_sp.sql +++ b/packaging/dbscripts/vms_sp.sql @@ -222,6 +222,7 @@ v_vm_ip VARCHAR(255) , v_vm_fqdn VARCHAR(255) , v_last_start_time TIMESTAMP WITH TIME ZONE , + v_last_stop_time TIMESTAMP WITH TIME ZONE , v_vm_pid INTEGER , v_display INTEGER , v_acpi_enable BOOLEAN , @@ -247,8 +248,8 @@ RETURNS VOID AS $procedure$ BEGIN -INSERT INTO vm_dynamic(app_list, guest_cur_user_name, console_cur_user_name, guest_last_login_time, guest_last_logout_time, console_user_id, guest_os, migrating_to_vds, RUN_ON_VDS, status, vm_guid, vm_host, vm_ip, last_start_time, vm_pid, display, acpi_enable, session, display_ip, display_type, kvm_enable, boot_sequence, display_secure_port, utc_diff, last_vds_run_on, client_ip, guest_requested_memory, hibernation_vol_handle,exit_status,pause_status,exit_message, guest_agent_nics_hash, last_watchdog_event, last_watchdog_action, is_run_once, vm_fqdn, cpu_name) - VALUES(v_app_list, v_guest_cur_user_name, v_console_cur_user_name, v_guest_last_login_time, v_guest_last_logout_time, v_console_user_id, v_guest_os, v_migrating_to_vds, v_run_on_vds, v_status, v_vm_guid, v_vm_host, v_vm_ip, v_last_start_time, v_vm_pid, v_display, v_acpi_enable, v_session, v_display_ip, v_display_type, v_kvm_enable, v_boot_sequence, v_display_secure_port, v_utc_diff, v_last_vds_run_on, v_client_ip, v_guest_requested_memory, v_hibernation_vol_handle, v_exit_status, v_pause_status, v_exit_message, v_guest_agent_nics_hash, v_last_watchdog_event, v_last_watchdog_action, v_is_run_once, v_vm_fqdn, v_cpu_name); +INSERT INTO vm_dynamic(app_list, guest_cur_user_name, console_cur_user_name, guest_last_login_time, guest_last_logout_time, console_user_id, guest_os, migrating_to_vds, RUN_ON_VDS, status, vm_guid, vm_host, vm_ip, last_start_time, last_stop_time, vm_pid, display, acpi_enable, session, display_ip, display_type, kvm_enable, boot_sequence, display_secure_port, utc_diff, last_vds_run_on, client_ip, guest_requested_memory, hibernation_vol_handle,exit_status,pause_status,exit_message, guest_agent_nics_hash, last_watchdog_event, last_watchdog_action, is_run_once, vm_fqdn, cpu_name) + VALUES(v_app_list, v_guest_cur_user_name, v_console_cur_user_name, v_guest_last_login_time, v_guest_last_logout_time, v_console_user_id, v_guest_os, v_migrating_to_vds, v_run_on_vds, v_status, v_vm_guid, v_vm_host, v_vm_ip, v_last_start_time, v_last_stop_time, v_vm_pid, v_display, v_acpi_enable, v_session, v_display_ip, v_display_type, v_kvm_enable, v_boot_sequence, v_display_secure_port, v_utc_diff, v_last_vds_run_on, v_client_ip, v_guest_requested_memory, v_hibernation_vol_handle, v_exit_status, v_pause_status, v_exit_message, v_guest_agent_nics_hash, v_last_watchdog_event, v_last_watchdog_action, v_is_run_once, v_vm_fqdn, v_cpu_name); END; $procedure$ LANGUAGE plpgsql; @@ -269,6 +270,7 @@ v_vm_ip VARCHAR(255) , v_vm_fqdn VARCHAR(255) , v_last_start_time TIMESTAMP WITH TIME ZONE , + v_last_stop_time TIMESTAMP WITH TIME ZONE , v_vm_pid INTEGER , v_display INTEGER , v_acpi_enable BOOLEAN , @@ -306,6 +308,7 @@ guest_os = v_guest_os,migrating_to_vds = v_migrating_to_vds,RUN_ON_VDS = v_run_on_vds, status = v_status,vm_host = v_vm_host,vm_ip = v_vm_ip,vm_fqdn = v_vm_fqdn, last_start_time = v_last_start_time, + last_stop_time = v_last_stop_time, vm_pid = v_vm_pid,display = v_display,acpi_enable = v_acpi_enable, session = v_session,display_ip = v_display_ip, display_type = v_display_type,kvm_enable = v_kvm_enable,boot_sequence = v_boot_sequence, -- To view, visit http://gerrit.ovirt.org/22429 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0f94a56e0c82246a932fc1800a2c9ef8c5205e13 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Adam Litke <ali...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches