use of org.ovirt.engine.core.common.businessentities.QuotaStorage 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.QuotaStorage 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");
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class AddEmptyStoragePoolCommand method addDefaultQuotaToDb.
private void addDefaultQuotaToDb() {
Quota quota = new Quota();
quota.setId(Guid.newGuid());
quota.setQuotaName("Default");
quota.setDescription("Default unlimited quota");
quota.setStoragePoolId(getStoragePool().getId());
quota.setDefault(true);
QuotaCluster quotaCluster = new QuotaCluster();
quotaCluster.setMemSizeMB(QuotaCluster.UNLIMITED_MEM);
quotaCluster.setVirtualCpu(QuotaCluster.UNLIMITED_VCPU);
quota.setGlobalQuotaCluster(quotaCluster);
QuotaStorage quotaStorage = new QuotaStorage();
quotaStorage.setStorageSizeGB(QuotaStorage.UNLIMITED);
quota.setGlobalQuotaStorage(quotaStorage);
quotaDao.save(quota);
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class RemoveQuotaCommandTest method mockStorageQuota.
private Quota mockStorageQuota(Guid guid) {
Quota generalQuota = new Quota();
generalQuota.setDescription("New Quota to create");
generalQuota.setQuotaName("New Quota Name");
QuotaStorage storageQuota = new QuotaStorage();
storageQuota.setStorageSizeGB(100L);
storageQuota.setStorageSizeGBUsage(0d);
generalQuota.setGlobalQuotaStorage(storageQuota);
QuotaCluster clusterQuota = new QuotaCluster();
clusterQuota.setVirtualCpu(0);
clusterQuota.setVirtualCpuUsage(0);
clusterQuota.setMemSizeMB(0L);
clusterQuota.setMemSizeMBUsage(0L);
generalQuota.setGlobalQuotaCluster(clusterQuota);
generalQuota.setId(guid);
generalQuota.setStoragePoolId(storagePoolUUID);
return generalQuota;
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class BackendQuotaStorageLimitsResourceTest method getStorageGlobalCpuLimit.
private QuotaStorage getStorageGlobalCpuLimit() {
QuotaStorage storageGlobalLimit = new QuotaStorage();
storageGlobalLimit.setQuotaId(GUIDS[0]);
storageGlobalLimit.setStorageId(STORAGE_ID_1);
storageGlobalLimit.setStorageSizeGB(STORAGE_SIZE_GB);
return storageGlobalLimit;
}
Aggregations