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);
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations