use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResource method exportCertificates.
@ApiOperation(notes = "Retrieves a Compressed File of Entitlement Certificates", value = "exportCertificates")
@ApiResponses({ @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces("application/zip")
@Path("/{consumer_uuid}/certificates")
public File exportCertificates(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("serials") String serials) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert export", consumer);
return null;
}
revokeOnGuestMigration(consumer);
Set<Long> serialSet = this.extractSerials(serials);
// empty
if (serialSet.isEmpty()) {
serialSet = null;
}
File archive;
try {
archive = manifestManager.generateEntitlementArchive(consumer, serialSet);
response.addHeader("Content-Disposition", "attachment; filename=" + archive.getName());
return archive;
} catch (ExportCreationException e) {
throw new IseException(i18n.tr("Unable to create entitlement certificate archive"), e);
}
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerTypeResource method create.
@ApiOperation(notes = "Creates a Consumer Type", value = "create")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ConsumerTypeDTO create(@ApiParam(name = "consumerType", required = true) ConsumerTypeDTO dto) throws BadRequestException {
try {
ConsumerType type = new ConsumerType();
this.populateEntity(type, dto);
type = consumerTypeCurator.create(type);
return this.translator.translate(type, ConsumerTypeDTO.class);
} catch (Exception e) {
log.error("Problem creating unit type: ", e);
throw new BadRequestException(i18n.tr("Problem creating unit type: {0}", dto));
}
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class EntitlementRules method postUnbindVirtLimit.
private void postUnbindVirtLimit(PoolManager poolManager, Entitlement entitlement, Pool pool, Consumer consumer, Map<String, String> attributes) {
log.debug("Running virt_limit post unbind.");
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
boolean hostLimited = "true".equals(attributes.get(Product.Attributes.HOST_LIMITED));
if (!config.getBoolean(ConfigProperties.STANDALONE) && !hostLimited && ctype.isManifest()) {
// We're making an assumption that VIRT_LIMIT is defined the same way in every possible
// source for the attributes map.
String virtLimit = attributes.get(Product.Attributes.VIRT_LIMIT);
if (!"unlimited".equals(virtLimit)) {
// As we have unbound an entitlement from a physical pool that was previously
// exported, we need to add back the reduced bonus pool quantity.
int virtQuantity = Integer.parseInt(virtLimit) * entitlement.getQuantity();
if (virtQuantity > 0) {
List<Pool> pools = poolManager.lookupBySubscriptionId(pool.getOwner(), pool.getSubscriptionId());
for (int idex = 0; idex < pools.size(); idex++) {
Pool derivedPool = pools.get(idex);
if (derivedPool.getAttributeValue(Pool.Attributes.DERIVED_POOL) != null) {
poolManager.updatePoolQuantity(derivedPool, virtQuantity);
}
}
}
} else {
// As we have unbound an entitlement from a physical pool that
// was previously
// exported, we need to set the unlimited bonus pool quantity to
// -1.
List<Pool> pools = poolManager.lookupBySubscriptionId(pool.getOwner(), pool.getSubscriptionId());
for (int idex = 0; idex < pools.size(); idex++) {
Pool derivedPool = pools.get(idex);
if (derivedPool.getAttributeValue(Pool.Attributes.DERIVED_POOL) != null && derivedPool.getQuantity() == 0) {
poolManager.setPoolQuantity(derivedPool, -1);
}
}
}
}
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class EntitlementRules method runPostEntitlement.
protected void runPostEntitlement(PoolManager poolManager, Consumer consumer, Owner owner, Map<String, Entitlement> entitlementMap, List<Pool> subPoolsForStackIds, boolean isUpdate, Map<String, PoolQuantity> poolQuantityMap) {
Map<String, Map<String, String>> flatAttributeMaps = new HashMap<>();
Map<String, Entitlement> virtLimitEntitlements = new HashMap<>();
for (Entry<String, Entitlement> entry : entitlementMap.entrySet()) {
Entitlement entitlement = entry.getValue();
Map<String, String> attributes = PoolHelper.getFlattenedAttributes(entitlement.getPool());
if (attributes.containsKey("virt_limit")) {
virtLimitEntitlements.put(entry.getKey(), entitlement);
flatAttributeMaps.put(entry.getKey(), attributes);
}
}
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
// Perform pool management based on the attributes of the pool:
if (!virtLimitEntitlements.isEmpty()) {
/* Share and manifest consumers only need to compute postBindVirtLimit in hosted mode
because for both these types, of all the operations implemented in postBindVirtLimit today,
we only care about decrementing host bonus pool quantity and that is only implemented
in hosted mode. These checks are done further below, but doing this up-front to save
us some computation.
*/
if (!(ctype.isType(ConsumerTypeEnum.SHARE) || ctype.isManifest()) || !config.getBoolean(ConfigProperties.STANDALONE)) {
postBindVirtLimit(poolManager, consumer, virtLimitEntitlements, flatAttributeMaps, subPoolsForStackIds, isUpdate, poolQuantityMap);
}
}
if (ctype.isType(ConsumerTypeEnum.SHARE) && !isUpdate) {
postBindShareCreate(poolManager, consumer, owner, entitlementMap);
}
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class EntitlementRules method adjustHostedBonusPoolQuantity.
/*
* When distributors/share consumers bind to virt_limit pools in hosted, we need to go adjust the
* quantity on the bonus pool, as those entitlements have now been exported to on-site or to the share.
*/
private void adjustHostedBonusPoolQuantity(PoolManager poolManager, Consumer consumer, List<Entitlement> entitlements, Map<String, Map<String, String>> attributesMaps, Map<String, PoolQuantity> poolQuantityMap) {
ConsumerType type = this.consumerTypeCurator.getConsumerType(consumer);
boolean consumerFactExpression = (type.isManifest() || type.isType(ConsumerTypeEnum.SHARE)) && !config.getBoolean(ConfigProperties.STANDALONE);
if (!consumerFactExpression) {
return;
}
// pre-fetch subscription and respective pools in a batch
Set<String> subscriptionIds = new HashSet<>();
for (Entitlement entitlement : entitlements) {
subscriptionIds.add(entitlement.getPool().getSubscriptionId());
}
List<Pool> subscriptionPools = poolManager.lookupBySubscriptionIds(consumer.getOwnerId(), subscriptionIds);
Map<String, List<Pool>> subscriptionPoolMap = new HashMap<>();
for (Pool pool : subscriptionPools) {
if (!subscriptionPoolMap.containsKey(pool.getSubscriptionId())) {
subscriptionPoolMap.put(pool.getSubscriptionId(), new ArrayList<>());
}
subscriptionPoolMap.get(pool.getSubscriptionId()).add(pool);
}
for (Entitlement entitlement : entitlements) {
Pool pool = entitlement.getPool();
Map<String, String> attributes = attributesMaps.get(pool.getId());
boolean hostLimited = "true".equals(attributes.get(Product.Attributes.HOST_LIMITED));
if (!hostLimited) {
String virtLimit = attributes.get(Product.Attributes.VIRT_LIMIT);
if (!"unlimited".equals(virtLimit)) {
/* if the bonus pool is not unlimited, then the bonus pool
* quantity needs to be adjusted based on the virt limit
*
* poolQuantity map contains the quantity change requested in the entitlement.
* If this is a bind, then change = entitlement quantity, as change is always > 0.
* But if this is an entitlement update, change can be positive or negative, hence
* we may need to increment or decrement the bonus pool quantity based on the change
*/
int virtQuantity = Integer.parseInt(virtLimit) * poolQuantityMap.get(pool.getId()).getQuantity();
if (virtQuantity != 0) {
List<Pool> pools = subscriptionPoolMap.get(pool.getSubscriptionId());
for (int idex = 0; idex < pools.size(); idex++) {
Pool derivedPool = pools.get(idex);
if (derivedPool.getAttributeValue(Pool.Attributes.DERIVED_POOL) != null) {
poolManager.updatePoolQuantity(derivedPool, -1L * virtQuantity);
}
}
}
} else {
// if the bonus pool is unlimited, then the quantity needs
// to go to 0 when the physical pool is exhausted completely
// by export or share. A quantity of 0 will block future binds,
// whereas -1 does not.
Long notConsumedLocally = pool.getExported() + pool.getShared();
if (pool.getQuantity().equals(notConsumedLocally)) {
// getting all pools matching the sub id. Filtering out
// the 'parent'.
List<Pool> pools = subscriptionPoolMap.get(pool.getSubscriptionId());
if (pools != null) {
for (int idex = 0; idex < pools.size(); idex++) {
Pool derivedPool = pools.get(idex);
if (derivedPool.getAttributeValue(Pool.Attributes.DERIVED_POOL) != null) {
derivedPool = poolManager.setPoolQuantity(derivedPool, 0);
}
}
}
}
}
}
}
}
Aggregations