ofri masad has uploaded a new change for review. Change subject: core: Quota refactor - MoveOrCopyDisk, RemoveDisk ......................................................................
core: Quota refactor - MoveOrCopyDisk, RemoveDisk Changed implementation of MoveOrCopyDiskCommand Changed implementation of RemoveDiskCommand QuotaCRUDCommand no longer implements Quotable. Change-Id: I28dc5d1cf3a29d2f3314429e0081758bf3582f27 Signed-off-by: Ofri Masad <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java 3 files changed, 40 insertions(+), 112 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/9001/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java index a75d06a..dce90e2 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java @@ -10,8 +10,9 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.command.utils.StorageDomainSpaceChecker; import org.ovirt.engine.core.bll.job.ExecutionHandler; -import org.ovirt.engine.core.bll.quota.Quotable; -import org.ovirt.engine.core.bll.quota.StorageQuotaValidationParameter; +import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; +import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; +import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.utils.PermissionSubject; import org.ovirt.engine.core.bll.validator.StorageDomainValidator; import org.ovirt.engine.core.common.AuditLogType; @@ -19,19 +20,7 @@ import org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdcReturnValueBase; -import org.ovirt.engine.core.common.businessentities.ActionGroup; -import org.ovirt.engine.core.common.businessentities.CopyVolumeType; -import org.ovirt.engine.core.common.businessentities.DiskImage; -import org.ovirt.engine.core.common.businessentities.ImageOperation; -import org.ovirt.engine.core.common.businessentities.ImageStatus; -import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; -import org.ovirt.engine.core.common.businessentities.VM; -import org.ovirt.engine.core.common.businessentities.VMStatus; -import org.ovirt.engine.core.common.businessentities.VmDevice; -import org.ovirt.engine.core.common.businessentities.VmDeviceId; -import org.ovirt.engine.core.common.businessentities.VmEntityType; -import org.ovirt.engine.core.common.businessentities.VmTemplate; -import org.ovirt.engine.core.common.businessentities.storage_domains; +import org.ovirt.engine.core.common.businessentities.*; import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.NGuid; @@ -44,7 +33,7 @@ @CustomLogFields({ @CustomLogField("DiskAlias") }) @NonTransactiveCommandAttribute public class MoveOrCopyDiskCommand<T extends MoveOrCopyImageGroupParameters> extends MoveOrCopyImageGroupCommand<T> - implements Quotable { + implements QuotaStorageDependent { private static final long serialVersionUID = -7219975636530710384L; private Map<String, String> sharedLockMap; @@ -338,7 +327,6 @@ /** * The following method will determine if a provided vm/template exists - * @param retValue * @return */ private boolean canFindVmOrTemplate() { @@ -385,69 +373,33 @@ } @Override - public boolean validateAndSetQuota() { - if (ImageOperation.Move.equals(getParameters().getOperation())) { - // If source and destination are in the same quota - do nothing and return true - if (getImage().getQuotaId() != null && getImage().getQuotaId().equals(getQuotaId())) { - return true; - } - if (getQuotaManager() - .validateAndSetStorageQuota(getStoragePool(), - getDestQuotaListParameters(), - getReturnValue().getCanDoActionMessages())) { - return true; - } - getQuotaManager().rollbackQuota(getStoragePool(), - getQuotaManager().getQuotaListFromParameters(getSourceStorageQuotaListParameters())); - return false; + public List<QuotaStorageConsumptionParameter> getQuotaStorageConsumptionParameters() { + List<QuotaStorageConsumptionParameter> list = new ArrayList<QuotaStorageConsumptionParameter>(); + // If source and destination are in the same quota - do nothing and return true + if (getImage().getQuotaId() != null && getImage().getQuotaId().equals(getDestinationQuotaId())) { + return list; } - return getQuotaManager().validateAndSetStorageQuota(getStoragePool(), - getDestQuotaListParameters(), - getReturnValue().getCanDoActionMessages()); - } - @Override - public void rollbackQuota() { - if (ImageOperation.Move.equals(getParameters().getOperation())) { - getQuotaManager().rollbackQuota(getStoragePool(), - getQuotaManager().getQuotaListFromParameters(getSourceStorageQuotaListParameters())); - } - getQuotaManager().rollbackQuota(getStoragePool(), - getQuotaManager().getQuotaListFromParameters(getDestQuotaListParameters())); - } - - private List<StorageQuotaValidationParameter> getSourceStorageQuotaListParameters() { - List<StorageQuotaValidationParameter> list = new ArrayList<StorageQuotaValidationParameter>(); - list.add(new StorageQuotaValidationParameter(getImage().getQuotaId(), - getParameters().getSourceDomainId().getValue(), - getImage().getSizeInGigabytes())); - return list; - } - - private List<StorageQuotaValidationParameter> getDestQuotaListParameters() { - List<StorageQuotaValidationParameter> list = new ArrayList<StorageQuotaValidationParameter>(); - list.add(new StorageQuotaValidationParameter(getQuotaId(), + list.add(new QuotaStorageConsumptionParameter( + getDestinationQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.CONSUME, getParameters().getStorageDomainId(), - getImage().getSizeInGigabytes())); + (double)getImage().getSizeInGigabytes())); + + if (ImageOperation.Move.equals(getParameters().getOperation())) { + list.add(new QuotaStorageConsumptionParameter( + getImage().getQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.RELEASE, + getParameters().getSourceDomainId().getValue(), + (double)getImage().getSizeInGigabytes())); + } return list; } - @Override - public Guid getQuotaId() { + private Guid getDestinationQuotaId() { return getParameters().getQuotaId(); - } - - @Override - public void addQuotaPermissionSubject(List<PermissionSubject> quotaPermissionList) { - if (getStoragePool() != null && - getQuotaId() != null && - !getStoragePool().getQuotaEnforcementType().equals(QuotaEnforcementTypeEnum.DISABLED)) { - if (!getQuotaId().equals(getDiskImage().getQuotaId())) { - quotaPermissionList.add(new PermissionSubject(getQuotaId(), - VdcObjectType.Quota, - ActionGroup.CONSUME_QUOTA)); - } - } } @Override diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java index ba6df46..2490f14 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/QuotaCRUDCommand.java @@ -3,7 +3,6 @@ import java.util.List; import org.ovirt.engine.core.bll.utils.PermissionSubject; -import org.ovirt.engine.core.bll.quota.Quotable; import org.ovirt.engine.core.common.action.QuotaCRUDParameters; import org.ovirt.engine.core.common.businessentities.Quota; import org.ovirt.engine.core.common.businessentities.QuotaStorage; @@ -15,7 +14,7 @@ import org.ovirt.engine.core.dao.QuotaDAO; @CustomLogFields({ @CustomLogField("QuotaName") }) -public abstract class QuotaCRUDCommand extends CommandBase<QuotaCRUDParameters> implements Quotable { +public abstract class QuotaCRUDCommand extends CommandBase<QuotaCRUDParameters> { private Quota quota; @@ -112,17 +111,7 @@ return isValid; } - @Override - public boolean validateAndSetQuota() { - return true; - } - - @Override - public void rollbackQuota() { - } - - @Override - public Guid getQuotaId() { + protected Guid getQuotaId() { return getQuota().getId(); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java index 7a589f7..9aa9f3b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java @@ -9,12 +9,13 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.job.ExecutionHandler; -import org.ovirt.engine.core.bll.quota.StorageQuotaValidationParameter; import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator; import org.ovirt.engine.core.bll.validator.StorageDomainValidator; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.bll.utils.PermissionSubject; -import org.ovirt.engine.core.bll.quota.Quotable; +import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; +import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; +import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.action.RemoveDiskParameters; import org.ovirt.engine.core.common.action.RemoveImageParameters; @@ -50,7 +51,7 @@ @CustomLogFields({ @CustomLogField("DiskAlias") }) @NonTransactiveCommandAttribute public class RemoveDiskCommand<T extends RemoveDiskParameters> extends CommandBase<T> - implements Quotable { + implements QuotaStorageDependent { private static final long serialVersionUID = -4520874214339816607L; private final Disk disk; @@ -308,7 +309,6 @@ @Override protected void endWithFailure() { endCommand(); - rollbackQuota(); } private void endCommand() { @@ -367,34 +367,21 @@ return jobProperties; } - @Override - public boolean validateAndSetQuota() { + public List<QuotaStorageConsumptionParameter> getQuotaStorageConsumptionParameters() { + List<QuotaStorageConsumptionParameter> list = new ArrayList<QuotaStorageConsumptionParameter>(); if (disk != null && DiskStorageType.IMAGE == disk.getDiskStorageType()) { - getQuotaManager().decreaseStorageQuota(getStoragePool(), getStorageQuotaParameters()); + list.add(new QuotaStorageConsumptionParameter( + getQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.RELEASE, + getStorageDomainId().getValue(), + (double)((DiskImage) disk).getSizeInGigabytes())); } - return true; - } - - @Override - public void rollbackQuota() { - if (disk != null - && DiskStorageType.IMAGE == disk.getDiskStorageType()) { - getQuotaManager().rollbackQuota(getStoragePool(), - getQuotaManager().getQuotaListFromParameters(getStorageQuotaParameters())); - } - } - - private List<StorageQuotaValidationParameter> getStorageQuotaParameters() { - List<StorageQuotaValidationParameter> list = new ArrayList<StorageQuotaValidationParameter>(); - list.add(new StorageQuotaValidationParameter(getQuotaId(), - getStorageDomainId().getValue(), - ((DiskImage) disk).getSizeInGigabytes())); return list; } - @Override - public Guid getQuotaId() { + private Guid getQuotaId() { if (disk != null && DiskStorageType.IMAGE == disk.getDiskStorageType()) { return ((DiskImage) disk).getQuotaId(); -- To view, visit http://gerrit.ovirt.org/9001 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I28dc5d1cf3a29d2f3314429e0081758bf3582f27 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
