Search in sources :

Example 91 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RefreshLunsSizeCommandTest method createLunMap.

private Map<String, List<Pair<VDS, LUNs>>> createLunMap(boolean sameLunSizesPerHost) {
    RandomUtils rnd = RandomUtils.instance();
    String lunId = rnd.nextString(34);
    int lunSize = rnd.nextInt();
    List<Pair<VDS, LUNs>> lunList = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        LUNs lun = new LUNs();
        if (!sameLunSizesPerHost) {
            lunSize++;
        }
        lun.setDeviceSize(lunSize);
        lunList.add(new Pair<>(new VDS(), lun));
    }
    return Collections.singletonMap(lunId, lunList);
}
Also used : RandomUtils(org.ovirt.engine.core.utils.RandomUtils) VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 92 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class ProcessOvfUpdateForStoragePoolCommandTest method mockAnswers.

private void mockAnswers() {
    doAnswer(invocation -> {
        VM vm = (VM) invocation.getArguments()[0];
        return vm.getId().toString();
    }).when(ovfUpdateProcessHelper).generateVmMetadata(any(), any());
    doAnswer(invocation -> {
        VmTemplate template = (VmTemplate) ((FullEntityOvfData) invocation.getArguments()[0]).getVmBase();
        return template.getId().toString();
    }).when(ovfUpdateProcessHelper).generateVmTemplateMetadata(any());
    doAnswer(invocation -> {
        List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
        return neededIds.stream().map(id -> vms.get(id)).collect(Collectors.toList());
    }).when(vmDao).getVmsByIds(any());
    doAnswer(invocation -> {
        List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
        return neededIds.stream().map(id -> templates.get(id)).collect(Collectors.toList());
    }).when(vmTemplateDao).getVmTemplatesByIds(any());
    doAnswer(invocation -> {
        Map<Guid, KeyValuePairCompat<String, List<Guid>>> updateMap = (Map<Guid, KeyValuePairCompat<String, List<Guid>>>) invocation.getArguments()[1];
        assertTrue("too many ovfs were sent in one vdsm call", updateMap.size() <= ITEMS_COUNT_PER_UPDATE);
        return true;
    }).when(ovfUpdateProcessHelper).executeUpdateVmInSpmCommand(any(), any(), any());
    doReturn(true).when(ovfUpdateProcessHelper).executeRemoveVmInSpm(any(), any(), any());
    doAnswer(invocation -> {
        List<Guid> ids = (List<Guid>) invocation.getArguments()[0];
        List<Long> values = (List<Long>) invocation.getArguments()[1];
        assertFalse("update of ovf version in db shouldn't be called with an empty value list", values.isEmpty());
        assertTrue("update of ovf version in db shouldn't be called with more items then MAX_ITEMS_PER_SQL_STATEMENT", values.size() <= StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT);
        assertEquals("the size of the list of ids for update is not the same as the size of the " + "list with the new ovf values", values.size(), ids.size());
        Guid[] ids_array = ids.toArray(new Guid[ids.size()]);
        Long[] values_array = values.toArray(new Long[values.size()]);
        for (int i = 0; i < ids_array.length; i++) {
            executedUpdatedOvfGenerationIdsInDb.put(ids_array[i], values_array[i]);
        }
        return null;
    }).when(vmAndTemplatesGenerationsDao).updateOvfGenerations(any(), any(), any());
    doAnswer(invocation -> {
        StoragePoolStatus desiredStatus = (StoragePoolStatus) invocation.getArguments()[0];
        return buildStoragePoolsList().stream().filter(p -> desiredStatus.equals(p.getStatus())).collect(Collectors.toList());
    }).when(storagePoolDao).getAllByStatus(any());
    doReturn(poolDomainsOvfInfo.values().stream().map(Pair::getSecond).collect(Collectors.toList())).when(storageDomainDao).getAllForStoragePool(any());
    doAnswer(invocation -> {
        Guid domainId = (Guid) invocation.getArguments()[0];
        Pair<List<StorageDomainOvfInfo>, StorageDomain> pair = poolDomainsOvfInfo.get(domainId);
        if (pair != null) {
            return pair.getFirst();
        }
        return null;
    }).when(storageDomainOvfInfoDao).getAllForDomain(any());
}
Also used : ClusterDao(org.ovirt.engine.core.dao.ClusterDao) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) StorageDomainOvfInfoDao(org.ovirt.engine.core.dao.StorageDomainOvfInfoDao) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) MockConfigRule.mockConfig(org.ovirt.engine.core.utils.MockConfigRule.mockConfig) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) Collectors(java.util.stream.Collectors) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) VmDao(org.ovirt.engine.core.dao.VmDao) ProcessOvfUpdateParameters(org.ovirt.engine.core.common.action.ProcessOvfUpdateParameters) DbUserDao(org.ovirt.engine.core.dao.DbUserDao) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) VmAndTemplatesGenerationsDao(org.ovirt.engine.core.dao.VmAndTemplatesGenerationsDao) LabelDao(org.ovirt.engine.core.dao.LabelDao) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) MockConfigRule(org.ovirt.engine.core.utils.MockConfigRule) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Mock(org.mockito.Mock) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) HashMap(java.util.HashMap) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) CollectionUtils(org.apache.commons.collections.CollectionUtils) AffinityGroupDao(org.ovirt.engine.core.dao.scheduling.AffinityGroupDao) StorageDomainOvfInfoStatus(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfoStatus) LinkedList(java.util.LinkedList) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Pair(org.ovirt.engine.core.common.utils.Pair) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) VmTemplateStatus(org.ovirt.engine.core.common.businessentities.VmTemplateStatus) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) VM(org.ovirt.engine.core.common.businessentities.VM) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 93 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class AttachStorageDomainToPoolCommandTest method mockGetStorageDomainInfoVdsCommand.

