use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class RegisterEntityModel method updateClusterQuota.
private void updateClusterQuota(List<Cluster> clusters) {
if (!isQuotaEnabled()) {
return;
}
List<QueryType> queries = new ArrayList<>();
List<QueryParametersBase> params = new ArrayList<>();
for (Cluster cluster : clusters) {
queries.add(QueryType.GetAllRelevantQuotasForCluster);
params.add(new IdQueryParameters(cluster.getId()));
}
Frontend.getInstance().runMultipleQueries(queries, params, result -> {
Map<Guid, List<Quota>> clusterQuotasMap = new HashMap<>();
for (int i = 0; i < result.getReturnValues().size(); i++) {
List<Quota> quotas = result.getReturnValues().get(i).getReturnValue();
Guid clusterId = ((IdQueryParameters) result.getParameters().get(i)).getId();
clusterQuotasMap.put(clusterId, quotas);
}
getClusterQuotasMap().setEntity(clusterQuotasMap);
});
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaListModel method onCreateQuotaInternal.
private void onCreateQuotaInternal(boolean isClone) {
QuotaModel model = (QuotaModel) getWindow();
if (!model.validate()) {
return;
}
Quota quota = model.getEntity();
quota.setQuotaName(model.getName().getEntity());
quota.setDescription(model.getDescription().getEntity());
quota.setStoragePoolId(model.getDataCenter().getSelectedItem().getId());
quota.setGraceClusterPercentage(model.getGraceClusterAsInteger());
quota.setGraceStoragePercentage(model.getGraceStorageAsInteger());
quota.setThresholdClusterPercentage(model.getThresholdClusterAsInteger());
quota.setThresholdStoragePercentage(model.getThresholdStorageAsInteger());
if (model.getGlobalClusterQuota().getEntity()) {
QuotaCluster quotaCluster;
for (QuotaCluster iter : model.getQuotaClusters().getItems()) {
quota.setGlobalQuotaCluster(new QuotaCluster());
quota.getGlobalQuotaCluster().setMemSizeMB(iter.getMemSizeMB());
quota.getGlobalQuotaCluster().setVirtualCpu(iter.getVirtualCpu());
quota.getQuotaClusters().clear();
}
} else {
quota.setGlobalQuotaCluster(null);
ArrayList<QuotaCluster> quotaClusterList = new ArrayList<>();
QuotaCluster quotaCluster;
for (QuotaCluster iter : model.getAllDataCenterClusters().getItems()) {
quotaCluster = iter;
if (quotaCluster.getMemSizeMB() != null) {
quotaClusterList.add(quotaCluster);
}
}
quota.setQuotaClusters(quotaClusterList);
}
if (model.getGlobalStorageQuota().getEntity()) {
QuotaStorage quotaStorage;
for (QuotaStorage iter : model.getQuotaStorages().getItems()) {
quota.setGlobalQuotaStorage(new QuotaStorage());
quota.getGlobalQuotaStorage().setStorageSizeGB(iter.getStorageSizeGB());
quota.getQuotaStorages().clear();
}
} else {
quota.setGlobalQuotaStorage(null);
ArrayList<QuotaStorage> quotaStorageList = new ArrayList<>();
QuotaStorage quotaStorage;
for (QuotaStorage iter : model.getAllDataCenterStorages().getItems()) {
quotaStorage = iter;
if (quotaStorage.getStorageSizeGB() != null) {
quotaStorageList.add(quotaStorage);
}
}
quota.setQuotaStorages(quotaStorageList);
}
Guid guid = quota.getId();
QuotaCRUDParameters parameters = new QuotaCRUDParameters(quota);
if (isClone) {
parameters.setCopyPermissions(model.getCopyPermissions().getEntity());
parameters.setQuotaId(quota.getId());
quota.setId(Guid.Empty);
}
ActionType actionType = ActionType.AddQuota;
if (!quota.getId().equals(Guid.Empty)) {
actionType = ActionType.UpdateQuota;
}
Frontend.getInstance().runAction(actionType, parameters, result -> setWindow(null));
quota.setId(guid);
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaListModel method remove.
public void remove() {
if (getWindow() != null) {
return;
}
ConfirmationModel model = new ConfirmationModel();
setWindow(model);
model.setTitle(ConstantsManager.getInstance().getConstants().removeQuotasTitle());
model.setHelpTag(HelpTag.remove_quota);
// $NON-NLS-1$
model.setHashName("remove_quota");
ArrayList<String> list = new ArrayList<>();
for (Quota a : getSelectedItems()) {
list.add(a.getQuotaName());
}
model.setItems(list);
// $NON-NLS-1$
UICommand tempVar = UICommand.createDefaultOkUiCommand("OnRemove", this);
model.getCommands().add(tempVar);
// $NON-NLS-1$
UICommand tempVar2 = UICommand.createCancelUiCommand("Cancel", this);
model.getCommands().add(tempVar2);
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method updateQuotaByCluster.
protected void updateQuotaByCluster(final Guid defaultQuota, final String quotaName) {
if (getModel().getQuota().getIsAvailable()) {
Cluster cluster = getModel().getSelectedCluster();
if (cluster == null) {
return;
}
AsyncDataProvider.getInstance().getAllRelevantQuotasForClusterSorted(new AsyncQuery<>(quotaList -> {
UnitVmModel vmModel = getModel();
if (quotaList == null) {
return;
}
if (!quotaList.isEmpty()) {
vmModel.getQuota().setItems(quotaList);
}
if (defaultQuota != null && !Guid.Empty.equals(defaultQuota)) {
boolean hasQuotaInList = false;
if (!quotaList.isEmpty()) {
hasQuotaInList = defaultQuota.equals(quotaList.get(0).getId());
}
// Add the quota to the list only in edit mode
if (!hasQuotaInList && !getModel().getIsNew()) {
Quota quota = new Quota();
quota.setId(defaultQuota);
quota.setQuotaName(quotaName);
quotaList.add(0, quota);
vmModel.getQuota().setItems(quotaList);
vmModel.getQuota().setSelectedItem(quota);
}
}
}), cluster.getId(), defaultQuota);
}
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class MainQuotaView method initTable.
void initTable() {
getTable().enableColumnResizing();
QuotaDcStatusColumn dcStatusColumn = new QuotaDcStatusColumn();
dcStatusColumn.setContextMenuTitle(constants.dcStatusQuota());
// $NON-NLS-1$
getTable().addColumn(dcStatusColumn, constants.empty(), "30px");
AbstractTextColumn<Quota> nameColumn = new AbstractLinkColumn<Quota>(new FieldUpdater<Quota, String>() {
@Override
public void update(int index, Quota quota, String value) {
Map<String, String> parameters = new HashMap<>();
parameters.put(FragmentParams.NAME.getName(), quota.getName());
parameters.put(FragmentParams.DATACENTER.getName(), quota.getStoragePoolName());
// The link was clicked, now fire an event to switch to details.
getPlaceTransitionHandler().handlePlaceTransition(WebAdminApplicationPlaces.quotaClusterSubTabPlace, parameters);
}
}) {
@Override
public String getValue(Quota object) {
// $NON-NLS-1$
return object.getQuotaName() == null ? "" : object.getQuotaName();
}
};
nameColumn.makeSortable(QuotaConditionFieldAutoCompleter.NAME);
// $NON-NLS-1$
getTable().addColumn(nameColumn, constants.nameQuota(), "120px");
AbstractTextColumn<Quota> dataCenterColumn = new AbstractTextColumn<Quota>() {
@Override
public String getValue(Quota object) {
return object.getStoragePoolName() == null ? "" : object.getStoragePoolName();
}
};
dataCenterColumn.makeSortable(QuotaConditionFieldAutoCompleter.STORAGEPOOLNAME);
// $NON-NLS-1$
getTable().addColumn(dataCenterColumn, constants.dcQuota(), "120px");
AbstractTextColumn<Quota> descriptionColumn = new AbstractTextColumn<Quota>() {
@Override
public String getValue(Quota object) {
// $NON-NLS-1$
return object.getDescription() == null ? "" : object.getDescription();
}
};
descriptionColumn.makeSortable(QuotaConditionFieldAutoCompleter.DESCRIPTION);
// $NON-NLS-1$
getTable().addColumn(descriptionColumn, constants.descriptionQuota(), "120px");
getTable().addColumn(new AbstractQuotaPercentColumn<Quota>() {
@Override
protected Integer getProgressValue(Quota object) {
int value;
long allocated = 0;
long used = 0;
if (object.getGlobalQuotaCluster() != null) {
allocated = object.getGlobalQuotaCluster().getMemSizeMB();
used = object.getGlobalQuotaCluster().getMemSizeMBUsage();
} else {
for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
if (!QuotaCluster.UNLIMITED_MEM.equals(quotaCluster.getMemSizeMB())) {
allocated += quotaCluster.getMemSizeMB() != null ? quotaCluster.getMemSizeMB() : 0;
used += quotaCluster.getMemSizeMBUsage();
} else {
allocated = QuotaCluster.UNLIMITED_MEM;
break;
}
}
}
if (allocated == 0) {
return 0;
}
value = (int) (((double) used / allocated) * 100);
return allocated < 0 ? -1 : value > 100 ? 100 : value;
}
}, constants.usedMemoryQuota(), // $NON-NLS-1$
"145px");
getTable().addColumn(new AbstractTextColumn<Quota>() {
@Override
public String getValue(Quota object) {
int value;
long allocated = 0;
long used = 0;
if (object.getGlobalQuotaCluster() != null) {
allocated = object.getGlobalQuotaCluster().getMemSizeMB();
used = object.getGlobalQuotaCluster().getMemSizeMBUsage();
} else {
for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
if (!QuotaCluster.UNLIMITED_MEM.equals(quotaCluster.getMemSizeMB())) {
allocated += quotaCluster.getMemSizeMB() != null ? quotaCluster.getMemSizeMB() : 0;
used += quotaCluster.getMemSizeMBUsage();
} else {
allocated = QuotaCluster.UNLIMITED_MEM;
break;
}
}
}
value = (int) (allocated - used);
String returnVal;
if (allocated < 0) {
returnVal = constants.unlimited();
} else if (value <= 0) {
// $NON-NLS-1$
returnVal = messages.megabytes("0");
} else if (value <= 5 * 1024) {
returnVal = messages.megabytes(String.valueOf(value));
} else {
returnVal = messages.gibibytes(decimalFormat.format((double) value / 1024));
}
return returnVal;
}
}, constants.freeMemory(), // $NON-NLS-1$
"100px");
getTable().addColumn(new AbstractQuotaPercentColumn<Quota>() {
@Override
protected Integer getProgressValue(Quota object) {
int value;
int allocated = 0;
int used = 0;
if (object.getGlobalQuotaCluster() != null) {
allocated = object.getGlobalQuotaCluster().getVirtualCpu() != null ? object.getGlobalQuotaCluster().getVirtualCpu() : 0;
used = object.getGlobalQuotaCluster().getVirtualCpuUsage();
} else {
for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
if (!QuotaCluster.UNLIMITED_VCPU.equals(quotaCluster.getVirtualCpu())) {
allocated += quotaCluster.getVirtualCpu();
used += quotaCluster.getVirtualCpuUsage();
} else {
allocated = QuotaCluster.UNLIMITED_VCPU;
break;
}
}
}
if (allocated == 0) {
return 0;
}
value = (int) (((double) used / allocated) * 100);
return allocated < 0 ? -1 : value > 100 ? 100 : value;
}
}, constants.runningCpuQuota(), // $NON-NLS-1$
"135px");
getTable().addColumn(new AbstractTextColumn<Quota>() {
@Override
public String getValue(Quota object) {
int value;
int allocated = 0;
int used = 0;
if (object.getGlobalQuotaCluster() != null) {
allocated = object.getGlobalQuotaCluster().getVirtualCpu() != null ? object.getGlobalQuotaCluster().getVirtualCpu() : 0;
used = object.getGlobalQuotaCluster().getVirtualCpuUsage();
} else {
for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
if (!QuotaCluster.UNLIMITED_VCPU.equals(quotaCluster.getVirtualCpu())) {
allocated += quotaCluster.getVirtualCpu();
used += quotaCluster.getVirtualCpuUsage();
} else {
allocated = QuotaCluster.UNLIMITED_VCPU;
break;
}
}
}
value = allocated - used;
String returnVal;
if (allocated < 0) {
returnVal = constants.unlimited();
} else if (value <= 0) {
// $NON-NLS-1$
returnVal = "0";
} else {
// $NON-NLS-1$
returnVal = value + "";
}
return returnVal;
}
}, constants.freeVcpu(), // $NON-NLS-1$
"100px");
getTable().addColumn(new AbstractQuotaPercentColumn<Quota>() {
@Override
protected Integer getProgressValue(Quota object) {
int value;
double allocated = 0;
double used = 0;
if (object.getGlobalQuotaStorage() != null) {
allocated = object.getGlobalQuotaStorage().getStorageSizeGB();
used = object.getGlobalQuotaStorage().getStorageSizeGBUsage();
} else {
for (QuotaStorage quotaStorage : object.getQuotaStorages()) {
if (!QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
allocated += quotaStorage.getStorageSizeGB();
used += quotaStorage.getStorageSizeGBUsage();
} else {
allocated = QuotaStorage.UNLIMITED;
break;
}
}
}
if (allocated == 0) {
return 0;
}
value = (int) ((used / allocated) * 100);
return allocated < 0 ? -1 : value > 100 ? 100 : value;
}
}, constants.usedStorageQuota(), // $NON-NLS-1$
"155px");
getTable().addColumn(new AbstractTextColumn<Quota>() {
@Override
public String getValue(Quota object) {
double value;
double allocated = 0;
double used = 0;
if (object.getGlobalQuotaStorage() != null) {
allocated = object.getGlobalQuotaStorage().getStorageSizeGB();
used = object.getGlobalQuotaStorage().getStorageSizeGBUsage();
} else {
for (QuotaStorage quotaStorage : object.getQuotaStorages()) {
if (!QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
allocated += quotaStorage.getStorageSizeGB();
used += quotaStorage.getStorageSizeGBUsage();
} else {
allocated = QuotaStorage.UNLIMITED;
break;
}
}
}
value = allocated - used;
String returnVal;
if (allocated < 0) {
returnVal = constants.unlimited();
} else if (value <= 0) {
// $NON-NLS-1$
returnVal = messages.gibibytes("0");
} else {
returnVal = diskSizeRenderer.render(value);
}
return returnVal;
}
}, constants.freeStorage(), // $NON-NLS-1$
"100px");
}
Aggregations