Omer Frenkel has uploaded a new change for review. Change subject: core: add NEXT_RUN snapshot ......................................................................
core: add NEXT_RUN snapshot Change-Id: I4d68f1d7a2de9e66854985583761f47d6db553bd Signed-off-by: Omer Frenkel <ofren...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmNextRunConfigurationQuery.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Snapshot.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/queries/VdcQueryType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java M packaging/dbscripts/create_views.sql M packaging/dbscripts/snapshots_sp.sql A packaging/dbscripts/upgrade/03_05_0300_index_for_snapshot_type.sql 9 files changed, 87 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/57/26757/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmNextRunConfigurationQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmNextRunConfigurationQuery.java new file mode 100644 index 0000000..27268d8 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmNextRunConfigurationQuery.java @@ -0,0 +1,37 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.bll.snapshots.SnapshotVmConfigurationHelper; +import org.ovirt.engine.core.common.businessentities.Snapshot; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.dao.SnapshotDao; + +public class GetVmNextRunConfigurationQuery<P extends IdQueryParameters> extends QueriesCommandBase<P> { + + public GetVmNextRunConfigurationQuery(P parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + SnapshotVmConfigurationHelper snapshotVmConfigurationHelper = getSnapshotVmConfigurationHelper(); + Snapshot snapshot = getSnapshotDao().get(getParameters().getId(), Snapshot.SnapshotType.NEXT_RUN, getUserID(), getParameters().isFiltered()); + VM vm = null; + + if (snapshot != null) { + vm = snapshotVmConfigurationHelper.getVmFromConfiguration( + snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId()); + } + + getQueryReturnValue().setReturnValue(vm); + } + + protected SnapshotDao getSnapshotDao() { + return getDbFacade().getSnapshotDao(); + } + + protected SnapshotVmConfigurationHelper getSnapshotVmConfigurationHelper() { + return new SnapshotVmConfigurationHelper(); + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Snapshot.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Snapshot.java index 38a10da..cfc0550 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Snapshot.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Snapshot.java @@ -275,7 +275,8 @@ REGULAR("Regular"), ACTIVE("Active"), STATELESS("Stateless"), - PREVIEW("In Preview"); + PREVIEW("In Preview"), + NEXT_RUN("Next Run"); private String typeName; 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 8f529ac..41c3e22 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 @@ -44,6 +44,8 @@ private ArchitectureType clusterArch; + private boolean nextRunConfigurationExists; + public String getUserDefinedProperties() { return vmStatic.getUserDefinedProperties(); } @@ -1727,4 +1729,12 @@ public void setBootMenuEnabled(boolean enabled) { vmStatic.setBootMenuEnabled(enabled); } + + public void setNextRunConfigurationExists(boolean nextRunConfigurationExists) { + this.nextRunConfigurationExists = nextRunConfigurationExists; + } + + public boolean isNextRunConfigurationExists() { + return nextRunConfigurationExists; + } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index 9a657dc..cc086ca 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -23,6 +23,7 @@ GetTemplatesByVnicProfileId, GetVirtioScsiControllers(VdcQueryAuthType.User), GetVmsInit, + GetVmNextRunConfiguration(VdcQueryAuthType.User), // Vds queries GetVdsByVdsId, diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java index ff5a87e..c1ac2ad 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java @@ -62,6 +62,23 @@ Snapshot get(Guid vmId, SnapshotType type); /** + * Return the {@link Snapshot} <b>first</b> id that matches the given parameters.<br> + * <b>Note:</b> If more than one snapshot answers to the parameters, only the first will be returned (oldest by + * creation date). + * + * @param vmId + * The id of the VM to check for. + * @param type + * The type of snapshot. + * @param userId + * ID of the user that invoked the query + * @param isFiltered + * whether the filtering will be performed + * @return The snapshot, or <code>null</code> if it doesn't exist. + */ + Snapshot get(Guid vmId, SnapshotType type, Guid userId, boolean isFiltered); + + /** * Return the <b>first</b> {@link Snapshot} that matches the given parameters.<br> * <b>Note:</b> If more than one snapshot answers to the parameters, only the first will be returned (oldest by * creation date). @@ -121,7 +138,7 @@ * * @param vmId * The VM id. - * @param userID + * @param userId * the ID of the user requesting the information * @param isFiltered * Whether the results should be filtered according to the user's permissions diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java index 4abefb1..55670a0 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java @@ -204,9 +204,16 @@ @Override public Snapshot get(Guid vmId, SnapshotType type) { + return get(vmId, type, null, false); + } + + @Override + public Snapshot get(Guid vmId, SnapshotType type, Guid userId, boolean isFiltered) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("vm_id", vmId) - .addValue("snapshot_type", EnumUtils.nameOrNull(type)); + .addValue("snapshot_type", EnumUtils.nameOrNull(type)) + .addValue("user_id", userId) + .addValue("is_filtered", isFiltered); return getCallsHandler().executeRead("GetSnapshotByVmIdAndType", createEntityRowMapper(), diff --git a/packaging/dbscripts/create_views.sql b/packaging/dbscripts/create_views.sql index 26a7aab..57b9435 100644 --- a/packaging/dbscripts/create_views.sql +++ b/packaging/dbscripts/create_views.sql @@ -626,7 +626,7 @@ 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.original_template_id as original_template_id, vm_static.original_template_name as original_template_name, vm_dynamic.last_stop_time as last_stop_time, vm_static.migration_downtime as migration_downtime, vm_static.template_version_number as template_version_number, vm_static.serial_number_policy as serial_number_policy, vm_static.custom_serial_number as custom_serial_number, - vm_static.is_boot_menu_enabled as is_boot_menu_enabled + vm_static.is_boot_menu_enabled as is_boot_menu_enabled, (snapshot_id is not null) as next_run_config_exists 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 @@ -637,6 +637,7 @@ quota ON vm_static.quota_id = quota.id LEFT OUTER JOIN vds_static ON vm_dynamic.run_on_vds = vds_static.vds_id LEFT OUTER JOIN vm_pool_map_view ON vm_static.vm_guid = vm_pool_map_view.vm_guid +left outer join snapshots on vm_static.vm_guid = snapshots.vm_id and snapshot_type='NEXT_RUN' WHERE vm_static.entity_type = 'VM'; @@ -669,13 +670,14 @@ vms.migration_downtime as migration_downtime, vms.template_version_number as template_version_number, vms.current_cd as current_cd, vms.reason as reason, vms.serial_number_policy as serial_number_policy, vms.custom_serial_number as custom_serial_number, vms.exit_reason as exit_reason, - vms.is_boot_menu_enabled as is_boot_menu_enabled + vms.is_boot_menu_enabled as is_boot_menu_enabled, (snapshots.snapshot_id is not null) as next_run_config_exists FROM vms LEFT OUTER JOIN tags_vm_map_view ON vms.vm_guid = tags_vm_map_view.vm_id LEFT OUTER JOIN vm_device ON vm_device.vm_id = vms.vm_guid LEFT OUTER JOIN images ON images.image_group_id = vm_device.device_id LEFT OUTER JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid LEFT OUTER JOIN storage_domain_static ON storage_domain_static.id = image_storage_domain_map.storage_domain_id + left outer join snapshots on vms.vm_guid = snapshots.vm_id and snapshot_type='NEXT_RUN' WHERE images.active IS NULL OR images.active = TRUE; CREATE OR REPLACE VIEW server_vms diff --git a/packaging/dbscripts/snapshots_sp.sql b/packaging/dbscripts/snapshots_sp.sql index a270966..43ef49f 100644 --- a/packaging/dbscripts/snapshots_sp.sql +++ b/packaging/dbscripts/snapshots_sp.sql @@ -227,7 +227,9 @@ Create or replace FUNCTION GetSnapshotIdsByVmIdAndType( v_vm_id UUID, - v_snapshot_type VARCHAR(32)) + v_snapshot_type VARCHAR(32), + v_user_id UUID, + v_is_filtered BOOLEAN) RETURNS SETOF idUuidType STABLE AS $procedure$ BEGIN @@ -236,6 +238,9 @@ FROM snapshots WHERE vm_id = v_vm_id AND snapshot_type = v_snapshot_type + AND (NOT v_is_filtered OR EXISTS (SELECT 1 + FROM user_vm_permissions_view + WHERE user_id = v_user_id AND entity_id = v_vm_id)) ORDER BY creation_date ASC; END; $procedure$ LANGUAGE plpgsql; diff --git a/packaging/dbscripts/upgrade/03_05_0300_index_for_snapshot_type.sql b/packaging/dbscripts/upgrade/03_05_0300_index_for_snapshot_type.sql new file mode 100644 index 0000000..bc10f69 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_0300_index_for_snapshot_type.sql @@ -0,0 +1 @@ +CREATE INDEX IDX_snapshots_snapshot_type ON snapshots(snapshot_type); -- To view, visit http://gerrit.ovirt.org/26757 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4d68f1d7a2de9e66854985583761f47d6db553bd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Omer Frenkel <ofren...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches