fix handling of dynamic mergedIndexPath

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1470363 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-04-21 23:35:17 +00:00
parent 3b64d5dca9
commit 0da207565c
3 changed files with 55 additions and 29 deletions

View File

@ -100,7 +100,7 @@ public class DefaultIndexMerger
try try
{ {
File indexLocation = new File( tempRepoFile, ".indexer" ); File indexLocation = new File( tempRepoFile, indexMergerRequest.getMergedIndexPath() );
IndexingContext indexingContext = IndexingContext indexingContext =
indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null, indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null,
mavenIndexerUtils.getAllIndexCreators() ); mavenIndexerUtils.getAllIndexCreators() );
@ -124,7 +124,8 @@ public class DefaultIndexMerger
temporaryGroupIndexes.add( temporaryGroupIndexes.add(
new TemporaryGroupIndex( tempRepoFile, tempRepoId, indexMergerRequest.getGroupId() ) ); new TemporaryGroupIndex( tempRepoFile, tempRepoId, indexMergerRequest.getGroupId() ) );
stopWatch.stop(); stopWatch.stop();
log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime() ); log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(),
stopWatch.getTime() );
return indexingContext; return indexingContext;
} }
catch ( IOException e ) catch ( IOException e )

View File

@ -40,6 +40,8 @@ public class IndexMergerRequest
*/ */
private String groupId; private String groupId;
private String mergedIndexPath = "/.indexer";
public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId ) public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId )
{ {
this.repositoriesIds = repositoriesIds; this.repositoriesIds = repositoriesIds;
@ -47,6 +49,18 @@ public class IndexMergerRequest
this.groupId = groupId; this.groupId = groupId;
} }
/**
* @since 1.4-M4
*/
public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId,
String mergedIndexPath )
{
this.repositoriesIds = repositoriesIds;
this.packIndex = packIndex;
this.groupId = groupId;
this.mergedIndexPath = mergedIndexPath;
}
public Collection<String> getRepositoriesIds() public Collection<String> getRepositoriesIds()
{ {
return repositoriesIds; return repositoriesIds;
@ -77,14 +91,24 @@ public class IndexMergerRequest
this.groupId = groupId; this.groupId = groupId;
} }
public String getMergedIndexPath()
{
return mergedIndexPath;
}
public void setMergedIndexPath( String mergedIndexPath )
{
this.mergedIndexPath = mergedIndexPath;
}
@Override @Override
public String toString() public String toString()
{ {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder( "IndexMergerRequest{" );
sb.append( "IndexMergerRequest" ); sb.append( "repositoriesIds=" ).append( repositoriesIds );
sb.append( "{repositoriesIds=" ).append( repositoriesIds );
sb.append( ", packIndex=" ).append( packIndex ); sb.append( ", packIndex=" ).append( packIndex );
sb.append( ", groupId='" ).append( groupId ).append( '\'' ); sb.append( ", groupId='" ).append( groupId ).append( '\'' );
sb.append( ", mergedIndexPath='" ).append( mergedIndexPath ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -272,7 +272,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, archivaLocator.getRepositoryId() ); resourcesInAbsolutePath, repoGroupConfig );
} }
} }
else else
@ -435,7 +435,7 @@ 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 ) RepositoryGroupConfiguration repoGroupConfig )
throws DavException throws DavException
{ {
DavResource resource = null; DavResource resource = null;
@ -450,7 +450,7 @@ public class ArchivaDavResourceFactory
// we are in the case of index file request // we are in the case of index file request
String requestedFileName = StringUtils.substringAfterLast( pathInfo, "/" ); String requestedFileName = StringUtils.substringAfterLast( pathInfo, "/" );
File temporaryIndexDirectory = File temporaryIndexDirectory =
buildMergedIndexDirectory( repositories, activePrincipal, request, repositoryGroupId ); buildMergedIndexDirectory( repositories, activePrincipal, request, repoGroupConfig );
File resourceFile = new File( temporaryIndexDirectory, requestedFileName ); File resourceFile = new File( temporaryIndexDirectory, requestedFileName );
resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), requestedFileName, null, resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), requestedFileName, null,
@ -931,11 +931,10 @@ public class ArchivaDavResourceFactory
// remove last / // remove last /
String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" );
if ( StringUtils.endsWith( pathInfo, "/" + repositoryGroupConfiguration.getMergedIndexPath() ) if ( StringUtils.endsWith( pathInfo, repositoryGroupConfiguration.getMergedIndexPath() ) )
|| StringUtils.endsWith( pathInfo, "/" + repositoryGroupConfiguration.getMergedIndexPath() + "/" ) )
{ {
File mergedRepoDir = buildMergedIndexDirectory( repositories, activePrincipal, request, File mergedRepoDir =
repositoryGroupConfiguration.getId() ); buildMergedIndexDirectory( repositories, activePrincipal, request, repositoryGroupConfiguration );
mergedRepositoryContents.add( mergedRepoDir ); mergedRepositoryContents.add( mergedRepoDir );
} }
else else
@ -1163,7 +1162,8 @@ public class ArchivaDavResourceFactory
} }
protected File buildMergedIndexDirectory( List<String> repositories, String activePrincipal, protected File buildMergedIndexDirectory( List<String> repositories, String activePrincipal,
DavServletRequest request, String groupId ) DavServletRequest request,
RepositoryGroupConfiguration repositoryGroupConfiguration )
throws DavException throws DavException
{ {
@ -1179,7 +1179,7 @@ public class ArchivaDavResourceFactory
temporaryGroupIndexMap = new HashMap<String, TemporaryGroupIndex>(); temporaryGroupIndexMap = new HashMap<String, TemporaryGroupIndex>();
} }
TemporaryGroupIndex tmp = temporaryGroupIndexMap.get( groupId ); TemporaryGroupIndex tmp = temporaryGroupIndexMap.get( repositoryGroupConfiguration.getId() );
if ( tmp != null && tmp.getDirectory() != null && tmp.getDirectory().exists() ) if ( tmp != null && tmp.getDirectory() != null && tmp.getDirectory().exists() )
{ {
@ -1187,13 +1187,13 @@ public class ArchivaDavResourceFactory
* 1000 ) ) * 1000 ) )
{ {
log.debug( MarkerFactory.getMarker( "group.merged.index" ), log.debug( MarkerFactory.getMarker( "group.merged.index" ),
"tmp group index '{}' is too old so delete it", groupId ); "tmp group index '{}' is too old so delete it", repositoryGroupConfiguration.getId() );
indexMerger.cleanTemporaryGroupIndex( tmp ); indexMerger.cleanTemporaryGroupIndex( tmp );
} }
else else
{ {
log.debug( MarkerFactory.getMarker( "group.merged.index" ), log.debug( MarkerFactory.getMarker( "group.merged.index" ),
"merged index for group '{}' found in cache", groupId ); "merged index for group '{}' found in cache", repositoryGroupConfiguration.getId() );
return tmp.getDirectory(); return tmp.getDirectory();
} }
} }
@ -1218,15 +1218,16 @@ public class ArchivaDavResourceFactory
e.getMessage() ); e.getMessage() );
} }
} }
log.info( "generate temporary merged index for repository group '{}' for repositories '{}'", groupId, log.info( "generate temporary merged index for repository group '{}' for repositories '{}'",
authzRepos ); repositoryGroupConfiguration.getId(), authzRepos );
IndexingContext indexingContext = IndexingContext indexingContext = indexMerger.buildMergedIndex(
indexMerger.buildMergedIndex( new IndexMergerRequest( authzRepos, true, groupId ) ); new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(),
repositoryGroupConfiguration.getMergedIndexPath() ) );
File mergedRepoDir = indexingContext.getIndexDirectoryFile(); File mergedRepoDir = indexingContext.getIndexDirectoryFile();
TemporaryGroupIndex temporaryGroupIndex = TemporaryGroupIndex temporaryGroupIndex = new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(),
new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(), groupId ).setCreationTime( repositoryGroupConfiguration.getId() ).setCreationTime(
new Date().getTime() ); new Date().getTime() );
temporaryGroupIndexMap.put( groupId, temporaryGroupIndex ); temporaryGroupIndexMap.put( repositoryGroupConfiguration.getId(), temporaryGroupIndex );
session.setAttribute( TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, session.setAttribute( TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY,
temporaryGroupIndexMap ); temporaryGroupIndexMap );
return mergedRepoDir; return mergedRepoDir;