use of org.ovirt.engine.core.common.businessentities.QuotaStorage 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.QuotaStorage 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.QuotaStorage in project ovirt-engine by oVirt.
the class QuotaManager method saveNewConsumptionValues.
private void saveNewConsumptionValues(Map<Guid, Quota> quotaMap, Map<Guid, Double> newUsedGlobalStorageSize, Map<Guid, Map<Guid, Double>> newUsedSpecificStorageSize) {
// cache new storage size.
for (Map.Entry<Guid, Double> entry : newUsedGlobalStorageSize.entrySet()) {
Quota quota = quotaMap.get(entry.getKey());
double value = entry.getValue();
if (value < 0) {
log.error("Quota id '{}' cached storage size is negative, removing from cache", entry.getKey());
quotaMap.remove(entry.getKey());
continue;
}
quota.getGlobalQuotaStorage().setStorageSizeGBUsage(value);
}
for (Map.Entry<Guid, Map<Guid, Double>> quotaStorageEntry : newUsedSpecificStorageSize.entrySet()) {
Quota quota = quotaMap.get(quotaStorageEntry.getKey());
for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
if (quotaStorageEntry.getValue().containsKey(quotaStorage.getStorageId())) {
double value = quotaStorageEntry.getValue().get(quotaStorage.getStorageId());
if (value < 0) {
log.error("Quota id '{}' cached storage size is negative, removing from cache", quotaStorageEntry.getKey());
quotaMap.remove(quotaStorageEntry.getKey());
continue;
}
quotaStorage.setStorageSizeGBUsage(value);
}
}
}
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class QuotaManager method checkConsumptionForSpecificStorageQuota.
private boolean checkConsumptionForSpecificStorageQuota(QuotaConsumptionParametersWrapper parameters, Map<Guid, Map<Guid, Double>> desiredStorageSizeQuotaMap, Map<Guid, Map<Guid, Double>> newUsedSpecificStorageSize, Guid quotaId, Quota quota, Pair<AuditLogType, AuditLogableBase> auditLogPair) {
newUsedSpecificStorageSize.put(quotaId, new HashMap<>());
for (Guid storageId : desiredStorageSizeQuotaMap.get(quotaId).keySet()) {
boolean hasStorageId = false;
for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
if (quotaStorage.getStorageId().equals(storageId)) {
hasStorageId = true;
if (!QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
double storageUsagePercentage = quotaStorage.getStorageSizeGBUsage() / quotaStorage.getStorageSizeGB() * 100;
double storageRequestPercentage = desiredStorageSizeQuotaMap.get(quotaId).get(storageId) / quotaStorage.getStorageSizeGB() * 100;
if (!checkQuotaStorageLimits(parameters.getAuditLogable().getStoragePool().getQuotaEnforcementType(), quota, quotaStorage.getStorageSizeGB(), storageUsagePercentage, storageRequestPercentage, parameters.getValidationMessages(), auditLogPair)) {
return false;
}
newUsedSpecificStorageSize.get(quotaId).put(storageId, quotaStorage.getStorageSizeGBUsage() + desiredStorageSizeQuotaMap.get(quotaId).get(storageId));
}
}
}
if (!hasStorageId) {
if (quota.getQuotaEnforcementType() == QuotaEnforcementTypeEnum.HARD_ENFORCEMENT) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN.toString());
return false;
} else {
auditLogPair.setFirst(AuditLogType.MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE);
}
}
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class QuotaDaoTest method testFetchSpecificAndGeneralQuotaForStorage.
@Test
public void testFetchSpecificAndGeneralQuotaForStorage() throws Exception {
List<QuotaStorage> quotaStorageList = dao.getQuotaStorageByStorageGuid(null, FixturesTool.QUOTA_SPECIFIC_AND_GENERAL);
QuotaStorage quotaStorage = quotaStorageList.get(0);
assertEquals(1, quotaStorageList.size());
assertNotNull(quotaStorage);
// Check if the global variable returns when null is initialization.
assertTrue(quotaStorage.getStorageSizeGBUsage() > 0);
}
Aggregations