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());
}
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());
}
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());
}
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);
}
}
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.");
}
Aggregations