aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-scheduler
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-11-02 22:31:42 +0000
committerOlivier Lamy <olamy@apache.org>2011-11-02 22:31:42 +0000
commit0262091faaaed893c6c43d2a7090d5d92cbba4aa (patch)
tree47a12f345d5b90e43924b10d96e7e444380be7fd /archiva-modules/archiva-scheduler
parentb698377ca760cdabda8f0bbf5dd6ba4afd364fc7 (diff)
downloadarchiva-0262091faaaed893c6c43d2a7090d5d92cbba4aa.tar.gz
archiva-0262091faaaed893c6c43d2a7090d5d92cbba4aa.zip
[MRM-815] aggregate indices for repository groups.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1196840 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-scheduler')
-rw-r--r--archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java87
1 files changed, 27 insertions, 60 deletions
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java
index 18a5a98e3..83439050b 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java
@@ -47,7 +47,6 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
-import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
@@ -62,7 +61,7 @@ public class DefaultDownloadRemoteIndexScheduler
implements ConfigurationListener, DownloadRemoteIndexScheduler
{
- private Logger log = LoggerFactory.getLogger( getClass( ) );
+ private Logger log = LoggerFactory.getLogger( getClass() );
@Inject
@Named( value = "taskScheduler#indexDownloadRemote" )
@@ -94,50 +93,35 @@ public class DefaultDownloadRemoteIndexScheduler
private IndexUpdater indexUpdater;
// store ids about currently running remote download : updated in DownloadRemoteIndexTask
- private List<String> runningRemoteDownloadIds = new CopyOnWriteArrayList<String>( );
+ private List<String> runningRemoteDownloadIds = new CopyOnWriteArrayList<String>();
@PostConstruct
- public void startup( )
+ public void startup()
throws ArchivaException, RepositoryAdminException, PlexusSisuBridgeException, IOException,
UnsupportedExistingLuceneIndexException, DownloadRemoteIndexException
{
archivaConfiguration.addListener( this );
// TODO add indexContexts even if null
- // FIXME get this from ArchivaAdministration
- String appServerBase = System.getProperty( "appserver.base" );
-
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
indexUpdater = plexusSisuBridge.lookup( IndexUpdater.class );
- for ( RemoteRepository remoteRepository : remoteRepositoryAdmin.getRemoteRepositories( ) )
+ for ( RemoteRepository remoteRepository : remoteRepositoryAdmin.getRemoteRepositories() )
{
- String contextKey = "remote-" + remoteRepository.getId( );
- if ( nexusIndexer.getIndexingContexts( ).get( contextKey ) != null )
+ String contextKey = "remote-" + remoteRepository.getId();
+ IndexingContext context = nexusIndexer.getIndexingContexts().get( contextKey );
+ if ( context == null )
{
continue;
}
- // create path
- File repoDir = new File( appServerBase, "data/remotes/" + remoteRepository.getId( ) );
- if ( !repoDir.exists( ) )
- {
- repoDir.mkdirs( );
- }
- File indexDirectory = new File( repoDir, ".index" );
- if ( !indexDirectory.exists( ) )
- {
- indexDirectory.mkdirs( );
- }
- nexusIndexer.addIndexingContext( contextKey, remoteRepository.getId( ), repoDir, indexDirectory,
- remoteRepository.getUrl( ), calculateIndexRemoteUrl( remoteRepository ),
- mavenIndexerUtils.getAllIndexCreators( ) );
+
// TODO record jobs from configuration
- if ( remoteRepository.isDownloadRemoteIndex( ) && StringUtils.isNotEmpty(
- remoteRepository.getCronExpression( ) ) )
+ if ( remoteRepository.isDownloadRemoteIndex() && StringUtils.isNotEmpty(
+ remoteRepository.getCronExpression() ) )
{
- boolean fullDownload = indexDirectory.list( ).length == 0;
- scheduleDownloadRemote( remoteRepository.getId( ), false, fullDownload );
+ boolean fullDownload = context.getIndexDirectoryFile().list().length == 0;
+ scheduleDownloadRemote( remoteRepository.getId(), false, fullDownload );
}
}
@@ -145,13 +129,13 @@ public class DefaultDownloadRemoteIndexScheduler
}
@PreDestroy
- public void shutdown( )
+ public void shutdown()
throws RepositoryAdminException, IOException
{
- for ( RemoteRepository remoteRepository : remoteRepositoryAdmin.getRemoteRepositories( ) )
+ for ( RemoteRepository remoteRepository : remoteRepositoryAdmin.getRemoteRepositories() )
{
- String contextKey = "remote-" + remoteRepository.getId( );
- IndexingContext context = nexusIndexer.getIndexingContexts( ).get( contextKey );
+ String contextKey = "remote-" + remoteRepository.getId();
+ IndexingContext context = nexusIndexer.getIndexingContexts().get( contextKey );
if ( context == null )
{
continue;
@@ -178,65 +162,48 @@ public class DefaultDownloadRemoteIndexScheduler
return;
}
NetworkProxy networkProxy = null;
- if ( StringUtils.isNotBlank( remoteRepository.getRemoteDownloadNetworkProxyId( ) ) )
+ if ( StringUtils.isNotBlank( remoteRepository.getRemoteDownloadNetworkProxyId() ) )
{
- networkProxy = networkProxyAdmin.getNetworkProxy( remoteRepository.getRemoteDownloadNetworkProxyId( ) );
+ networkProxy = networkProxyAdmin.getNetworkProxy( remoteRepository.getRemoteDownloadNetworkProxyId() );
if ( networkProxy == null )
{
log.warn(
"your remote repository is configured to download remote index trought a proxy we cannot find id:{}",
- remoteRepository.getRemoteDownloadNetworkProxyId( ) );
+ remoteRepository.getRemoteDownloadNetworkProxyId() );
}
}
DownloadRemoteIndexTaskRequest downloadRemoteIndexTaskRequest =
- new DownloadRemoteIndexTaskRequest( ).setRemoteRepository( remoteRepository ).setNetworkProxy(
+ new DownloadRemoteIndexTaskRequest().setRemoteRepository( remoteRepository ).setNetworkProxy(
networkProxy ).setFullDownload( fullDownload ).setWagonFactory( wagonFactory ).setNexusIndexer(
nexusIndexer ).setIndexUpdater( indexUpdater );
if ( now )
{
- log.info( "schedule download remote index for repository {}", remoteRepository.getId( ) );
+ log.info( "schedule download remote index for repository {}", remoteRepository.getId() );
// do it in async
taskScheduler.schedule(
new DownloadRemoteIndexTask( downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds ),
- new Date( ) );
+ new Date() );
}
else
{
log.info( "schedule download remote index for repository {} with cron expression {}",
- remoteRepository.getId( ), remoteRepository.getCronExpression( ) );
+ remoteRepository.getId(), remoteRepository.getCronExpression() );
taskScheduler.schedule(
new DownloadRemoteIndexTask( downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds ),
- new CronTrigger( remoteRepository.getCronExpression( ) ) );
+ new CronTrigger( remoteRepository.getCronExpression() ) );
}
}
catch ( RepositoryAdminException e )
{
- log.error( e.getMessage( ), e );
- throw new DownloadRemoteIndexException( e.getMessage( ), e );
+ log.error( e.getMessage(), e );
+ throw new DownloadRemoteIndexException( e.getMessage(), e );
}
}
- protected String calculateIndexRemoteUrl( RemoteRepository remoteRepository )
- {
- if ( StringUtils.startsWith( remoteRepository.getRemoteIndexUrl( ), "http" ) )
- {
- String baseUrl = remoteRepository.getRemoteIndexUrl( );
- return baseUrl.endsWith( "/" ) ? StringUtils.substringBeforeLast( baseUrl, "/" ) : baseUrl;
- }
- String baseUrl = StringUtils.endsWith( remoteRepository.getUrl( ), "/" ) ? StringUtils.substringBeforeLast(
- remoteRepository.getUrl( ), "/" ) : remoteRepository.getUrl( );
-
- baseUrl = StringUtils.isEmpty( remoteRepository.getRemoteIndexUrl( ) )
- ? baseUrl + "/.index"
- : baseUrl + "/" + remoteRepository.getRemoteIndexUrl( );
- return baseUrl;
-
- }
-
- public TaskScheduler getTaskScheduler( )
+ public TaskScheduler getTaskScheduler()
{
return taskScheduler;
}