use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final StoreKey storeKey, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer transfer = getIndexedTransfer(storeKey, null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
logger.debug("Returning indexed transfer: {}", transfer);
return transfer;
}
ArtifactStore store;
try {
store = storeDataManager.getArtifactStore(storeKey);
} catch (IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup ArtifactStore: %s for NFC handling. Reason: %s", e, storeKey, e.getMessage());
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = storeKey.getType();
if (StoreType.group == type) {
Group g = (Group) store;
if (g == null) {
throw new IndyWorkflowException("Cannot find requested group: %s", storeKey);
}
if (nfc.isMissing(resource)) {
logger.debug("NFC / MISSING: {}", resource);
return null;
}
logger.debug("No group index hits. Devolving to member store indexes.");
for (StoreKey key : g.getConstituents()) {
transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
try {
return delegate.getTransfer(member, path, op);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to getTransfer() for member path: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
logger.debug("Returning indexed transfer: {} from member: {}", transfer, key);
return transfer;
}
}
}
transfer = delegate.getTransfer(storeKey, path, op);
if (transfer != null) {
logger.debug("Indexing transfer: {}", transfer);
indexManager.indexTransferIn(transfer, storeKey);
}
return transfer;
}
use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
return transfer;
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = store.getKey().getType();
if (StoreType.group == type) {
if (!nfc.isMissing(resource)) {
logger.debug("No group index hits. Devolving to member store indexes.");
transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
try {
return delegate.getTransfer(member, path, op);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to getTransfer() for: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
return transfer;
}
} else {
logger.debug("NFC marks {} as missing. Returning null.", resource);
return null;
}
}
transfer = delegate.getTransfer(store, path, op);
// index the transfer only if it exists, it cannot be null at this point
if (transfer != null && transfer.exists()) {
indexManager.indexTransferIn(transfer, store.getKey());
}
logger.debug("Returning transfer: {}", transfer);
return transfer;
}
use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.
the class FoloTrackingListener method onFileUpload.
public void onFileUpload(@Observes final FileStorageEvent event) {
logger.debug("FILE STORAGE: {}", event);
if (TransferOperation.UPLOAD != event.getType()) {
logger.debug("Not a file upload from client; skipping tracking of storage");
return;
}
EventMetadata metadata = event.getEventMetadata();
final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
if (trackingKey == null) {
logger.info("No tracking key. Not recording.");
return;
}
final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
final Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.info("No transfer. Not recording.");
return;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
logger.info("Invalid transfer source location: {}. Not recording.", location);
return;
} else if (!foloConfig.isGroupContentTracked() && ((KeyedLocation) location).getKey().getType() == group) {
logger.debug("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.debug("Ignoring transfer operation: {} for: {}", op, transfer);
return;
}
}
try {
final KeyedLocation keyedLocation = (KeyedLocation) location;
logger.debug("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