Search in sources :

Example 16 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementNoCoreCapableBindError.

@Test
public void preEntitlementNoCoreCapableBindError() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("cpu.core(s)_per_socket", "2");
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.CORES, "2");
    Pool p = TestUtil.createPool(prod);
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
    assertNotNull(results);
    assertEquals(0, results.getWarnings().size());
    ValidationError error = results.getErrors().get(0);
    assertEquals("rulefailed.cores.unsupported.by.consumer", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementNoRamCapableListWarn.

@Test
public void preEntitlementNoRamCapableListWarn() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("memory.memtotal", "2000000");
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.RAM, "2");
    Pool p = TestUtil.createPool(prod);
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.LIST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    ValidationWarning warning = results.getWarnings().get(0);
    assertEquals("rulewarning.ram.unsupported.by.consumer", warning.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationWarning(org.candlepin.policy.ValidationWarning) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with ConsumerCapability

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

the class ConsumerTranslatorTest method initSourceObject.

@Override
protected Consumer initSourceObject() {
    ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
    Environment environment = this.environmentTranslatorTest.initSourceObject();
    Owner owner = this.ownerTranslatorTest.initSourceObject();
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    Consumer consumer = new Consumer();
    consumer.setId("consumer_id");
    consumer.setUuid("consumer_uuid");
    consumer.setName("consumer_name");
    consumer.setUsername("consumer_user_name");
    consumer.setEntitlementStatus("consumer_ent_status");
    consumer.setServiceLevel("consumer_service_level");
    consumer.setReleaseVer(new Release("releaseVer"));
    consumer.setOwner(owner);
    consumer.setEnvironment(environment);
    consumer.setEntitlementCount(0L);
    consumer.setLastCheckin(new Date());
    consumer.setCanActivate(Boolean.TRUE);
    consumer.setHypervisorId(hypervisorIdTranslatorTest.initSourceObject());
    consumer.setAutoheal(Boolean.TRUE);
    consumer.setRecipientOwnerKey("test_recipient_owner_key");
    consumer.setAnnotations("test_annotations");
    consumer.setContentAccessMode("test_content_access_mode");
    consumer.setIdCert((IdentityCertificate) this.certificateTranslatorTest.initSourceObject());
    consumer.setType(ctype);
    Map<String, String> facts = new HashMap<>();
    for (int i = 0; i < 5; ++i) {
        facts.put("fact-" + i, "value-" + i);
    }
    consumer.setFacts(facts);
    Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        ConsumerInstalledProduct installedProduct = cipTranslatorTest.initSourceObject();
        installedProduct.setId("installedProduct-" + i);
        installedProducts.add(installedProduct);
    }
    consumer.setInstalledProducts(installedProducts);
    Set<ConsumerCapability> capabilities = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        ConsumerCapability capability = capabilityTranslatorTest.initSourceObject();
        capability.setName("capability-" + i);
        capabilities.add(capability);
    }
    consumer.setCapabilities(capabilities);
    Set<String> contentTags = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        contentTags.add("contentTag-" + i);
    }
    consumer.setContentTags(contentTags);
    List<GuestId> guestIds = new LinkedList<>();
    for (int i = 0; i < 5; ++i) {
        GuestId guestId = guestIdTranslatorTest.initSourceObject();
        guestId.setId("guestId-" + i);
        guestIds.add(guestId);
    }
    consumer.setGuestIds(guestIds);
    when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(mockEnvironmentCurator.find(eq(environment.getId()))).thenReturn(environment);
    when(mockEnvironmentCurator.getConsumerEnvironment(eq(consumer))).thenReturn(environment);
    return consumer;
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) Date(java.util.Date) LinkedList(java.util.LinkedList) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Environment(org.candlepin.model.Environment) ConsumerType(org.candlepin.model.ConsumerType) Release(org.candlepin.model.Release) HashSet(java.util.HashSet)

Example 19 with ConsumerCapability

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

the class DefaultEntitlementCertServiceAdapter method shouldGenerateV3.

