Search in sources :

Example 21 with Cdn

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

the class ManifestManagerTest method verifyCdnExistsBeforeSchedulingManifestGeneration.

@Test
public void verifyCdnExistsBeforeSchedulingManifestGeneration() throws Exception {
    Owner owner = TestUtil.createOwner();
    Consumer consumer = this.createMockConsumer(owner, true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Map<String, String> extData = new HashMap<>();
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(null);
    try {
        manager.generateManifestAsync(consumer.getUuid(), owner.getKey(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
        fail("Expected ForbiddenException not thrown");
    } catch (Exception e) {
        assertTrue(e instanceof ForbiddenException);
        String expectedMsg = String.format("A CDN with label %s does not exist on this system.", cdn.getLabel());
        assertEquals(e.getMessage(), expectedMsg);
    }
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Cdn(org.candlepin.model.Cdn) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) Test(org.junit.Test)

Example 22 with Cdn

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

the class CdnManagerTest method createCdn.

private Cdn createCdn(String label) {
    CertificateSerial serial = certSerialCurator.create(new CertificateSerial(new Date()));
    CdnCertificate cert = new CdnCertificate();
    cert.setKey("key");
    cert.setCert("cert");
    cert.setSerial(serial);
    Cdn cdn = new Cdn(label, "Test CDN", "test.url", cert);
    manager.createCdn(cdn);
    return cdn;
}
Also used : CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Cdn(org.candlepin.model.Cdn) Date(java.util.Date)

Example 23 with Cdn

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

the class CdnTranslatorTest method initSourceObject.

@Override
protected Cdn initSourceObject() {
    Cdn source = new Cdn();
    source.setName("cdn-name");
    source.setId("cdn-id");
    source.setUrl("cdn-url");
    source.setLabel("cdn-label");
    CdnCertificate cdnCert = new CdnCertificate();
    cdnCert.setId("cdn-cert-id");
    cdnCert.setKey("cdn-cert-key");
    cdnCert.setCert("cdn-cert-cert");
    CertificateSerial serial = new CertificateSerial();
    serial.setRevoked(false);
    serial.setCollected(false);
    serial.setExpiration(new Date());
    serial.setSerial(5L);
    serial.setId(1L);
    cdnCert.setSerial(serial);
    source.setCertificate(cdnCert);
    return source;
}
Also used : CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Cdn(org.candlepin.model.Cdn) Date(java.util.Date)

Example 24 with Cdn

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

the class EntitlementImporter method importObject.

public Subscription importObject(ObjectMapper mapper, Reader reader, Owner owner, Map<String, ProductDTO> productsById, String consumerUuid, Meta meta) throws IOException, SyncDataFormatException {
    EntitlementDTO entitlementDTO = mapper.readValue(reader, EntitlementDTO.class);
    Entitlement entitlement = new Entitlement();
    populateEntity(entitlement, entitlementDTO);
    Subscription subscription = new Subscription();
    log.debug("Building subscription for owner: {}", owner);
    log.debug("Using pool from entitlement: {}", entitlement.getPool());
    // Now that we no longer store Subscriptions in the on-site database, we need to
    // manually give the subscription a downstream ID. Note that this may later be
    // overwritten by reconciliation code if it determines this Subscription
    // should replace and existing one.
    subscription.setId(Util.generateDbUUID());
    subscription.setUpstreamPoolId(entitlement.getPool().getId());
    subscription.setUpstreamEntitlementId(entitlement.getId());
    subscription.setUpstreamConsumerId(consumerUuid);
    subscription.setOwner(owner);
    subscription.setStartDate(entitlement.getStartDate());
    subscription.setEndDate(entitlement.getEndDate());
    subscription.setAccountNumber(entitlement.getPool().getAccountNumber());
    subscription.setContractNumber(entitlement.getPool().getContractNumber());
    subscription.setOrderNumber(entitlement.getPool().getOrderNumber());
    subscription.setQuantity(entitlement.getQuantity().longValue());
    for (Branding b : entitlement.getPool().getBranding()) {
        subscription.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
    }
    String cdnLabel = meta.getCdnLabel();
    if (!StringUtils.isBlank(cdnLabel)) {
        Cdn cdn = cdnCurator.lookupByLabel(cdnLabel);
        if (cdn != null) {
            subscription.setCdn(cdn);
        }
    }
    ProductDTO productDTO = this.findProduct(productsById, entitlement.getPool().getProductId());
    subscription.setProduct(this.translator.translate(productDTO, ProductData.class));
    // Add any sub product data to the subscription.
    if (entitlement.getPool().getDerivedProductId() != null) {
        productDTO = this.findProduct(productsById, entitlement.getPool().getDerivedProductId());
        subscription.setDerivedProduct(this.translator.translate(productDTO, ProductData.class));
    }
    associateProvidedProducts(productsById, entitlement, subscription);
    Set<EntitlementCertificate> certs = entitlement.getCertificates();
    // subscriptions have one cert
    int entcnt = 0;
    for (EntitlementCertificate cert : certs) {
        ++entcnt;
        CertificateSerial cs = new CertificateSerial();
        cs.setCollected(cert.getSerial().isCollected());
        cs.setExpiration(cert.getSerial().getExpiration());
        cs.setUpdated(cert.getSerial().getUpdated());
        cs.setCreated(cert.getSerial().getCreated());
        SubscriptionsCertificate sc = new SubscriptionsCertificate();
        sc.setKey(cert.getKey());
        sc.setCertAsBytes(cert.getCertAsBytes());
        sc.setSerial(cs);
        subscription.setCertificate(sc);
    }
    if (entcnt > 1) {
        log.error("More than one entitlement cert found for subscription");
    }
    return subscription;
}
Also used : ProductData(org.candlepin.model.dto.ProductData) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Branding(org.candlepin.model.Branding) Cdn(org.candlepin.model.Cdn) EntitlementDTO(org.candlepin.dto.manifest.v1.EntitlementDTO) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) Entitlement(org.candlepin.model.Entitlement) Subscription(org.candlepin.model.dto.Subscription) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO)

Example 25 with Cdn

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

the class Exporter method exportContentDeliveryNetworks.

private void exportContentDeliveryNetworks(File baseDir) throws IOException {
    ResultIterator<Cdn> iterator = this.cdnCurator.listAll().iterate();
    try {
        if (iterator.hasNext()) {
            File cdnDir = new File(baseDir.getCanonicalPath(), "content_delivery_network");
            cdnDir.mkdir();
            while (iterator.hasNext()) {
                Cdn cdn = iterator.next();
                log.debug("Exporting CDN: {}", cdn.getName());
                FileWriter writer = null;
                try {
                    File file = new File(cdnDir.getCanonicalPath(), cdn.getLabel() + ".json");
                    writer = new FileWriter(file);
                    cdnExporter.export(mapper, writer, cdn);
                } finally {
                    if (writer != null) {
                        writer.close();
                    }
                }
            }
        }
    } finally {
        iterator.close();
    }
}
Also used : FileWriter(java.io.FileWriter) Cdn(org.candlepin.model.Cdn) File(java.io.File)

Aggregations

Cdn (org.candlepin.model.Cdn)26 Test (org.junit.Test)16 Consumer (org.candlepin.model.Consumer)11 HashMap (java.util.HashMap)7 Owner (org.candlepin.model.Owner)7 File (java.io.File)5 BadRequestException (org.candlepin.common.exceptions.BadRequestException)5 ArrayList (java.util.ArrayList)4 Event (org.candlepin.audit.Event)4 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)4 NotFoundException (org.candlepin.common.exceptions.NotFoundException)4 CertificateSerial (org.candlepin.model.CertificateSerial)4 ConsumerType (org.candlepin.model.ConsumerType)4 Entitlement (org.candlepin.model.Entitlement)4 ManifestFile (org.candlepin.sync.file.ManifestFile)3 ApiOperation (io.swagger.annotations.ApiOperation)2 Reader (java.io.Reader)2 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2