Search in sources :

Example 21 with ConsumerCapability

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

the class DefaultContentAccessCertServiceAdapter method consumerIsCertV3Capable.

/**
 * Checks if the specified consumer is capable of using v3 certificates
 *
 * @param consumer
 *  The consumer to check
 *
 * @return
 *  true if the consumer is capable of using v3 certificates; false otherwise
 */
private boolean consumerIsCertV3Capable(Consumer consumer) {
    if (consumer == null || consumer.getTypeId() == null) {
        throw new IllegalArgumentException("consumer is null or lacks a consumer type");
    }
    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.");
}
Also used : ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType)

Example 22 with ConsumerCapability

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

the class ConsumerTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
    dest = super.populate(translator, source, dest);
    dest.setId(source.getId()).setUuid(source.getUuid()).setName(source.getName()).setUsername(source.getUsername()).setEntitlementStatus(source.getEntitlementStatus()).setServiceLevel(source.getServiceLevel()).setEntitlementCount(source.getEntitlementCount()).setFacts(source.getFacts()).setLastCheckin(source.getLastCheckin()).setCanActivate(source.isCanActivate()).setContentTags(source.getContentTags()).setAutoheal(source.isAutoheal()).setRecipientOwnerKey(source.getRecipientOwnerKey()).setAnnotations(source.getAnnotations()).setContentAccessMode(source.getContentAccessMode());
    Release release = source.getReleaseVer();
    if (release != null) {
        dest.setReleaseVersion(release.getReleaseVer());
    }
    // Process nested objects if we have a ModelTranslator to use to the translation...
    if (translator != null) {
        if (StringUtils.isNotEmpty(source.getOwnerId())) {
            Owner owner = ownerCurator.findOwnerById(source.getOwnerId());
            dest.setOwner(translator.translate(owner, OwnerDTO.class));
        }
        Environment environment = this.environmentCurator.getConsumerEnvironment(source);
        dest.setEnvironment(translator.translate(environment, EnvironmentDTO.class));
        Set<ConsumerInstalledProduct> installedProducts = source.getInstalledProducts();
        if (installedProducts != null) {
            ObjectTranslator<ConsumerInstalledProduct, ConsumerInstalledProductDTO> cipTranslator = translator.findTranslatorByClass(ConsumerInstalledProduct.class, ConsumerInstalledProductDTO.class);
            Set<ConsumerInstalledProductDTO> ips = new HashSet<>();
            for (ConsumerInstalledProduct cip : installedProducts) {
                if (cip != null) {
                    ConsumerInstalledProductDTO dto = cipTranslator.translate(translator, cip);
                    if (dto != null) {
                        ips.add(dto);
                    }
                }
            }
            dest.setInstalledProducts(ips);
        }
        Set<ConsumerCapability> capabilities = source.getCapabilities();
        if (capabilities != null) {
            Set<CapabilityDTO> capabilitiesDTO = new HashSet<>();
            ObjectTranslator<ConsumerCapability, CapabilityDTO> capabilityTranslator = translator.findTranslatorByClass(ConsumerCapability.class, CapabilityDTO.class);
            for (ConsumerCapability capability : capabilities) {
                if (capability != null) {
                    CapabilityDTO dto = capabilityTranslator.translate(translator, capability);
                    if (dto != null) {
                        capabilitiesDTO.add(dto);
                    }
                }
            }
            dest.setCapabilities(capabilitiesDTO);
        }
        // Temporary measure to maintain API compatibility
        if (source.getTypeId() != null) {
            ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
            dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
        } else {
            dest.setType(null);
        }
        // This will put in the property so that the virtWho instances won't error
        dest.setGuestIds(new ArrayList<>());
        dest.setHypervisorId(translator.translate(source.getHypervisorId(), HypervisorIdDTO.class));
        dest.setIdCert(translator.translate(source.getIdCert(), CertificateDTO.class));
    } else {
        dest.setReleaseVersion(null);
        dest.setOwner(null);
        dest.setEnvironment(null);
        dest.setInstalledProducts(null);
        dest.setCapabilities(null);
        dest.setHypervisorId(null);
        dest.setType(null);
        dest.setIdCert(null);
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) Environment(org.candlepin.model.Environment) ConsumerType(org.candlepin.model.ConsumerType) Release(org.candlepin.model.Release) HashSet(java.util.HashSet)

Example 23 with ConsumerCapability

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

the class ConsumerTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
    dest = super.populate(translator, source, dest);
    dest.setUuid(source.getUuid()).setUsername(source.getUsername()).setServiceLevel(source.getServiceLevel()).setFacts(source.getFacts());
    // Process nested objects if we have a ModelTranslator to use to the translation...
    if (translator != null) {
        if (StringUtils.isNotEmpty(source.getOwnerId())) {
            Owner owner = ownerCurator.findOwnerById(source.getOwnerId());
            dest.setOwner(translator.translate(owner, OwnerDTO.class));
        }
        Set<ConsumerInstalledProduct> installedProducts = source.getInstalledProducts();
        if (installedProducts != null) {
            Set<String> ips = new HashSet<>();
            for (ConsumerInstalledProduct cip : installedProducts) {
                if (cip != null && cip.getProductId() != null) {
                    ips.add(cip.getProductId());
                }
            }
            dest.setInstalledProducts(ips);
        }
        Set<ConsumerCapability> capabilities = source.getCapabilities();
        if (capabilities != null) {
            Set<String> capabilitiesDTO = new HashSet<>();
            for (ConsumerCapability capability : capabilities) {
                if (capability != null && capability.getName() != null) {
                    capabilitiesDTO.add(capability.getName());
                }
            }
            dest.setCapabilities(capabilitiesDTO);
        }
        // Temporary measure to maintain API compatibility
        if (source.getTypeId() != null) {
            ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
            dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
        } else {
            dest.setType(null);
        }
    } else {
        dest.setOwner(null);
        dest.setInstalledProducts(null);
        dest.setCapabilities(null);
        dest.setType(null);
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet)

Example 24 with ConsumerCapability

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

the class ConsumerResourceUpdateTest method consumerCapabilityUpdate.

@Test
public void consumerCapabilityUpdate() {
    ConsumerType ct = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
    this.mockConsumerType(ct);
    Consumer c = getFakeConsumer();
    Set<ConsumerCapability> caps = new HashSet<>();
    ConsumerCapability cca = new ConsumerCapability(c, "capability_a");
    ConsumerCapability ccb = new ConsumerCapability(c, "capability_b");
    ConsumerCapability ccc = new ConsumerCapability(c, "capability_c");
    caps.add(cca);
    caps.add(ccb);
    caps.add(ccc);
    c.setCapabilities(caps);
    c.setType(ct);
    assertEquals(3, c.getCapabilities().size());
    // no capability list in update object does not change existing
    // also shows that setCapabilites can accept null and not error
    ConsumerDTO updated = new ConsumerDTO();
    updated.setCapabilities(null);
    resource.updateConsumer(c.getUuid(), updated, principal);
    assertEquals(3, c.getCapabilities().size());
    // empty capability list in update object does change existing
    updated = new ConsumerDTO();
    updated.setCapabilities(new HashSet<>());
    resource.updateConsumer(c.getUuid(), updated, principal);
    assertEquals(0, c.getCapabilities().size());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementNoCoreCapableListWarn.

@Test
public void preEntitlementNoCoreCapableListWarn() {
    // 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.LIST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    ValidationWarning warning = results.getWarnings().get(0);
    assertEquals("rulewarning.cores.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)

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