use of org.candlepin.sync.ExportResult in project candlepin by candlepin.
the class ManifestManager method generateAndStoreManifest.
/**
* Generates a manifest for the specifed consumer and stores the resulting file via the
* {@link ManifestFileService}.
*
* @param consumerUuid the target consumer's UUID.
* @param cdnLabel the CDN label to store in the meta file.
* @param webUrl the URL pointing to the manifest's originating web application.
* @param apiUrl the API URL pointing to the manifest's originating candlepin API.
* @param extensionData data to be passed to the {@link ExportExtensionAdapter} when creating
* a new export of the target consumer.
* @return an {@link ExportResult} containing the details of the stored file.
* @throws ExportCreationException if there are any issues generating the manifest.
*/
public ExportResult generateAndStoreManifest(String consumerUuid, String cdnLabel, String webUrl, String apiUrl, Map<String, String> extensionData) throws ExportCreationException {
Consumer consumer = validateConsumerForExport(consumerUuid, cdnLabel);
File export = null;
try {
poolManager.regenerateDirtyEntitlements(entitlementCurator.listByConsumer(consumer));
export = exporter.getFullExport(consumer, cdnLabel, webUrl, apiUrl, extensionData);
ManifestFile manifestFile = storeExport(export, consumer);
sink.queueEvent(eventFactory.exportCreated(consumer));
return new ExportResult(consumer.getUuid(), manifestFile.getId());
} catch (ManifestFileServiceException e) {
throw new ExportCreationException("Unable to create export archive", e);
} finally {
// We no longer need the export work directory since the archive has been saved in the DB.
if (export != null) {
File workDir = export.getParentFile();
try {
FileUtils.deleteDirectory(workDir);
} catch (IOException ioe) {
// It'll get cleaned up by the ManifestCleanerJob if it couldn't
// be deleted for some reason.
}
}
}
}
use of org.candlepin.sync.ExportResult in project candlepin by candlepin.
the class ManifestManagerTest method testGenerateAndStoreManifest.
@Test
public void testGenerateAndStoreManifest() throws Exception {
Consumer consumer = this.createMockConsumer(true);
Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
String webAppPrefix = "webapp-prefix";
String apiUrl = "api-url";
Map<String, String> extData = new HashMap<>();
Event event = mock(Event.class);
when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
UserPrincipal principal = TestUtil.createOwnerPrincipal();
when(principalProvider.get()).thenReturn(principal);
String exportId = "export-id";
ManifestFile manifest = mock(ManifestFile.class);
when(manifest.getId()).thenReturn(exportId);
when(fileService.store(eq(ManifestFileType.EXPORT), any(File.class), eq(principal.getName()), any(String.class))).thenReturn(manifest);
when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
List<Entitlement> ents = new ArrayList<>();
when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents);
ExportResult result = manager.generateAndStoreManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
assertEquals(consumer.getUuid(), result.getExportedConsumer());
assertEquals(exportId, result.getExportId());
verify(entitlementCurator).listByConsumer(eq(consumer));
verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData));
verify(eventFactory).exportCreated(eq(consumer));
verify(eventSink).queueEvent(eq(event));
verify(fileService).delete(eq(ManifestFileType.EXPORT), eq(consumer.getUuid()));
}
use of org.candlepin.sync.ExportResult in project candlepin by candlepin.
the class ExportJob method toExecute.
@Override
public void toExecute(JobExecutionContext context) throws JobExecutionException {
JobDataMap map = context.getMergedJobDataMap();
String consumerUuid = map.getString(JobStatus.TARGET_ID);
String cdnLabel = map.getString(CDN_LABEL);
String webAppPrefix = map.getString(WEBAPP_PREFIX);
String apiUrl = map.getString(API_URL);
Map<String, String> extensionData = (Map<String, String>) map.get(EXTENSION_DATA);
log.info("Starting async export for {}", consumerUuid);
try {
ExportResult result = manifestManager.generateAndStoreManifest(consumerUuid, cdnLabel, webAppPrefix, apiUrl, extensionData);
context.setResult(result);
log.info("Async export complete.");
} catch (Exception e) {
throw new JobExecutionException(e.getMessage(), e, false);
}
}
use of org.candlepin.sync.ExportResult in project candlepin by candlepin.
the class ExportJobTest method ensureJobSuccess.
@Test
public void ensureJobSuccess() throws Exception {
Owner owner = TestUtil.createOwner();
owner.setId(TestUtil.randomString());
Consumer distributor = TestUtil.createDistributor(owner);
String cdnLabel = "cdn-label";
String webappPrefix = "webapp-prefix";
String apiUrl = "url";
String manifestId = "1234";
Map<String, String> extData = new HashMap<>();
ExportResult result = new ExportResult(distributor.getUuid(), manifestId);
when(manifestManager.generateAndStoreManifest(eq(distributor.getUuid()), eq(cdnLabel), eq(webappPrefix), eq(apiUrl), eq(extData))).thenReturn(result);
JobDetail detail = job.scheduleExport(distributor, owner.getKey(), cdnLabel, webappPrefix, apiUrl, extData);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
job.execute(ctx);
verify(manifestManager).generateAndStoreManifest(eq(distributor.getUuid()), eq(cdnLabel), eq(webappPrefix), eq(apiUrl), eq(extData));
verify(ctx).setResult(eq(result));
}
Aggregations