use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class AutobindRulesTest method autobindForPhysicalSocketPicksBestFitOvercoverage.
@Test
public void autobindForPhysicalSocketPicksBestFitOvercoverage() {
List<Pool> pools = createSocketPool(2, 100, "1");
pools.addAll(createSocketPool(32, 100, "2"));
setupConsumer("8", false);
List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
// Should always pick the 2 socket subscriptions because there is no over-coverage
assertEquals(1, bestPools.size());
PoolQuantity q = bestPools.get(0);
assertEquals(new Integer(4), q.getQuantity());
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class AutobindRulesTest method testFindBestWithSingleProductSinglePoolReturnsProvidedPool.
@Test
public void testFindBestWithSingleProductSinglePoolReturnsProvidedPool() {
Product product = TestUtil.createProduct(productId, "A test product");
Pool pool = TestUtil.createPool(owner, product);
pool.setId("DEAD-BEEF");
List<Pool> pools = new LinkedList<>();
pools.add(pool);
List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
assertEquals(1, bestPools.size());
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class AutobindRulesTest method autobindForPhysicalSocketPicksBestFitBalanceQuantityStack.
@Test
public void autobindForPhysicalSocketPicksBestFitBalanceQuantityStack() {
List<Pool> pools = createSocketPool(1, 100, "1");
pools.addAll(createSocketPool(5, 100, "1"));
setupConsumer("9", false);
List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
// Should always pick the 2 5 socket subscriptions over 9 1 socket subscriptions
// although we're slightly overconsuming, it's better than wasting subs that may be
// used elsewhere
assertEquals(1, bestPools.size());
PoolQuantity q = bestPools.get(0);
assertEquals(new Integer(2), q.getQuantity());
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class AutobindRulesTest method autobindForPhysicalSocketPicksBestFitStack.
@Test
public void autobindForPhysicalSocketPicksBestFitStack() {
List<Pool> pools = createSocketPool(1, 100, "1");
pools.addAll(createSocketPool(2, 100, "1"));
setupConsumer("32", false);
List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
// Should always pick the 2 socket subscriptions because less are required
assertEquals(1, bestPools.size());
PoolQuantity q = bestPools.get(0);
assertEquals(new Integer(16), q.getQuantity());
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class ConsumerResource method dryBind.
@ApiOperation(notes = "Retrieves a list of Pools and quantities that would be the " + "result of an auto-bind. This is a dry run of an autobind. It allows the client " + "to see what would be the result of an autobind without executing it. It can only" + " do this for the prevously established list of installed products for the consumer" + " If a service level is included in the request, then that level will override " + "the one stored on the consumer. If no service level is included then the existing " + "one will be used. The Response has a list of PoolQuantity objects", value = "dryBind")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{consumer_uuid}/entitlements/dry-run")
public List<PoolQuantityDTO> dryBind(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("service_level") String serviceLevel) {
// Verify consumer exists:
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
if (owner.isAutobindDisabled()) {
throw new BadRequestException(i18n.tr("Owner has autobind disabled."));
}
List<PoolQuantity> dryRunPools = new ArrayList<>();
try {
consumerBindUtil.validateServiceLevel(consumer.getOwnerId(), serviceLevel);
dryRunPools = entitler.getDryRun(consumer, owner, serviceLevel);
} catch (ForbiddenException fe) {
return Collections.<PoolQuantityDTO>emptyList();
} catch (BadRequestException bre) {
throw bre;
} catch (RuntimeException re) {
return Collections.<PoolQuantityDTO>emptyList();
}
if (dryRunPools != null) {
List<PoolQuantityDTO> dryRunPoolDtos = new ArrayList<>();
for (PoolQuantity pq : dryRunPools) {
dryRunPoolDtos.add(this.translator.translate(pq, PoolQuantityDTO.class));
}
return dryRunPoolDtos;
} else {
return Collections.<PoolQuantityDTO>emptyList();
}
}
Aggregations