public QuotaStorage(QuotaStorage quotaStorage) { this.quotaStorageId = quotaStorage.getQuotaStorageId(); this.quotaId = quotaStorage.getQuotaId(); this.storageId = quotaStorage.getStorageId(); this.setStorageSizeGB(quotaStorage.getStorageSizeGB()); this.storageLimitGigaByteUsage = quotaStorage.getStorageSizeGBUsage(); }
@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); } } }
Quota quota = allQuotaMap.get(quotaStorage.getQuotaId()); if (quota != null) { if (quotaStorage.getStorageId() == null || quotaStorage.getStorageId().equals(Guid.Empty)) { quota.setGlobalQuotaStorage(quotaStorage); } else {
@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; }
@Override public QuotaStorageLimits list() { Quota quota = getQuota(); QuotaStorageLimits limits = new QuotaStorageLimits(); if (quota.getGlobalQuotaStorage() != null) { addLimit(quotaId.toString(), limits, quota); } else if (quota.getQuotaStorages() != null) { for (QuotaStorage quotaStorage : quota.getQuotaStorages()) { addLimit(quotaStorage.getStorageId().toString(), limits, quota); } } return limits; }
/** * Build quota storage parameter map, for quota limitation table, to indicate specific limitation on storage domain. * * @param quotaId * - The global quota id which the storage is referencing to * @param quotaStorage * - The business entity which reflects the limitation on the specific storage. * @return - Parameter Map */ private MapSqlParameterSource getQuotaStorageParameterMap(Guid quotaId, QuotaStorage quotaStorage) { return createQuotaIdParameterMapper(quotaStorage.getQuotaStorageId()).addValue("quota_id", quotaId) .addValue("storage_id", quotaStorage.getStorageId()) .addValue("cluster_id", null) .addValue("storage_size_gb", quotaStorage.getStorageSizeGB()) .addValue("virtual_cpu", null) .addValue("mem_size_mb", null); }
/** * Asserts that when {@link QuotaDao#getQuotaStorageByQuotaGuidWithGeneralDefault(Guid)} is called * with a specific quota, all the relevant storages are returned */ @Test public void testQuotaStorageByQuotaGuidWithGeneralDefaultNoDefault() { List<QuotaStorage> quotaStorageList = dao.getQuotaStorageByQuotaGuidWithGeneralDefault(FixturesTool.QUOTA_SPECIFIC); assertNotNull(quotaStorageList); assertEquals(1, quotaStorageList.size(), "wrong number of quotas returned"); for (QuotaStorage group : quotaStorageList) { assertNotNull(group.getStorageId(), "Storage ID should not be null in specific mode"); assertNotNull(group.getStorageName(), "Storage name should not be null in specific mode"); } }
/** * Asserts that when {@link QuotaDao#getQuotaStorageByQuotaGuidWithGeneralDefault(Guid)} is called * with a specific quota, all the relevant VDSs are returned */ @Test public void testQuotaStorageByQuotaGuidWithGeneralDefaultWithDefault() { List<QuotaStorage> quotaStorageList = dao.getQuotaStorageByQuotaGuidWithGeneralDefault(FixturesTool.DEFAULT_QUOTA_GENERAL); assertNotNull(quotaStorageList); assertEquals(1, quotaStorageList.size(), "wrong number of quotas returned"); for (QuotaStorage group : quotaStorageList) { assertEquals(Guid.Empty, group.getStorageId(), "Storage ID should not be null in general mode"); assertNull(group.getStorageName(), "Storage name should not be null in general mode"); } }
boolean containStorage = false; for (QuotaStorage iter : quota.getQuotaStorages()) { if (quotaStorage.getStorageId().equals(iter.getStorageId())) { quotaStorage.setQuotaStorageId(iter.getQuotaStorageId()); quotaStorage.setStorageSizeGB(iter.getStorageSizeGB());