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);
}
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations