use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class FoloContentAccessResource method doCreate.
@ApiOperation("Store and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 201, message = "Content was stored successfully"), @ApiResponse(code = 400, message = "No appropriate storage location was found in the specified store (this store, or a member if a group is specified).") })
@PUT
@Path("/{path: (.*)}")
public Response doCreate(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam("Package type (eg. maven, npm)") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("path") final String path, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
final TrackingKey tk = new TrackingKey(id);
EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.MAVEN_REPO);
return handler.doCreate(packageType, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(getClass()).path(path).build(id, packageType, type, name));
}
use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class FoloBackupListener method onCacheEntryRemoved.
@CacheEntryRemoved
public void onCacheEntryRemoved(final CacheEntryRemovedEvent<TrackingKey, TrackedContent> event) {
if (event.isPre()) {
return;
}
TrackingKey key = event.getKey();
logger.debug("Cache entry with key {} removed in cache {}", key, event.getCache());
adminController.removeFromSerialized(key);
}
use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class FoloChecksumAdvisor method getChecksumWriteAdvice.
@Override
public Optional<ChecksummingDecoratorAdvisor.ChecksumAdvice> getChecksumWriteAdvice(final Transfer transfer, final TransferOperation operation, final EventMetadata eventMetadata) {
final TrackingKey trackingKey = (TrackingKey) eventMetadata.get(FoloConstants.TRACKING_KEY);
if (trackingKey == null) {
return Optional.empty();
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Enabling checksumming for {} of: {} with tracking key: {}", operation, transfer, trackingKey);
return Optional.of(CALCULATE_NO_WRITE);
}
use of org.commonjava.indy.folo.model.TrackingKey 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 = null;
if (!failed.get()) {
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.TrackingKey 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;
}
Aggregations