Permalink
Browse files

Merge pull request #847 from sonatype/nexus-5511-refine-reasoning

[REVIEW] NEXUS-5511 Refine reasoning
  • Loading branch information...
2 parents 1a148aa + 557256b commit 040cc7df5b761383c53b70eb7eb17b797a81eb03 @cstamas cstamas committed Apr 30, 2013
@@ -48,8 +48,8 @@
import org.sonatype.nexus.proxy.item.uid.IsHiddenAttribute;
import org.sonatype.nexus.proxy.maven.EvictUnusedMavenItemsWalkerProcessor.EvictUnusedMavenItemsWalkerFilter;
import org.sonatype.nexus.proxy.maven.packaging.ArtifactPackagingMapper;
-import org.sonatype.nexus.proxy.maven.routing.ProxyRequestFilter;
import org.sonatype.nexus.proxy.maven.routing.Manager;
+import org.sonatype.nexus.proxy.maven.routing.ProxyRequestFilter;
import org.sonatype.nexus.proxy.repository.AbstractProxyRepository;
import org.sonatype.nexus.proxy.repository.DefaultRepositoryKind;
import org.sonatype.nexus.proxy.repository.HostedRepository;
@@ -414,7 +414,7 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )
throw new ItemNotFoundException( reasonFor( request, this,
"Retrieval of %s from %s is forbidden by repository policy %s.", request.getRequestPath(),
- RepositoryStringUtils.getHumanizedNameString( this ), getRepositoryPolicy() ) );
+ this, getRepositoryPolicy() ) );
}
if ( getRepositoryKind().isFacetAvailable( ProxyRepository.class )
@@ -454,14 +454,12 @@ private StorageItem doRetrieveArtifactItem( ResourceStoreRequest hashRequest, St
}
@Override
- protected boolean shouldTryRemote( final ResourceStoreRequest request )
+ protected void shouldTryRemote( final ResourceStoreRequest request )
throws IllegalOperationException, ItemNotFoundException
{
- final boolean shouldTryRemote = super.shouldTryRemote( request );
- if ( !shouldTryRemote )
- {
- return false;
- }
+ // do super first
+ super.shouldTryRemote( request );
+ // if here, super did not throw any exception, so let's continue
// apply autorouting filter to "normal" requests only, not hidden (which is meta or plain hidden)
final RepositoryItemUid uid = createUid( request.getRequestPath() );
if ( !uid.getBooleanAttributeValue( IsHiddenAttribute.class ) )
@@ -472,13 +470,12 @@ protected boolean shouldTryRemote( final ResourceStoreRequest request )
final boolean proxyFilterAllowed = getProxyRequestFilter().allowed( this, request );
if ( !proxyFilterAllowed )
{
- getLogger().debug( "Automatic routing filter rejected remote request for path {} in {}.",
- request.getRequestPath(), RepositoryStringUtils.getHumanizedNameString( this ) );
- return false;
+ throw new ItemNotFoundException( ItemNotFoundException.reasonFor( request, this,
+ "Automatic routing filter rejected remote request for path %s from %s", request.getRequestPath(),
+ this ) );
}
}
}
- return true;
}
@Override
@@ -260,7 +260,7 @@ public void expireCaches( ResourceStoreRequest request )
{
throw new GroupItemNotFoundException( reasonFor( request, this,
"The %s not found in local storage of group repository %s (no member processing happened).",
- request.getRequestPath(), RepositoryStringUtils.getHumanizedNameString( this ) ), memberThrowables );
+ request.getRequestPath(), this ), memberThrowables );
}
}
@@ -417,7 +417,7 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )
{
throw new GroupItemNotFoundException( reasonFor( request, this,
"The %s not found in local storage of group repository %s (no member processing happened).",
- request.getRequestPath(), RepositoryStringUtils.getHumanizedNameString( this ) ), memberThrowables );
+ request.getRequestPath(), this ), memberThrowables );
}
}
finally
@@ -666,7 +666,7 @@ public void removeMemberRepositoryId( String repositoryId )
{
throw new GroupItemNotFoundException( reasonFor( request, this,
"The %s not found in local storage of group repository %s (no member processing happened).",
- request.getRequestPath(), RepositoryStringUtils.getHumanizedNameString( this ) ), memberThrowables );
+ request.getRequestPath(), this ), memberThrowables );
}
}
@@ -12,6 +12,8 @@
*/
package org.sonatype.nexus.proxy.repository;
+import static org.sonatype.nexus.proxy.ItemNotFoundException.reasonFor;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -74,8 +76,6 @@
import org.sonatype.nexus.util.NumberSequence;
import org.sonatype.nexus.util.SystemPropertiesHelper;
-import static org.sonatype.nexus.proxy.ItemNotFoundException.reasonFor;
-
/**
* Adds the proxying capability to a simple repository. The proxying will happen only if reposiory has remote storage!
* So, this implementation is used in both "simple" repository cases: hosted and proxy, but in 1st case there is no
@@ -1152,10 +1152,19 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )
}
}
- protected boolean shouldTryRemote( final ResourceStoreRequest request )
+ protected void shouldTryRemote( final ResourceStoreRequest request )
throws IllegalOperationException, ItemNotFoundException
{
- return !request.isRequestLocalOnly() && getProxyMode() != null && getProxyMode().shouldProxy();
+ if ( request.isRequestLocalOnly() )
+ {
+ throw new ItemNotFoundException( ItemNotFoundException.reasonFor( request, this,
+ "Request is marked as local-only, remote access not allowed from %s", this ) );
+ }
+ if ( getProxyMode() != null && !getProxyMode().shouldProxy() )
+ {
+ throw new ItemNotFoundException( ItemNotFoundException.reasonFor( request, this,
+ "Repository proxy-mode is %s, remote access not allowed from %s", getProxyMode(), this ) );
+ }
}
protected StorageItem doRetrieveItem0( ResourceStoreRequest request, AbstractStorageItem localItem )
@@ -1165,11 +1174,17 @@ protected StorageItem doRetrieveItem0( ResourceStoreRequest request, AbstractSto
AbstractStorageItem remoteItem = null;
// proxyMode and request.localOnly decides 1st
- boolean shouldProxy = shouldTryRemote( request );
-
- ItemNotFoundException requestProcessorReason = null;
+ ItemNotFoundException noRemoteAccessReason = null;
+ try
+ {
+ shouldTryRemote( request );
+ }
+ catch ( ItemNotFoundException e )
+ {
+ noRemoteAccessReason = e;
+ }
- if ( shouldProxy )
+ if ( noRemoteAccessReason == null )
{
for ( RequestStrategy strategy : getRegisteredStrategies().values() )
{
@@ -1179,15 +1194,14 @@ protected StorageItem doRetrieveItem0( ResourceStoreRequest request, AbstractSto
}
catch ( ItemNotFoundException e )
{
- requestProcessorReason = e;
- shouldProxy = false;
+ noRemoteAccessReason = e;
// escape
break;
}
}
}
- if ( shouldProxy )
+ if ( noRemoteAccessReason == null )
{
// we are able to go remote
if ( localItem == null || request.isRequestAsExpired() || isOld( localItem ) )
@@ -1338,8 +1352,8 @@ protected StorageItem doRetrieveItem0( ResourceStoreRequest request, AbstractSto
}
throw new ItemNotFoundException( reasonFor( request, this,
- "Path %s not found in local nor in remote storage of %s repository.", request.getRequestPath(),
- RepositoryStringUtils.getHumanizedNameString( this ) ) );
+ "Path %s not found in local nor in remote storage of %s", request.getRequestPath(),
+ this ) );
}
else if ( localItem != null && remoteItem == null )
{
@@ -1384,18 +1398,8 @@ else if ( localItem != null && remoteItem == null )
+ " does not exist locally and cannot go remote, throwing ItemNotFoundException." );
}
- if ( requestProcessorReason != null )
- {
- throw new ItemNotFoundException( ItemNotFoundException.reasonFor( request, this,
- "Request processor prevented remote access" ), requestProcessorReason );
- }
- else
- {
- // a generic one
- throw new ItemNotFoundException( reasonFor( request, this,
- "Path %s not found in local storage and remote storage access is prevented of %s repository.",
- request.getRequestPath(), RepositoryStringUtils.getHumanizedNameString( this ) ) );
- }
+ throw new ItemNotFoundException( ItemNotFoundException.reasonFor( request, this,
+ noRemoteAccessReason.getMessage() ), noRemoteAccessReason );
}
}
@@ -1734,8 +1738,8 @@ else if ( lastException instanceof ItemNotFoundException )
// validation failed, I guess.
throw new ItemNotFoundException( reasonFor( request, this,
- "Path %s fetched from remote but failed validation in %s.", request.getRequestPath(),
- RepositoryStringUtils.getHumanizedNameString( this ) ) );
+ "Path %s fetched from remote storage of %s but failed validation.", request.getRequestPath(),
+ this ) );
}
finally
{
@@ -1831,7 +1835,7 @@ public Object call()
RemoteStatus.UNAVAILABLE,
new ItemNotFoundException( reasonFor( request, AbstractProxyRepository.this,
"Proxy mode %s or repository %s forbids remote storage use.", getProxyMode(),
- RepositoryStringUtils.getHumanizedNameString( AbstractProxyRepository.this ) ) ) );
+ AbstractProxyRepository.this ) ) );
}
else
{
@@ -1843,7 +1847,7 @@ public Object call()
{
autoBlockProxying( new ItemNotFoundException( reasonFor( request,
AbstractProxyRepository.this, "Remote peer of repository %s detected as unavailable.",
- RepositoryStringUtils.getHumanizedNameString( AbstractProxyRepository.this ) ) ) );
+ AbstractProxyRepository.this ) ) );
}
}
}
@@ -674,8 +674,8 @@ public StorageItem retrieveItem( ResourceStoreRequest request )
getId() + " retrieveItem() :: FOUND a collection on " + request.toString()
+ " but repository is not Browseable." );
- throw new ItemNotFoundException( reasonFor( request, this, "Repository %s is not browsable.",
- RepositoryStringUtils.getHumanizedNameString( this ) ) );
+ throw new ItemNotFoundException( reasonFor( request, this, "Repository %s is not browsable",
+ this ) );
}
checkPostConditions( request, item );
@@ -772,7 +772,7 @@ public void createCollection( ResourceStoreRequest request, Map<String, String>
}
else
{
- throw new ItemNotFoundException( reasonFor( request, this, "Repository %s is not browsable!" ) );
+ throw new ItemNotFoundException( reasonFor( request, this, "Repository %s is not browsable", this ) );
}
return items;
@@ -871,7 +871,8 @@ public StorageItem retrieveItem( boolean fromTask, ResourceStoreRequest request
RepositoryStringUtils.getHumanizedNameString( this ), uid.getPath(), key ) );
throw new ItemNotFoundException( reasonFor( request, this,
- "The generator for generated path %s not found!" ) );
+ "The generator for generated path %s with key %s not found in %s", request.getRequestPath(),
+ key, this ) );
}
}
@@ -1141,8 +1142,8 @@ public void storeItem( boolean fromTask, StorageItem item )
}
else
{
- throw new ItemNotFoundException( reasonFor( request, this, "Path %s in repository %s is not a collection.",
- request.getRequestPath(), RepositoryStringUtils.getHumanizedNameString( this ) ) );
+ throw new ItemNotFoundException( reasonFor( request, this, "Path %s in repository %s is not a collection",
+ request.getRequestPath(), this ) );
}
}
@@ -1215,8 +1216,7 @@ public void maintainNotFoundCache( ResourceStoreRequest request )
}
throw new ItemNotFoundException( reasonFor( request, this,
- "The path %s is in NFC of repository %s.", request.getRequestPath(),
- RepositoryStringUtils.getHumanizedNameString( this ) ) );
+ "The path %s is still cached as not found for repository %s", request.getRequestPath(), this ) );
}
}
}

0 comments on commit 040cc7d

Please sign in to comment.