Search in sources :

Example 6 with QuotaConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter in project ovirt-engine by oVirt.

the class TransferDiskImageCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    if (getParameters().getAddDiskParameters() != null) {
        AddDiskParameters parameters = getAddDiskParameters();
        list.add(new QuotaStorageConsumptionParameter(((DiskImage) parameters.getDiskInfo()).getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.CONSUME, getStorageDomainId(), (double) parameters.getDiskInfo().getSize() / SizeConverter.BYTES_IN_GB));
    }
    return list;
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) AddDiskParameters(org.ovirt.engine.core.common.action.AddDiskParameters)

Example 7 with QuotaConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter in project ovirt-engine by oVirt.

the class CommandBase method internalValidateAndSetQuota.

private boolean internalValidateAndSetQuota() {
    // Quota accounting is done only in the most external Command.
    if (!isQuotaDependant()) {
        return true;
    }
    QuotaConsumptionParametersWrapper quotaConsumptionParametersWrapper = new QuotaConsumptionParametersWrapper(this, getReturnValue().getValidationMessages());
    quotaConsumptionParametersWrapper.setParameters(getQuotaConsumptionParameters());
    List<QuotaConsumptionParameter> quotaParams = quotaConsumptionParametersWrapper.getParameters();
    if (quotaParams == null) {
        throw new InvalidQuotaParametersException("Command: " + this.getClass().getName() + ". No Quota parameters available.");
    }
    // scenarios like this must set its QuotaConsumptionParameter to an empty list.
    if (quotaParams.isEmpty()) {
        return true;
    }
    if (getStoragePool() == null) {
        throw new InvalidQuotaParametersException("Command: " + this.getClass().getName() + ". Storage pool is not available for quota calculation. ");
    }
    boolean result = getQuotaManager().consume(quotaConsumptionParametersWrapper);
    setQuotaChanged(result);
    return result;
}
Also used : InvalidQuotaParametersException(org.ovirt.engine.core.bll.quota.InvalidQuotaParametersException) QuotaConsumptionParametersWrapper(org.ovirt.engine.core.bll.quota.QuotaConsumptionParametersWrapper) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter)

Example 8 with QuotaConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter in project ovirt-engine by oVirt.

the class HotSetAmountOfMemoryCommand method getQuotaVdsConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaVdsConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    // Calculate the change in memory consumption,
    // result above Zero means we add memory to the VM (consume)
    // result bellow Zero means we subtracted memory from the VM (release)
    QuotaConsumptionParameter.QuotaAction quotaAction = (getParameters().getMemoryDeviceSizeMb() > 0) ? QuotaConsumptionParameter.QuotaAction.CONSUME : QuotaConsumptionParameter.QuotaAction.RELEASE;
    list.add(new QuotaClusterConsumptionParameter(getVm().getQuotaId(), null, quotaAction, getVm().getClusterId(), 0, Math.abs(getParameters().getMemoryDeviceSizeMb())));
    return list;
}
Also used : QuotaClusterConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaClusterConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter)

Example 9 with QuotaConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter in project ovirt-engine by oVirt.

the class HotSetNumberOfCpusCommand method getQuotaVdsConsumptionParameters.

@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 QuotaClusterConsumptionParameter(getVm().getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.CONSUME, getVm().getClusterId(), getVm().getCpuPerSocket() * getVm().getThreadsPerCpu() * cpuToConsume, 0));
    } else if (cpuToConsume < 0) {
        // Release CPU quota
        list.add(new QuotaClusterConsumptionParameter(getVm().getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.RELEASE, getVm().getClusterId(), getVm().getCpuPerSocket() * getVm().getThreadsPerCpu() * Math.abs(cpuToConsume), 0));
    }
    return list;
}
Also used : QuotaClusterConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaClusterConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter)

Example 10 with QuotaConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter in project ovirt-engine by oVirt.

the class MoveOrCopyDiskCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    list.add(new QuotaStorageConsumptionParameter(getDestinationQuotaId(), null, QuotaConsumptionParameter.QuotaAction.CONSUME, getParameters().getStorageDomainId(), (double) getImage().getSizeInGigabytes()));
    if (isMoveOperation()) {
        if (getImage().getQuotaId() != null && !Guid.Empty.equals(getImage().getQuotaId())) {
            list.add(new QuotaStorageConsumptionParameter(getImage().getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.RELEASE, getParameters().getSourceDomainId(), (double) getImage().getSizeInGigabytes()));
        }
    }
    return list;
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter)

Aggregations

QuotaConsumptionParameter (org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter)18 ArrayList (java.util.ArrayList)17 QuotaStorageConsumptionParameter (org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 QuotaClusterConsumptionParameter (org.ovirt.engine.core.bll.quota.QuotaClusterConsumptionParameter)5 QuotaSanityParameter (org.ovirt.engine.core.bll.quota.QuotaSanityParameter)4 Guid (org.ovirt.engine.core.compat.Guid)2 InvalidQuotaParametersException (org.ovirt.engine.core.bll.quota.InvalidQuotaParametersException)1 QuotaConsumptionParametersWrapper (org.ovirt.engine.core.bll.quota.QuotaConsumptionParametersWrapper)1 AddDiskParameters (org.ovirt.engine.core.common.action.AddDiskParameters)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)1