use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaListModel method createQuota.
protected void createQuota(boolean populateDataCenter) {
final QuotaModel qModel = new QuotaModel();
qModel.setTitle(ConstantsManager.getInstance().getConstants().newQuotaTitle());
qModel.setHelpTag(HelpTag.new_quota);
// $NON-NLS-1$
qModel.setHashName("new_quota");
Quota newQuota = new Quota();
qModel.setEntity(newQuota);
setWindow(qModel);
qModel.startProgress();
if (populateDataCenter) {
AsyncDataProvider.getInstance().getDataCenterList(new AsyncQuery<>(dataCenterList -> {
if (dataCenterList == null || dataCenterList.size() == 0) {
return;
}
QuotaModel quotaModel = (QuotaModel) getWindow();
quotaModel.getDataCenter().setItems(dataCenterList);
quotaModel.getDataCenter().setSelectedItem(dataCenterList.get(0));
}));
}
qModel.getDataCenter().getSelectedItemChangedEvent().addListener((ev, sender, args) -> {
StoragePool selectedDataCenter = qModel.getDataCenter().getSelectedItem();
if (selectedDataCenter == null) {
return;
}
AsyncDataProvider.getInstance().getClusterList(new AsyncQuery<>(clusterList -> {
if (clusterList == null || clusterList.size() == 0) {
qModel.getAllDataCenterClusters().setItems(new ArrayList<QuotaCluster>());
return;
}
ArrayList<QuotaCluster> quotaClusterList = new ArrayList<>();
QuotaCluster quotaCluster;
for (Cluster cluster : clusterList) {
quotaCluster = new QuotaCluster();
quotaCluster.setClusterId(cluster.getId());
quotaCluster.setClusterName(cluster.getName());
quotaCluster.setMemSizeMB(null);
quotaCluster.setMemSizeMBUsage((long) 0);
quotaCluster.setVirtualCpu(null);
quotaCluster.setVirtualCpuUsage(0);
quotaClusterList.add(quotaCluster);
}
qModel.getAllDataCenterClusters().setItems(quotaClusterList);
}), selectedDataCenter.getId());
AsyncDataProvider.getInstance().getStorageDomainList(new AsyncQuery<>(storageList -> {
if (storageList == null || storageList.size() == 0) {
qModel.getAllDataCenterStorages().setItems(new ArrayList<QuotaStorage>());
qModel.stopProgress();
return;
}
ArrayList<QuotaStorage> quotaStorageList = new ArrayList<>();
QuotaStorage quotaStorage;
for (StorageDomain storage : storageList) {
if (!storage.getStorageDomainType().isDataDomain()) {
continue;
}
quotaStorage = new QuotaStorage();
quotaStorage.setStorageId(storage.getId());
quotaStorage.setStorageName(storage.getStorageName());
quotaStorage.setStorageSizeGB(null);
quotaStorage.setStorageSizeGBUsage((double) 0);
quotaStorageList.add(quotaStorage);
}
qModel.getAllDataCenterStorages().setItems(quotaStorageList);
qModel.stopProgress();
}), selectedDataCenter.getId());
});
// $NON-NLS-1$
UICommand command = UICommand.createDefaultOkUiCommand("OnCreateQuota", this);
qModel.getCommands().add(command);
// $NON-NLS-1$
qModel.getCommands().add(UICommand.createCancelUiCommand("Cancel", this));
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaListModel method editQuota.
private void editQuota(boolean isClone) {
Quota outer_quota = getSelectedItem();
final QuotaModel qModel = new QuotaModel();
qModel.getName().setEntity(outer_quota.getQuotaName());
qModel.getGraceCluster().setEntity(outer_quota.getGraceClusterPercentage());
qModel.getThresholdCluster().setEntity(outer_quota.getThresholdClusterPercentage());
qModel.getGraceStorage().setEntity(outer_quota.getGraceStoragePercentage());
qModel.getThresholdStorage().setEntity(outer_quota.getThresholdStoragePercentage());
qModel.getDescription().setEntity(outer_quota.getDescription());
qModel.setTitle(isClone ? ConstantsManager.getInstance().getConstants().cloneQuotaTitle() : ConstantsManager.getInstance().getConstants().editQuotaTitle());
if (isClone) {
qModel.setHelpTag(HelpTag.clone_quota);
// $NON-NLS-1$
qModel.setHashName("clone_quota");
} else {
qModel.setHelpTag(HelpTag.edit_quota);
// $NON-NLS-1$
qModel.setHashName("edit_quota");
}
UICommand command;
if (!isClone) {
// $NON-NLS-1$
command = UICommand.createDefaultOkUiCommand("OnCreateQuota", this);
} else {
// $NON-NLS-1$
command = UICommand.createDefaultOkUiCommand("onCloneQuota", this);
qModel.getName().setEntity(COPY_OF + outer_quota.getQuotaName());
// $NON-NLS-1$
qModel.getDescription().setEntity("");
qModel.getCopyPermissions().setIsAvailable(true);
}
qModel.getCommands().add(command);
// $NON-NLS-1$
UICommand cancelCommand = UICommand.createCancelUiCommand("Cancel", this);
qModel.getCommands().add(cancelCommand);
AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<>(returnValue -> {
final Quota quota = returnValue.getReturnValue();
qModel.setEntity(quota);
if (quota.getGlobalQuotaCluster() != null) {
QuotaCluster cluster = ((ArrayList<QuotaCluster>) qModel.getQuotaClusters().getItems()).get(0);
cluster.setMemSizeMB(quota.getGlobalQuotaCluster().getMemSizeMB());
cluster.setVirtualCpu(quota.getGlobalQuotaCluster().getVirtualCpu());
cluster.setMemSizeMBUsage(quota.getGlobalQuotaCluster().getMemSizeMBUsage());
cluster.setVirtualCpuUsage(quota.getGlobalQuotaCluster().getVirtualCpuUsage());
qModel.getGlobalClusterQuota().setEntity(true);
}
if (quota.getGlobalQuotaStorage() != null) {
QuotaStorage storage = ((ArrayList<QuotaStorage>) qModel.getQuotaStorages().getItems()).get(0);
storage.setStorageSizeGB(quota.getGlobalQuotaStorage().getStorageSizeGB());
storage.setStorageSizeGBUsage(quota.getGlobalQuotaStorage().getStorageSizeGBUsage());
qModel.getGlobalStorageQuota().setEntity(true);
}
setWindow(qModel);
qModel.startProgress();
qModel.getDataCenter().getSelectedItemChangedEvent().addListener((ev, sender, args) -> {
StoragePool selectedDataCenter = qModel.getDataCenter().getSelectedItem();
AsyncDataProvider.getInstance().getClusterList(new AsyncQuery<>(clusterList -> {
if (clusterList == null || clusterList.size() == 0) {
qModel.getAllDataCenterClusters().setItems(new ArrayList<QuotaCluster>());
if (quota.getGlobalQuotaCluster() == null) {
qModel.getSpecificClusterQuota().setEntity(true);
}
return;
}
ArrayList<QuotaCluster> quotaClusterList = new ArrayList<>();
QuotaCluster quotaCluster;
for (Cluster cluster : clusterList) {
quotaCluster = new QuotaCluster();
quotaCluster.setClusterId(cluster.getId());
quotaCluster.setClusterName(cluster.getName());
quotaCluster.setQuotaId(quota.getId());
boolean containCluster = false;
for (QuotaCluster iter : quota.getQuotaClusters()) {
if (quotaCluster.getClusterId().equals(iter.getClusterId())) {
quotaCluster.setQuotaClusterId(iter.getQuotaClusterId());
quotaCluster.setMemSizeMB(iter.getMemSizeMB());
quotaCluster.setVirtualCpu(iter.getVirtualCpu());
quotaCluster.setMemSizeMBUsage(iter.getMemSizeMBUsage());
quotaCluster.setVirtualCpuUsage(iter.getVirtualCpuUsage());
containCluster = true;
break;
}
}
if (!containCluster) {
quotaCluster.setMemSizeMB(null);
quotaCluster.setVirtualCpu(null);
quotaCluster.setMemSizeMBUsage((long) 0);
quotaCluster.setVirtualCpuUsage(0);
}
quotaClusterList.add(quotaCluster);
}
qModel.getAllDataCenterClusters().setItems(quotaClusterList);
if (quota.getGlobalQuotaCluster() == null) {
qModel.getSpecificClusterQuota().setEntity(true);
}
}), selectedDataCenter.getId());
AsyncDataProvider.getInstance().getStorageDomainList(new AsyncQuery<>(storageList -> {
if (storageList == null || storageList.size() == 0) {
qModel.getAllDataCenterStorages().setItems(new ArrayList<QuotaStorage>());
if (quota.getGlobalQuotaStorage() == null) {
qModel.getSpecificStorageQuota().setEntity(true);
}
qModel.stopProgress();
return;
}
ArrayList<QuotaStorage> quotaStorageList = new ArrayList<>();
QuotaStorage quotaStorage;
for (StorageDomain storage : storageList) {
if (!storage.getStorageDomainType().isDataDomain()) {
continue;
}
quotaStorage = new QuotaStorage();
quotaStorage.setStorageId(storage.getId());
quotaStorage.setStorageName(storage.getStorageName());
quotaStorage.setQuotaId(quota.getId());
boolean containStorage = false;
for (QuotaStorage iter : quota.getQuotaStorages()) {
if (quotaStorage.getStorageId().equals(iter.getStorageId())) {
quotaStorage.setQuotaStorageId(iter.getQuotaStorageId());
quotaStorage.setStorageSizeGB(iter.getStorageSizeGB());
quotaStorage.setStorageSizeGBUsage(iter.getStorageSizeGBUsage());
containStorage = true;
break;
}
}
if (!containStorage) {
quotaStorage.setStorageSizeGB(null);
quotaStorage.setStorageSizeGBUsage(0.0);
}
quotaStorageList.add(quotaStorage);
}
qModel.getAllDataCenterStorages().setItems(quotaStorageList);
if (quota.getGlobalQuotaStorage() == null) {
qModel.getSpecificStorageQuota().setEntity(true);
}
qModel.stopProgress();
}), selectedDataCenter.getId());
});
ArrayList<StoragePool> dataCenterList = new ArrayList<>();
StoragePool dataCenter = new StoragePool();
dataCenter.setId(quota.getStoragePoolId());
dataCenter.setName(quota.getStoragePoolName());
dataCenterList.add(dataCenter);
qModel.getDataCenter().setItems(dataCenterList);
qModel.getDataCenter().setSelectedItem(dataCenter);
qModel.getDataCenter().setIsChangeable(false);
});
IdQueryParameters quotaParameters = new IdQueryParameters(outer_quota.getId());
Frontend.getInstance().runQuery(QueryType.GetQuotaByQuotaId, quotaParameters, asyncQuery);
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaModel method validateNotEmpty.
private boolean validateNotEmpty() {
getSpecificClusterQuota().setIsValid(true);
getSpecificStorageQuota().setIsValid(true);
if (getGlobalClusterQuota().getEntity() || getGlobalStorageQuota().getEntity()) {
return true;
}
if (getAllDataCenterClusters().getItems() != null) {
for (QuotaCluster quotaCluster : getAllDataCenterClusters().getItems()) {
if (quotaCluster.getMemSizeMB() != null) {
return true;
}
}
}
if (getAllDataCenterStorages().getItems() != null) {
for (QuotaStorage quotaStorage : getAllDataCenterStorages().getItems()) {
if (quotaStorage.getStorageSizeGB() != null) {
return true;
}
}
}
getSpecificClusterQuota().validateEntity(new IValidation[] { quotaEmptyValidation });
getSpecificStorageQuota().validateEntity(new IValidation[] { quotaEmptyValidation });
return false;
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaManager method checkClusterMatchQuota.
// In case this param is a QuotaVdsConsumptionParameter - check that it has a valid
// vds group id which is handled by this quota
private boolean checkClusterMatchQuota(QuotaConsumptionParametersWrapper parameters, QuotaClusterConsumptionParameter param) {
Quota quota = param.getQuota();
if (param.getClusterId() == null) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
log.error("Quota Vds parameters from command '{}' are missing vds group id", parameters.getAuditLogable().getClass().getName());
return false;
}
boolean clusterInQuota = false;
if (quota.getGlobalQuotaCluster() != null) {
clusterInQuota = true;
} else {
for (QuotaCluster cluster : quota.getQuotaClusters()) {
if (cluster.getClusterId().equals(param.getClusterId())) {
clusterInQuota = true;
break;
}
}
}
if (!clusterInQuota) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
log.error("Quota Vds parameters from command '{}'. Vds group does not match quota", parameters.getAuditLogable().getClass().getName());
return false;
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaManager method rollBackClusterConsumptionParameters.
private void rollBackClusterConsumptionParameters(List<QuotaClusterConsumptionParameter> executed) {
for (QuotaClusterConsumptionParameter parameter : executed) {
long requestedMemory = parameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? -parameter.getRequestedMemory() : parameter.getRequestedMemory();
int requestedCpu = parameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? -parameter.getRequestedCpu() : parameter.getRequestedCpu();
QuotaCluster quotaCluster = null;
Quota quota = parameter.getQuota();
if (quota.getGlobalQuotaCluster() != null) {
// global cluster quota
quotaCluster = quota.getGlobalQuotaCluster();
} else {
for (QuotaCluster cluster : quota.getQuotaClusters()) {
if (cluster.getClusterId().equals(parameter.getClusterId())) {
quotaCluster = cluster;
break;
}
}
}
if (quotaCluster != null) {
long newMemory = requestedMemory + quotaCluster.getMemSizeMBUsage();
int newVcpu = requestedCpu + quotaCluster.getVirtualCpuUsage();
cacheNewValues(quotaCluster, newMemory, newVcpu);
}
}
}
Aggregations