Permalink
Browse files

Cleanup: removed separate no-scrape marker file

Changed prefix file format to allow encoding of no-scrape request
using "@ unsupported" directive. Single automatic routing medata
file makes proper synchronization easier to implement and simplifies
overall implementation.

This also eliminated two HEAD requests per remote (due to a bug
original implementation performed HEAD no-scrape file for each
discovery strategy, not once per remote).

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
  • Loading branch information...
1 parent 954df0f commit 34c57970caeeb49358c666e08e82140a7fad4e2a @ifedorenko ifedorenko committed Mar 30, 2013
Showing with 314 additions and 261 deletions.
  1. +7 −0 nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/content/Content.java
  2. +24 −4 ...nt-core/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/JerseyContent.java
  3. +1 −16 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/Config.java
  4. +2 −1 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/Manager.java
  5. +6 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/PrefixSource.java
  6. +16 −1 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/discovery/StrategyResult.java
  7. +6 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/ArrayListPrefixSource.java
  8. +0 −14 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/ConfigImpl.java
  9. +37 −2 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/FilePrefixSource.java
  10. +13 −80 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/ManagerImpl.java
  11. +1 −1 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/ProxyRequestFilterImpl.java
  12. +11 −2 ...re/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/RemoteContentDiscovererImpl.java
  13. +14 −30 ...-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/RemotePrefixFileStrategy.java
  14. +1 −40 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/RemoteScrapeStrategy.java
  15. +63 −3 ...src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/TextFilePrefixSourceMarshaller.java
  16. +12 −12 .../java/org/sonatype/nexus/proxy/maven/routing/internal/PrefixFileUpdatePropagationContentTest.java
  17. +6 −6 ...rc/test/java/org/sonatype/nexus/proxy/maven/routing/internal/PrefixFileUpdatePropagationTest.java
  18. +12 −12 ...rc/test/java/org/sonatype/nexus/proxy/maven/routing/internal/RemoteContentDiscovererImplTest.java
  19. +2 −2 ...e/src/test/java/org/sonatype/nexus/proxy/maven/routing/internal/RemotePrefixFileStrategyTest.java
  20. +4 −4 ...test/java/org/sonatype/nexus/proxy/maven/routing/internal/TextFilePrefixSourceMarshallerTest.java
  21. +6 −0 ...c/test/java/org/sonatype/nexus/proxy/maven/routing/internal/WritablePrefixSourceModifierTest.java
  22. +25 −0 nexus-test/nexus-core-testsuite/src/test/java/core/routing/ITSupport.java
  23. +14 −10 nexus-test/nexus-core-testsuite/src/test/java/core/routing/WithGroupRepositoryIT.java
  24. +14 −10 nexus-test/nexus-core-testsuite/src/test/java/core/routing/WithHostedRepositoryIT.java
  25. +17 −11 nexus-test/nexus-core-testsuite/src/test/java/core/routing/WithProxyRepositoryIT.java
