Beispiel #1
0
 /**
  * Removes a CDN
  *
  * @httpcode 400
  * @httpcode 404
  * @httpcode 200
  */
 @DELETE
 @Produces(MediaType.WILDCARD)
 @Path("/{label}")
 public void delete(@PathParam("label") String label, @Context Principal principal) {
   Cdn cdn = curator.lookupByLabel(label);
   if (cdn != null) {
     curator.delete(cdn);
   }
 }
  @Test
  public void testAsyncExport() {
    CdnCurator mockedCdnCurator = mock(CdnCurator.class);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            mockedCdnCurator,
            null,
            null,
            productCurator,
            manifestManager);

    List<KeyValueParameter> extParams = new ArrayList<KeyValueParameter>();
    Owner owner = TestUtil.createOwner();
    Consumer consumer =
        TestUtil.createConsumer(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), owner);
    Cdn cdn = new Cdn("cdn-label", "test", "url");

    when(mockedConsumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid())))
        .thenReturn(consumer);
    when(mockedCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);

    cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
    verify(manifestManager)
        .generateManifestAsync(
            eq(consumer.getUuid()),
            eq(cdn.getLabel()),
            eq("prefix"),
            eq(cdn.getUrl()),
            any(Map.class));
  }
Beispiel #3
0
 /**
  * Creates a CDN
  *
  * @return a Cdn object
  * @httpcode 200
  */
 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Cdn create(Cdn cdn, @Context Principal principal) {
   Cdn existing = curator.lookupByLabel(cdn.getLabel());
   if (existing != null) {
     throw new BadRequestException(
         i18n.tr("A CDN with the label {0}" + "already exists", cdn.getLabel()));
   }
   return curator.create(cdn);
 }
Beispiel #4
0
  private void exportContentDeliveryNetworks(File baseDir) throws IOException {
    List<Cdn> cdns = cdnCurator.list();
    if (cdns == null || cdns.isEmpty()) {
      return;
    }

    File cdnDir = new File(baseDir.getCanonicalPath(), "content_delivery_network");
    cdnDir.mkdir();

    FileWriter writer = null;
    for (Cdn cdn : cdns) {
      if (log.isDebugEnabled()) {
        log.debug("Exporting Content Delivery Network" + cdn.getName());
      }
      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();
        }
      }
    }
  }
Beispiel #5
0
  private Cdn verifyAndLookupCdn(String label) {
    Cdn cdn = curator.lookupByLabel(label);

    if (cdn == null) {
      throw new NotFoundException(i18n.tr("No such content delivery network: {0}", label));
    }
    return cdn;
  }
Beispiel #6
0
 /**
  * Updates a CDN
  *
  * @return a Cdn object
  * @httpcode 200
  */
 @PUT
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 @Path("/{label}")
 public Cdn update(@PathParam("label") String label, Cdn cdn, @Context Principal principal) {
   Cdn existing = verifyAndLookupCdn(label);
   if (!StringUtils.isBlank(cdn.getName())) {
     existing.setName(cdn.getName());
   }
   if (!StringUtils.isBlank(cdn.getUrl())) {
     existing.setUrl(cdn.getUrl());
   }
   if (cdn.getCertificate() != null) {
     existing.setCertificate(cdn.getCertificate());
   }
   curator.merge(existing);
   return existing;
 }
Beispiel #7
0
 /**
  * Retrieves a list of CDN's
  *
  * <p>
  *
  * <pre>
  * {
  *   "id" : "database_id",
  *   "label" : "the-cdn",
  *   "name" : "The CDN",
  *   "url" : "https://location.cdn.redhat.com",
  *   "certificate" : {
  *     "key" : "",
  *     "cert" : "",
  *     "id" : "",
  *     "serial" : "serial number",
  *     "created" : [date],
  *     "updated" : [date]
  *   },
  *   "created" : [date],
  *   "updated" : [date]
  * }
  * </pre>
  *
  * @return a list of Cdn objects
  * @httpcode 200
  */
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public List<Cdn> getContentDeliveryNetworks() {
   return curator.list();
 }