Search in sources :

Example 31 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.

the class QuotaDaoTest method testQuotaClusterByQuotaGuidWithGeneralDefaultNoDefault.

/**
 * Asserts that when {@link QuotaDao#getQuotaClusterByQuotaGuidWithGeneralDefault(Guid)} is called
 * with a specific quota, all the relevant VDSs are returned
 */
@Test
public void testQuotaClusterByQuotaGuidWithGeneralDefaultNoDefault() {
    List<QuotaCluster> quotaClusterList = dao.getQuotaClusterByQuotaGuidWithGeneralDefault(FixturesTool.QUOTA_SPECIFIC);
    assertNotNull(quotaClusterList);
    assertEquals("wrong number of quotas returned", 2, quotaClusterList.size());
    for (QuotaCluster group : quotaClusterList) {
        assertNotNull("VDS ID should not be null in specific mode", group.getClusterId());
        assertNotNull("VDS name should not be null in specific mode", group.getClusterName());
    }
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Test(org.junit.Test)

Example 32 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.

the class QuotaDaoTest method testUpdateQuota.

/**
 * Make Quota specific to be the same as Quota general and specific.
 */
@Test
public void testUpdateQuota() throws Exception {
    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.
    assertFalse(quotaName.equals(quotaGeneralToSpecific.getQuotaName()));
    assertNotEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size());
    assertFalse(quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB().equals(newStorageLimit));
    // 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());
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Test(org.junit.Test)

Example 33 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.

the class UpdateQuotaCommandTest method setUpQuota.

private Quota setUpQuota(Guid guid) {
    Quota quota = new Quota();
    quota.setId(guid);
    int numQutoaClusters = RandomUtils.instance().nextInt(10);
    List<QuotaCluster> quotaClusters = new ArrayList<>(numQutoaClusters);
    for (int i = 0; i < numQutoaClusters; ++i) {
        quotaClusters.add(new QuotaCluster());
    }
    quota.setQuotaClusters(quotaClusters);
    int numQutoaStorages = RandomUtils.instance().nextInt(10);
    List<QuotaStorage> quotaStorages = new ArrayList<>(numQutoaStorages);
    for (int i = 0; i < numQutoaClusters; ++i) {
        quotaStorages.add(new QuotaStorage());
    }
    quota.setQuotaStorages(quotaStorages);
    return quota;
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 34 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.

the class GetQuotaClusterByQuotaIdQueryTest method testExecuteQueryCommand.

@Test
public void testExecuteQueryCommand() {
    // Mock the parameters
    Guid quotaId = Guid.newGuid();
    when(params.getId()).thenReturn(quotaId);
    // Create the return value
    QuotaCluster group = new QuotaCluster();
    group.setQuotaId(quotaId);
    // Mock the Dao
    when(quotaDao.getQuotaClusterByQuotaGuidWithGeneralDefault(quotaId)).thenReturn(Collections.singletonList(group));
    // Execute the query
    getQuery().executeQueryCommand();
    // Assert the result
    @SuppressWarnings("unchecked") List<QuotaCluster> results = getQuery().getQueryReturnValue().getReturnValue();
    assertEquals("Wrong number of results returned", 1, results.size());
    assertEquals("Wrong results returned", group, results.get(0));
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 35 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.

the class QuotaCRUDCommand method setQuotaCluster.

private void setQuotaCluster(Quota quota) {
    // Create unlimited global cluster quota if no other is specified
    if (quota.isEmptyClusterQuota()) {
        quota.setGlobalQuotaCluster(new QuotaCluster(Guid.newGuid(), quota.getId(), null, -1, 0, -1L, 0L));
        return;
    }
    if (quota.isGlobalClusterQuota()) {
        quota.getGlobalQuotaCluster().setQuotaId(quota.getId());
        quota.getGlobalQuotaCluster().setQuotaClusterId(Guid.newGuid());
        return;
    }
    for (QuotaCluster quotaCluster : quota.getQuotaClusters()) {
        quotaCluster.setQuotaId(quota.getId());
        quotaCluster.setQuotaClusterId(Guid.newGuid());
    }
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Aggregations

QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)36 Quota (org.ovirt.engine.core.common.businessentities.Quota)17 QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)14 Test (org.junit.Test)12 Guid (org.ovirt.engine.core.compat.Guid)8 ArrayList (java.util.ArrayList)5 ActionType (org.ovirt.engine.core.common.action.ActionType)3 QuotaCRUDParameters (org.ovirt.engine.core.common.action.QuotaCRUDParameters)3 Inject (com.google.inject.Inject)2 HashMap (java.util.HashMap)2 List (java.util.List)2 QuotaClusterLimit (org.ovirt.engine.api.model.QuotaClusterLimit)2 QuotaClusterLimits (org.ovirt.engine.api.model.QuotaClusterLimits)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 IdParameters (org.ovirt.engine.core.common.action.IdParameters)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 SearchType (org.ovirt.engine.core.common.interfaces.SearchType)2 ApplicationMode (org.ovirt.engine.core.common.mode.ApplicationMode)2