@@ -14,6 +14,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
/**
* @since 2.1
@@ -37,6 +38,12 @@ void download( Location location, File target )
void downloadWith( Location location, Directive directive, File target )
throws IOException;
+ /**
+ * @since 2.4
+ */
+ void downloadWith( Location location, Directive directive, OutputStream target )
+ throws IOException;
+
void upload( Location location, File target )
throws IOException;
@@ -17,6 +17,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import javax.ws.rs.core.Response;
@@ -131,6 +132,13 @@ public void downloadWith( final Location location, final Directive directive, fi
download( location, toUri( location, directive ), target );
}
+ @Override
+ public void downloadWith( Location location, Directive directive, OutputStream target )
+ throws IOException
+ {
+ download( location, toUri( location, directive ), target );
+ }
+
protected void download( final Location location, final String uri, final File target )
throws IOException
{
@@ -146,6 +154,21 @@ protected void download( final Location location, final String uri, final File t
target.getAbsolutePath() );
}
+ FileOutputStream fos = null;
+ try
+ {
+ fos = new FileOutputStream( target );
+ download( location, uri, fos );
+ }
+ finally
+ {
+ IOUtil.close( fos );
+ }
+ }
+
+ protected void download( final Location location, final String uri, final OutputStream target )
+ throws IOException
+ {
try
{
final ClientResponse response = getNexusClient().uri( uri ).get( ClientResponse.class );
@@ -166,16 +189,13 @@ public String getMessage( final int status )
} );
}
- FileOutputStream fos = null;
try
{
- fos = new FileOutputStream( target );
- IOUtil.copy( response.getEntityInputStream(), fos );
+ IOUtil.copy( response.getEntityInputStream(), target );
}
finally
{
response.close();
- IOUtil.close( fos );
}
}
catch ( ClientHandlerException e )
@@ -12,9 +12,8 @@
*/
package org.sonatype.nexus.proxy.maven.routing;
-
/**
- * WL Configuration.
+ * Automatic routing configuration.
*
* @author cstamas
* @since 2.4
@@ -31,27 +30,13 @@
*/
boolean isFeatureActive();
- /**
- * Returns the "no scrape" file path used for flagging a repository to not be scraped.
- *
- * @return the no scrape file path.
- */
- String getLocalNoScrapeFlagPath();
-
/**
* Returns the local file path to publish prefix file.
*
* @return the prefix file path.
*/
String getLocalPrefixFilePath();
- /**
- * Returns the path that should be checked for published no scrape flag on remote.
- *
- * @return the array of paths to have checked on remote.
- */
- String getRemoteNoScrapeFlagPath();
-
/**
* Returns the path that should be checked for published prefix file on remote.
*
@@ -176,7 +176,8 @@ boolean revokeEntry( final MavenHostedRepository mavenHostedRepository, String e
/**
* Returns {@link PrefixSource} for given {@link MavenRepository}.For the existence of the WL in question (if you
- * want to read it), check {@link PrefixSource#exists()} method! Never returns {@code null}.
+ * want to read it), check {@link PrefixSource#exists()} and {@link PrefixSource#supported()} method! Never returns
+ * {@code null}.
*
* @param mavenRepository
* @return the {@link PrefixSource} for given repository.
@@ -31,6 +31,12 @@
*/
boolean exists();
+ /**
+ * Returns {@code true} if automatic routing is supported. Automatic routing is considered unsupported if
+ * {@link #exists()} returns {@code false}.
+ */
+ boolean supported();
+
/**
* Reads entries for this source, of {@code null} if not exists ({@link #exists()} returns {@code false} in this
* case).
@@ -27,16 +27,19 @@
private final PrefixSource prefixSource;
+ private final boolean routingEnabled;
+
/**
* Constructor.
*
* @param message
* @param prefixSource
*/
- public StrategyResult( final String message, final PrefixSource prefixSource )
+ public StrategyResult( final String message, final PrefixSource prefixSource, boolean routingEnabled )
{
this.message = checkNotNull( message );
this.prefixSource = checkNotNull( prefixSource );
+ this.routingEnabled = routingEnabled;
}
/**
@@ -58,4 +61,16 @@ public PrefixSource getPrefixSource()
{
return prefixSource;
}
+
+ /**
+ * Returns <code>false</code> if remote explicitly requested automatic routing to be disabled. This normally
+ * indicates that remote is not able to provide reliable path prefix information. For example, remote itself is a
+ * proxy of a repository that does not provide prefix file and cannot be scraped.
+ *
+ * @return
+ */
+ public boolean isRoutingEnabled()
+ {
+ return routingEnabled;
+ }
}
@@ -62,6 +62,12 @@ public boolean exists()
return true;
}
+ @Override
+ public boolean supported()
+ {
+ return true;
+ }
+
@Override
public List<String> readEntries()
throws IOException
@@ -49,8 +49,6 @@
*/
public static final String FEATURE_ACTIVE_KEY = Config.class.getName() + ".featureActive";
- private static final String LOCAL_NO_SCRAPE_FLAG_PATH = "/.meta/noscrape.txt";
-
private static final String LOCAL_PREFIX_FILE_PATH = "/.meta/prefixes.txt";
private static final int REMOTE_SCRAPE_DEPTH = SystemPropertiesHelper.getInteger( Config.class.getName()
@@ -94,24 +92,12 @@ public boolean isFeatureActive()
return featureActive;
}
- @Override
- public String getLocalNoScrapeFlagPath()
- {
- return LOCAL_NO_SCRAPE_FLAG_PATH;
- }
-
@Override
public String getLocalPrefixFilePath()
{
return LOCAL_PREFIX_FILE_PATH;
}
- @Override
- public String getRemoteNoScrapeFlagPath()
- {
- return LOCAL_NO_SCRAPE_FLAG_PATH;
- }
-
@Override
public String getRemotePrefixFilePath()
{
@@ -32,9 +32,9 @@
import org.sonatype.nexus.proxy.item.StorageFileItem;
import org.sonatype.nexus.proxy.item.StorageItem;
import org.sonatype.nexus.proxy.maven.MavenRepository;
-import org.sonatype.nexus.proxy.maven.routing.PrefixSource;
import org.sonatype.nexus.proxy.maven.routing.Config;
import org.sonatype.nexus.proxy.maven.routing.Manager;
+import org.sonatype.nexus.proxy.maven.routing.PrefixSource;
import org.sonatype.nexus.proxy.maven.routing.WritablePrefixSource;
import org.sonatype.nexus.proxy.storage.UnsupportedStorageOperationException;
@@ -132,6 +132,33 @@ public Boolean call()
return false;
}
+ @Override
+ public boolean supported()
+ {
+ try
+ {
+ return doReadProtected( new Callable<Boolean>()
+ {
+ @Override
+ public Boolean call()
+ throws IOException
+ {
+ StorageFileItem file = getFileItem();
+ if ( file != null )
+ {
+ return getPrefixSourceMarshaller().read( file ).supported();
+ }
+ return false;
+ }
+ } );
+ }
+ catch ( IOException e )
+ {
+ // bam
+ }
+ return false;
+ }
+
@Override
public long getLostModifiedTimestamp()
{
@@ -177,7 +204,7 @@ public Long call()
{
return null;
}
- return getPrefixSourceMarshaller().read( file );
+ return getPrefixSourceMarshaller().read( file ).entries();
}
} );
}
@@ -318,4 +345,12 @@ protected void deleteFileItem()
// ignore
}
}
+
+ public void writeUnsupported()
+ throws IOException
+ {
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ getPrefixSourceMarshaller().writeUnsupported( bos );
+ putFileItem( new PreparedContentLocator( new ByteArrayInputStream( bos.toByteArray() ), "text/plain" ) );
+ }
}
Oops, something went wrong.

0 comments on commit 34c5797

Please sign in to comment.