use of org.ovirt.engine.core.common.businessentities.Quota 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.Quota in project ovirt-engine by oVirt.
the class QuotaListModel method onRemove.
public void onRemove() {
ConfirmationModel model = (ConfirmationModel) getWindow();
if (model.getProgress() != null) {
return;
}
ArrayList<ActionParametersBase> prms = new ArrayList<>();
for (Quota a : getSelectedItems()) {
IdParameters idParameters = new IdParameters(a.getId());
prms.add(idParameters);
}
model.startProgress();
Frontend.getInstance().runMultipleAction(ActionType.RemoveQuota, prms, result -> {
ConfirmationModel localModel = (ConfirmationModel) result.getState();
localModel.stopProgress();
cancel();
}, model);
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class ImportExportRepoImageBaseModel method updateQuotas.
private void updateQuotas() {
StorageDomain storageDomain = getStorageDomain().getSelectedItem();
if (getDataCenterQuotaEnforcementType() == QuotaEnforcementTypeEnum.DISABLED || storageDomain == null) {
getQuota().setItems(null);
getQuota().setIsEmpty(true);
updateControlsAvailability();
return;
}
startProgress();
AsyncDataProvider.getInstance().getAllRelevantQuotasForStorageSorted(new AsyncQuery<>(quotas -> {
quotas = (quotas != null) ? quotas : new ArrayList<Quota>();
getQuota().setItems(quotas);
getQuota().setIsEmpty(quotas.isEmpty());
updateControlsAvailability();
stopProgress();
}), storageDomain.getId(), null);
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class ImportRepoImageModel method executeCommand.
@Override
public void executeCommand(UICommand command) {
if (!validate()) {
return;
}
super.executeCommand(command);
startProgress();
ArrayList<ActionParametersBase> actionParameters = new ArrayList<>();
final StringBuilder imageNames = new StringBuilder();
for (EntityModel entity : getEntities()) {
RepoImage repoImage = (RepoImage) entity.getEntity();
// $NON-NLS-1$
imageNames.append("\n -");
imageNames.append(repoImage.getRepoImageName());
ImportRepoImageParameters importParameters = new ImportRepoImageParameters();
// source
importParameters.setSourceRepoImageId(repoImage.getRepoImageId());
importParameters.setSourceStorageDomainId(sourceStorageDomain.getId());
// destination
importParameters.setDiskAlias(((RepoImageModel) entity).getDiskImageAlias());
importParameters.setStoragePoolId(getDataCenter().getSelectedItem().getId());
importParameters.setStorageDomainId(getStorageDomain().getSelectedItem().getId());
importParameters.setClusterId(getStorageDomain().getSelectedItem().getId());
Quota selectedQuota = getQuota().getSelectedItem();
if (selectedQuota != null) {
importParameters.setQuotaId(selectedQuota.getId());
}
Boolean importAsTemplate = getImportAsTemplate().getEntity();
importParameters.setImportAsTemplate(importAsTemplate);
if (importAsTemplate) {
importParameters.setClusterId(getCluster().getSelectedItem().getId());
String templateName = getTemplateName().getEntity();
if (StringHelper.isNotNullOrEmpty(templateName)) {
importParameters.setTemplateName(templateName);
}
}
actionParameters.add(importParameters);
}
Frontend.getInstance().runMultipleAction(ActionType.ImportRepoImage, actionParameters, result -> {
ImportExportRepoImageBaseModel model = (ImportExportRepoImageBaseModel) result.getState();
model.stopProgress();
model.cancel();
ConfirmationModel confirmModel = new ConfirmationModel();
storageIsoListModel.setConfirmWindow(confirmModel);
confirmModel.setTitle(ConstantsManager.getInstance().getConstants().importImagesTitle());
confirmModel.setHelpTag(HelpTag.import_images);
// $NON-NLS-1$
confirmModel.setHashName("import_images");
confirmModel.setMessage(ConstantsManager.getInstance().getMessages().importProcessHasBegunForImages(imageNames.toString()));
confirmModel.getCommands().add(// $NON-NLS-1$
new UICommand("CancelConfirm", storageIsoListModel).setTitle(ConstantsManager.getInstance().getConstants().close()).setIsDefault(true).setIsCancel(true));
}, this);
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaManager method updateQuotaCacheImpl.
private synchronized void updateQuotaCacheImpl() {
if (!isCacheUpdateNeeded()) {
return;
}
log.debug("Updating Quota Cache...");
long timeStart = System.currentTimeMillis();
List<Quota> allQuotaIncludingConsumption = getQuotaDao().getAllQuotaIncludingConsumption();
if (allQuotaIncludingConsumption.isEmpty()) {
return;
}
HashMap<Guid, Map<Guid, Quota>> newStoragePoolQuotaMap = new HashMap<>();
HashMap<Guid, Guid> newDefaultQuotaIdMap = new HashMap<>();
for (Quota quota : allQuotaIncludingConsumption) {
if (!newStoragePoolQuotaMap.containsKey(quota.getStoragePoolId())) {
newStoragePoolQuotaMap.put(quota.getStoragePoolId(), new HashMap<>());
}
newStoragePoolQuotaMap.get(quota.getStoragePoolId()).put(quota.getId(), quota);
if (quota.isDefault()) {
newDefaultQuotaIdMap.put(quota.getStoragePoolId(), quota.getId());
}
}
lock.writeLock().lock();
try {
storagePoolQuotaMap = newStoragePoolQuotaMap;
storagePoolDefaultQuotaIdMap = newDefaultQuotaIdMap;
} finally {
lock.writeLock().unlock();
}
long timeEnd = System.currentTimeMillis();
log.info("Quota Cache updated. ({} msec)", timeEnd - timeStart);
}
Aggregations