Search in sources :

Example 6 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ManifestManager method validateConsumerForExport.

private Consumer validateConsumerForExport(String consumerUuid, String cdnLabel) {
    // FIXME Should this be testing the CdnLabel as well?
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype == null || !ctype.isManifest()) {
        throw new ForbiddenException(i18n.tr("Unit {0} cannot be exported. A manifest cannot be made for units of type \"{1}\".", consumerUuid, ctype != null ? ctype.getLabel() : "unknown type"));
    }
    if (!StringUtils.isBlank(cdnLabel) && cdnCurator.lookupByLabel(cdnLabel) == null) {
        throw new ForbiddenException(i18n.tr("A CDN with label {0} does not exist on this system.", cdnLabel));
    }
    return consumer;
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType)

Example 7 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class RevocationOp method determineExcessEntitlements.

/**
 * In the second part, the list of entitlements is compiled from the main pool plus the shared pools
 * It is sorted in the order of LIFO. Entitlements are put in the revoke list until the count is
 * acceptable for the main pool. Any entitlements that came from a shared pool are also reflected in
 * the adjustment for the source entitlement for that shared pool.
 *
 * @param pool
 */
private void determineExcessEntitlements(Pool pool) {
    List<Pool> pools = new ArrayList<>();
    pools.add(pool);
    if (sharedPools.get(pool) != null) {
        pools.addAll(sharedPools.get(pool));
    }
    List<Entitlement> entitlements = this.poolCurator.retrieveOrderedEntitlementsOf(pools);
    long newConsumed = poolNewConsumed.get(pool);
    long existing = pool.getQuantity();
    for (Entitlement ent : entitlements) {
        if (newConsumed > existing) {
            ConsumerType ctype = this.consumerTypeCurator.getConsumerType(ent.getConsumer());
            if (!ctype.isType(ConsumerTypeEnum.SHARE)) {
                if (ent.getPool().isCreatedByShare()) {
                    Entitlement source = ent.getPool().getSourceEntitlement();
                    // the source entitlement may have already been adjusted in the shared pool reduction
                    if (shareEntitlementsToAdjust.get(source) == null) {
                        addEntitlementToAdjust(source, source.getQuantity());
                    }
                    addEntitlementToAdjust(source, shareEntitlementsToAdjust.get(source) - ent.getQuantity());
                    if (shareEntitlementsToAdjust.get(source) == 0) {
                        shareEntitlementsToAdjust.remove(source);
                        addEntitlmentToRevoke(source);
                    }
                }
                addEntitlementToRevoke(ent);
                newConsumed -= ent.getQuantity();
            }
        }
    }
    poolNewConsumed.put(pool, newConsumed);
}
Also used : ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) ConsumerType(org.candlepin.model.ConsumerType)

Example 8 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ComplianceOp method execute.

/**
 * compute the compliance hash from a compliance status and updates the consumer.
 * @param context
 */
@Override
public boolean execute(BindContext context) {
    Consumer consumer = context.getLockedConsumer();
    ConsumerType ctype = context.getConsumerType();
    complianceRules.updateEntsOnStart(consumer);
    if (!ctype.isManifest() && !ctype.isType(ConsumerTypeEnum.SHARE)) {
        complianceRules.applyStatus(consumer, status, false);
    }
    return true;
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType)

Example 9 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method ensureV3CertIsCreatedWhenHypervisor.

@Test
public void ensureV3CertIsCreatedWhenHypervisor() throws Exception {
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.HYPERVISOR);
    ctype.setId("test-id");
    consumer.setType(ctype);
    when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(mockConsumerTypeCurator.getConsumerType(consumer)).thenReturn(ctype);
    DefaultEntitlementCertServiceAdapter entAdapter = this.initCertServiceAdapter();
    entAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, new HashSet<>(), getProductModels(product, new HashSet<>(), "prefix", entitlement), new BigInteger("1234"), keyPair, true);
    verify(mockV3extensionUtil).getExtensions();
    verify(mockV3extensionUtil).getByteExtensions(eq(product), any(List.class), any(String.class), any(Map.class));
    verifyZeroInteractions(mockExtensionUtil);
}
Also used : BigInteger(java.math.BigInteger) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method setUp.

