use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class AutobindRulesTest method createPool.
protected Pool createPool(Owner owner, Product product, int quantity, Date startDate, Date endDate) {
Pool p = TestUtil.createPool(owner, product, quantity);
p.setId("testpool" + TestUtil.randomInt());
p.setSourceSubscription(new SourceSubscription("testsub" + TestUtil.randomInt(), "master"));
p.setStartDate(startDate);
p.setEndDate(endDate);
return p;
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolHelper method createHostRestrictedPools.
/**
* Create a pool only for virt guests of a particular host consumer.
*
* @param pools Pools these host restricted pools are being derived from.
* @return pools the created pools
*/
public static List<Pool> createHostRestrictedPools(PoolManager poolManager, Consumer consumer, List<Pool> pools, Map<String, Entitlement> sourceEntitlements, Map<String, Map<String, String>> attributeMaps, ProductCurator productCurator) {
List<Pool> poolsToCreate = new ArrayList<>();
List<Pool> poolsToUpdateFromStack = new ArrayList<>();
for (Pool pool : pools) {
Product product = pool.getProduct();
Pool consumerSpecificPool = null;
Map<String, String> attributes = attributeMaps.get(pool.getId());
String quantity = attributes.get("virt_limit");
if (pool.getDerivedProduct() == null) {
consumerSpecificPool = createPool(product, pool.getOwner(), quantity, pool.getStartDate(), pool.getEndDate(), pool.getContractNumber(), pool.getAccountNumber(), pool.getOrderNumber(), productCurator.getPoolProvidedProductsCached(pool), sourceEntitlements.get(pool.getId()), pool.hasSharedAncestor());
} else {
// If a derived product is on the pool, we want to define the
// derived pool
// with the derived product data that was defined on the parent
// pool,
// allowing the derived pool to have different attributes than
// the parent.
consumerSpecificPool = createPool(pool.getDerivedProduct(), pool.getOwner(), quantity, pool.getStartDate(), pool.getEndDate(), pool.getContractNumber(), pool.getAccountNumber(), pool.getOrderNumber(), productCurator.getPoolDerivedProvidedProductsCached(pool), sourceEntitlements.get(pool.getId()), pool.hasSharedAncestor());
}
consumerSpecificPool.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer.getUuid());
consumerSpecificPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
consumerSpecificPool.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
consumerSpecificPool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
// parent pool.
if (pool.isStacked()) {
poolsToUpdateFromStack.add(consumerSpecificPool);
} else {
// attribute per 795431, useful for rolling up pool info in headpin
consumerSpecificPool.setAttribute(Pool.Attributes.SOURCE_POOL_ID, pool.getId());
String subscriptionId = pool.getSubscriptionId();
if (subscriptionId != null && !subscriptionId.isEmpty()) {
consumerSpecificPool.setSourceSubscription(new SourceSubscription(subscriptionId, sourceEntitlements.get(pool.getId()).getId()));
}
}
poolsToCreate.add(consumerSpecificPool);
}
if (CollectionUtils.isNotEmpty(poolsToUpdateFromStack)) {
poolManager.updatePoolsFromStack(consumer, poolsToUpdateFromStack);
}
return poolManager.createPools(poolsToCreate);
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class CandlepinPoolManager method convertToMasterPoolImpl.
/**
* Builds a pool instance from the given subscription, using the specified owner and products
* for resolution.
* <p></p>
* The provided owner and products will be used to match and resolve the owner and product
* DTOs present on the subscription. If the subscription uses DTOs which cannot be resolved,
* this method will throw an exception.
*
* @param sub
* The subscription to convert to a pool
*
* @param owner
* The owner the pool will be assigned to
*/
private Pool convertToMasterPoolImpl(Subscription sub, Owner owner, Map<String, Product> productMap) {
if (sub == null) {
throw new IllegalArgumentException("subscription is null");
}
if (owner == null || (owner.getKey() == null && owner.getId() == null)) {
throw new IllegalArgumentException("owner is null or incomplete");
}
if (productMap == null) {
throw new IllegalArgumentException("productMap is null");
}
Pool pool = new Pool();
// Validate and resolve owner...
if (sub.getOwner() == null || (sub.getOwner().getId() != null ? !owner.getId().equals(sub.getOwner().getId()) : !owner.getKey().equals(sub.getOwner().getKey()))) {
throw new IllegalStateException("Subscription references an invalid owner: " + sub.getOwner());
}
pool.setOwner(owner);
pool.setQuantity(sub.getQuantity());
pool.setStartDate(sub.getStartDate());
pool.setEndDate(sub.getEndDate());
pool.setContractNumber(sub.getContractNumber());
pool.setAccountNumber(sub.getAccountNumber());
pool.setOrderNumber(sub.getOrderNumber());
// Copy over subscription details
pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
// Copy over upstream details
pool.setUpstreamPoolId(sub.getUpstreamPoolId());
pool.setUpstreamEntitlementId(sub.getUpstreamEntitlementId());
pool.setUpstreamConsumerId(sub.getUpstreamConsumerId());
pool.setCdn(sub.getCdn());
pool.setCertificate(sub.getCertificate());
// Add in branding
if (sub.getBranding() != null) {
Set<Branding> branding = new HashSet<>();
for (Branding brand : sub.getBranding()) {
// Impl note:
// We create a new instance here since we don't have a separate branding DTO (yet),
// and we need to be certain that we don't try to move or change a branding object
// associated with another pool.
branding.add(new Branding(brand.getProductId(), brand.getType(), brand.getName()));
}
pool.setBranding(branding);
}
if (sub.getProduct() == null || sub.getProduct().getId() == null) {
throw new IllegalStateException("Subscription has no product, or its product is incomplete: " + sub.getProduct());
}
Product product = productMap.get(sub.getProduct().getId());
if (product == null) {
throw new IllegalStateException("Subscription references a product which cannot be resolved: " + sub.getProduct());
}
pool.setProduct(product);
if (sub.getDerivedProduct() != null) {
product = productMap.get(sub.getDerivedProduct().getId());
if (product == null) {
throw new IllegalStateException("Subscription's derived product references a product which " + "cannot be resolved: " + sub.getDerivedProduct());
}
pool.setDerivedProduct(product);
}
if (sub.getProvidedProducts() != null) {
Set<Product> products = new HashSet<>();
for (ProductData pdata : sub.getProvidedProducts()) {
if (pdata != null) {
product = productMap.get(pdata.getId());
if (product == null) {
throw new IllegalStateException("Subscription's provided products references a " + "product which cannot be resolved: " + pdata);
}
products.add(product);
}
}
pool.setProvidedProducts(products);
}
if (sub.getDerivedProvidedProducts() != null) {
Set<Product> products = new HashSet<>();
for (ProductData pdata : sub.getDerivedProvidedProducts()) {
if (pdata != null) {
product = productMap.get(pdata.getId());
if (product == null) {
throw new IllegalStateException("Subscription's derived provided products " + "references a product which cannot be resolved: " + pdata);
}
products.add(product);
}
}
pool.setDerivedProvidedProducts(products);
}
return pool;
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class DatabaseTestFixture method createPool.
/**
* Create an entitlement pool.
*
* @return an entitlement pool
*/
protected Pool createPool(Owner owner, Product product, Long quantity, Date startDate, Date endDate) {
Pool pool = new Pool(owner, product, new HashSet<>(), quantity, startDate, endDate, DEFAULT_CONTRACT, DEFAULT_ACCOUNT, DEFAULT_ORDER);
pool.setSourceSubscription(new SourceSubscription(Util.generateDbUUID(), "master"));
return poolCurator.create(pool);
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method createPoolsForPoolBonusExist.
@Test(expected = IllegalStateException.class)
public void createPoolsForPoolBonusExist() {
Owner owner = this.getOwner();
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
List<Pool> existingPools = new LinkedList<>();
Pool p = TestUtil.createPool(prod);
p.setSourceSubscription(new SourceSubscription(TestUtil.randomString(), "derived"));
existingPools.add(p);
pRules.createAndEnrichPools(p, existingPools);
List<Pool> newPools = pRules.createAndEnrichPools(p, existingPools);
assertEquals(1, newPools.size());
assertEquals("master", newPools.get(0).getSourceSubscription().getSubscriptionSubKey());
}
Aggregations