use of org.candlepin.model.Product in project candlepin by candlepin.
the class Refresher method run.
public void run() {
// If products were specified on the refresher, lookup any subscriptions
// using them, regardless of organization, and trigger a refresh for those
// specific subscriptions.
Set<Subscription> subscriptions = new HashSet<>();
for (Product product : products) {
// TODO: This adapter call is not implemented in prod, and cannot be. We plan
// to fix this whole code path in near future by looking for pools using the
// given products to be refreshed.
List<Subscription> subs = subAdapter.getSubscriptions(product.toDTO());
log.debug("Will refresh {} subscriptions in all orgs using product: ", subs.size(), product.getId());
if (log.isDebugEnabled()) {
for (Subscription s : subs) {
Owner so = s.getOwner();
if (so == null || so.getKey() == null) {
log.debug(" Received a subscription without a well-defined owner: {}", s.getId());
continue;
}
if (!this.owners.containsKey(so.getKey())) {
log.debug(" {}", s);
}
}
}
subscriptions.addAll(subs);
}
for (Subscription subscription : subscriptions) {
// drop any subs for owners in our owners list. we'll get them with the full
// refreshPools call.
Owner so = subscription.getOwner();
// This probably shouldn't ever happen, but let's make sure it doesn't anyway.
if (so == null || so.getKey() == null) {
log.error("Received a subscription without a well-defined owner: {}", subscription.getId());
continue;
}
if (this.owners.containsKey(so.getKey())) {
log.debug("Skipping subscription \"{}\" for owner: {}", subscription.getId(), so);
continue;
}
/*
* on the off chance that this is actually a new subscription, make
* the required pools. this shouldn't happen; we should really get a
* refresh pools by owner call for it, but why not handle it, just
* in case!
*
* Regenerate certificates here, that way if it fails, the whole
* thing rolls back. We don't want to refresh without marking ents
* dirty, they will never get regenerated
*/
Pool masterPool = poolManager.convertToMasterPool(subscription);
poolManager.refreshPoolsForMasterPool(masterPool, true, lazy, Collections.<String, Product>emptyMap());
}
for (Owner owner : this.owners.values()) {
poolManager.refreshPoolsWithRegeneration(this.subAdapter, owner, this.lazy);
poolManager.recalculatePoolQuantitiesForOwner(owner);
ownerManager.refreshContentAccessMode(this.ownerAdapter, owner);
ownerManager.updateRefreshDate(owner);
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ActivationKeyTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public ActivationKeyDTO populate(ModelTranslator modelTranslator, ActivationKey source, ActivationKeyDTO dest) {
dest = super.populate(modelTranslator, source, dest);
dest.setId(source.getId()).setName(source.getName()).setDescription(source.getDescription()).setServiceLevel(source.getServiceLevel()).setAutoAttach(source.isAutoAttach());
// Process nested objects if we have a model translator to use to the translation...
if (modelTranslator != null) {
Owner owner = source.getOwner();
dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
Set<ActivationKeyPool> pools = source.getPools();
if (pools != null && !pools.isEmpty()) {
for (ActivationKeyPool poolEntry : pools) {
if (poolEntry != null) {
dest.addPool(new ActivationKeyDTO.ActivationKeyPoolDTO(poolEntry.getPool().getId(), poolEntry.getQuantity()));
}
}
} else {
dest.setPools(Collections.<ActivationKeyDTO.ActivationKeyPoolDTO>emptySet());
}
Set<Product> products = source.getProducts();
if (products != null && !products.isEmpty()) {
for (Product prod : products) {
if (prod != null) {
dest.addProductId(prod.getId());
}
}
} else {
dest.setProductIds(Collections.<String>emptySet());
}
Set<ActivationKeyContentOverride> overrides = source.getContentOverrides();
if (overrides != null && !overrides.isEmpty()) {
for (ActivationKeyContentOverride override : overrides) {
if (override != null) {
dest.addContentOverride(new ActivationKeyDTO.ActivationKeyContentOverrideDTO(override.getContentLabel(), override.getName(), override.getValue()));
}
}
} else {
dest.setContentOverrides(Collections.<ActivationKeyDTO.ActivationKeyContentOverrideDTO>emptySet());
}
Release release = source.getReleaseVer();
if (release != null) {
dest.setReleaseVersion(release.getReleaseVer());
}
}
return dest;
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method tooManyContentSetsAcrossMultipleProducts.
@Test(expected = CertificateSizeException.class)
public void tooManyContentSetsAcrossMultipleProducts() throws Exception {
Set<Product> providedProducts = new HashSet<>();
Product pp1 = new Product("12346", "Provided 1", "variant", "version", ARCH_LABEL, "SVC");
for (Content content : generateContent(100, "PP1")) {
pp1.addContent(content, false);
}
providedProducts.add(pp1);
Product pp2 = new Product("12347", "Provided 2", "variant", "version", ARCH_LABEL, "SVC");
for (Content content : generateContent(100, "PP2")) {
pp2.addContent(content, false);
}
providedProducts.add(pp2);
// TODO: Is this even needed anymore?
// subscription.setProvidedProducts(providedProducts);
certServiceAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, providedProducts, getProductModels(product, providedProducts, "prefix", entitlement), new BigInteger("1234"), keyPair, true);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsNoCompatibleArch.
@Test
public void testPrepareV1ExtensionsNoCompatibleArch() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
// product with no compatible content, but marked as 'ALL' arch
Product wrongArchProduct = TestUtil.createProduct("12345", "a product");
wrongArchProduct.setAttribute(Product.Attributes.VERSION, "version");
wrongArchProduct.setAttribute(Product.Attributes.VARIANT, "variant");
wrongArchProduct.setAttribute(Product.Attributes.TYPE, "SVC");
wrongArchProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL");
// no x86_64, ie ARCH_LABEL
String wrongArches = "s390x,s390,ppc64,ia64";
Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, wrongArches);
wrongArchProduct.addContent(wrongArchContent, false);
products.add(wrongArchProduct);
setupEntitlements(ARCH_LABEL, "1.0");
Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null);
Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions);
Map<String, String> extMap = getEncodedContentMap(extensions);
assertFalse(isEncodedContentValid(map));
assertFalse(map.containsKey(CONTENT_URL));
// make sure we don't set content type to "null"
assertFalse(extMapHasContentType(kickstartContent, extMap, "null"));
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsKnownAndUnknownContentTypes.
@Test
public void testPrepareV1ExtensionsKnownAndUnknownContentTypes() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
// product with a kickstart content
Product product = TestUtil.createProduct("12345", "a product");
product.setAttribute(Product.Attributes.VERSION, "version");
product.setAttribute(Product.Attributes.VARIANT, "variant");
product.setAttribute(Product.Attributes.TYPE, "SVC");
product.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
product.addContent(content, false);
product.addContent(fileContent, false);
product.addContent(kickstartContent, false);
product.addContent(unknownTypeContent, false);
products.add(product);
setupEntitlements(ARCH_LABEL, "1.0");
Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null);
Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions);
Map<String, String> extMap = getEncodedContentMap(extensions);
// we skip content of unknown type for v1 certs, but other
// content should still get added
assertTrue(isEncodedContentValid(map));
// other contents are in there
assertTrue(map.containsKey(CONTENT_URL));
// unknown is not
assertFalse(map.containsKey(CONTENT_TYPE_UNKNOWN));
assertFalse(map.containsKey(CONTENT_URL_UNKNOWN_TYPE));
// we have a yum,file, and kickstart content and
// we do not have any unknown content types
assertTrue(extMapHasContentType(content, extMap, "1"));
assertTrue(extMapHasContentType(fileContent, extMap, "2"));
assertTrue(extMapHasContentType(kickstartContent, extMap, "3"));
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "1"));
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "2"));
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "3"));
// make sure we don't set content type to "null"
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "null"));
}
Aggregations