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