Search in sources :

Example 96 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class AttachPermissionTest method blocksModifyPool.

@Test
public void blocksModifyPool() {
    Pool p = new Pool();
    p.setOwner(owner);
    assertFalse(perm.canAccess(p, SubResource.NONE, Access.ALL));
}
Also used : Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 97 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class AttachPermissionTest method blocksBindToOtherOrgPools.

@Test
public void blocksBindToOtherOrgPools() {
    Pool p = new Pool();
    Owner owner2 = new Owner("someother", "whatever");
    p.setOwner(owner2);
    assertFalse(perm.canAccess(p, SubResource.ENTITLEMENTS, Access.CREATE));
}
Also used : Owner(org.candlepin.model.Owner) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 98 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class AttachPermissionTest method allowsBindToOrgPools.

@Test
public void allowsBindToOrgPools() {
    Pool p = new Pool();
    p.setOwner(owner);
    assertTrue(perm.canAccess(p, SubResource.ENTITLEMENTS, Access.CREATE));
}
Also used : Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 99 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class SubscriptionReconciler method reconcile.

/**
 *  Reconciles incoming entitlements to existing pools to attempt to limit
 *  the number of pools we must destroy and revoke.
 *
 *  Each set is mapped against the upstream pool ID. Subscriptions originating from
 *  different pools will never match each other for replacement.
 *
 *  First match attempts a direct match of entitlement ID from incoming
 *  entitlements for comparison to existing pools. If so we re-use the existing pool.
 *  (note that despite the same entitlement ID, quantity and other data may have
 *  changed)
 *
 *  Next we attempt to match on exact quantity. This would allow the user to re-create
 *  a distributor upstream and re-assign it the same entitlement quantities from the
 *  same pools, without triggering a mass regen on import.
 *
 *  The last attempt will order the remaining incoming entitlements by quantity, and
 *  match these against a quantity ordered list of the remaining pools for that
 *  upstream pool.
 *
 *  Remaining incoming subscriptions that did not match any pools per the above are
 *  treated as new subscriptions.
 *
 * @param owner
 *  The owner for which the subscriptions are being imported
 *
 * @param subsToImport
 *  A collection of subscriptions which are being imported
 *
 * @return
 *  The collection of reconciled subscriptions
 */
public Collection<Subscription> reconcile(Owner owner, Collection<Subscription> subsToImport) {
    Map<String, Map<String, Pool>> existingPoolsByUpstreamPool = this.mapPoolsByUpstreamPool(owner);
    // if we can match to the entitlement id do it.
    // we need a new list to hold the ones that are left
    Set<Subscription> subscriptionsStillToImport = new HashSet<>();
    for (Subscription subscription : subsToImport) {
        Pool local = null;
        Map<String, Pool> map = existingPoolsByUpstreamPool.get(subscription.getUpstreamPoolId());
        if (map == null || map.isEmpty()) {
            log.info("New subscription for incoming entitlement ID: {}", subscription.getUpstreamEntitlementId());
            continue;
        }
        local = map.get(subscription.getUpstreamEntitlementId());
        if (local != null) {
            mergeSubscription(subscription, local, map);
            log.info("Merging subscription for incoming entitlement id [{}] into subscription with " + "existing entitlement id [{}]. Entitlement id match.", subscription.getUpstreamEntitlementId(), local.getUpstreamEntitlementId());
        } else {
            subscriptionsStillToImport.add(subscription);
            log.warn("Subscription for incoming entitlement id [{}] does not have an entitlement id " + "match in the current subscriptions for the upstream pool id [{}]", subscription.getUpstreamEntitlementId(), subscription.getUpstreamPoolId());
        }
    }
    // matches will be made against the upstream pool id and quantity.
    // we need a new list to hold the ones that are left
    List<Subscription> subscriptionsNeedQuantityMatch = new ArrayList<>();
    for (Subscription subscription : subscriptionsStillToImport) {
        Pool local = null;
        Map<String, Pool> map = existingPoolsByUpstreamPool.get(subscription.getUpstreamPoolId());
        if (map == null) {
            map = new HashMap<>();
        }
        for (Pool localSub : map.values()) {
            // TODO quantity
            long quantity = localSub.getQuantity() != null ? localSub.getQuantity() : 1;
            long multiplier = localSub.getProduct().getMultiplier() != null ? localSub.getProduct().getMultiplier() : 1;
            Long effectiveQuantity = Long.valueOf(quantity / multiplier);
            if (effectiveQuantity.equals(subscription.getQuantity())) {
                local = localSub;
                break;
            }
        }
        if (local != null) {
            mergeSubscription(subscription, local, map);
            log.info("Merging subscription for incoming entitlement id [{}] into subscription with " + "existing entitlement id [{}]. Exact quantity match.", subscription.getUpstreamEntitlementId(), local.getUpstreamEntitlementId());
        } else {
            subscriptionsNeedQuantityMatch.add(subscription);
            log.warn("Subscription for incoming entitlement id [{}] does not have an exact quantity " + "match in the current subscriptions for the upstream pool id [{}]", subscription.getUpstreamEntitlementId(), subscription.getUpstreamPoolId());
        }
    }
    // matches will be made against the upstream pool id and quantity.
    // quantities will just match by position from highest to lowest
    // we need a new list to hold the ones that are left
    Subscription[] inNeed = subscriptionsNeedQuantityMatch.toArray(new Subscription[0]);
    Arrays.sort(inNeed, new SubQuantityComparator());
    for (Subscription subscription : inNeed) {
        Pool local = null;
        Map<String, Pool> map = existingPoolsByUpstreamPool.get(subscription.getUpstreamPoolId());
        if (map == null || map.isEmpty()) {
            log.info("Creating new subscription for incoming entitlement with id [{}]", subscription.getUpstreamEntitlementId());
            continue;
        }
        Pool[] locals = map.values().toArray(new Pool[0]);
        Arrays.sort(locals, new QuantityComparator());
        local = locals[0];
        mergeSubscription(subscription, local, map);
        log.info("Merging subscription for incoming entitlement id [{}] into subscription with " + "existing entitlement id [{}] Ordered quantity match.", subscription.getUpstreamEntitlementId(), local.getUpstreamEntitlementId());
    }
    return subsToImport;
}
Also used : ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 100 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class ConsumerPrincipalTest method noAaccessToListEntitlementsInPool.

@Test
public void noAaccessToListEntitlementsInPool() {
    Pool p = mock(Pool.class);
    when(p.getOwner()).thenReturn(o);
    assertFalse(principal.canAccess(p, SubResource.ENTITLEMENTS, Access.READ_ONLY));
}
Also used : Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30