Search in sources :

Example 16 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testRegenerateEntitlementCertificatesWithSingleEntitlement.

@Test
public void testRegenerateEntitlementCertificatesWithSingleEntitlement() throws Exception {
    AutobindData data = AutobindData.create(childVirtSystem, o).on(new Date()).forProducts(new String[] { provisioning.getId() });
    this.entitlementCurator.refresh(poolManager.entitleByProducts(data).get(0));
    regenerateECAndAssertNotSameCertificates();
}
Also used : AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 17 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class ConsumerResource method revokeOnGuestMigration.

/*
     * Check if this consumer is a guest, and if it appears to have migrated.
     * We only check for existing entitlements, restricted to a host that does not match
     * the guest's current host, as determined by the most recent guest ID report in the
     * db. If autobind has been disabled for the guest's owner, the host_restricted entitlements
     * from the old host are still removed, but no auto-bind occurs.
     */
protected void revokeOnGuestMigration(Consumer guest) {
    if (guest == null || !guest.isGuest() || !guest.hasFact("virt.uuid")) {
        // No consumer provided, it's not a guest or it doesn't have a virt UUID
        return;
    }
    Consumer host = consumerCurator.getHost(guest);
    // we need to create a list of entitlements to delete before actually
    // deleting, otherwise we are tampering with the loop iterator (BZ #786730)
    Set<Entitlement> deletableGuestEntitlements = new HashSet<>();
    log.debug("Revoking {} entitlements not matching host: {}", guest, host);
    for (Entitlement entitlement : guest.getEntitlements()) {
        Pool pool = entitlement.getPool();
        // virt-only then the host-guest dynamic doesn't apply, so skip it.
        if (!pool.hasAttribute(Pool.Attributes.REQUIRES_HOST) && !pool.isUnmappedGuestPool() && !isVirtOnly(pool)) {
            continue;
        }
        if (pool.hasAttribute(Pool.Attributes.REQUIRES_HOST)) {
            String requiredHost = getRequiredHost(pool);
            if (host != null && !requiredHost.equals(host.getUuid())) {
                log.debug("Removing entitlement {} from guest {} due to host mismatch.", entitlement.getId(), guest.getUuid());
                deletableGuestEntitlements.add(entitlement);
            }
        } else if (pool.isUnmappedGuestPool() && host != null) {
            log.debug("Removing unmapped guest pool from {} now that it is mapped", guest.getUuid());
            deletableGuestEntitlements.add(entitlement);
        }
    }
    // perform the entitlement revocation
    for (Entitlement entitlement : deletableGuestEntitlements) {
        poolManager.revokeEntitlement(entitlement);
    }
    if (deletableGuestEntitlements.size() > 0) {
        // auto heal guests after revocations
        boolean hasInstalledProducts = guest.getInstalledProducts() != null && !guest.getInstalledProducts().isEmpty();
        if (guest.isAutoheal() && !deletableGuestEntitlements.isEmpty() && hasInstalledProducts) {
            Owner owner = ownerCurator.findOwnerById(guest.getOwnerId());
            AutobindData autobindData = AutobindData.create(guest, owner).on(new Date());
            // perform the autobind for the guest.
            try {
                List<Entitlement> ents = entitler.bindByProducts(autobindData);
                entitler.sendEvents(ents);
            } catch (AutobindDisabledForOwnerException e) {
                log.warn("Guest auto-attach skipped. {}", e.getMessage());
            }
        }
    }
}
Also used : Owner(org.candlepin.model.Owner) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) AutobindDisabledForOwnerException(org.candlepin.controller.AutobindDisabledForOwnerException) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 18 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class Entitler method bindByProducts.

public List<Entitlement> bindByProducts(String[] productIds, String consumeruuid, Date entitleDate, Collection<String> fromPools) throws AutobindDisabledForOwnerException {
    Consumer c = consumerCurator.findByUuid(consumeruuid);
    Owner o = ownerCurator.findOwnerById(c.getOwnerId());
    AutobindData data = AutobindData.create(c, o).on(entitleDate).forProducts(productIds).withPools(fromPools);
    return bindByProducts(data);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) AutobindData(org.candlepin.resource.dto.AutobindData)

Example 19 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class ConsumerResourceTest method futureHealing.

@Test
public void futureHealing() throws Exception {
    Owner o = createOwner();
    o.setId(TestUtil.randomString());
    Consumer c = createConsumer(o);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
    Set<ConsumerInstalledProduct> products = new HashSet<>();
    products.add(cip);
    when(mockOwnerCurator.findOwnerById(eq(o.getId()))).thenReturn(o);
    when(cip.getProductId()).thenReturn("product-foo");
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq(c.getUuid()))).thenReturn(c);
    ConsumerResource cr = new ConsumerResource(cc, mockConsumerTypeCurator, null, sa, this.mockOwnerServiceAdapter, null, null, null, null, null, null, null, null, null, null, null, mockOwnerCurator, null, e, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    String dtStr = "2011-09-26T18:10:50.184081+00:00";
    Date dt = ResourceDateParser.parseDateString(dtStr);
    cr.bind(c.getUuid(), null, null, null, null, null, false, dtStr, null);
    AutobindData data = AutobindData.create(c, o).on(dt);
    verify(e).bindByProducts(eq(data));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) AutobindData(org.candlepin.resource.dto.AutobindData) Matchers.anyString(org.mockito.Matchers.anyString) Entitler(org.candlepin.controller.Entitler) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) ConsumerCurator(org.candlepin.model.ConsumerCurator) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class ConsumerBindUtilTest method registerWithKeyWithPoolAndInstalledProductsAutoAttach.

@Test
public void registerWithKeyWithPoolAndInstalledProductsAutoAttach() throws Exception {
    Product prod = TestUtil.createProduct();
    String[] prodIds = new String[] { prod.getId() };
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setId("id-string");
    List<String> poolIds = new ArrayList<>();
    poolIds.add(pool.getId());
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    key1.addPool(pool, 0L);
    key1.setAutoAttach(true);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    Set<ConsumerInstalledProduct> cips = new HashSet<>();
    ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod);
    cips.add(cip);
    consumer.setInstalledProducts(cips);
    AutobindData ad = new AutobindData(consumer, owner).withPools(poolIds).forProducts(prodIds);
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
    verify(entitler).bindByProducts(eq(ad));
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AutobindData (org.candlepin.resource.dto.AutobindData)27 Test (org.junit.Test)22 Date (java.util.Date)18 Consumer (org.candlepin.model.Consumer)17 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)16 Product (org.candlepin.model.Product)15 ArrayList (java.util.ArrayList)13 Pool (org.candlepin.model.Pool)13 Owner (org.candlepin.model.Owner)12 HashSet (java.util.HashSet)11 Entitlement (org.candlepin.model.Entitlement)10 List (java.util.List)8 ProductData (org.candlepin.model.dto.ProductData)5 LinkedList (java.util.LinkedList)4 CandlepinQuery (org.candlepin.model.CandlepinQuery)4 ValidationResult (org.candlepin.policy.ValidationResult)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Set (java.util.Set)3 Page (org.candlepin.common.paging.Page)3 PageRequest (org.candlepin.common.paging.PageRequest)3