/**
 * Checks if the specified consumer is capable of using v3 certificates
 *
 * @param consumer
 *  The consumer to check
 *
 * @return
 *  true if the consumer should use v3 certificates; false otherwise
 */
private boolean shouldGenerateV3(Consumer consumer) {
    if (consumer != null) {
        ConsumerType type = this.consumerTypeCurator.getConsumerType(consumer);
        if (type.isManifest()) {
            for (ConsumerCapability capability : consumer.getCapabilities()) {
                if ("cert_v3".equals(capability.getName())) {
                    return true;
                }
            }
            return false;
        } else if (type.isType(ConsumerTypeEnum.HYPERVISOR)) {
            // Hypervisors in this context don't use content, so V3 is allowed
            return true;
        }
        // Consumer isn't a special type, check their certificate_version fact
        String entitlementVersion = consumer.getFact("system.certificate_version");
        return entitlementVersion != null && entitlementVersion.startsWith("3.");
    }
    return false;
}
Also used : ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType)

Example 20 with ConsumerCapability

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

the class ConsumerResource method updateCapabilities.

/**
 * @param existing
 * @param update
 * @return a String object
 */
private boolean updateCapabilities(Consumer existing, ConsumerDTO update) {
    boolean change = false;
    if (update == null) {
        // create
        if ((existing.getCapabilities() == null || existing.getCapabilities().isEmpty()) && existing.getFact("distributor_version") != null) {
            Set<DistributorVersionCapability> capabilities = distributorVersionCurator.findCapabilitiesByDistVersion(existing.getFact("distributor_version"));
            if (capabilities != null) {
                Set<ConsumerCapability> ccaps = new HashSet<>();
                for (DistributorVersionCapability dvc : capabilities) {
                    ConsumerCapability cc = new ConsumerCapability(existing, dvc.getName());
                    ccaps.add(cc);
                }
                existing.setCapabilities(ccaps);
            }
            change = true;
        }
    } else {
        // update
        if (update.getCapabilities() != null) {
            Set<ConsumerCapability> entityCapabilities = populateCapabilities(existing, update);
            if (!entityCapabilities.equals(existing.getCapabilities())) {
                existing.setCapabilities(entityCapabilities);
                change = true;
            }
        } else if (update.getFact("distributor_version") != null) {
            DistributorVersion dv = distributorVersionCurator.findByName(update.getFact("distributor_version"));
            if (dv != null) {
                Set<ConsumerCapability> ccaps = new HashSet<>();
                for (DistributorVersionCapability dvc : dv.getCapabilities()) {
                    ConsumerCapability cc = new ConsumerCapability(existing, dvc.getName());
                    ccaps.add(cc);
                }
                existing.setCapabilities(ccaps);
            }
            change = true;
        }
    }
    if (change) {
        log.debug("Capabilities changed.");
    } else {
        log.debug("Capability list either null or does not contain changes.");
    }
    return change;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) DistributorVersionCapability(org.candlepin.model.DistributorVersionCapability) ConsumerCapability(org.candlepin.model.ConsumerCapability) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) DistributorVersion(org.candlepin.model.DistributorVersion)

Aggregations

ConsumerCapability (org.candlepin.model.ConsumerCapability)26 HashSet (java.util.HashSet)19 Consumer (org.candlepin.model.Consumer)15 Test (org.junit.Test)14 ConsumerType (org.candlepin.model.ConsumerType)11 Pool (org.candlepin.model.Pool)11 Product (org.candlepin.model.Product)11 ValidationResult (org.candlepin.policy.ValidationResult)11 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)7 Environment (org.candlepin.model.Environment)4 Owner (org.candlepin.model.Owner)4 HashMap (java.util.HashMap)3 Release (org.candlepin.model.Release)3 ValidationError (org.candlepin.policy.ValidationError)3 ValidationWarning (org.candlepin.policy.ValidationWarning)3 ArrayList (java.util.ArrayList)2 GuestId (org.candlepin.model.GuestId)2 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1