use of org.commonjava.indy.folo.model.TrackedContent in project indy by Commonjava.
the class FoloAdminController method recalculateRecord.
public TrackedContentDTO recalculateRecord(final String id, final String baseUrl) throws IndyWorkflowException {
TrackingKey trackingKey = new TrackingKey(id);
TrackedContent record = recordManager.get(trackingKey);
AtomicBoolean failed = new AtomicBoolean(false);
Set<TrackedContentEntry> recalculatedUploads = recalculateEntrySet(record.getUploads(), id, failed);
Set<TrackedContentEntry> recalculatedDownloads = recalculateEntrySet(record.getDownloads(), id, failed);
if (failed.get()) {
throw new IndyWorkflowException("Failed to recalculate tracking record: %s. See Indy logs for more information", id);
}
TrackedContent recalculated = new TrackedContent(record.getKey(), recalculatedUploads, recalculatedDownloads);
recordManager.replaceTrackingRecord(recalculated);
return constructContentDTO(recalculated, baseUrl);
}
use of org.commonjava.indy.folo.model.TrackedContent in project indy by Commonjava.
the class FoloAdminController method renderRepositoryZip.
public File renderRepositoryZip(final String id) throws IndyWorkflowException {
final TrackingKey tk = new TrackingKey(id);
File file = filer.getRepositoryZipFile(tk).getDetachedFile();
file.getParentFile().mkdirs();
logger.debug("Retrieving tracking record for: {}", tk);
final TrackedContent record = recordManager.get(tk);
logger.debug("Got: {}", record);
if (record == null) {
throw new IndyWorkflowException(ApplicationStatus.NOT_FOUND.code(), "No tracking record available for: %s. Maybe you forgot to seal it?", tk);
}
final Set<String> seenPaths = new HashSet<>();
final List<Transfer> items = new ArrayList<>();
addTransfers(record.getUploads(), items, id, seenPaths);
addTransfers(record.getDownloads(), items, id, seenPaths);
logger.debug("Retrieved {} files. Creating zip.", items.size());
Collections.sort(items, (f, s) -> f.getPath().compareTo(s.getPath()));
try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(file))) {
for (final Transfer item : items) {
// logger.info( "Adding: {}", item );
if (item != null) {
final String path = item.getPath();
final ZipEntry ze = new ZipEntry(path);
stream.putNextEntry(ze);
InputStream itemStream = null;
try {
itemStream = item.openInputStream();
copy(itemStream, stream);
} finally {
closeQuietly(itemStream);
}
}
}
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to generate repository zip from tracking record: {}. Reason: {}", e, id, e.getMessage());
}
return file;
}
use of org.commonjava.indy.folo.model.TrackedContent in project indy by Commonjava.
the class FoloRecordCache method seal.
public TrackedContent seal(final TrackingKey trackingKey) {
TrackedContent record = sealedRecordCache.get(trackingKey);
Logger logger = LoggerFactory.getLogger(getClass());
if (record != null) {
logger.debug("Tracking record: {} already sealed! Returning sealed record.", trackingKey);
return record;
}
logger.debug("Listing unsealed tracking record entries for: {}...", trackingKey);
return inProgressByTrackingKey(trackingKey, (qb, cacheHandle) -> {
Query query = qb.build();
List<TrackedContentEntry> results = query.list();
TrackedContent created = null;
if (results != null) {
logger.debug("Adding {} entries to record: {}", results.size(), trackingKey);
Set<TrackedContentEntry> uploads = new TreeSet<>();
Set<TrackedContentEntry> downloads = new TreeSet<>();
results.forEach((result) -> {
if (StoreEffect.DOWNLOAD == result.getEffect()) {
downloads.add(result);
} else if (StoreEffect.UPLOAD == result.getEffect()) {
uploads.add(result);
}
logger.debug("Removing in-progress entry: {}", result);
inProgressRecordCache.remove(result);
});
created = new TrackedContent(trackingKey, uploads, downloads);
}
logger.debug("Sealing record for: {}", trackingKey);
sealedRecordCache.put(trackingKey, created);
return created;
});
}
use of org.commonjava.indy.folo.model.TrackedContent in project indy by Commonjava.
the class FoloRecordCacheTest method clearRecordDeletesRecord.
@Test
public void clearRecordDeletesRecord() throws Exception {
final TrackingKey key = newKey();
assertThat(cache.hasRecord(key), equalTo(false));
cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, 127L, "", "", ""));
TrackedContent record = cache.seal(key);
assertThat(record, notNullValue());
assertThat(cache.hasRecord(key), equalTo(true));
cache.delete(key);
assertThat(cache.hasRecord(key), equalTo(false));
assertThat(cache.get(key), nullValue());
}
use of org.commonjava.indy.folo.model.TrackedContent in project indy by Commonjava.
the class FoloRecordCacheTest method sealRemovesInProgressAndCreatesSealedRecord.
@Test
public void sealRemovesInProgressAndCreatesSealedRecord() throws Exception {
final TrackingKey key = newKey();
assertThat(cache.hasRecord(key), equalTo(false));
cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, 124L, "", "", ""));
assertThat(cache.hasRecord(key), equalTo(true));
assertThat(cache.hasInProgressRecord(key), equalTo(true));
assertThat(cache.hasSealedRecord(key), equalTo(false));
TrackedContent record = cache.seal(key);
assertThat(record, notNullValue());
assertThat(cache.hasRecord(key), equalTo(true));
assertThat(cache.hasInProgressRecord(key), equalTo(false));
assertThat(cache.hasSealedRecord(key), equalTo(true));
}
Aggregations