Omer Frenkel has uploaded a new change for review. Change subject: core: WIP update vms on new version ......................................................................
core: WIP update vms on new version still not ready! Change-Id: I5449eee954bd6096b6f2e423a75a8cac3e5bcc3b Signed-off-by: Omer Frenkel <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromVersionCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreStatelessVmCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CopyOnNewVersion.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/errors/VdcBllMessages.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/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M packaging/dbscripts/vms_sp.sql 15 files changed, 350 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/23188/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromVersionCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromVersionCommand.java new file mode 100644 index 0000000..15075bd --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromVersionCommand.java @@ -0,0 +1,52 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.common.action.VmManagementParametersBase; +import org.ovirt.engine.core.compat.Guid; + +//TODO: verify locking +@LockIdNameAttribute(isReleaseAtEndOfExecute = false) +@InternalCommandAttribute +public class AddVmFromVersionCommand<T extends VmManagementParametersBase> extends AddVmCommand<T> { + + public AddVmFromVersionCommand(T parameters) { + super(parameters); + } + + protected AddVmFromVersionCommand(Guid commandId) { + super(commandId); + } + + /** + * return false for name check as vm does exist in the db and its ok + * @param name + * @return false + */ + @Override + protected boolean isVmWithSameNameExists(String name) { + return false; + } + + /** + * update vm data instead of adding a new record + */ + @Override + protected void addVmStatic() { + //TODO: check if db generation needed here + getVmStaticDAO().update(getParameters().getVmStaticData()); + } + + @Override + void addVmDynamic() { + // nothing to do, already exists + } + + @Override + void addVmStatistics() { + // nothing to do, already exists + } + + @Override + protected void addVmPermission() { + // nothing to do, keeping old permissions + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java index 7652a8d..2cf275a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java @@ -31,6 +31,7 @@ import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.action.VmOperationParameterBase; import org.ovirt.engine.core.common.asynctasks.EntityInfo; import org.ovirt.engine.core.common.businessentities.ActionGroup; import org.ovirt.engine.core.common.businessentities.ArchitectureType; @@ -560,6 +561,14 @@ private void endDefaultOperations() { endUnlockOps(); + + // in case of new version of a template, update vms marked to use latest + + + // TODO: what happens if tasks created here? + for (Guid vmId : getVmDAO().GetVmIdsForVersionUpdate()) { + getBackend().runInternalAction(VdcActionType.UpdateVmVersion, new VmOperationParameterBase(vmId)); + } } private void endUnlockOps() { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreStatelessVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreStatelessVmCommand.java index 70b3037..2314f94 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreStatelessVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreStatelessVmCommand.java @@ -30,27 +30,44 @@ @Override protected void executeCommand() { - boolean returnVal = true; - Guid snapshotId = DbFacade.getInstance().getSnapshotDao().getId(getVmId(), SnapshotType.STATELESS); - List<DiskImage> imagesList = null; + VdcReturnValueBase result = + getBackend().runInternalAction(VdcActionType.UpdateVmVersion, + new VmOperationParameterBase(getVmId()), + ExecutionHandler.createDefaultContexForTasks(getExecutionContext(), getLock())); - if (snapshotId != null) { - imagesList = DbFacade.getInstance().getDiskImageDao().getAllSnapshotsForVmSnapshot(snapshotId); - } + // if it fail because of canDoAction, its safe to restore the snapshot + // and the vm will still be usable with previous version + if (!result.getSucceeded() && !result.getCanDoAction()) { + log.warnFormat("Couldn't update VM {0} ({1}) version, continue with restoring stateless snapshot.", + getVm().getName(), + getVmId()); - if (imagesList != null && imagesList.size() > 0) { - /** - * restore all snapshots - */ - RestoreAllSnapshotsParameters tempVar = new RestoreAllSnapshotsParameters(getVm().getId(), snapshotId); - tempVar.setShouldBeLogged(false); - tempVar.setImages(imagesList); - VdcReturnValueBase vdcReturn = - Backend.getInstance().runInternalAction(VdcActionType.RestoreAllSnapshots, - tempVar, - ExecutionHandler.createDefaultContexForTasks(getExecutionContext(), getLock())); - returnVal = vdcReturn.getSucceeded(); + boolean returnVal = true; + Guid snapshotId = DbFacade.getInstance().getSnapshotDao().getId(getVmId(), SnapshotType.STATELESS); + List<DiskImage> imagesList = null; + + if (snapshotId != null) { + imagesList = DbFacade.getInstance().getDiskImageDao().getAllSnapshotsForVmSnapshot(snapshotId); + } + + if (imagesList != null && imagesList.size() > 0) { + /** + * restore all snapshots + */ + RestoreAllSnapshotsParameters tempVar = new RestoreAllSnapshotsParameters(getVm().getId(), snapshotId); + tempVar.setShouldBeLogged(false); + tempVar.setImages(imagesList); + VdcReturnValueBase vdcReturn = + Backend.getInstance().runInternalAction(VdcActionType.RestoreAllSnapshots, + tempVar, + ExecutionHandler.createDefaultContexForTasks(getExecutionContext(), getLock())); + returnVal = vdcReturn.getSucceeded(); + } + setSucceeded(returnVal); } - setSucceeded(returnVal); + } + + private void overrideVmComfig() { + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java new file mode 100644 index 0000000..b8d80b2 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmVersionCommand.java @@ -0,0 +1,149 @@ +package org.ovirt.engine.core.bll; + +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.ovirt.engine.core.bll.job.ExecutionHandler; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VmManagementParametersBase; +import org.ovirt.engine.core.common.action.VmOperationParameterBase; +import org.ovirt.engine.core.common.businessentities.CopyOnNewVersion; +import org.ovirt.engine.core.common.businessentities.VmBase; +import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType; +import org.ovirt.engine.core.common.businessentities.VmPayload; +import org.ovirt.engine.core.common.businessentities.VmTemplate; +import org.ovirt.engine.core.common.businessentities.VmWatchdog; +import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.locks.LockingGroup; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.common.utils.Pair; +import org.ovirt.engine.core.common.utils.VmDeviceType; +import org.ovirt.engine.core.compat.Guid; + +/** + * This class updates VM to the latest template version for stateless vms that has newer template version + */ +@InternalCommandAttribute +@LockIdNameAttribute +public class UpdateVmVersionCommand<T extends VmOperationParameterBase> extends VmCommand<T> { + + /** + * Constructor for command creation when compensation is applied on startup + * + * @param commandId + */ + protected UpdateVmVersionCommand(Guid commandId) { + super(commandId); + } + + public UpdateVmVersionCommand(T parameters) { + super(parameters); + } + + @Override + protected boolean canDoAction() { + if (getVm() == null) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND); + } + + if (getVm().getTemplateVersion() != null) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_SET_FOR_LATEST); + } + + VmTemplate latest = getVmTemplateDAO().getTemplateWithLatestVersionInChain(getVm().getVmtGuid()); + if (latest == null) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_TEMPLATE_DOES_NOT_EXIST); + } + + if (getVm().getVmtGuid().equals(latest.getId())) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_ALREADY_IN_LATEST_VERSION); + } + + setVmTemplateId(latest.getId()); + setVmTemplate(latest); + + return true; + } + + @Override + protected void setActionMessageParameters() { + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__UPDATE_VM_VERSION); + addCanDoActionMessage(VdcBllMessages.VAR__TYPE__VM); + } + + @Override + protected void executeVmCommand() { + // TODO: remove disks, networks and devices + + + + + copyData(getVmTemplate(), getVm().getStaticData()); + + VmManagementParametersBase addVmParams = new VmManagementParametersBase(getVm()); + + addVmParams.setConsoleEnabled(deviceExists(VmDeviceGeneralType.CONSOLE, VmDeviceType.CONSOLE)); + addVmParams.setBalloonEnabled(deviceExists(VmDeviceGeneralType.BALLOON, VmDeviceType.BALLOON)); + addVmParams.setSoundDeviceEnabled(deviceExists(VmDeviceGeneralType.SOUND, VmDeviceType.SOUND)); + addVmParams.setVirtioScsiEnabled(deviceExists(VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSCSI)); + + List<VmWatchdog> watchdogs = getBackend().runInternalQuery(VdcQueryType.GetWatchdog, + new IdQueryParameters(getVmTemplateId())).getReturnValue(); + if (!watchdogs.isEmpty()) { + addVmParams.setWatchdog(watchdogs.get(0)); + } + + // TODO: do we have payload for templates?! + VmPayload payload = getBackend().runInternalQuery(VdcQueryType.GetVmPayload, + new IdQueryParameters(getVmTemplateId())).getReturnValue(); + + if (payload != null) { + addVmParams.setVmPayload(payload); + } + + getBackend().runInternalAction(VdcActionType.AddVmFromVersion, addVmParams, + ExecutionHandler.createDefaultContexForTasks(getExecutionContext(), getLock())); + } + + /** + * Copy fields that annotated with {@link CopyOnNewVersion} from the new template version to the vm + * + * @param source + * - template to copy data from + * @param dest + * - vm to copy data to + */ + private void copyData(VmBase source, VmBase dest) { + for (Field srcFld : VmBase.class.getDeclaredFields()) { + try { + if (srcFld.getAnnotation(CopyOnNewVersion.class) != null) { + srcFld.setAccessible(true); + + Field dstFld = VmBase.class.getDeclaredField(srcFld.getName()); + dstFld.setAccessible(true); + dstFld.set(dest, srcFld.get(source)); + } + } catch (Exception exp) { + log.errorFormat("Failed to copy field {0} of new version to VM {1} ({2}), error: {3}", + srcFld.getName(), + source.getName(), + source.getId(), + exp.getMessage()); + } + } + } + + private boolean deviceExists(VmDeviceGeneralType generalType, VmDeviceType deviceType) { + return !getVmDeviceDao().getVmDeviceByVmIdTypeAndDevice( + getVmTemplateId(), generalType, deviceType.getName()).isEmpty(); + } + + @Override + protected Map<String, Pair<String, String>> getExclusiveLocks() { + return Collections.singletonMap(getVmId().toString(), + LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM, VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED)); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java index 5ef0cad..b859a38 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java @@ -50,6 +50,8 @@ ActivateDeactivateVmNic(42, QuotaDependency.NONE), AddVmFromSnapshot(52, ActionGroup.CREATE_VM, QuotaDependency.BOTH), ImportVmFromConfiguration(43, ActionGroup.IMPORT_EXPORT_VM, QuotaDependency.NONE), + AddVmFromVersion(44, QuotaDependency.BOTH), //TODO: what is quota dependency ? + UpdateVmVersion(45, QuotaDependency.NONE), // VdsCommands AddVds(101, ActionGroup.CREATE_HOST, QuotaDependency.NONE), UpdateVds(102, ActionGroup.EDIT_HOST_CONFIGURATION, false, QuotaDependency.NONE), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CopyOnNewVersion.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CopyOnNewVersion.java new file mode 100644 index 0000000..b0e8645 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CopyOnNewVersion.java @@ -0,0 +1,16 @@ +package org.ovirt.engine.core.common.businessentities; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation is used to mark a field + * that need to be copied to vm, from a new template version + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface CopyOnNewVersion { + +} 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 6737c4c..2d3631d 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 @@ -48,6 +48,7 @@ @EditableOnTemplate private Guid vdsGroupId; + @CopyOnNewVersion @EditableField private int osId; @@ -62,69 +63,87 @@ @EditableField private String comment; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private int memSizeMb; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private int numOfSockets; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private int cpuPerSocket; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate @IntegerContainedInConfigValueList(configValue = ConfigValues.ValidNumOfMonitors, message = "VALIDATION.VM.NUM_OF_MONITORS.EXCEEDED") private int numOfMonitors; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private boolean singleQxlPci; + @CopyOnNewVersion @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_DOMAIN_SIZE) private String domain; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate @Size(max = BusinessEntitiesDefinitions.GENERAL_TIME_ZONE_SIZE) private String timeZone; + @CopyOnNewVersion @EditableField private VmType vmType; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private UsbPolicy usbPolicy; + @CopyOnNewVersion private boolean failBack; + @CopyOnNewVersion @EditableField private BootSequence defaultBootSequence; + @CopyOnNewVersion @EditableOnVmStatusField private int niceLevel; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private int cpuShares; + @CopyOnNewVersion @EditableField private int priority; + @CopyOnNewVersion @EditableField private boolean autoStartup; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private boolean stateless; + @CopyOnNewVersion @EditableField private boolean deleteProtected; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private SsoMethod ssoMethod; @@ -132,15 +151,18 @@ @EditableField private long dbGeneration; + @CopyOnNewVersion @EditableField private boolean smartcardEnabled; + @CopyOnNewVersion @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) private String isoPath; private OriginType origin; + @CopyOnNewVersion @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) @Pattern(regexp = ValidationUtils.NO_TRIMMING_WHITE_SPACES_PATTERN, @@ -148,6 +170,7 @@ UpdateEntity.class }) private String kernelUrl; + @CopyOnNewVersion @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) @Pattern(regexp = ValidationUtils.NO_TRIMMING_WHITE_SPACES_PATTERN, @@ -155,6 +178,7 @@ UpdateEntity.class }) private String kernelParams; + @CopyOnNewVersion @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) @Pattern(regexp = ValidationUtils.NO_TRIMMING_WHITE_SPACES_PATTERN, @@ -162,12 +186,14 @@ UpdateEntity.class }) private String initrdUrl; + @CopyOnNewVersion @EditableField private boolean allowConsoleReconnect; /** * if this field is null then value should be taken from cluster */ + @CopyOnNewVersion @EditableField private Boolean tunnelMigration; @@ -220,11 +246,13 @@ @EditableField private QuotaEnforcementTypeEnum quotaEnforcementType; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate @OvfExportOnlyField(valueToIgnore = "MIGRATABLE", exportOption = ExportOption.EXPORT_NON_IGNORED_VALUES) private MigrationSupport migrationSupport; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate private Guid dedicatedVmForVds; @@ -233,6 +261,7 @@ @EditableOnTemplate private DisplayType defaultDisplayType; + @CopyOnNewVersion @EditableOnVmStatusField @EditableOnTemplate @NullOrStringContainedInConfigValueList(configValue = ConfigValues.VncKeyboardLayoutValidValues, @@ -240,9 +269,11 @@ message = "VALIDATION.VM.INVALID_KEYBOARD_LAYOUT") private String vncKeyboardLayout; + @CopyOnNewVersion @EditableField private int minAllocatedMem; + @CopyOnNewVersion @EditableField private boolean runAndPause; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 69b473f..7fc9ca4 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -100,6 +100,7 @@ VAR__ACTION__EXTEND_IMAGE_SIZE, VAR__ACTION__REMOVE_BRICKS_STOP, VAR__ACTION__REMOVE_BRICKS_COMMIT, + VAR__ACTION__UPDATE_VM_VERSION, // Host statuses replacements VAR__HOST_STATUS__UP, @@ -158,6 +159,8 @@ ACTION_TYPE_FAILED_VM_NOT_FOUND(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VM_NOT_EXIST(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VM_ALREADY_EXIST(ErrorType.CONFLICT), + ACTION_TYPE_FAILED_VM_NOT_SET_FOR_LATEST(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_FAILED_VM_ALREADY_IN_LATEST_VERSION(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VM_GUID_ALREADY_EXIST(ErrorType.CONFLICT), ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL(ErrorType.CONFLICT), ACTION_TYPE_FAILED_VM_STATUS_ILLEGAL(ErrorType.CONFLICT), 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 51446f1..e65f7b6 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 @@ -282,4 +282,15 @@ * @return the list of VMs */ List<VM> getAllFailedAutoStartVms(); + + /** + * Retrieves all ids of vms that are candidate for version update: + * template_version is set to null + * status is down + * vm is stateless or belong to vm pool + * (for vm in pool, check there is no stateless snapshot for it [manual pool]) + * + * @return the list of ids of these vms + */ + List<Guid> GetVmIdsForVersionUpdate(); } 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 598aa46..6628b78 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 @@ -269,6 +269,12 @@ ); } + @Override + public List<Guid> GetVmIdsForVersionUpdate() { + return getCallsHandler().executeReadList("GetVmIdsForVersionUpdate", + createGuidMapper(), getCustomMapSqlParameterSource()); + } + static final class VMRowMapper implements RowMapper<VM> { public static final VMRowMapper instance = new VMRowMapper(); diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index a117496..3734115 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -171,6 +171,8 @@ ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER=Cannot ${action} ${type}. The VM was running as Stateless and didn't clean up successfully. Please try to run the VM which should clean up the VM, and then try again when VM is not running. ACTION_TYPE_FAILED_VM_IN_USE_BY_OTHER_USER=Cannot ${action} ${type}. The VM is in use by other user. ACTION_TYPE_FAILED_VM_NOT_FOUND=Cannot ${action} ${type}. VM is not found. +ACTION_TYPE_FAILED_VM_NOT_SET_FOR_LATEST=Cannot ${action} ${type}. Vm is set to use a specific version, and not automatically update to the latest version. +ACTION_TYPE_FAILED_VM_ALREADY_IN_LATEST_VERSION=Cannot ${action} ${type}. Vm is already at the latest version. ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE=Cannot ${action} ${type}. VM is non migratable. ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE=Cannot ${action} ${type}. VM is non migratable and user did not specify the force-migration flag ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST=Cannot ${action} ${type}. VM is pinned to Host. @@ -328,6 +330,7 @@ VAR__ACTION__SCAN_ALIGNMENT=$action scan alignment VAR__ACTION__FORCE_SELECT=$action force select VAR__ACTION__EXTEND_IMAGE_SIZE=$action extend +VAR__ACTION__UPDATE_VM_VERSION=$action update version for VAR__HOST_STATUS__UP=$hostStatus Up VAR__HOST_STATUS__UP_MAINTENANCE_OR_NON_OPERATIONAL=$hostStatus Up, Maintenance or Non operational VAR__HOST_STATUS__UP_OR_MAINTENANCE=$hostStatus 'Up' or 'Maintenance' diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index 9a9f789..d9954e4 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -440,6 +440,12 @@ @DefaultStringValue("Cannot ${action} ${type}. VM is not found.") String ACTION_TYPE_FAILED_VM_NOT_FOUND(); + @DefaultStringValue("Cannot ${action} ${type}. Vm is set to use a specific version, and not automatically update to the latest version.") + String ACTION_TYPE_FAILED_VM_NOT_SET_FOR_LATEST(); + + @DefaultStringValue("Cannot ${action} ${type}. Vm is already at the latest version.") + String ACTION_TYPE_FAILED_VM_ALREADY_IN_LATEST_VERSION(); + @DefaultStringValue("Cannot ${action} ${type}. VM is non migratable.") String ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE(); @@ -899,6 +905,9 @@ @DefaultStringValue("$action disable") String VAR__ACTION__DISABLE(); + @DefaultStringValue("$action update version for") + String VAR__ACTION__UPDATE_VM_VERSION(); + @DefaultStringValue("$hostStatus Up") String VAR__HOST_STATUS__UP(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 3212bf6..dbe9ce3 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -164,6 +164,8 @@ ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER=Cannot ${action} ${type}. The VM was running as Stateless and didn't clean up successfully. Please try to run the VM which should clean up the VM, and then try again when VM is not running. ACTION_TYPE_FAILED_VM_IN_USE_BY_OTHER_USER=Cannot ${action} ${type}. The VM is in use by other user. ACTION_TYPE_FAILED_VM_NOT_FOUND=Cannot ${action} ${type}. VM is not found. +ACTION_TYPE_FAILED_VM_NOT_SET_FOR_LATEST=Cannot ${action} ${type}. Vm is set to use a specific version, and not automatically update to the latest version. +ACTION_TYPE_FAILED_VM_ALREADY_IN_LATEST_VERSION=Cannot ${action} ${type}. Vm is already at the latest version. ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE=Cannot ${action} ${type}. VM is non migratable. ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE=Cannot ${action} ${type}. VM is non migratable and user did not specify the force-migration flag ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST=Cannot ${action} ${type}. VM is pinned to Host. @@ -308,6 +310,7 @@ VAR__ACTION__ASSIGN=$action assign VAR__ACTION__SCAN_ALIGNMENT=$action scan alignment VAR__ACTION__EXTEND_IMAGE_SIZE=$action extend +VAR__ACTION__UPDATE_VM_VERSION=$action update version for VAR__HOST_STATUS__UP=$hostStatus Up VAR__HOST_STATUS__UP_MAINTENANCE_OR_NON_OPERATIONAL=$hostStatus Up, Maintenance or Non operational VAR__HOST_STATUS__UP_OR_MAINTENANCE=$hostStatus 'Up' or 'Maintenance' diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index c44a7e4..00b30fa 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -168,6 +168,8 @@ ACTION_TYPE_FAILED_VM_HAS_STATELESS_SNAPSHOT_LEFTOVER=Cannot ${action} ${type}. The VM was running as Stateless and didn't clean up successfully. Please try to run the VM which should clean up the VM, and then try again when VM is not running. ACTION_TYPE_FAILED_VM_IN_USE_BY_OTHER_USER=Cannot ${action} ${type}. The VM is in use by other user. ACTION_TYPE_FAILED_VM_NOT_FOUND=Cannot ${action} ${type}. VM is not found. +ACTION_TYPE_FAILED_VM_NOT_SET_FOR_LATEST=Cannot ${action} ${type}. Vm is set to use a specific version, and not automatically update to the latest version. +ACTION_TYPE_FAILED_VM_ALREADY_IN_LATEST_VERSION=Cannot ${action} ${type}. Vm is already at the latest version. ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE=Cannot ${action} ${type}. VM is non migratable. ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE=Cannot ${action} ${type}. VM is non migratable and user did not specify the force-migration flag ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST=Cannot ${action} ${type}. VM is pinned to Host. @@ -331,6 +333,7 @@ VAR__ACTION__SCAN_ALIGNMENT=$action scan alignment VAR__ACTION__FORCE_SELECT=$action force select VAR__ACTION__EXTEND_IMAGE_SIZE=$action extend +VAR__ACTION__UPDATE_VM_VERSION=$action update version for VAR__HOST_STATUS__UP=$hostStatus Up VAR__HOST_STATUS__UP_MAINTENANCE_OR_NON_OPERATIONAL=$hostStatus Up, Maintenance or Non operational VAR__HOST_STATUS__UP_OR_MAINTENANCE=$hostStatus 'Up' or 'Maintenance' diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql index 9dcf75e..19fd8af 100644 --- a/packaging/dbscripts/vms_sp.sql +++ b/packaging/dbscripts/vms_sp.sql @@ -1138,3 +1138,20 @@ END; $procedure$ LANGUAGE plpgsql; + +Create or replace FUNCTION GetVmIdsForVersionUpdate(v_storage_pool_id UUID) RETURNS SETOF UUID STABLE +AS $procedure$ +BEGIN +RETURN QUERY select vs.vm_guid + from vm_static vs + natural join vm_dynamic + where template_version is null and entity_type='VM' and status=0 + and (is_stateless = TRUE or + (exists (select * from vm_pool_map where vm_guid = vs.vm_guid) + and not exists + (SELECT * + FROM snapshots + WHERE vm_id = vs.vm_guid + AND snapshot_type = 'STATELESS'))); +END; $procedure$ +LANGUAGE plpgsql; \ No newline at end of file -- To view, visit http://gerrit.ovirt.org/23188 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5449eee954bd6096b6f2e423a75a8cac3e5bcc3b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Omer Frenkel <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
