mirror of
https://github.com/apache/archiva.git
synced 2025-02-08 11:06:03 +00:00
PR: MRM-105
executed cacheFailure configuration option git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@386244 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c59ef6d44f
commit
859145b3df
@ -47,6 +47,7 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Edwin Punzalan
|
||||
@ -81,6 +82,11 @@ public class DefaultProxyManager
|
||||
*/
|
||||
private Map repositoryLayoutMap;
|
||||
|
||||
/**
|
||||
* A map
|
||||
*/
|
||||
private Map failuresCache = new HashMap();
|
||||
|
||||
public void setConfiguration( ProxyConfiguration config )
|
||||
{
|
||||
this.config = config;
|
||||
@ -187,16 +193,77 @@ private void getArtifact( Artifact artifact, List repositories )
|
||||
|
||||
if ( !artifactFile.exists() )
|
||||
{
|
||||
for ( Iterator iter = repositories.iterator(); iter.hasNext(); )
|
||||
{
|
||||
ProxyRepository repository = (ProxyRepository) iter.next();
|
||||
try
|
||||
{
|
||||
//@todo usage of repository cache period
|
||||
wagonManager.getArtifact( artifact, repositories );
|
||||
if ( checkIfFailureCached( repository.pathOf( artifact ), repository ) )
|
||||
{
|
||||
getLogger().debug( "Skipping repository " + repository.getKey() +
|
||||
" for a cached path failure." );
|
||||
}
|
||||
else
|
||||
{
|
||||
wagonManager.getArtifact( artifact, repository );
|
||||
}
|
||||
}
|
||||
catch ( TransferFailedException e )
|
||||
{
|
||||
if ( repository.isHardfail() )
|
||||
{
|
||||
throw new ProxyException( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
//handle the failure cache then throw exception as expected
|
||||
doCacheFailure( repository.pathOf( artifact ), repository );
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doCacheFailure( String path, ProxyRepository repository )
|
||||
{
|
||||
if ( repository.isCacheFailures() )
|
||||
{
|
||||
String key = repository.getKey();
|
||||
if ( !failuresCache.containsKey( key ) )
|
||||
{
|
||||
failuresCache.put( key, new ArrayList() );
|
||||
}
|
||||
|
||||
List failureCache = (List) failuresCache.get( key );
|
||||
if ( !failureCache.contains( path ) )
|
||||
{
|
||||
failureCache.add( path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIfFailureCached( String path, ProxyRepository repository )
|
||||
{
|
||||
boolean pathAlreadyFailed = false;
|
||||
|
||||
if ( repository.isCacheFailures() )
|
||||
{
|
||||
String key = repository.getKey();
|
||||
|
||||
if ( failuresCache.containsKey( key ) )
|
||||
{
|
||||
List failureCache = (List) failuresCache.get( key );
|
||||
|
||||
if ( failureCache.contains( path ) )
|
||||
{
|
||||
pathAlreadyFailed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pathAlreadyFailed;
|
||||
}
|
||||
|
||||
private ArtifactRepositoryLayout getLayout()
|
||||
@ -284,10 +351,6 @@ private File getRepositoryFile( String path, List repositories )
|
||||
private File getRepositoryFile( String path, List repositories, boolean useChecksum )
|
||||
throws ResourceDoesNotExistException, ProxyException
|
||||
{
|
||||
Map checksums = null;
|
||||
Wagon wagon = null;
|
||||
boolean connected = false;
|
||||
|
||||
ArtifactRepository cache = getRepositoryCache();
|
||||
File target = new File( cache.getBasedir(), path );
|
||||
|
||||
@ -295,6 +358,32 @@ private File getRepositoryFile( String path, List repositories, boolean useCheck
|
||||
{
|
||||
ProxyRepository repository = (ProxyRepository) repos.next();
|
||||
|
||||
if ( checkIfFailureCached( path, repository ) )
|
||||
{
|
||||
getLogger().debug( "Skipping repository " + repository.getKey() +
|
||||
" for a cached path failure." );
|
||||
}
|
||||
else
|
||||
{
|
||||
getFromRepository( target, path, repository, useChecksum );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !target.exists() )
|
||||
{
|
||||
throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." );
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
private void getFromRepository( File target, String path, ProxyRepository repository, boolean useChecksum )
|
||||
throws ProxyException
|
||||
{
|
||||
boolean connected = false;
|
||||
Map checksums = null;
|
||||
Wagon wagon = null;
|
||||
|
||||
try
|
||||
{
|
||||
wagon = wagonManager.getWagon( repository.getProtocol() );
|
||||
@ -349,8 +438,6 @@ private File getRepositoryFile( String path, List repositories, boolean useCheck
|
||||
{
|
||||
moveTempToTarget( temp, target );
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
//try next repository
|
||||
}
|
||||
@ -361,8 +448,7 @@ private File getRepositoryFile( String path, List repositories, boolean useCheck
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
//@todo usage for cacheFailure
|
||||
//do nothing, file not found in this repository
|
||||
doCacheFailure( path, repository );
|
||||
}
|
||||
catch ( AuthorizationException e )
|
||||
{
|
||||
@ -389,9 +475,6 @@ private File getRepositoryFile( String path, List repositories, boolean useCheck
|
||||
}
|
||||
}
|
||||
|
||||
throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." );
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to add checksum observers as transfer listeners to the wagonManager object
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user