Hello Kobi Ianko, I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/27492 to review the following change. Change subject: core: Set HotSetNumberOfCpusCommand as Quota consume ...................................................................... core: Set HotSetNumberOfCpusCommand as Quota consume Set the command as consuming Quota as an internal command. This command is called from the update VM command, and changes the number of CPU on the VM, This changes the CPU consumption. Change-Id: I6d1db7c2f7cbc4ae94e540b26e15dbcf7246bde0 Bug-Url: https://bugzilla.redhat.com/1083177 Signed-off-by: Kobi Ianko <k...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetNumberOfCpusCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java 2 files changed, 39 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/27492/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetNumberOfCpusCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetNumberOfCpusCommand.java index 3a4cd46..03782c4 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetNumberOfCpusCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetNumberOfCpusCommand.java @@ -1,5 +1,11 @@ package org.ovirt.engine.core.bll; +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; +import org.ovirt.engine.core.bll.quota.QuotaVdsDependent; +import org.ovirt.engine.core.bll.quota.QuotaVdsGroupConsumptionParameter; import org.ovirt.engine.core.bll.scheduling.SlaValidator; import org.ovirt.engine.core.bll.validator.LocalizedVmStatus; import org.ovirt.engine.core.common.AuditLogType; @@ -21,7 +27,7 @@ * The execute will never throw an exception. it will rather wrap a return value in case of failure. */ @NonTransactiveCommandAttribute -public class HotSetNumberOfCpusCommand<T extends HotSetNumerOfCpusParameters> extends VmManagementCommandBase<T> { +public class HotSetNumberOfCpusCommand<T extends HotSetNumerOfCpusParameters> extends VmManagementCommandBase<T> implements QuotaVdsDependent { public static final String LOGABLE_FIELD_NUMBER_OF_CPUS = "numberOfCpus"; public static final String LOGABLE_FIELD_ERROR_MESSAGE = "ErrorMessage"; @@ -98,4 +104,35 @@ addCanDoActionMessage(String.format("$clusterVersion %1$s", getVm().getVdsGroupCompatibilityVersion() )); addCanDoActionMessage(String.format("$architecture %1$s", getVm().getClusterArch())); } + + @Override + public List<QuotaConsumptionParameter> getQuotaVdsConsumptionParameters() { + List<QuotaConsumptionParameter> list = new ArrayList<>(); + + // Calculate the change in CPU consumption, result above Zero means we add CPUs to + // the VM + // result bellow Zero means we subtracted CPUs from the VM + int cpuToConsume = + getParameters().getVm().getNumOfCpus() - getVm().getNumOfCpus(); + + if (cpuToConsume > 0) { + // Consume CPU quota + list.add(new QuotaVdsGroupConsumptionParameter(getVm().getQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.CONSUME, + getVm().getVdsGroupId(), + getVm().getCpuPerSocket() * cpuToConsume, + 0)); + + } else if (cpuToConsume < 0) { + // Release CPU quota + list.add(new QuotaVdsGroupConsumptionParameter(getVm().getQuotaId(), + null, + QuotaConsumptionParameter.QuotaAction.RELEASE, + getVm().getVdsGroupId(), + getVm().getCpuPerSocket() * Math.abs(cpuToConsume), + 0)); + } + return list; + } } 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 9fee534..97dde5c 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 @@ -41,7 +41,7 @@ DetachDiskFromVm(181, ActionGroup.CONFIGURE_VM_STORAGE, false, QuotaDependency.NONE), HotPlugDiskToVm(182, ActionGroup.CONFIGURE_VM_STORAGE, false, QuotaDependency.NONE), HotUnPlugDiskFromVm(183, ActionGroup.CONFIGURE_VM_STORAGE, false, QuotaDependency.NONE), - HotSetNumberOfCpus(184, ActionGroup.EDIT_VM_PROPERTIES, false, QuotaDependency.NONE), + HotSetNumberOfCpus(184, ActionGroup.EDIT_VM_PROPERTIES, false, QuotaDependency.VDS_GROUP, true), ChangeFloppy(35, QuotaDependency.NONE), ImportVm(36, ActionGroup.IMPORT_EXPORT_VM, QuotaDependency.STORAGE), RemoveVmFromImportExport(37, ActionGroup.DELETE_VM, QuotaDependency.NONE), -- To view, visit http://gerrit.ovirt.org/27492 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6d1db7c2f7cbc4ae94e540b26e15dbcf7246bde0 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> Gerrit-Reviewer: Kobi Ianko <k...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches