Liron Aravot has uploaded a new change for review. Change subject: core:WIP: introducing OvfAutoUpdate ......................................................................
core:WIP: introducing OvfAutoUpdate vm/template configurations (including disks info) are stored on the master storage domain for backup purposes, import/export and also to provide the abillity to run VMs without having a running engine/db. Currently ovf update is done synchronously when performing various operations on vms/templates - update, save, adding/removing a disk, etc. What's more, currently updating the ovf (updateVM vdsm call) is usually done within a transcation. The idea behined OvfAutoUpdater is to perform batch ovf update operations that aggregate all outstanding updates per data center. These updates will be done in specifed time intervals which will reduce XML-RPC calls and will enable the removal of this syncronous vdsm call from all over the code. known issues that will be addressed: 1. Unite the operations of vm template ovf update/ vm update to single vdsm command execution. 2. remove updateVmInSpm/updateVmTemplateInSpm from VmTemplateCommand/VmCommand 3. Remove call to this methods from all calling commands while updating the vm/template update date instead. 4. log prints 5. tests 6. remove duplicate methods from vm dao/vm template dao - currently some methods are implemented for both though they can be implemented for vmstatic only. it was implemented like this at the moment in order to avoid different implementation than how's it currently implemented for other methods. Change-Id: I9b5132300fb1f1fd94f771cab15efe5246dbeca8 Signed-off-by: Liron Aravot <[email protected]> --- M backend/manager/dbscripts/create_views.sql A backend/manager/dbscripts/upgrade/03_01_1490_add_vm_generation_columns.sql M backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql M backend/manager/dbscripts/vm_templates_sp.sql M backend/manager/dbscripts/vms_sp.sql M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.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/VmTemplateDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties 19 files changed, 396 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/9328/1 diff --git a/backend/manager/dbscripts/create_views.sql b/backend/manager/dbscripts/create_views.sql index fb15073..9db04fb 100644 --- a/backend/manager/dbscripts/create_views.sql +++ b/backend/manager/dbscripts/create_views.sql @@ -333,6 +333,8 @@ vm_templates.mem_size_mb as mem_size_mb, vm_templates.os as os, vm_templates.creation_date as creation_date, + vm_templates.db_generation as db_generation, + vm_templates.ovf_generation as ovf_generation, vm_templates.child_count as child_count, vm_templates.num_of_sockets as num_of_sockets, vm_templates.cpu_per_socket as cpu_per_socket, @@ -370,7 +372,7 @@ quota.quota_name as quota_name, vm_templates.migration_support, vm_templates.dedicated_vm_for_vds -FROM vm_static AS vm_templates INNER JOIN +FROM vm_static AS vm_templates INNER JOIN vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id left outer JOIN storage_pool ON storage_pool.id = vds_groups.storage_pool_id @@ -519,7 +521,7 @@ AS SELECT vm_static.vm_name as vm_name, vm_static.mem_size_mb as vm_mem_size_mb, vm_static.nice_level as nice_level, vm_static.vmt_guid as vmt_guid, vm_static.os as vm_os, vm_static.description as vm_description, vm_static.vds_group_id as vds_group_id, - vm_static.domain as vm_domain, vm_static.creation_date as vm_creation_date, vm_static.auto_startup as auto_startup, vm_static.is_stateless as is_stateless, vm_static.is_smartcard_enabled as is_smartcard_enabled, vm_static.dedicated_vm_for_vds as dedicated_vm_for_vds, + vm_static.domain as vm_domain, vm_static.ovf_generation as ovf_generation, vm_static.db_generation as db_generation, vm_static.creation_date as vm_creation_date, vm_static.auto_startup as auto_startup, vm_static.is_stateless as is_stateless, vm_static.is_smartcard_enabled as is_smartcard_enabled, vm_static.dedicated_vm_for_vds as dedicated_vm_for_vds, vm_static.fail_back as fail_back, vm_static.default_boot_sequence as default_boot_sequence, vm_static.vm_type as vm_type, vm_static.hypervisor_type as hypervisor_type, vm_static.operation_mode as operation_mode, vds_groups.name as vds_group_name, vds_groups.selection_algorithm as selection_algorithm, vds_groups.transparent_hugepages as transparent_hugepages, storage_pool.id as storage_pool_id, storage_pool.name as storage_pool_name, diff --git a/backend/manager/dbscripts/upgrade/03_01_1490_add_vm_generation_columns.sql b/backend/manager/dbscripts/upgrade/03_01_1490_add_vm_generation_columns.sql new file mode 100644 index 0000000..2f5a9dd --- /dev/null +++ b/backend/manager/dbscripts/upgrade/03_01_1490_add_vm_generation_columns.sql @@ -0,0 +1,4 @@ +select fn_db_add_column('vm_static', 'ovf_generation', 'BIGINT'); +select fn_db_add_column('vm_static', 'db_generation', 'BIGINT default 1'); +UPDATE vm_static set ovf_generation = 1; +ALTER TABLE vm_static ALTER COLUMN ovf_generation set default 0; diff --git a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql index 2f651d5..e514aeb 100644 --- a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql +++ b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql @@ -550,6 +550,7 @@ --Handling Keyboard Layout configuration for VNC select fn_db_add_config_value('VncKeyboardLayout','en-us','general'); select fn_db_add_config_value('WaitForVdsInitInSec','60','general'); +select fn_db_add_config_value('OvfUpdateIntervalInMinutes','1','general'); --The default network connectivity check timeout select fn_db_add_config_value('NetworkConnectivityCheckTimeoutInSeconds','120','general'); -- AutoRecoveryConfiguration diff --git a/backend/manager/dbscripts/vm_templates_sp.sql b/backend/manager/dbscripts/vm_templates_sp.sql index 2a136f7..d50b49b 100644 --- a/backend/manager/dbscripts/vm_templates_sp.sql +++ b/backend/manager/dbscripts/vm_templates_sp.sql @@ -132,6 +132,40 @@ LANGUAGE plpgsql; +Create or replace FUNCTION UpdateVmTemplateOvfGeneration(v_vmt_guid UUID, + v_ovf_generation BIGINT) +RETURNS VOID + AS $procedure$ +BEGIN + UPDATE vm_static + SET ovf_generation = v_ovf_generation + WHERE vm_guid = v_vmt_guid + AND entity_type = 'TEMPLATE'; +END; $procedure$ +LANGUAGE plpgsql; + + + + + + + +Create or replace FUNCTION IncrementVmTemplateDbGeneration(v_vmt_guid UUID, + v_ovf_generation BIGINT) +RETURNS VOID + AS $procedure$ +BEGIN + UPDATE vm_static + SET db_generation = db_generation+1; + WHERE vm_guid = v_vmt_guid + AND entity_type = 'TEMPLATE'; +END; $procedure$ +LANGUAGE plpgsql; + + + + + @@ -249,6 +283,18 @@ +Create or replace FUNCTION GetAllVmTemplatesForOvfUpdate(v_storage_pool_id UUID) RETURNS SETOF vm_templates_view + AS $procedure$ +BEGIN +RETURN QUERY SELECT * + FROM vm_templates + WHERE db_generation > ovf_generation AND vds_group_id = v_storage_pool_id ; +END; $procedure$ +LANGUAGE plpgsql; + + + + Create or replace FUNCTION getAllVmTemplatesRelatedToQuotaId(v_quota_id UUID) RETURNS SETOF vm_templates_view AS $procedure$ BEGIN diff --git a/backend/manager/dbscripts/vms_sp.sql b/backend/manager/dbscripts/vms_sp.sql index db000b6..d32bd52 100644 --- a/backend/manager/dbscripts/vms_sp.sql +++ b/backend/manager/dbscripts/vms_sp.sql @@ -137,7 +137,7 @@ Create or replace FUNCTION UpdateVmDynamic(v_app_list VARCHAR(4000) , v_guest_cur_user_id UUID , - v_guest_cur_user_name VARCHAR(255) , + v_guest_cur_user_name AR(255) , v_guest_last_login_time TIMESTAMP WITH TIME ZONE , v_guest_last_logout_time TIMESTAMP WITH TIME ZONE , v_console_user_id UUID, @@ -317,6 +317,56 @@ END; $procedure$ LANGUAGE plpgsql; + + + + + +Create or replace FUNCTION UpdateVmOvfGeneration(v_vm_guid UUID, + v_ovf_generation BIGINT) +RETURNS VOID + AS $procedure$ +BEGIN + UPDATE vm_static + SET ovf_generation = v_ovf_generation + WHERE vm_guid = v_vm_guid + AND entity_type = 'VM'; +END; $procedure$ +LANGUAGE plpgsql; + + + + + + +Create or replace FUNCTION IncrementVmDbGeneration(v_vm_guid UUID, + v_ovf_generation BIGINT) +RETURNS VOID + AS $procedure$ +BEGIN + UPDATE vm_static + SET db_generation = db_generation + 1 + WHERE vm_guid = v_vm_guid + AND entity_type = 'VM'; +END; $procedure$ +LANGUAGE plpgsql; + + + + + + + +OvfGeneration(v_vmt_guid UUID, + v_ovf_generation BIGINT) +RETURNS VOID + AS $procedure$ +BEGIN + UPDATE vm_static + SET ovf_generation = v_ovf_generation + WHERE vm_guid = v_vmt_guid; +END; $procedure$ +LANGUAGE plpgsql; @@ -544,6 +594,21 @@ +Create or replace FUNCTION GetAllVmsForOvfUpdate(v_storage_pool_id UUID) RETURNS SETOF vms + AS $procedure$ +BEGIN +RETURN QUERY SELECT vms.* + FROM vms + WHERE db_generation > ovf_generation AND + vds_group_id = v_storage_pool_id; +END; $procedure$ +LANGUAGE plpgsql; + + + + + + Create or replace FUNCTION GetVmByVmGuid(v_vm_guid UUID, v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vms AS $procedure$ BEGIN diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java index 7152106..d46834c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java @@ -36,6 +36,8 @@ ResourceManager.getInstance().init(); AsyncTaskManager.getInstance().InitAsyncTaskManager(); log.infoFormat("AsyncTaskManager: {0}", new Date()); + OvfDataUpdater.getInstance().InitOvfDataUpdater(); + log.infoFormat("OvfDataUpdater: {0}", new Date()); if (Config.<Boolean> GetValue(ConfigValues.EnableVdsLoadBalancing)) { VdsLoadBalancer.EnableLoadBalancer(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java new file mode 100644 index 0000000..893e265 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java @@ -0,0 +1,147 @@ +package org.ovirt.engine.core.bll; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.ovirt.engine.core.common.AuditLogType; +import org.ovirt.engine.core.common.businessentities.DiskImage; +import org.ovirt.engine.core.common.businessentities.ImageStatus; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.businessentities.VmTemplate; +import org.ovirt.engine.core.common.businessentities.VmTemplateStatus; +import org.ovirt.engine.core.common.businessentities.storage_pool; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; +import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; +import org.ovirt.engine.core.utils.log.Log; +import org.ovirt.engine.core.utils.log.LogFactory; +import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation; +import org.ovirt.engine.core.utils.timer.SchedulerUtil; +import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl; + +public final class OvfDataUpdater { + private static final Log log = LogFactory.getLog(OvfDataUpdater.class); + private static final OvfDataUpdater INSTANCE = new OvfDataUpdater(); + + private OvfDataUpdater(){ + SchedulerUtil scheduler = SchedulerUtilQuartzImpl.getInstance(); + scheduler.scheduleAFixedDelayJob(this, "ovfUpdate_timer", new Class[] {}, + new Object[] {}, Config.<Integer> GetValue(ConfigValues.OvfUpdateIntervalInMinutes), + Config.<Integer> GetValue(ConfigValues.OvfUpdateIntervalInMinutes), TimeUnit.SECONDS); + } + + public static OvfDataUpdater getInstance() { + return INSTANCE; + } + + public void InitOvfDataUpdater() { + log.info("OvfDataUpdater: Initialization of OvfDataUpdater completed successfully."); + } + + @OnTimerMethodAnnotation("ovfUpdate_timer") + public void ovfUpdate_timer() { + log.info("OvfDataUpdater: Attempting to update VMs/Templates Ovf."); + List<storage_pool> storagePools = DbFacade.getInstance().getStoragePoolDao().getAll(); + for (storage_pool pool : storagePools) { + try { + if (StoragePoolStatus.Up == pool.getstatus()) { + log.infoFormat("OvfDataUpdater: Attempting to update VMs/Templates Ovf in Data Center {0}", + pool.getname()); + List<VM> vmsForUpdate = + getVmsForUpdate(DbFacade.getInstance() + .getVmDao() + .getAllVmsForOvfUpdateForStoragePool(pool.getId())); + VmCommand.updateVmInSpm(pool.getId(), vmsForUpdate); + if (!vmsForUpdate.isEmpty()) { + for (VM vm : vmsForUpdate) { + DbFacade.getInstance() + .getVmDao() + .updateVmOvfGeneration(vm.getId(), vm.getStaticData().getDb_generation()); + } + } + List<VmTemplate> templatesForUpdate = getTemplatesForUpdate(DbFacade.getInstance() + .getVmTemplateDao() + .getAllVmTemplatesForOvfUpdateForStoragePool(pool.getId())); + if (!templatesForUpdate.isEmpty()) { + VmTemplateCommand.UpdateTemplateInSpm(pool.getId(), templatesForUpdate); + for (VmTemplate template : templatesForUpdate) { + DbFacade.getInstance() + .getVmDao() + .updateVmOvfGeneration(template.getId(), template.getDb_generation()); + } + } + } + } catch (Exception ex) { + addAuditLogError(pool.getname()); + log.errorFormat("Exception while trying to update VMs/Templates ovf in Data Center {0}, the exception is {1}", + pool.getname(), + ex.getMessage()); + } + } + } + + /** + * returns a list of vms that are valid for update from the given vm list. + * valid vm is a vm which is not locked and none of it's disks is locked. + * @param vms + * @return + */ + private List<VM> getVmsForUpdate(List<VM> vms) { + List<VM> toReturn = new ArrayList<VM>(); + for (VM vm : vms) { + if (VMStatus.ImageLocked != vm.getstatus()) { + VmHandler.updateDisksFromDb(vm); + boolean verifyDisksNotLocked = verifyDisksNotLocked(vm.getDiskList()); + if (verifyDisksNotLocked) { + toReturn.add(vm); + } + } + } + return toReturn; + } + + /** + * returns a list of templates that are valid for update from the given templates list. + * valid template is a template which is not locked and none of it's disks is locked. + * @param templates + * @return + */ + private List<VmTemplate> getTemplatesForUpdate(List<VmTemplate> templates) { + List<VmTemplate> toReturn = new ArrayList<VmTemplate>(); + for (VmTemplate template : templates) { + if (VmTemplateStatus.Locked != template.getstatus()) { + VmTemplateHandler.UpdateDisksFromDb(template); + boolean verifyDisksNotLocked = verifyDisksNotLocked(template.getDiskList()); + if (verifyDisksNotLocked) { + toReturn.add(template); + } + } + } + return toReturn; + } + + /** + * returns true if none of the given disks is in status 'LOCKED', otherwise false. + * @param disks + * @return + */ + private boolean verifyDisksNotLocked (List<DiskImage> disks) { + for (DiskImage disk : disks) { + if (disk.getimageStatus() == ImageStatus.LOCKED) { + return false; + } + } + return true; + } + + private void addAuditLogError(String storagePoolName) { + AuditLogableBase logable = new AuditLogableBase(); + logable.AddCustomValue("StoragePoolName", storagePoolName); + AuditLogDirector.log(logable, AuditLogType.UPDATE_OVF_FOR_STORAGE_POOL_FAILED); + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java index 59e9b02..36d4f27 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java @@ -1,7 +1,6 @@ package org.ovirt.engine.core.bll; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -256,7 +255,7 @@ if (getVm().getstatus() == VMStatus.ImageLocked) { VmHandler.unlockVm(getVm(), getCompensationContext()); } - updateVmInSpm(getVm().getstorage_pool_id(), Arrays.asList(getVm())); + throw new RuntimeException("asd"); } else { setCommandShouldBeLogged(false); log.warn("VmCommand::EndVmCommand: Vm is null - not performing EndAction on Vm"); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java index 2d7a1c1..fb187ad 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java @@ -608,6 +608,7 @@ USER_ATTACH_STORAGE_DOMAINS_TO_POOL(1002), USER_ATTACH_STORAGE_DOMAINS_TO_POOL_FAILED(1003), STORAGE_DOMAIN_TASKS_ERROR(1004), + UPDATE_OVF_FOR_STORAGE_POOL_FAILED(1005), RELOAD_CONFIGURATIONS_SUCCESS(1010), RELOAD_CONFIGURATIONS_FAILURE(1011), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java index 6c3102b..e7ff4aa 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java @@ -117,6 +117,12 @@ @Column(name = "is_stateless") private boolean stateless; + @Column(name = "db_generation") + private long db_generation; + + @Column(name = "ovf_generation") + private long ovf_generation; + @Column(name = "is_smartcard_enabled") private boolean smartcardEnabled; @@ -234,6 +240,22 @@ setQuotaId(quotaId); } + public long getDb_generation() { + return db_generation; + } + + public void setDb_generation(long db_generation) { + this.db_generation = db_generation; + } + + public long getOvf_generation() { + return ovf_generation; + } + + public void setOvf_generation(long ovf_generation) { + this.ovf_generation = ovf_generation; + } + public List<VmNetworkInterface> getInterfaces() { return interfaces; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java index 932ab12..b81c542 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java @@ -821,6 +821,10 @@ @DefaultValueAttribute("60") WaitForVdsInitInSec(230), + @TypeConverterAttribute(Integer.class) + @DefaultValueAttribute("1") + OvfUpdateIntervalInMinutes(231), + // JTODO - temporarily using values from 256 for Java specific options @TypeConverterAttribute(String.class) @DefaultValueAttribute("keys/engine.p12") diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java index a8aa28e..ec9af0c 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java @@ -63,6 +63,7 @@ VdsFenceOptionTypes, ServerCPUList, SupportedClusterLevels(ConfigAuthType.User), + OvfUpdateIntervalInMinutes, ProductRPMVersion(ConfigAuthType.User), RhevhLocalFSPath, CustomPublicConfig_AppsWebSite(ConfigAuthType.User), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java index 15b4637..92b5cb3 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java @@ -37,6 +37,8 @@ entity.setpriority(rs.getInt("priority")); entity.setauto_startup(rs.getBoolean("auto_startup")); entity.setis_stateless(rs.getBoolean("is_stateless")); + entity.setOvf_generation(rs.getLong("ovf_generation")); + entity.setDb_generation(rs.getLong("db_generation")); entity.setiso_path(rs.getString("iso_path")); entity.setorigin(OriginType.forValue(rs.getInt("origin"))); entity.setkernel_url(rs.getString("kernel_url")); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java index 7a8c220..c00fbf9 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java @@ -369,6 +369,7 @@ mSeverities.put(AuditLogType.USER_ACTIVATED_STORAGE_DOMAIN_ASYNC, AuditLogSeverity.NORMAL); mSeverities.put(AuditLogType.USER_ACTIVATE_STORAGE_DOMAIN_FAILED_ASYNC, AuditLogSeverity.WARNING); mSeverities.put(AuditLogType.STORAGE_DOMAIN_TASKS_ERROR, AuditLogSeverity.WARNING); + mSeverities.put(AuditLogType.UPDATE_OVF_FOR_STORAGE_POOL_FAILED, AuditLogSeverity.WARNING); } private static void initQuotaSeverities() { diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java index 924de84..d009dec 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java @@ -160,6 +160,14 @@ public List<VM> getAllVmsRelatedToQuotaId(Guid quotaId); /** + * Get all vms which were updated in db since last ovf update + * + * @param quotaId + * @return + */ + public List<VM> getAllVmsForOvfUpdateForStoragePool(Guid storagePoolId); + + /** * Retrieves the list of all VMS with optional permission filtering. * * @param userID @@ -179,6 +187,23 @@ List<VM> getAll(); /** + * Updates the vm ovf update date to the given value + * + * @param id - vm id + * @param date - date to update the ovf update date to + * @return + */ + public void updateVmOvfGeneration(Guid id, long generation); + + /** + * increment the vm db generation by 1 + * + * @param id - vm id + * @return + */ + public void incrementVmDbGeneration(Guid id); + + /** * Saves the supplied VM. * * @param vm 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 116b7db..24c9243 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 @@ -9,9 +9,7 @@ import org.ovirt.engine.core.common.businessentities.BootSequence; import org.ovirt.engine.core.common.businessentities.DisplayType; -import org.ovirt.engine.core.common.businessentities.HypervisorType; import org.ovirt.engine.core.common.businessentities.MigrationSupport; -import org.ovirt.engine.core.common.businessentities.OperationMode; import org.ovirt.engine.core.common.businessentities.OriginType; import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; import org.ovirt.engine.core.common.businessentities.SessionState; @@ -161,6 +159,13 @@ VMRowMapper.instance, getCustomMapSqlParameterSource() .addValue("quota_id", quotaId)); + } + + @Override + public List<VM> getAllVmsForOvfUpdateForStoragePool(Guid storagePoolId) { + return getCallsHandler().executeReadList("GetAllVmsForOvfUpdate", + VMRowMapper.instance, + getCustomMapSqlParameterSource().addValue("storage_pool_id", storagePoolId)); } @Override @@ -324,8 +329,8 @@ entity.setvm_type(VmType.forValue(rs.getInt("vm_type"))); entity.setstorage_pool_id(Guid.createGuidFromString(rs.getString("storage_pool_id"))); entity.setstorage_pool_name(rs.getString("storage_pool_name")); - entity.sethypervisor_type(HypervisorType.forValue(rs.getInt("hypervisor_type"))); - entity.setoperation_mode(OperationMode.forValue(rs.getInt("operation_mode"))); + //entity.sethypervisor_type(HypervisorType.forValue(rs.getInt("hypervisor_type"))); + //entity.setoperation_mode(OperationMode.forValue(rs.getInt("operation_mode"))); entity.setselection_algorithm(VdsSelectionAlgorithm.forValue(rs.getInt("selection_algorithm"))); entity.setTransparentHugePages(rs.getBoolean("transparent_hugepages")); entity.setnice_level(rs.getInt("nice_level")); @@ -356,6 +361,19 @@ } } + @Override + public void updateVmOvfGeneration(Guid id, long generation) { + getCallsHandler().executeModification("UpdateVmOvfGeneration", getCustomMapSqlParameterSource() + .addValue("vm_guid", id) + .addValue("ovf_generation", generation)); + } + + @Override + public void incrementVmDbGeneration(Guid id) { + getCallsHandler().executeModification("IncrementVmDbGeneration", getCustomMapSqlParameterSource() + .addValue("vm_guid", id)); + } + private static class VMWithPlugInfo { public VM getVM() { diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java index 010c7a8..b99c27e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java @@ -78,6 +78,14 @@ List<VmTemplate> getAllTemplatesRelatedToQuotaId(Guid quotaId); /** + * Get all vm templates which were updated in db since last ovf update + * + * @param quotaId + * @return + */ + public List<VmTemplate> getAllVmTemplatesForOvfUpdateForStoragePool(Guid storagePoolId); + + /** * Retrieves templates with permissions to perform the given action. * * @param userId @@ -103,4 +111,21 @@ * @return the list of VmTemplates */ List<VmTemplate> getAllForNetwork(Guid networkId); + + /** + * Updates the vm template ovf update date to the given value + * + * @param id - vm id + * @param generation - generation the ovf generation to + * @return + */ + public void updateVmTemplateOvfGeneration(Guid id, long generation); + + /** + * increment the vm template generation by 1 + * + * @param id - vm template id + * @return + */ + public void incrementVmTemplateDbGeneration(Guid id); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java index ccf6c8e..46b4113 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java @@ -51,6 +51,13 @@ } @Override + public List<VmTemplate> getAllVmTemplatesForOvfUpdateForStoragePool(Guid storagePoolId) { + return getCallsHandler().executeReadList("GetAllVmsForOvfUpdate", + VMTemplateRowMapper.instance, + getCustomMapSqlParameterSource().addValue("storage_pool_id", storagePoolId)); + } + + @Override public List<VmTemplate> getAllForStorageDomain(Guid storageDomain) { return getAllForStorageDomain(storageDomain, null, false); } @@ -82,8 +89,7 @@ public List<VmTemplate> getAllTemplatesRelatedToQuotaId(Guid quotaId) { return getCallsHandler().executeReadList("GetAllVmTemplatesRelatedToQuotaId", VMTemplateRowMapper.instance, - getCustomMapSqlParameterSource() - .addValue("quota_id", quotaId)); + getCustomMapSqlParameterSource()); } @Override @@ -185,6 +191,19 @@ .addValue("network_id", id)); } + @Override + public void updateVmTemplateOvfGeneration(Guid id, long generation) { + getCallsHandler().executeModification("UpdateVmTemplateOvfGeneration", getCustomMapSqlParameterSource() + .addValue("vmt_guid", id) + .addValue("ovf_generation", generation)); + } + + @Override + public void incrementVmTemplateDbGeneration(Guid id) { + getCallsHandler().executeModification("IncrementVmTemplateDbGeneration", getCustomMapSqlParameterSource() + .addValue("vmt_guid", id)); + } + private final static class VMTemplateRowMapper extends AbstractVmRowMapper<VmTemplate> { public static final VMTemplateRowMapper instance = new VMTemplateRowMapper(); diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index 57584ad..9d3f4f1 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -528,6 +528,7 @@ USER_ACCOUNT_DISABLED_OR_LOCKED=User ${UserName} cannot login, as it got disabled or locked. Please contact the system administrator. USER_ACCOUNT_PASSWORD_EXPIRED=User ${UserName} cannot login, as the user account password has expired. Please contact the system administrator. STORAGE_DOMAIN_TASKS_ERROR=Storage Domain ${StorageDomainName} is down while there are tasks running on it. These tasks may fail. +UPDATE_OVF_FOR_STORAGE_POOL_FAILED=Failed to update VMs/Templates OVF data in Data Center ${StoragePoolName}. IMPORTEXPORT_IMPORT_VM_INVALID_INTERFACES=While importing VM ${VmName}, the Network/s ${Networks} were found to be Non-VM Networks or do not exist in Cluster. Network Name was not set in the Interface/s ${Interfaces}. IMPORTEXPORT_IMPORT_TEMPLATE_INVALID_INTERFACES=While importing Template ${VmTemplateName}, the Network/s ${Networks} were found to be Non-VM Networks or do not exist in Cluster. Network Name was not set in the Interface/s ${Interfaces}. VDS_SET_NON_OPERATIONAL_VM_NETWORK_IS_BRIDGELESS=Host ${VdsName} does not comply with the cluster ${VdsGroupName} networks, the following VM networks are bridgeless: '${Networks}' -- To view, visit http://gerrit.ovirt.org/9328 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b5132300fb1f1fd94f771cab15efe5246dbeca8 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liron Aravot <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
