use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class SpecialPathManagerImpl method getPathInfo.
private SpecialPathInfo getPathInfo(Location location, String path, Collection<SpecialPathInfo> from) {
SpecialPathInfo firstHit = null;
// Location is not used in current SpecialPathMatcher impl classes, so removed the null check.
if (path != null) {
for (SpecialPathInfo info : from) {
if (info.getMatcher().matches(location, path)) {
if (firstHit != null) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error("Duplicate special-path registration for: {}:{}. Using: {}", location, path, firstHit);
} else {
firstHit = info;
}
}
}
}
// TODO: Return SpecialPathConstants.DEFAULT_FILE or SpecialPathConstants.DEFAULT_DIR based on path if firstHit is null!
return firstHit;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project indy by Commonjava.
the class InfinispanGalleyStorageProvider method setup.
@PostConstruct
public void setup() {
SpecialPathInfo infoSpi = SpecialPathInfo.from(new FilePatternMatcher(".+\\.info")).setDecoratable(false).setDeletable(false).setListable(false).setPublishable(false).setRetrievable(false).setStorable(false).build();
specialPathManager.registerSpecialPathInfo(infoSpi);
transferDecorator = new ChecksummingTransferDecorator(Collections.singleton(TransferOperation.GENERATE), specialPathManager, new Md5GeneratorFactory(), new Sha1GeneratorFactory());
this.cacheProvider = new GridFileSystemCacheProvider(pathGenerator, fileEventManager, transferDecorator, cacheFs);
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project indy by Commonjava.
the class ScheduleManager method setProxyTimeouts.
public synchronized void setProxyTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
RemoteRepository repo = null;
try {
repo = (RemoteRepository) dataManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
}
if (repo == null) {
return;
}
int timeout = config.getPassthroughTimeoutSeconds();
final ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(repo), path);
final SpecialPathInfo info = specialPathManager.getSpecialPathInfo(resource);
if (!repo.isPassthrough()) {
if ((info != null && info.isMetadata()) && repo.getMetadataTimeoutSeconds() > 0) {
logger.debug("Using metadata timeout for: {}", resource);
timeout = repo.getMetadataTimeoutSeconds();
} else {
if (info == null) {
logger.debug("No special path info for: {}", resource);
} else {
logger.debug("{} is a special path, but not metadata.", resource);
}
timeout = repo.getCacheTimeoutSeconds();
}
}
if (timeout > 0) {
// logger.info( "[PROXY TIMEOUT SET] {}/{}; {}", repo.getKey(), path, new Date( System.currentTimeMillis()
// + timeout ) );
cancel(new StoreKeyMatcher(key, CONTENT_JOB_TYPE), path);
scheduleContentExpiration(key, path, timeout);
}
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class TransferManagerImpl method retrieve.
@Override
public Transfer retrieve(final ConcreteResource resource, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
// logger.info( "Attempting to resolve: {}", resource );
// TODO: Handle the case where storage isn't allowed?
// NOTE: This would expand the notion out from simply:
// "don't allow storing new stuff"
// to:
// "don't ever cache this stuff"
Transfer target = null;
try {
// TODO: (see above re:storing) Handle things like local archives that really don't need to be cached...
target = getCacheReference(resource);
if (target.exists()) {
logger.debug("Using cached copy of: {}", target);
return target;
}
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
if (!resource.allowsDownloading() || (specialPathInfo != null && !specialPathInfo.isRetrievable())) {
logger.debug("Download not allowed for: {}. Returning null transfer.", resource);
return null;
}
final Transfer retrieved = downloader.download(resource, target, getTimeoutSeconds(resource), getTransport(resource), suppressFailures, eventMetadata);
if (retrieved != null && retrieved.exists() && !target.equals(retrieved)) {
if (specialPathInfo == null || specialPathInfo.isCachable()) {
cacheProvider.createAlias(retrieved.getResource(), target.getResource());
}
}
if (target.exists()) {
logger.debug("DOWNLOADED: {}", resource);
return target;
} else {
logger.debug("NOT DOWNLOADED: {}", resource);
return null;
}
} catch (final TransferException e) {
fileEventManager.fire(new FileErrorEvent(target, e, eventMetadata));
throw e;
} catch (final IOException e) {
final TransferException error = new TransferException("Failed to download: {}. Reason: {}", e, resource, e.getMessage());
fileEventManager.fire(new FileErrorEvent(target, error, eventMetadata));
throw error;
}
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class ChecksummingTransferDecorator method decorateWrite.
public OutputStream decorateWrite(final OutputStream stream, final Transfer transfer, final TransferOperation op, final EventMetadata eventMetadata) throws IOException {
Object forceObj = eventMetadata.get(FORCE_CHECKSUM);
boolean force = Boolean.TRUE.equals(forceObj) || Boolean.parseBoolean(String.valueOf(forceObj));
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer, eventMetadata.getPackageType());
logger.trace("SpecialPathInfo for: {} is: {} (decoratable? {})", transfer, specialPathInfo, (specialPathInfo == null || specialPathInfo.isDecoratable()));
if (force || specialPathInfo == null || specialPathInfo.isDecoratable()) {
ChecksummingDecoratorAdvisor.ChecksumAdvice advice = writerFilter.getDecorationAdvice(transfer, op, eventMetadata);
if (force && advice == NO_DECORATE) {
advice = CALCULATE_NO_WRITE;
}
boolean consumerNeedsIt = (consumer == null || consumer.needsMetadataFor(transfer));
logger.trace("Advice is: {} for {} of: {} (and consumer is missing or needs it? {})", advice, op, transfer, consumerNeedsIt);
// 2. if we have a metadata consumer AND the consumer needs metadata for this transfer
if (advice != NO_DECORATE && (consumer == null || consumer.needsMetadataFor(transfer))) {
logger.trace("Wrapping output stream to: {} for checksum generation.", transfer);
return new ChecksummingOutputStream(checksumFactories, stream, transfer, consumer, advice == CALCULATE_AND_WRITE);
}
}
logger.trace("NOT decorating write with ChecksummingTransferDecorator for: {}", transfer);
return stream;
}
Aggregations