]> source.dussan.org Git - archiva.git/commitdiff
add a service to know repositories ids running a remote download
authorOlivier Lamy <olamy@apache.org>
Thu, 14 Nov 2013 03:11:06 +0000 (03:11 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 14 Nov 2013 03:11:06 +0000 (03:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1541794 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DefaultDownloadRemoteIndexScheduler.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexScheduler.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadMergedIndexNonDefaultPathTest.java

index 39da82728a49398bde73702596deb7bb3c7aa173..ce91e803db9a3f924b3fd819c851447b98eaa103 100644 (file)
@@ -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<String> getRunningRemoteDownloadIds();
 }
index 665860d9cdfabe9a6256d35cae1ceafd13faa456..e634195bcb9c9b6b3e82ec6992600ae1f1e0e48b 100644 (file)
@@ -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,
index 7afba55d38bd52db034d368c164abd114b86218f..249ef0c6ad1c9b07e5cca2ac790515202308d7fa 100644 (file)
@@ -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();
 
 }
index c8b6423ae78620b0501a323a38fd878086e0ddfa..a3910b449a537d96b0cb57ec8e789d1a587a53c6 100644 (file)
@@ -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;
index 4eeb9ebccc7a9910cbccfe7e0e9308a6adda361b..f7aa3dfd61094831b533fecf8a2b81992bd9a77b 100644 (file)
@@ -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();