Search in sources :

Example 31 with PoolQuantity

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());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 32 with PoolQuantity

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());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 33 with PoolQuantity

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());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 34 with PoolQuantity

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());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 35 with PoolQuantity

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();
    }
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) PoolQuantityDTO(org.candlepin.dto.api.v1.PoolQuantityDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PoolQuantity (org.candlepin.model.PoolQuantity)75 Pool (org.candlepin.model.Pool)65 Test (org.junit.Test)52 Entitlement (org.candlepin.model.Entitlement)34 LinkedList (java.util.LinkedList)30 Product (org.candlepin.model.Product)28 HashMap (java.util.HashMap)27 ArrayList (java.util.ArrayList)21 Consumer (org.candlepin.model.Consumer)12 List (java.util.List)11 ConsumerType (org.candlepin.model.ConsumerType)11 Matchers.anyString (org.mockito.Matchers.anyString)11 Date (java.util.Date)8 Set (java.util.Set)8 HashSet (java.util.HashSet)7 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)7 ValidationResult (org.candlepin.policy.ValidationResult)7 Subscription (org.candlepin.model.dto.Subscription)6 Matchers.anyLong (org.mockito.Matchers.anyLong)6 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)5