[MRM-815] aggregate indices for repository groups.

correctlty returned various index files.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-11-05 09:08:42 +00:00
parent f0a3cbb416
commit 3332f36a12
2 changed files with 116 additions and 71 deletions

View File

@ -85,6 +85,10 @@
</listener-class> </listener-class>
</listener> </listener>
<listener>
<listener-class>net.sf.ehcache.constructs.web.ShutdownListener</listener-class>
</listener>
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value> <param-value>
@ -190,4 +194,9 @@
<url-pattern>/restServices/*</url-pattern> <url-pattern>/restServices/*</url-pattern>
</servlet-mapping> </servlet-mapping>
<session-config>
<!-- 30 minutes session timeout -->
<session-timeout>30</session-timeout>
</session-config>
</web-app> </web-app>

View File

@ -98,8 +98,10 @@ import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@ -253,7 +255,8 @@ public class ArchivaDavResourceFactory
// handle browse requests for virtual repos // handle browse requests for virtual repos
if ( RepositoryPathUtil.getLogicalResource( archivaLocator.getOrigResourcePath() ).endsWith( "/" ) ) if ( RepositoryPathUtil.getLogicalResource( archivaLocator.getOrigResourcePath() ).endsWith( "/" ) )
{ {
return getResource( request, repoGroupConfig.getRepositories(), archivaLocator ); return getResource( request, repoGroupConfig.getRepositories(), archivaLocator,
archivaLocator.getRepositoryId() );
} }
else else
{ {
@ -262,7 +265,7 @@ public class ArchivaDavResourceFactory
// infrequent // infrequent
List<String> repositories = new ArrayList<String>( repoGroupConfig.getRepositories() ); List<String> repositories = new ArrayList<String>( repoGroupConfig.getRepositories() );
resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal, resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal,
resourcesInAbsolutePath ); resourcesInAbsolutePath, archivaLocator.getRepositoryId() );
} }
} }
else else
@ -394,51 +397,71 @@ public class ArchivaDavResourceFactory
private DavResource processRepositoryGroup( final DavServletRequest request, private DavResource processRepositoryGroup( final DavServletRequest request,
ArchivaDavResourceLocator archivaLocator, List<String> repositories, ArchivaDavResourceLocator archivaLocator, List<String> repositories,
String activePrincipal, List<String> resourcesInAbsolutePath ) String activePrincipal, List<String> resourcesInAbsolutePath,
String repositoryGroupId )
throws DavException throws DavException
{ {
DavResource resource = null; DavResource resource = null;
List<DavException> storedExceptions = new ArrayList<DavException>(); List<DavException> storedExceptions = new ArrayList<DavException>();
for ( String repositoryId : repositories ) String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" );
String rootPath = StringUtils.substringBeforeLast( pathInfo, "/" );
if ( StringUtils.endsWith( rootPath, "/.indexer" ) )
{ {
ManagedRepositoryContent managedRepository; // we are in the case of index file request
try String requestedFileName = StringUtils.substringAfterLast( pathInfo, "/" );
{ File temporaryIndexDirectory =
managedRepository = repositoryFactory.getManagedRepositoryContent( repositoryId ); buildMergedIndexDirectory( repositories, activePrincipal, request, repositoryGroupId );
}
catch ( RepositoryNotFoundException e )
{
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
catch ( RepositoryException e )
{
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
try File resourceFile = new File( temporaryIndexDirectory, requestedFileName );
resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), requestedFileName, null,
request.getRemoteAddr(), activePrincipal, request.getDavSession(),
archivaLocator, this, mimeTypes, auditListeners, scheduler );
}
else
{
for ( String repositoryId : repositories )
{ {
DavResource updatedResource = ManagedRepositoryContent managedRepository;
processRepository( request, archivaLocator, activePrincipal, managedRepository ); try
if ( resource == null )
{ {
resource = updatedResource; managedRepository = repositoryFactory.getManagedRepositoryContent( repositoryId );
}
catch ( RepositoryNotFoundException e )
{
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
catch ( RepositoryException e )
{
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
} }
String logicalResource = RepositoryPathUtil.getLogicalResource( archivaLocator.getResourcePath() ); try
if ( logicalResource.endsWith( "/" ) )
{ {
logicalResource = logicalResource.substring( 1 ); DavResource updatedResource =
processRepository( request, archivaLocator, activePrincipal, managedRepository );
if ( resource == null )
{
resource = updatedResource;
}
String logicalResource = RepositoryPathUtil.getLogicalResource( archivaLocator.getResourcePath() );
if ( logicalResource.endsWith( "/" ) )
{
logicalResource = logicalResource.substring( 1 );
}
resourcesInAbsolutePath.add(
new File( managedRepository.getRepoRoot(), logicalResource ).getAbsolutePath() );
}
catch ( DavException e )
{
storedExceptions.add( e );
} }
resourcesInAbsolutePath.add(
new File( managedRepository.getRepoRoot(), logicalResource ).getAbsolutePath() );
}
catch ( DavException e )
{
storedExceptions.add( e );
} }
} }
if ( resource == null ) if ( resource == null )
{ {
if ( !storedExceptions.isEmpty() ) if ( !storedExceptions.isEmpty() )
@ -918,7 +941,7 @@ public class ArchivaDavResourceFactory
} }
private DavResource getResource( DavServletRequest request, List<String> repositories, private DavResource getResource( DavServletRequest request, List<String> repositories,
ArchivaDavResourceLocator locator ) ArchivaDavResourceLocator locator, String groupId )
throws DavException throws DavException
{ {
List<File> mergedRepositoryContents = new ArrayList<File>(); List<File> mergedRepositoryContents = new ArrayList<File>();
@ -945,21 +968,8 @@ public class ArchivaDavResourceFactory
String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" );
if ( StringUtils.endsWith( pathInfo, "/.indexer" ) ) if ( StringUtils.endsWith( pathInfo, "/.indexer" ) )
{ {
try File mergedRepoDir = buildMergedIndexDirectory( repositories, activePrincipal, request, groupId );
{ mergedRepositoryContents.add( mergedRepoDir );
File mergedRepoDir = buildMergedIndexDirectory( repositories, activePrincipal, request );
mergedRepositoryContents.add( mergedRepoDir );
}
catch ( RepositoryAdminException e )
{
throw new DavException( 500, e );
}
catch ( IndexMergerException e )
{
throw new DavException( 500, e );
}
} }
else else
{ {
@ -1181,35 +1191,61 @@ public class ArchivaDavResourceFactory
} }
protected File buildMergedIndexDirectory( List<String> repositories, String activePrincipal, protected File buildMergedIndexDirectory( List<String> repositories, String activePrincipal,
DavServletRequest request ) DavServletRequest request, String groupId )
throws RepositoryAdminException, IndexMergerException throws DavException
{ {
Set<String> authzRepos = new HashSet<String>(); try
for ( String repository : repositories )
{ {
try HttpSession session = request.getSession();
Map<String, File> testValue = (Map<String, File>) session.getAttribute( "TMP_GROUP_INDEXES" );
if ( testValue == null )
{ {
if ( servletAuth.isAuthorized( activePrincipal, repository, testValue = new HashMap<String, File>();
WebdavMethodUtil.getMethodPermission( request.getMethod() ) ) )
{
authzRepos.add( repository );
authzRepos.addAll( this.repositorySearch.getRemoteIndexingContextIds( repository ) );
}
} }
catch ( UnauthorizedException e )
{
// TODO: review exception handling
if ( log.isDebugEnabled() )
{
log.debug( "Skipping repository '" + repository + "' for user '" + activePrincipal + "': "
+ e.getMessage() );
}
}
}
File mergedRepoDir = indexMerger.buildMergedIndex( authzRepos, true ); File tmp = testValue.get( groupId );
return mergedRepoDir; if ( tmp != null )
{
return tmp;
}
Set<String> authzRepos = new HashSet<String>();
for ( String repository : repositories )
{
try
{
if ( servletAuth.isAuthorized( activePrincipal, repository,
WebdavMethodUtil.getMethodPermission( request.getMethod() ) ) )
{
authzRepos.add( repository );
authzRepos.addAll( this.repositorySearch.getRemoteIndexingContextIds( repository ) );
}
}
catch ( UnauthorizedException e )
{
// TODO: review exception handling
if ( log.isDebugEnabled() )
{
log.debug( "Skipping repository '" + repository + "' for user '" + activePrincipal + "': "
+ e.getMessage() );
}
}
}
File mergedRepoDir = indexMerger.buildMergedIndex( authzRepos, true );
testValue.put( groupId, mergedRepoDir );
session.setAttribute( "TMP_GROUP_INDEXES", testValue );
return mergedRepoDir;
}
catch ( RepositoryAdminException e )
{
throw new DavException( 500, e );
}
catch ( IndexMergerException e )
{
throw new DavException( 500, e );
}
} }