ofri masad has uploaded a new change for review. Change subject: core: Quota refactor - ImportVm ImportVmTemplate ......................................................................
core: Quota refactor - ImportVm ImportVmTemplate Changed implementation of ImportVmCommand Changed implementation of ImportVmTemplateCommand Change-Id: Ida97dc89d7f43e7fc0e06311feb72969e126a88b Signed-off-by: Ofri Masad <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java 2 files changed, 27 insertions(+), 110 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/9000/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java index 8d373c9..794fb42 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java @@ -14,13 +14,14 @@ import org.ovirt.engine.core.bll.command.utils.StorageDomainSpaceChecker; import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.network.VmInterfaceManager; -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.snapshots.SnapshotsManager; import org.ovirt.engine.core.bll.utils.VmDeviceUtils; 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.common.VdcObjectType; import org.ovirt.engine.core.common.action.ImportVmParameters; import org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters; @@ -35,7 +36,6 @@ import org.ovirt.engine.core.common.businessentities.DiskImageDynamic; import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.Network; -import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType; @@ -84,7 +84,7 @@ @DisableInPrepareMode @NonTransactiveCommandAttribute(forceCompensation = true) public class ImportVmCommand extends MoveOrCopyTemplateCommand<ImportVmParameters> - implements Quotable { + implements QuotaStorageDependent { private static final long serialVersionUID = -5500615685812075744L; private static VmStatic vmStaticForDefaultValues = new VmStatic(); @@ -561,7 +561,7 @@ p.setStoragePoolId(getParameters().getStoragePoolId()); p.setImportEntity(true); p.setEntityId(disk.getImageId()); - p.setQuotaId(disk.getQuotaId() != null ? disk.getQuotaId() : getQuotaId()); + p.setQuotaId(disk.getQuotaId() != null ? disk.getQuotaId() : getParameters().getQuotaId()); if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(diskGuidList.get(i))) { DiskImageBase diskImageBase = @@ -906,7 +906,6 @@ // No point in trying to end action again, as the imported VM does not exist in the DB. getReturnValue().setEndActionTryAgain(false); } - rollbackQuota(); } protected void removeVmNetwork() { @@ -988,67 +987,26 @@ } @Override - public boolean validateAndSetQuota() { - if (getQuotaManager().validateQuotaForStoragePool(getStoragePool(), - getVdsGroupId(), - getQuotaId(), - getReturnValue().getCanDoActionMessages())) { - return getQuotaManager().validateAndSetStorageQuota(getStoragePool(), - getStorageQuotaListParameters(), - getReturnValue().getCanDoActionMessages()); - } - return false; + protected AuditLogType getAuditLogTypeForInvalidInterfaces() { + return AuditLogType.IMPORTEXPORT_IMPORT_VM_INVALID_INTERFACES; } @Override - public void rollbackQuota() { - getQuotaManager().rollbackQuota(getStoragePool(), - getQuotaManager().getQuotaListFromParameters(getStorageQuotaListParameters())); - } + public List<QuotaStorageConsumptionParameter> getQuotaStorageConsumptionParameters() { + List<QuotaStorageConsumptionParameter> list = new ArrayList<QuotaStorageConsumptionParameter>(); - private List<StorageQuotaValidationParameter> getStorageQuotaListParameters() { - List<StorageQuotaValidationParameter> list = new ArrayList<StorageQuotaValidationParameter>(); for (Disk disk : getParameters().getVm().getDiskMap().values()) { + //TODO: handle import more than once; if(disk instanceof DiskImage){ DiskImage diskImage = (DiskImage)disk; - list.add(new StorageQuotaValidationParameter(diskImage.getQuotaId(), - //TODO: handle import more than once; + list.add(new QuotaStorageConsumptionParameter( + diskImage.getQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.CONSUME, imageToDestinationDomainMap.get(diskImage.getId()), - diskImage.getSizeInGigabytes())); + (double)diskImage.getSizeInGigabytes())); } } return list; - } - - @Override - public Guid getQuotaId() { - return getParameters().getQuotaId(); - } - - @Override - public void addQuotaPermissionSubject(List<PermissionSubject> quotaPermissionList) { - if (getStoragePool() != null && - getQuotaId() != null && - !getStoragePool().getQuotaEnforcementType().equals(QuotaEnforcementTypeEnum.DISABLED)) { - quotaPermissionList.add(new PermissionSubject(getQuotaId(), VdcObjectType.Quota, ActionGroup.CONSUME_QUOTA)); - Map<Guid, Guid> quotaMap = new HashMap<Guid, Guid>(); - quotaMap.put(getQuotaId(), getQuotaId()); - for (Disk disk : getVm().getDiskMap().values()) { - if (disk instanceof DiskImage) { - DiskImage diskImage = (DiskImage) disk; - if (diskImage.getQuotaId() != null && !quotaMap.containsKey(diskImage.getQuotaId())) { - quotaPermissionList.add(new PermissionSubject(diskImage.getQuotaId(), - VdcObjectType.Quota, - ActionGroup.CONSUME_QUOTA)); - quotaMap.put(diskImage.getQuotaId(), diskImage.getQuotaId()); - } - } - } - } - } - - @Override - protected AuditLogType getAuditLogTypeForInvalidInterfaces() { - return AuditLogType.IMPORTEXPORT_IMPORT_VM_INVALID_INTERFACES; } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java index 5b53afd..0dcaf9b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java @@ -10,24 +10,22 @@ import org.ovirt.engine.core.bll.command.utils.StorageDomainSpaceChecker; import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.network.VmInterfaceManager; -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.VmDeviceUtils; 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.common.VdcObjectType; import org.ovirt.engine.core.common.action.ImportVmTemplateParameters; 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.DiskImageDynamic; import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.Network; -import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; import org.ovirt.engine.core.common.businessentities.StorageDomainType; import org.ovirt.engine.core.common.businessentities.StorageType; import org.ovirt.engine.core.common.businessentities.VmDeviceId; @@ -58,7 +56,7 @@ @DisableInPrepareMode @NonTransactiveCommandAttribute(forceCompensation = true) public class ImportVmTemplateCommand extends MoveOrCopyTemplateCommand<ImportVmTemplateParameters> - implements Quotable { + implements QuotaStorageDependent { private List<Guid> diskGuidList = new ArrayList<Guid>(); private List<Guid> imageGuidList = new ArrayList<Guid>(); @@ -428,7 +426,6 @@ removeImages(); DbFacade.getInstance().getVmTemplateDao().remove(getVmTemplateId()); - rollbackQuota(); setSucceeded(true); } @@ -491,57 +488,19 @@ } @Override - public boolean validateAndSetQuota() { - if (getQuotaManager().validateQuotaForStoragePool(getStoragePool(), - getVdsGroupId(), - getParameters().getQuotaId(), - getReturnValue().getCanDoActionMessages())) { - return getQuotaManager().validateAndSetStorageQuota(getStoragePool(), - getStorageQuotaListParameters(), - getReturnValue().getCanDoActionMessages()); - } - return false; - } + public List<QuotaStorageConsumptionParameter> getQuotaStorageConsumptionParameters() { + List<QuotaStorageConsumptionParameter> list = new ArrayList<QuotaStorageConsumptionParameter>(); - @Override - public void rollbackQuota() { - getQuotaManager().rollbackQuota(getStoragePool(), - getQuotaManager().getQuotaListFromParameters(getStorageQuotaListParameters())); - } - - private List<StorageQuotaValidationParameter> getStorageQuotaListParameters() { - List<StorageQuotaValidationParameter> list = new ArrayList<StorageQuotaValidationParameter>(); for (DiskImage disk : getParameters().getVmTemplate().getDiskList()) { - list.add(new StorageQuotaValidationParameter(disk.getQuotaId(), - //TODO: handle import more than once; + //TODO: handle import more than once; + list.add(new QuotaStorageConsumptionParameter( + disk.getQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.CONSUME, imageToDestinationDomainMap.get(disk.getId()), - disk.getSizeInGigabytes())); + (double)disk.getSizeInGigabytes())); } return list; - } - - @Override - public Guid getQuotaId() { - return getParameters().getQuotaId(); - } - - @Override - public void addQuotaPermissionSubject(List<PermissionSubject> quotaPermissionList) { - if (getStoragePool() != null && - getQuotaId() != null && - !getStoragePool().getQuotaEnforcementType().equals(QuotaEnforcementTypeEnum.DISABLED)) { - quotaPermissionList.add(new PermissionSubject(getQuotaId(), VdcObjectType.Quota, ActionGroup.CONSUME_QUOTA)); - Map<Guid, Guid> quotaMap = new HashMap<Guid, Guid>(); - quotaMap.put(getQuotaId(), getQuotaId()); - for (DiskImage disk : getParameters().getVmTemplate().getDiskList()) { - if (disk.getQuotaId() != null && !quotaMap.containsKey(disk.getQuotaId())) { - quotaPermissionList.add(new PermissionSubject(disk.getQuotaId(), - VdcObjectType.Quota, - ActionGroup.CONSUME_QUOTA)); - quotaMap.put(disk.getQuotaId(), disk.getQuotaId()); - } - } - } } @Override -- To view, visit http://gerrit.ovirt.org/9000 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ida97dc89d7f43e7fc0e06311feb72969e126a88b 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