private void mockGetStorageDomainInfoVdsCommand(StorageDomainStatic storageDomain) {
    Pair<StorageDomainStatic, Guid> pairResult = new Pair<>(storageDomain, null);
    VDSReturnValue returnValueForGetStorageDomainInfo = new VDSReturnValue();
    returnValueForGetStorageDomainInfo.setSucceeded(true);
    returnValueForGetStorageDomainInfo.setReturnValue(pairResult);
    when(vdsBrokerFrontend.runVdsCommand(eq(VDSCommandType.HSMGetStorageDomainInfo), any())).thenReturn(returnValueForGetStorageDomainInfo);
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 94 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class GetFileStorageDomainsWithAttachedStoragePoolGuidQueryTest method testNullStorageDomainListQuery.

@Test
public void testNullStorageDomainListQuery() {
    StoragePool storagePool = new StoragePool();
    storagePool.setStatus(StoragePoolStatus.Up);
    mockStoragePoolDao(storagePool);
    // Create parameters
    StorageDomainsAndStoragePoolIdQueryParameters paramsMock = getQueryParameters();
    when(paramsMock.getStorageDomainList()).thenReturn(null);
    // Run 'HSMGetStorageDomainInfo' command
    VDSReturnValue returnValue = new VDSReturnValue();
    returnValue.setSucceeded(true);
    Pair<StorageDomainStatic, Guid> storageDomainToPoolId = new Pair<>(storageDomain.getStorageStaticData(), Guid.newGuid());
    returnValue.setReturnValue(storageDomainToPoolId);
    when(vdsBrokerFrontendMock.runVdsCommand(eq(VDSCommandType.HSMGetStorageDomainInfo), any())).thenReturn(returnValue);
    // Execute command
    getQuery().executeQueryCommand();
    // Assert the query's results
    List<StorageDomainStatic> returnedStorageDomainList = new ArrayList<>();
    assertEquals(returnedStorageDomainList, getQuery().getQueryReturnValue().getReturnValue());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) StorageDomainsAndStoragePoolIdQueryParameters(org.ovirt.engine.core.common.queries.StorageDomainsAndStoragePoolIdQueryParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 95 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class AbstractGetStorageDomainsWithAttachedStoragePoolGuidQueryTestCase method testUnattachedStorageDomainWithStorageDomainsParameterQuery.

@Test
public void testUnattachedStorageDomainWithStorageDomainsParameterQuery() {
    StoragePool storagePool = new StoragePool();
    storagePool.setStatus(StoragePoolStatus.Up);
    mockStoragePoolDao(storagePool);
    // Create parameters
    List<StorageDomain> storageDomainList = new ArrayList<>();
    storageDomainList.add(storageDomain);
    StorageDomainsAndStoragePoolIdQueryParameters paramsMock = getQueryParameters();
    when(paramsMock.getStorageDomainList()).thenReturn(storageDomainList);
    // Run 'HSMGetStorageDomainInfo' command
    VDSReturnValue returnValue = new VDSReturnValue();
    returnValue.setSucceeded(true);
    Pair<StorageDomainStatic, Guid> storageDomainToPoolId = new Pair<>(storageDomain.getStorageStaticData(), null);
    returnValue.setReturnValue(storageDomainToPoolId);
    when(vdsBrokerFrontendMock.runVdsCommand(eq(VDSCommandType.HSMGetStorageDomainInfo), any())).thenReturn(returnValue);
    // Execute command
    getQuery().executeQueryCommand();
    // Assert the query's results
    List<StorageDomainStatic> returnedStorageDomainList = new ArrayList<>();
    assertEquals(returnedStorageDomainList, getQuery().getQueryReturnValue().getReturnValue());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) StorageDomainsAndStoragePoolIdQueryParameters(org.ovirt.engine.core.common.queries.StorageDomainsAndStoragePoolIdQueryParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test) AbstractQueryTest(org.ovirt.engine.core.bll.AbstractQueryTest)

Aggregations

Pair (org.ovirt.engine.core.common.utils.Pair)147 ArrayList (java.util.ArrayList)61 Guid (org.ovirt.engine.core.compat.Guid)61 HashMap (java.util.HashMap)30 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 Test (org.junit.Test)24 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Map (java.util.Map)13 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 VM (org.ovirt.engine.core.common.businessentities.VM)12 HashSet (java.util.HashSet)10 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)10 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)10 EngineException (org.ovirt.engine.core.common.errors.EngineException)9 Callable (java.util.concurrent.Callable)8 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8