mirror of https://github.com/apache/archiva.git
[MRM-815] aggregate indices for repository groups.
cleanup created temp directories. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1196846 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e36162963
commit
93e5fdfa27
|
@ -33,6 +33,20 @@
|
|||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-repository-admin-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-core</artifactId>
|
||||
|
|
|
@ -19,21 +19,28 @@ package org.apache.archiva.indexer.merger;
|
|||
*/
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
|
||||
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
|
||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.maven.index.NexusIndexer;
|
||||
import org.apache.maven.index.context.IndexingContext;
|
||||
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
||||
import org.apache.maven.index.packer.IndexPacker;
|
||||
import org.apache.maven.index.packer.IndexPackingRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
|
@ -44,6 +51,8 @@ public class DefaultIndexMerger
|
|||
implements IndexMerger
|
||||
{
|
||||
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject
|
||||
private ManagedRepositoryAdmin managedRepositoryAdmin;
|
||||
|
||||
|
@ -53,7 +62,9 @@ public class DefaultIndexMerger
|
|||
|
||||
private IndexPacker indexPacker;
|
||||
|
||||
@javax.inject.Inject
|
||||
private List<TemporaryIndex> temporaryIndexes = new CopyOnWriteArrayList<TemporaryIndex>();
|
||||
|
||||
@Inject
|
||||
public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils )
|
||||
throws PlexusSisuBridgeException
|
||||
{
|
||||
|
@ -93,6 +104,7 @@ public class DefaultIndexMerger
|
|||
IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexLocation );
|
||||
indexPacker.packIndex( request );
|
||||
}
|
||||
temporaryIndexes.add( new TemporaryIndex( tempRepoFile ) );
|
||||
return indexingContext.getIndexDirectoryFile();
|
||||
}
|
||||
catch ( IOException e )
|
||||
|
@ -104,4 +116,60 @@ public class DefaultIndexMerger
|
|||
throw new IndexMergerException( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Scheduled( fixedDelay = 900000 )
|
||||
public void cleanTemporaryIndex()
|
||||
{
|
||||
for ( TemporaryIndex temporaryIndex : temporaryIndexes )
|
||||
{
|
||||
// cleanup files older than 30 minutes
|
||||
if ( new Date().getTime() - temporaryIndex.creationTime > 1800000 )
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtils.deleteDirectory( temporaryIndex.directory );
|
||||
temporaryIndexes.remove( temporaryIndex );
|
||||
log.debug( "remove directory {}", temporaryIndex.directory );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
log.warn( "failed to remove directory:" + temporaryIndex.directory, e );
|
||||
}
|
||||
}
|
||||
temporaryIndexes.remove( temporaryIndex );
|
||||
}
|
||||
}
|
||||
|
||||
private static class TemporaryIndex
|
||||
{
|
||||
private long creationTime = new Date().getTime();
|
||||
|
||||
private File directory;
|
||||
|
||||
TemporaryIndex( File directory )
|
||||
{
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Long.toString( creationTime ).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( !( o instanceof TemporaryIndex ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.creationTime == ( (TemporaryIndex) o ).creationTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,17 +22,27 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:task="http://www.springframework.org/schema/task"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
default-lazy-init="true">
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/task
|
||||
http://www.springframework.org/schema/task/spring-task-3.0.xsd"
|
||||
default-lazy-init="false">
|
||||
|
||||
<context:annotation-config/>
|
||||
<context:component-scan base-package="org.apache.archiva.indexer.search,org.apache.archiva.indexer.merger"/>
|
||||
|
||||
<bean id="logger" class="org.apache.archiva.common.utils.Slf4JPlexusLogger">
|
||||
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
|
||||
<constructor-arg type="java.lang.Class">
|
||||
<value>org.apache.maven.index.DefaultNexusIndexer</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
<task:executor id="springExecutor" pool-size="2"/>
|
||||
<task:scheduler id="springScheduler" pool-size="2"/>
|
||||
<task:annotation-driven executor="springExecutor" scheduler="springScheduler"/>
|
||||
|
||||
</beans>
|
|
@ -73,6 +73,10 @@
|
|||
<level value="info"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.apache.archiva.indexer.merger">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<priority value ="info" />
|
||||
<appender-ref ref="console" />
|
||||
|
|
11
pom.xml
11
pom.xml
|
@ -1221,6 +1221,17 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
|
|
Loading…
Reference in New Issue