use of org.commonjava.indy.folo.data.FoloContentException in project indy by Commonjava.
the class FoloAdminResource method clearRecord.
@Path("/{id}/record")
@DELETE
public Response clearRecord(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id) {
Response response;
try {
controller.clearRecord(id);
response = Response.status(Status.NO_CONTENT).build();
} catch (FoloContentException e) {
response = responseHelper.formatResponse(e);
}
return response;
}
use of org.commonjava.indy.folo.data.FoloContentException in project indy by Commonjava.
the class FoloTrackingListener method onFileAccess.
public void onFileAccess(@Observes final FileAccessEvent event) {
logger.trace("FILE ACCESS: {}", event);
EventMetadata metadata = event.getEventMetadata();
final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
if (trackingKey == null) {
logger.trace("No tracking key for access to: {}", event.getTransfer());
return;
}
final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
final Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.trace("No transfer: {}", event);
return;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
logger.trace("Not in a keyed location: {}", event.getTransfer());
return;
}
try {
final KeyedLocation keyedLocation = (KeyedLocation) location;
if (!foloConfig.isGroupContentTracked() && keyedLocation.getKey().getType() == group) {
logger.trace("NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", keyedLocation.getKey());
return;
}
logger.trace("Tracking report: {} += {} in {} (DOWNLOAD)", trackingKey, transfer.getPath(), keyedLocation.getKey());
// Here we need to think about npm metadata retrieving case. As almost all npm metadata retrieving is through
// /$pkg from remote, but we use STORAGE_PATH in EventMetadata with /$pkg/package.json to store this metadata,
// so the real path for this transfer should be /$pkg but its current path is /$pkg/package.json. We need to
// think about if need to do the replacement here, especially for the originalUrl.
recordManager.recordArtifact(createEntry(trackingKey, keyedLocation.getKey(), accessChannel, transfer.getPath(), StoreEffect.DOWNLOAD, event.getEventMetadata()));
} catch (final FoloContentException | IndyWorkflowException e) {
logger.error(String.format("Failed to record download: %s. Reason: %s", transfer, e.getMessage()), e);
}
}
use of org.commonjava.indy.folo.data.FoloContentException in project indy by Commonjava.
the class FoloTrackingListener method onFileUpload.
public void onFileUpload(@Observes final FileStorageEvent event) {
logger.trace("FILE STORAGE: {}", event);
if (TransferOperation.UPLOAD != event.getType()) {
logger.trace("Not a file upload from client; skipping tracking of storage");
return;
}
EventMetadata metadata = event.getEventMetadata();
logger.warn(">>> Metadata: " + metadata);
final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
if (trackingKey == null) {
logger.trace("No tracking key. Not recording.");
return;
}
final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
final Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.trace("No transfer. Not recording.");
return;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
logger.trace("Invalid transfer source location: {}. Not recording.", location);
return;
} else if (!foloConfig.isGroupContentTracked() && ((KeyedLocation) location).getKey().getType() == group) {
logger.trace("NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", ((KeyedLocation) location).getKey());
return;
}
final TransferOperation op = event.getType();
StoreEffect effect = null;
switch(op) {
case DOWNLOAD:
{
effect = StoreEffect.DOWNLOAD;
break;
}
case UPLOAD:
{
effect = StoreEffect.UPLOAD;
break;
}
default:
{
logger.trace("Ignoring transfer operation: {} for: {}", op, transfer);
return;
}
}
try {
final KeyedLocation keyedLocation = (KeyedLocation) location;
logger.trace("Tracking report: {} += {} in {} ({})", trackingKey, transfer.getPath(), keyedLocation.getKey(), effect);
recordManager.recordArtifact(createEntry(trackingKey, keyedLocation.getKey(), accessChannel, transfer.getPath(), effect, event.getEventMetadata()));
} catch (final FoloContentException | IndyWorkflowException e) {
logger.error(String.format("Failed to record download: %s. Reason: %s", transfer, e.getMessage()), e);
}
}
Aggregations