PR: MNG-1109

better handling for timeout and other transfer failed exceptions that are recoverable (ie metadata), and then blacklist the repository for performance.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@306560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-06 09:40:13 +00:00
parent 6d14b4c4f3
commit 1d42338bb7
7 changed files with 74 additions and 12 deletions

View File

@ -139,6 +139,11 @@
<!-- <!--
<implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation> <implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
--> -->
<requirements>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirements>
</component> </component>
<!-- <!--

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.manager;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ConnectionException;
@ -72,6 +73,8 @@ public class DefaultWagonManager
private boolean online = true; private boolean online = true;
private ArtifactRepositoryFactory repositoryFactory;
public Wagon getWagon( String protocol ) public Wagon getWagon( String protocol )
throws UnsupportedProtocolException throws UnsupportedProtocolException
{ {
@ -253,7 +256,15 @@ public class DefaultWagonManager
ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots() : repository.getReleases(); ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots() : repository.getReleases();
if ( policy.isEnabled() ) if ( !policy.isEnabled() )
{
getLogger().debug( "Skipping disabled repository " + repository.getId() );
}
else if ( repository.isBlacklisted() )
{
getLogger().debug( "Skipping blacklisted repository " + repository.getId() );
}
else
{ {
getLogger().debug( "Trying repository " + repository.getId() ); getLogger().debug( "Trying repository " + repository.getId() );
getRemoteFile( repository, artifact.getFile(), remotePath, downloadMonitor, policy.getChecksumPolicy() ); getRemoteFile( repository, artifact.getFile(), remotePath, downloadMonitor, policy.getChecksumPolicy() );
@ -261,10 +272,6 @@ public class DefaultWagonManager
artifact.setResolved( true ); artifact.setResolved( true );
} }
else
{
getLogger().debug( "Skipping disabled repository " + repository.getId() );
}
} }
public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository repository, File destination, public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository repository, File destination,
@ -289,8 +296,9 @@ public class DefaultWagonManager
ArtifactRepository mirror = getMirror( repository.getId() ); ArtifactRepository mirror = getMirror( repository.getId() );
if ( mirror != null ) if ( mirror != null )
{ {
repository = new DefaultArtifactRepository( mirror.getId(), mirror.getUrl(), repository.getLayout(), repository = repositoryFactory.createArtifactRepository( mirror.getId(), mirror.getUrl(),
repository.getSnapshots(), repository.getReleases() ); repository.getLayout(), repository.getSnapshots(),
repository.getReleases() );
} }
String protocol = repository.getProtocol(); String protocol = repository.getProtocol();

View File

@ -40,6 +40,8 @@ public class DefaultArtifactRepository
private boolean uniqueVersion; private boolean uniqueVersion;
private boolean blacklisted;
/** /**
* Create a local repository or a test repository. * Create a local repository or a test repository.
* *
@ -139,4 +141,14 @@ public class DefaultArtifactRepository
{ {
return uniqueVersion; return uniqueVersion;
} }
public boolean isBlacklisted()
{
return blacklisted;
}
public void setBlacklisted( boolean blacklisted )
{
this.blacklisted = blacklisted;
}
} }

View File

@ -18,6 +18,9 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author jdcasey * @author jdcasey
*/ */
@ -29,8 +32,11 @@ public class DefaultArtifactRepositoryFactory
private String globalChecksumPolicy; private String globalChecksumPolicy;
private final Map artifactRepositories = new HashMap();
public ArtifactRepository createDeploymentArtifactRepository( String id, String url, public ArtifactRepository createDeploymentArtifactRepository( String id, String url,
ArtifactRepositoryLayout repositoryLayout, boolean uniqueVersion ) ArtifactRepositoryLayout repositoryLayout,
boolean uniqueVersion )
{ {
return new DefaultArtifactRepository( id, url, repositoryLayout, uniqueVersion ); return new DefaultArtifactRepository( id, url, repositoryLayout, uniqueVersion );
} }
@ -40,6 +46,16 @@ public class DefaultArtifactRepositoryFactory
ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy snapshots,
ArtifactRepositoryPolicy releases ) ArtifactRepositoryPolicy releases )
{ {
if ( artifactRepositories.containsKey( id ) )
{
ArtifactRepository repository = (ArtifactRepository) artifactRepositories.get( id );
// TODO: this should be an if there are duplicates?
if ( repository.getUrl().equals( url ) )
{
return repository;
}
}
if ( snapshots == null ) if ( snapshots == null )
{ {
snapshots = new ArtifactRepositoryPolicy(); snapshots = new ArtifactRepositoryPolicy();
@ -62,7 +78,12 @@ public class DefaultArtifactRepositoryFactory
releases.setChecksumPolicy( globalChecksumPolicy ); releases.setChecksumPolicy( globalChecksumPolicy );
} }
return new DefaultArtifactRepository( id, url, repositoryLayout, snapshots, releases ); DefaultArtifactRepository repository = new DefaultArtifactRepository( id, url, repositoryLayout, snapshots,
releases );
artifactRepositories.put( id, repository );
return repository;
} }
public void setGlobalUpdatePolicy( String updatePolicy ) public void setGlobalUpdatePolicy( String updatePolicy )

View File

@ -70,6 +70,10 @@ public class DefaultRepositoryMetadataManager
{ {
getLogger().debug( "Skipping disabled repository " + repository.getId() ); getLogger().debug( "Skipping disabled repository " + repository.getId() );
} }
else if ( repository.isBlacklisted() )
{
getLogger().debug( "Skipping blacklisted repository " + repository.getId() );
}
else else
{ {
File file = new File( localRepository.getBasedir(), File file = new File( localRepository.getBasedir(),
@ -111,7 +115,7 @@ public class DefaultRepositoryMetadataManager
ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots() ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
: repository.getReleases(); : repository.getReleases();
if ( policy.isEnabled() ) if ( policy.isEnabled() && !repository.isBlacklisted() )
{ {
if ( loadMetadata( metadata, repository, localRepository, previousMetadata ) ) if ( loadMetadata( metadata, repository, localRepository, previousMetadata ) )
{ {
@ -260,7 +264,6 @@ public class DefaultRepositoryMetadataManager
private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file, private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file,
String checksumPolicy ) String checksumPolicy )
throws ArtifactMetadataRetrievalException
{ {
if ( !wagonManager.isOnline() ) if ( !wagonManager.isOnline() )
{ {
@ -284,7 +287,11 @@ public class DefaultRepositoryMetadataManager
} }
catch ( TransferFailedException e ) catch ( TransferFailedException e )
{ {
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e ); getLogger().warn( metadata + " could not be found on repository: " + repository.getId() +
" due to an error: " + e.getCause().getMessage() );
getLogger().info( "Repository '" + repository.getId() + "' will be blacklisted" );
getLogger().debug( "Exception", e );
repository.setBlacklisted( true );
} }
} }

View File

@ -8,6 +8,11 @@
<component> <component>
<role>org.apache.maven.artifact.manager.WagonManager</role> <role>org.apache.maven.artifact.manager.WagonManager</role>
<implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation> <implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirements>
</component> </component>
<component> <component>

View File

@ -51,4 +51,8 @@ public interface ArtifactRepository
String getKey(); String getKey();
boolean isUniqueVersion(); boolean isUniqueVersion();
void setBlacklisted( boolean blackListed );
boolean isBlacklisted();
} }