public List<PoolQuantity> getBestPoolsForHost(Consumer guest,
Consumer host, Date entitleDate, Owner owner,
String serviceLevelOverride, Collection<String> fromPools)
throws EntitlementRefusedException {
ValidationResult failedResult = null;
Date activePoolDate = entitleDate;
if (entitleDate == null) {
activePoolDate = new Date();
}
PoolFilterBuilder poolFilter = new PoolFilterBuilder();
poolFilter.addIdFilters(fromPools);
List<Pool> allOwnerPools = this.listAvailableEntitlementPools(
host, null, owner, (String) null, activePoolDate, true, false,
poolFilter, null).getPageData();
List<Pool> allOwnerPoolsForGuest = this.listAvailableEntitlementPools(
guest, null, owner, (String) null, activePoolDate,
true, false, poolFilter,
null).getPageData();
for (Entitlement ent : host.getEntitlements()) {
//filter out pools that are attached, there is no need to
//complete partial stacks, as they are already granting
//virtual pools
allOwnerPools.remove(ent.getPool());
}
List<Pool> filteredPools = new LinkedList<Pool>();
ComplianceStatus guestCompliance = complianceRules.getStatus(guest, entitleDate, false);
Set<String> tmpSet = new HashSet<String>();
//we only want to heal red products, not yellow
tmpSet.addAll(guestCompliance.getNonCompliantProducts());
/*Do not attempt to create subscriptions for products that
already have virt_only pools available to the guest */
Set<String> productsToRemove = new HashSet<String>();
for (Pool pool : allOwnerPoolsForGuest) {
if (pool.hasProductAttribute("virt_only") || pool.hasAttribute("virt_only")) {
for (String prodId : tmpSet) {
if (pool.provides(prodId)) {
productsToRemove.add(prodId);
}
}
}
}
tmpSet.removeAll(productsToRemove);
String[] productIds = tmpSet.toArray(new String [] {});
if (log.isDebugEnabled()) {
log.debug("Attempting for products on date: " + entitleDate);
for (String productId : productIds) {
log.debug(" " + productId);
}
}
for (Pool pool : allOwnerPools) {
boolean providesProduct = false;
// Would parse the int here, but it can be 'unlimited'
// and we only need to check that it's non-zero
if (pool.hasProductAttribute("virt_limit") &&
!pool.getProductAttribute("virt_limit").getValue().equals("0")) {
for (String productId : productIds) {
// If this is a derived pool, we need to see if the derived product
// provides anything for the guest, otherwise we use the parent.
if (pool.providesDerived(productId)) {
providesProduct = true;
break;
}
}
}
if (providesProduct) {
ValidationResult result = enforcer.preEntitlement(host,
pool, 1, CallerType.BEST_POOLS);
if (result.hasErrors() || result.hasWarnings()) {
// Just keep the last one around, if we need it
failedResult = result;
if (log.isDebugEnabled()) {
log.debug("Pool filtered from candidates due to rules " +
"failure: " +