Search in sources :

Example 6 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementSuccessRamCapable.

@Test
public void preEntitlementSuccessRamCapable() {
    // 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<>();
    ConsumerCapability cc = new ConsumerCapability(c, "ram");
    caps.add(cc);
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.RAM, "2");
    Pool p = TestUtil.createPool(prod);
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    assertEquals(0, results.getWarnings().size());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementSuccessCoreCapable.

@Test
public void preEntitlementSuccessCoreCapable() {
    // 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<>();
    ConsumerCapability cc = new ConsumerCapability(c, "cores");
    caps.add(cc);
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.CORES, "2");
    Pool p = TestUtil.createPool(prod);
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    assertEquals(0, results.getWarnings().size());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementNoInstanceCapableListWarn.

@Test
public void preEntitlementNoInstanceCapableListWarn() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "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.instance.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 9 with ConsumerCapability

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

the class ConsumerResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO, during consumer creation (not update).
 * This method will not set the ID, entitlementStatus, complianceStatusHash, idCert, entitlements,
 * keyPair and canActivate, because clients are not allowed to create or update those properties.
 *
 * while autoheal is populated, it is overridden in create method.
 *
 * owner is not populated because create populates it differently.
 *
 * @param entity
 *  The entity instance to populate
 *
 * @param dto
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
protected void populateEntity(Consumer entity, ConsumerDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the consumer model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the consumer dto is null");
    }
    if (dto.getCreated() != null) {
        entity.setCreated(dto.getCreated());
    }
    if (dto.getName() != null) {
        entity.setName(dto.getName());
    }
    if (dto.getUuid() != null) {
        entity.setUuid(dto.getUuid());
    }
    if (dto.getFacts() != null) {
        entity.setFacts(dto.getFacts());
    }
    if (dto.getUsername() != null) {
        entity.setUsername(dto.getUsername());
    }
    if (dto.getServiceLevel() != null) {
        entity.setServiceLevel(dto.getServiceLevel());
    }
    if (dto.getReleaseVersion() != null) {
        entity.setReleaseVer(new Release(dto.getReleaseVersion()));
    }
    if (dto.getEnvironment() != null) {
        Environment env = environmentCurator.find(dto.getEnvironment().getId());
        if (env == null) {
            throw new NotFoundException(i18n.tr("Environment \"{0}\" could not be found.", dto.getEnvironment().getId()));
        }
        entity.setEnvironment(env);
    }
    if (dto.getLastCheckin() != null) {
        entity.setLastCheckin(dto.getLastCheckin());
    }
    if (dto.getCapabilities() != null) {
        Set<ConsumerCapability> capabilities = populateCapabilities(entity, dto);
        entity.setCapabilities(capabilities);
    }
    if (dto.getGuestIds() != null) {
        List<GuestId> guestIds = new ArrayList<>();
        for (GuestIdDTO guestIdDTO : dto.getGuestIds()) {
            if (guestIdDTO != null) {
                guestIds.add(new GuestId(guestIdDTO.getGuestId(), entity, guestIdDTO.getAttributes()));
            }
        }
        entity.setGuestIds(guestIds);
    }
    if (dto.getHypervisorId() != null && entity.getOwnerId() != null) {
        HypervisorId hypervisorId = new HypervisorId(entity, ownerCurator.findOwnerById(entity.getOwnerId()), dto.getHypervisorId().getHypervisorId(), dto.getHypervisorId().getReporterId());
        entity.setHypervisorId(hypervisorId);
    }
    if (dto.getHypervisorId() == null && dto.getFact("system_uuid") != null && !"true".equals(dto.getFact("virt.is_guest")) && entity.getOwnerId() != null) {
        HypervisorId hypervisorId = new HypervisorId(entity, ownerCurator.findOwnerById(entity.getOwnerId()), dto.getFact("system_uuid"));
        entity.setHypervisorId(hypervisorId);
    }
    if (dto.getContentTags() != null) {
        entity.setContentTags(dto.getContentTags());
    }
    if (dto.getAutoheal() != null) {
        entity.setAutoheal(dto.getAutoheal());
    }
    if (dto.getContentAccessMode() != null) {
        entity.setContentAccessMode(dto.getContentAccessMode());
    }
    if (dto.getRecipientOwnerKey() != null) {
        entity.setRecipientOwnerKey(dto.getRecipientOwnerKey());
    }
    if (dto.getAnnotations() != null) {
        entity.setAnnotations(dto.getAnnotations());
    }
    if (dto.getInstalledProducts() != null) {
        Set<ConsumerInstalledProduct> installedProducts = populateInstalledProducts(entity, dto);
        entity.setInstalledProducts(installedProducts);
    }
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerCapability(org.candlepin.model.ConsumerCapability) GuestId(org.candlepin.model.GuestId) Environment(org.candlepin.model.Environment) HypervisorId(org.candlepin.model.HypervisorId) Release(org.candlepin.model.Release)

Example 10 with ConsumerCapability

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

the class AutobindRules 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) {
        throw new IllegalArgumentException("consumer is 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.");
}
Also used : ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType)

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