From c230bdbe4102ad02eab38599da4f8f1545083fa4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 14 Nov 2013 03:11:06 +0000 Subject: [PATCH] add a service to know repositories ids running a remote download git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1541794 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultDownloadRemoteIndexScheduler.java | 5 +++++ .../indexing/DownloadRemoteIndexScheduler.java | 4 ++++ .../scheduler/indexing/DownloadRemoteIndexTask.java | 13 ++++++++----- .../rest/api/services/RepositoriesService.java | 10 ++++++++++ .../rest/services/DefaultRepositoriesService.java | 7 +++++++ .../DownloadMergedIndexNonDefaultPathTest.java | 8 +++++++- 6 files changed, 41 insertions(+), 6 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 d2405c66c..b4c2a633d 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 @@ -236,4 +236,9 @@ public class DefaultDownloadRemoteIndexScheduler { this.taskScheduler = taskScheduler; } + + public List getRunningRemoteDownloadIds() + { + return runningRemoteDownloadIds; + } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexScheduler.java index 39da82728..ce91e803d 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexScheduler.java @@ -18,6 +18,8 @@ package org.apache.archiva.scheduler.indexing; * under the License. */ +import java.util.List; + /** * @author Olivier Lamy * @since 1.4-M1 @@ -26,4 +28,6 @@ public interface DownloadRemoteIndexScheduler { void scheduleDownloadRemote( String repositoryId, boolean now, boolean fullDownload ) throws DownloadRemoteIndexException; + + List getRunningRemoteDownloadIds(); } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java index 665860d9c..e634195bc 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java @@ -232,16 +232,19 @@ public class DownloadRemoteIndexTask request.setLocalIndexCacheDir( indexCacheDirectory ); this.indexUpdater.fetchAndUpdateIndex( request ); - stopWatch.stop(); - log.info( "time update index from remote for repository {}: {} s", this.remoteRepository.getId(), - ( stopWatch.getTime() / 1000 ) ); // index packing optionnal ?? //IndexPackingRequest indexPackingRequest = // new IndexPackingRequest( indexingContext, indexingContext.getIndexDirectoryFile() ); //indexPacker.packIndex( indexPackingRequest ); + indexingContext.updateTimestamp( true ); + stopWatch.stop(); + log.info( "time update index from remote for repository {}: {} s", this.remoteRepository.getId(), + ( stopWatch.getTime() / 1000 ) ); + + } catch ( MalformedURLException e ) { @@ -263,7 +266,7 @@ public class DownloadRemoteIndexTask deleteDirectoryQuiet( tempIndexDirectory ); this.runningRemoteDownloadIds.remove( this.remoteRepository.getId() ); } - log.info( "end download remote index for remote repository " + this.remoteRepository.getId() ); + log.info( "end download remote index for remote repository {}", this.remoteRepository.getId() ); } private void deleteDirectoryQuiet( File f ) @@ -304,7 +307,7 @@ public class DownloadRemoteIndexTask { if ( response.getStatusLine().getStatusCode() != HttpStatus.SC_OK ) { - throw new ClientProtocolException( "Upload failed: " + response.getStatusLine() ); + throw new ClientProtocolException( "Download failed: " + response.getStatusLine() ); } long endTime = System.currentTimeMillis(); log.info( "end of transfer file {} {} kb: {}s", resourceName, this.totalLength / 1024, diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java index 7afba55d3..249ef0c6a 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java @@ -23,6 +23,7 @@ import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.redback.authorization.RedbackAuthorization; import org.apache.archiva.repository.scanner.RepositoryScanStatistics; import org.apache.archiva.rest.api.model.ArtifactTransferRequest; +import org.apache.archiva.rest.api.model.StringList; import org.apache.archiva.security.common.ArchivaRoleConstants; import javax.ws.rs.Consumes; @@ -34,6 +35,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import java.util.List; /** * @author Olivier Lamy @@ -166,5 +168,13 @@ public interface RepositoriesService @PathParam ("repositoryId") String repositoryId ) throws ArchivaRestServiceException; + /** + * @since 2.0 + */ + @Path ("runningRemoteDownloadIds") + @GET + @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) + @RedbackAuthorization (noPermission = true) + StringList getRunningRemoteDownloadIds(); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index c8b6423ae..a3910b449 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -64,6 +64,7 @@ import org.apache.archiva.repository.scanner.RepositoryScanStatistics; import org.apache.archiva.repository.scanner.RepositoryScanner; import org.apache.archiva.repository.scanner.RepositoryScannerException; import org.apache.archiva.rest.api.model.ArtifactTransferRequest; +import org.apache.archiva.rest.api.model.StringList; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.RepositoriesService; import org.apache.archiva.scheduler.ArchivaTaskScheduler; @@ -1153,6 +1154,12 @@ public class DefaultRepositoriesService checksum.fixChecksums( algorithms ); } + @Override + public StringList getRunningRemoteDownloadIds() + { + return new StringList( downloadRemoteIndexScheduler.getRunningRemoteDownloadIds() ); + } + public ManagedRepositoryAdmin getManagedRepositoryAdmin() { return managedRepositoryAdmin; diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadMergedIndexNonDefaultPathTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadMergedIndexNonDefaultPathTest.java index 4eeb9ebcc..f7aa3dfd6 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadMergedIndexNonDefaultPathTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadMergedIndexNonDefaultPathTest.java @@ -56,7 +56,7 @@ public class DownloadMergedIndexNonDefaultPathTest public static void setAppServerBase() { previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", "target/" + DownloadMergedIndexNonDefaultPathTest.class.getName() ); + System.setProperty( "appserver.base", System.getProperty( "basedir" ) + "/target/" + DownloadMergedIndexNonDefaultPathTest.class.getName() ); } @AfterClass @@ -175,11 +175,17 @@ public class DownloadMergedIndexNonDefaultPathTest repositoriesService.scheduleDownloadRemoteIndex( remoteId, true, true ); // wait a bit + /* timeout = 20000; while ( timeout > 0 ) { Thread.sleep( 500 ); timeout -= 500; + }*/ + // wait the end + while ( !repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty() ) + { + Thread.sleep( 500 ); } SearchService searchService = getSearchService(); -- 2.39.5