@Before
public void setUp() {
    Injector injector = Guice.createInjector(new TestingModules.MockJpaModule(), new TestingModules.ServletEnvironmentModule(), new TestingModules.StandardTest());
    injector.injectMembers(this);
    v3extensionUtil = new X509V3ExtensionUtil(config, entCurator);
    certServiceAdapter = new DefaultEntitlementCertServiceAdapter(mockedPKI, extensionUtil, v3extensionUtil, mock(EntitlementCertificateCurator.class), keyPairCurator, serialCurator, ownerCurator, entCurator, I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK), config, productCurator, this.mockConsumerTypeCurator, this.mockEnvironmentCurator);
    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);
    largeContentProduct = TestUtil.createProduct("67890", "large content product");
    largeContentProduct.setAttribute(Product.Attributes.VERSION, "version");
    largeContentProduct.setAttribute(Product.Attributes.VARIANT, "variant");
    largeContentProduct.setAttribute(Product.Attributes.TYPE, "SVC");
    largeContentProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
    content = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    content.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    content.setRequiredTags(REQUIRED_TAGS);
    kickstartContent = createContent(CONTENT_NAME, CONTENT_ID_KICKSTART, CONTENT_LABEL, CONTENT_TYPE_KICKSTART, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    kickstartContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    kickstartContent.setRequiredTags(REQUIRED_TAGS);
    fileContent = createContent(CONTENT_NAME, CONTENT_ID_FILE, CONTENT_LABEL, CONTENT_TYPE_FILE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    fileContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    fileContent.setRequiredTags(REQUIRED_TAGS);
    unknownTypeContent = createContent(CONTENT_NAME, CONTENT_ID_UNKNOWN, CONTENT_LABEL, CONTENT_TYPE_UNKNOWN, CONTENT_VENDOR, CONTENT_URL_UNKNOWN_TYPE, CONTENT_GPG_URL, ARCH_LABEL);
    unknownTypeContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
    unknownTypeContent.setRequiredTags(REQUIRED_TAGS);
    String emptyArches = "";
    noArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, emptyArches);
    superContent = new HashSet<>();
    int index = 0;
    for (String url : testUrls) {
        ++index;
        superContent.add(createContent(CONTENT_NAME + "-" + index, CONTENT_ID + "-" + index, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
    }
    largeContent = new HashSet<>();
    index = 0;
    for (String url : largeTestUrls) {
        ++index;
        largeContent.add(createContent(CONTENT_NAME + "-" + index, CONTENT_ID + "-" + index, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
    }
    subscription = TestUtil.createSubscription(null, product, new HashSet<>());
    subscription.setId("1");
    subscription.setQuantity(1L);
    largeContentSubscription = TestUtil.createSubscription(null, largeContentProduct, new HashSet<>());
    largeContentSubscription.setId("2");
    largeContentSubscription.setQuantity(1L);
    owner = new Owner();
    owner.setId(TestUtil.randomString());
    when(ownerCurator.findOwnerById(owner.getId())).thenReturn(owner);
    pool = new Pool();
    pool.setQuantity(1L);
    pool.setProduct(product);
    pool.setStartDate(subscription.getStartDate());
    pool.setEndDate(subscription.getEndDate());
    largeContentPool = new Pool();
    largeContentPool.setProduct(largeContentProduct);
    ConsumerType type = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
    type.setId("test-id");
    consumer = new Consumer("Test Consumer", "bob", owner, type);
    consumer.setUuid("test-consumer");
    when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(type);
    when(this.mockConsumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
    entitlement = new Entitlement();
    entitlement.setQuantity(new Integer(ENTITLEMENT_QUANTITY));
    entitlement.setConsumer(consumer);
    entitlement.setPool(pool);
    entitlement.setOwner(owner);
    largeContentEntitlement = new Entitlement();
    largeContentEntitlement.setQuantity(new Integer(ENTITLEMENT_QUANTITY));
    largeContentEntitlement.setConsumer(consumer);
    largeContentEntitlement.setPool(largeContentPool);
    largeContentEntitlement.setOwner(owner);
    product.addContent(content, false);
    Set empty = new HashSet<String>();
    when(productCurator.getPoolProvidedProductUuids(anyString())).thenReturn(empty);
// when(productAdapter.getProductById(eq(product.getOwner()), eq(product.getId())))
// .thenReturn(product);
// when(productAdapter.getProductById(
// eq(largeContentProduct.getOwner()), eq(largeContentProduct.getId()))
// ).thenReturn(largeContentProduct);
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) HashSet(java.util.HashSet) Matchers.anyString(org.mockito.Matchers.anyString) TestingModules(org.candlepin.TestingModules) BigInteger(java.math.BigInteger) X509V3ExtensionUtil(org.candlepin.util.X509V3ExtensionUtil) Consumer(org.candlepin.model.Consumer) Injector(com.google.inject.Injector) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16