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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations