private static Quota createGeneralQuota() { Quota quota = new Quota(); Guid quotaId = Guid.newGuid(); quota.setId(quotaId); quota.setStoragePoolId(FixturesTool.STORAGE_POOL_NFS); quota.setQuotaName("Watson"); quota.setDescription("General quota"); quota.setThresholdClusterPercentage(80); quota.setThresholdStoragePercentage(80); quota.setGraceClusterPercentage(20); quota.setGraceStoragePercentage(20); return quota; } }
private MapSqlParameterSource createQuotaMetaDataParameterMapper(Quota quota) { return createQuotaIdParameterMapper(quota.getId()).addValue("storage_pool_id", quota.getStoragePoolId()) .addValue("quota_name", quota.getQuotaName()) .addValue("description", quota.getDescription()) .addValue("threshold_cluster_percentage", quota.getThresholdClusterPercentage()) .addValue("threshold_storage_percentage", quota.getThresholdStoragePercentage()) .addValue("grace_cluster_percentage", quota.getGraceClusterPercentage()) .addValue("grace_storage_percentage", quota.getGraceStoragePercentage()) .addValue("is_default", quota.isDefault()); }
Map<Guid, Quota> allQuotaMap = new HashMap<>(); for (Quota quota : allThinQuota) { allQuotaMap.put(quota.getId(), quota); if (quota != null) { if (quotaStorage.getStorageId() == null || quotaStorage.getStorageId().equals(Guid.Empty)) { quota.setGlobalQuotaStorage(quotaStorage); } else { if (quota.getQuotaStorages() == null) { quota.setQuotaStorages(new ArrayList<>()); quota.getQuotaStorages().add(quotaStorage); if (quota != null) { if (quotaCluster.getClusterId() == null || quotaCluster.getClusterId().equals(Guid.Empty)) { quota.setGlobalQuotaCluster(quotaCluster); } else { if (quota.getQuotaClusters() == null) { quota.setQuotaClusters(new ArrayList<>()); quota.getQuotaClusters().add(quotaCluster);
private Quota getQuotaMetaDataFromResultSet(ResultSet rs) throws SQLException { Quota entity = new Quota(); entity.setId(getGuidDefaultEmpty(rs, "quota_id")); entity.setStoragePoolId(getGuidDefaultEmpty(rs, "storage_pool_id")); entity.setStoragePoolName(rs.getString("storage_pool_name")); entity.setQuotaName((String) rs.getObject("quota_name")); entity.setDescription((String) rs.getObject("description")); entity.setThresholdClusterPercentage((Integer) rs.getObject("threshold_cluster_percentage")); entity.setThresholdStoragePercentage((Integer) rs.getObject("threshold_storage_percentage")); entity.setGraceClusterPercentage((Integer) rs.getObject("grace_cluster_percentage")); entity.setGraceStoragePercentage((Integer) rs.getObject("grace_storage_percentage")); entity.setQuotaEnforcementType(QuotaEnforcementTypeEnum.forValue(rs.getInt("quota_enforcement_type"))); entity.setDefault(rs.getBoolean("is_default")); return entity; }
protected org.ovirt.engine.core.common.businessentities.Quota getQuota() { org.ovirt.engine.core.common.businessentities.Quota quota = new org.ovirt.engine.core.common.businessentities.Quota(); quota.setId(QUOTA_ID); quota.setStoragePoolId(DATACENTER_ID); return quota; }
@Override protected org.ovirt.engine.core.common.businessentities.Quota getEntity(int index) { org.ovirt.engine.core.common.businessentities.Quota quota = new org.ovirt.engine.core.common.businessentities.Quota(); quota.setId(GUIDS[index]); quota.setQuotaName(NAMES[index]); quota.setDescription(DESCRIPTIONS[index]); quota.setStoragePoolId(DATACENTER_ID); return quota; } }
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()); quota.setGlobalQuotaCluster(new QuotaCluster()); quota.getGlobalQuotaCluster().setMemSizeMB(iter.getMemSizeMB()); quota.getGlobalQuotaCluster().setVirtualCpu(iter.getVirtualCpu()); quota.getQuotaClusters().clear(); quota.setGlobalQuotaCluster(null); ArrayList<QuotaCluster> quotaClusterList = new ArrayList<>(); QuotaCluster quotaCluster; quota.setQuotaClusters(quotaClusterList); QuotaStorage quotaStorage; for (QuotaStorage iter : model.getQuotaStorages().getItems()) { quota.setGlobalQuotaStorage(new QuotaStorage()); quota.getGlobalQuotaStorage().setStorageSizeGB(iter.getStorageSizeGB()); quota.getQuotaStorages().clear(); quota.setGlobalQuotaStorage(null); ArrayList<QuotaStorage> quotaStorageList = new ArrayList<>(); QuotaStorage quotaStorage;
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()); } else { command = UICommand.createDefaultOkUiCommand("onCloneQuota", this); //$NON-NLS-1$ qModel.getName().setEntity(COPY_OF + outer_quota.getQuotaName()); qModel.getDescription().setEntity(""); //$NON-NLS-1$ qModel.getCopyPermissions().setIsAvailable(true); 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);
@Override public Object getQueryableId() { return getId(); }
/** * Make Quota specific to be the same as Quota general and specific. */ @Test public void testUpdateQuota() { Quota quotaGeneralToSpecific = dao.getById(FixturesTool.QUOTA_GENERAL); // Save quotaName and cluster list for future check. String quotaName = "New Temporary name"; List<QuotaCluster> quotaClusterList = getQuotaCluster(getSpecificQuotaCluster(quotaGeneralToSpecific.getId())); Long newStorageLimit = 2345L; // Check before the update, that the fields are not equal. assertNotEquals(quotaName, quotaGeneralToSpecific.getQuotaName()); assertNotEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size()); assertNotEquals(newStorageLimit, quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB()); // Update quotaGeneralToSpecific.setQuotaName(quotaName); quotaGeneralToSpecific.getGlobalQuotaStorage().setStorageSizeGB(newStorageLimit); quotaGeneralToSpecific.setQuotaClusters(quotaClusterList); dao.update(quotaGeneralToSpecific); quotaGeneralToSpecific = dao.getById(FixturesTool.QUOTA_GENERAL); // Check after the update, that the fields are equal now. assertEquals(quotaName, quotaGeneralToSpecific.getQuotaName()); assertEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size()); assertEquals(newStorageLimit, quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB()); }
boolean hasQuotaInList = false; if (!quotaList.isEmpty()) { hasQuotaInList = defaultQuota.equals(quotaList.get(0).getId()); Quota quota = new Quota(); quota.setId(defaultQuota); quota.setQuotaName(quotaName); quotaList.add(0, quota); vmModel.getQuota().setItems(quotaList);
@Override protected void updateEntityForRemove(Quota entity, Guid id) { // since we're mocking remove using update, we'll throw 404 if the object isn't found boolean throw404 = false; // global storage (has same id as quota) if (entity.getId().equals(id)) { if (entity.getGlobalQuotaStorage() == null) { throw404 = true; } else { entity.setGlobalQuotaStorage(null); } // specific storage (has same id as storage domain) } else { if (entity.getQuotaStorages() != null) { for (int i = 0; i < entity.getQuotaStorages().size(); i++) { if (entity.getQuotaStorages().get(i).getStorageId().equals(id)) { entity.getQuotaStorages().remove(i); return; } } throw404 = true; } } if (throw404) { throw new WebApplicationException(Response.Status.NOT_FOUND); } } }
@Override protected void updateEntityForRemove(Quota entity, Guid id) { // since we're mocking remove using update, we'll throw 404 if the object isn't found boolean throw404 = false; // global cluster (has same id as quota) if (entity.getId().equals(id)) { if (entity.getGlobalQuotaCluster() == null) { throw404 = true; } else { entity.setGlobalQuotaCluster(null); } // specific cluster (has same id as cluster) } else { if (entity.getQuotaClusters() != null) { Iterator<QuotaCluster> iterator = entity.getQuotaClusters().iterator(); while (iterator.hasNext()) { if (iterator.next().getClusterId().equals(id)) { iterator.remove(); return; } } throw404 = true; } } if (throw404) { throw new WebApplicationException(Response.Status.NOT_FOUND); } } }
@Test public void testSpecificAndGeneralQuotaLimitations() { // Set new Quota definition. Quota quota = createGeneralQuota(); quota.setQuotaClusters(getQuotaCluster(getSpecificQuotaCluster(quota.getId()))); quota.setQuotaStorages(getQuotaStorage(null)); quota.setGlobalQuotaStorage(new QuotaStorage(null, null, null, 10000L, 0d)); dao.save(quota); Quota quotaEntity = dao.getById(quota.getId()); assertNotNull(quotaEntity); assertEquals(quota, quotaEntity); }
@Mapping(from = org.ovirt.engine.core.common.businessentities.Quota.class, to = QuotaStorageLimit.class) public static QuotaStorageLimit map(org.ovirt.engine.core.common.businessentities.Quota entity, QuotaStorageLimit template) { QuotaStorageLimit model = template != null ? template : new QuotaStorageLimit(); Guid guid = GuidUtils.asGuid(model.getId()); // global if (guid.equals(entity.getId())) { map(model, entity.getGlobalQuotaStorage(), null, entity.getStoragePoolId().toString(), entity.getId() .toString()); } else { // specific if (entity.getQuotaStorages() != null) { for (QuotaStorage quotaStorage : entity.getQuotaStorages()) { if (quotaStorage.getStorageId() != null && quotaStorage.getStorageId().equals(guid)) { map(model, quotaStorage, quotaStorage.getStorageId().toString(), entity.getStoragePoolId() .toString(), entity.getId().toString()); } } } } return model; }
@Mapping(from = org.ovirt.engine.core.common.businessentities.Quota.class, to = QuotaClusterLimit.class) public static QuotaClusterLimit map(org.ovirt.engine.core.common.businessentities.Quota entity, QuotaClusterLimit template) { QuotaClusterLimit model = template != null ? template : new QuotaClusterLimit(); Guid guid = GuidUtils.asGuid(model.getId()); // global if (guid.equals(entity.getId())) { map(model, entity.getGlobalQuotaCluster(), null, entity.getStoragePoolId().toString(), entity.getId() .toString()); } else { // specific if (entity.getQuotaClusters() != null) { for (QuotaCluster quotaCluster : entity.getQuotaClusters()) { if (quotaCluster.getClusterId() != null && quotaCluster.getClusterId().equals(guid)) { map(model, quotaCluster, quotaCluster.getClusterId().toString(), entity.getStoragePoolId() .toString(), entity.getId().toString()); } } } } return model; }
@Test public void testGeneralQuotaLimitations() { // Set new Quota definition. Quota quota = createGeneralQuota(); setQuotaGlobalLimitations(quota); quota.setQuotaClusters(getQuotaCluster(null)); quota.setQuotaStorages(getQuotaStorage(null)); dao.save(quota); Quota quotaEntity = dao.getById(quota.getId()); assertNotNull(quotaEntity); assertEquals(quota, quotaEntity); assertEquals("rhel6.NFS", quotaEntity.getStoragePoolName()); assertEquals(QuotaEnforcementTypeEnum.DISABLED, quotaEntity.getQuotaEnforcementType()); }
@Mapping(from = QuotaClusterLimit.class, to = org.ovirt.engine.core.common.businessentities.Quota.class) public static org.ovirt.engine.core.common.businessentities.Quota map(QuotaClusterLimit model, org.ovirt.engine.core.common.businessentities.Quota template) { org.ovirt.engine.core.common.businessentities.Quota entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.Quota(); QuotaCluster quotaCluster = new QuotaCluster(); if (model.isSetVcpuLimit()) { quotaCluster.setVirtualCpu(model.getVcpuLimit()); } if (model.isSetMemoryLimit()) { double limit = model.getMemoryLimit(); quotaCluster.setMemSizeMB( (limit < 0) ? -1 : (long) (limit * 1024) ); } // specific cluster if (model.isSetCluster() && model.getCluster().isSetId()) { quotaCluster.setClusterId(GuidUtils.asGuid(model.getCluster().getId())); entity.getQuotaClusters().add(quotaCluster); } else { // global entity.setGlobalQuotaCluster(quotaCluster); } return entity; } }
@Mapping(from = QuotaStorageLimit.class, to = org.ovirt.engine.core.common.businessentities.Quota.class) public static org.ovirt.engine.core.common.businessentities.Quota map(QuotaStorageLimit model, org.ovirt.engine.core.common.businessentities.Quota template) { org.ovirt.engine.core.common.businessentities.Quota entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.Quota(); QuotaStorage quotaStorage = new QuotaStorage(); if (model.isSetLimit()) { quotaStorage.setStorageSizeGB(model.getLimit()); } // specific SD if(model.isSetStorageDomain() && model.getStorageDomain().isSetId()) { quotaStorage.setStorageId(GuidUtils.asGuid(model.getStorageDomain().getId())); entity.getQuotaStorages().add(quotaStorage); } else { // global entity.setGlobalQuotaStorage(quotaStorage); } return entity; }
/** * Build parameter map, for quota limitation table, to indicate global limitation on {@code StoragePool}. * * @param quota * - The global quota. * @return - Global quota Parameter Map. */ private MapSqlParameterSource getFullQuotaParameterMap(Quota quota) { return getCustomMapSqlParameterSource() .addValue("id", quota.getId()) .addValue("quota_id", quota.getId()) .addValue("cluster_id", null) .addValue("storage_id", null) .addValue("storage_size_gb", quota.getGlobalQuotaStorage() != null ? quota.getGlobalQuotaStorage() .getStorageSizeGB() : null) .addValue("virtual_cpu", quota.getGlobalQuotaCluster() != null ? quota.getGlobalQuotaCluster().getVirtualCpu() : null) .addValue("mem_size_mb", quota.getGlobalQuotaCluster() != null ? quota.getGlobalQuotaCluster().getMemSizeMB() : null); }