Kobi Ianko has uploaded a new change for review. Change subject: core: Apply Quota to the Cpu Hotplug Command ......................................................................
core: Apply Quota to the Cpu Hotplug Command Using the @QuotaVdsDependentForInternalCommand annotation to apply a Quota to an internal command. Implemented Quota consumption to the HotSetNumberOfCpusCommand command. Change-Id: If4c0fc8a97dc74ec849432c3bee5bcd676f94f2e Bug-Url: https://bugzilla.redhat.com/1083177 Signed-off-by: Kobi Ianko <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetNumberOfCpusCommand.java 1 file changed, 38 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/26735/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..b456250 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,12 @@ 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.QuotaVdsDependentForInternalCommand; +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 +28,8 @@ * 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> { +@QuotaVdsDependentForInternalCommand +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 +106,33 @@ 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; + } } -- To view, visit http://gerrit.ovirt.org/26735 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If4c0fc8a97dc74ec849432c3bee5bcd676f94f2e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Kobi Ianko <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
