Search in sources :

Example 51 with Pair

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

the class GetExistingStorageDomainListQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    ArrayList<StorageDomain> returnValue = new ArrayList<>();
    VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.HSMGetStorageDomainsList, new HSMGetStorageDomainsListVDSCommandParameters(getParameters().getId(), Guid.Empty, null, getParameters().getStorageDomainType(), getParameters().getPath()));
    if (vdsReturnValue.getSucceeded()) {
        ArrayList<Guid> guidsFromIrs = (ArrayList<Guid>) vdsReturnValue.getReturnValue();
        HashSet<Guid> guidsFromDb = new HashSet<>();
        if (guidsFromIrs.size() > 0) {
            List<StorageDomain> domainsInDb = storageDomainDao.getAll();
            for (StorageDomain domain : domainsInDb) {
                guidsFromDb.add(domain.getId());
            }
            for (Guid domainId : guidsFromIrs) {
                if (!guidsFromDb.contains(domainId)) {
                    Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getParameters().getId(), domainId)).getReturnValue();
                    StorageDomain domain = new StorageDomain();
                    domain.setStorageStaticData(domainFromIrs.getFirst());
                    domain.setStoragePoolId(domainFromIrs.getSecond());
                    if (getParameters().getStorageFormatType() == null || getParameters().getStorageFormatType() == domain.getStorageFormat()) {
                        if (getParameters().getStorageType() != null && domain.getStorageType().getValue() != getParameters().getStorageType().getValue()) {
                            log.warn("The storage type of domain {} has been changed from {} to {}", domain.getStorageName(), domain.getStorageType().toString(), getParameters().getStorageType().toString());
                            domain.setStorageType(getParameters().getStorageType());
                        }
                        returnValue.add(domain);
                    }
                }
            }
        }
        getQueryReturnValue().setReturnValue(returnValue);
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ArrayList(java.util.ArrayList) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) HSMGetStorageDomainsListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainsListVDSCommandParameters) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashSet(java.util.HashSet) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 52 with Pair

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

the class RankSelectorPolicyUnitTest method testSameWeightRanking.

@Test
public void testSameWeightRanking() {
    RankSelectorPolicyUnit.Selector selector = new RankSelectorPolicyUnit.Selector();
    List<Pair<Guid, Integer>> units = new ArrayList<>();
    units.add(new Pair<Guid, Integer>(unit1, 1));
    units.add(new Pair<Guid, Integer>(unit2, 100));
    selector.init(units, hosts);
    selector.record(unit1, host1, 200);
    selector.record(unit1, host2, 300);
    selector.record(unit1, host3, 200);
    selector.record(unit2, host3, 1);
    Guid best = selector.best().get();
    assertEquals(host1, best);
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 53 with Pair

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

the class RankSelectorPolicyUnitTest method testRanking.

@Test
public void testRanking() {
    RankSelectorPolicyUnit.Selector selector = new RankSelectorPolicyUnit.Selector();
    List<Pair<Guid, Integer>> units = new ArrayList<>();
    units.add(new Pair<Guid, Integer>(unit1, 1));
    units.add(new Pair<Guid, Integer>(unit2, 100));
    selector.init(units, hosts);
    selector.record(unit1, host1, 500000);
    selector.record(unit1, host2, 1000);
    selector.record(unit1, host3, 85366814);
    selector.record(unit2, host3, 50);
    selector.record(unit2, host1, 100);
    Guid best = selector.best().get();
    assertEquals(host2, best);
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 54 with Pair

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

the class BasicWeightSelectorPolicyUnitTest method testNormalizedWeightsWithExternalScheduler.

@Test
public void testNormalizedWeightsWithExternalScheduler() {
    BasicWeightSelectorPolicyUnit.Selector selector = new BasicWeightSelectorPolicyUnit.Selector();
    List<Pair<Guid, Integer>> units = new ArrayList<>();
    units.add(new Pair<Guid, Integer>(unit1, 1));
    units.add(new Pair<Guid, Integer>(unit2, 100));
    selector.init(units, hosts);
    // External scheduler result does not have unit Guid
    selector.record(null, host1, 50);
    selector.record(unit1, host2, 10);
    selector.record(unit1, host3, 200);
    selector.record(unit2, host2, 5);
    selector.record(unit2, host1, 10);
    Guid best = selector.best().get();
    assertEquals(host3, best);
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 55 with Pair

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

the class EvenDistributionWeightPolicyUnitTest method selectedBestHost.

protected <T extends EvenDistributionWeightPolicyUnit> Guid selectedBestHost(T unit, VM vm, ArrayList<VDS> hosts) {
    List<Pair<Guid, Integer>> scores = unit.score(new Cluster(), hosts, vm, null);
    scores.sort(Comparator.comparing(Pair::getSecond));
    return scores.get(0).getFirst();
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Pair(org.ovirt.engine.core.common.utils.Pair)

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