add REST method to really scan repositories

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-03-09 23:44:11 +00:00
parent 6ab573edc1
commit 33577da0f9
6 changed files with 64 additions and 10 deletions

View File

@ -19,18 +19,21 @@ package org.apache.archiva.repository.scanner;
* under the License. * under the License.
*/ */
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import javax.xml.bind.annotation.XmlRootElement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/** /**
* RepositoryScanStatistics - extension to the RepositoryContentStatistics model. * RepositoryScanStatistics - extension to the RepositoryContentStatistics model.
* *
* @version $Id$ * @version $Id$
*/ */
@XmlRootElement( name = "repositoryScanStatistics" )
public class RepositoryScanStatistics public class RepositoryScanStatistics
{ {
private transient List<String> knownConsumers; private transient List<String> knownConsumers;
@ -49,7 +52,7 @@ public class RepositoryScanStatistics
/** /**
* Field whenGathered * Field whenGathered
*/ */
private java.util.Date whenGathered; private Date whenGathered;
/** /**
* Field duration * Field duration

View File

@ -22,6 +22,7 @@ package org.apache.archiva.repository.scanner;
import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.springframework.scheduling.annotation.Async;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;

View File

@ -50,6 +50,11 @@
<artifactId>metadata-model</artifactId> <artifactId>metadata-model</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-scanner</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.redback</groupId> <groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-api</artifactId> <artifactId>redback-authorization-api</artifactId>

View File

@ -19,6 +19,7 @@ package org.apache.archiva.rest.api.services;
* under the License. * under the License.
*/ */
import org.apache.archiva.repository.scanner.RepositoryScanStatistics;
import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.Artifact;
import org.apache.archiva.rest.api.model.ArtifactTransferRequest; import org.apache.archiva.rest.api.model.ArtifactTransferRequest;
import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.archiva.security.common.ArchivaRoleConstants;
@ -45,11 +46,26 @@ public interface RepositoriesService
@GET @GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER ) @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
/**
* index repository
*/
Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId, Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
@QueryParam( "fullScan" ) boolean fullScan ) @QueryParam( "fullScan" ) boolean fullScan )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
@Path( "scanRepositoryDirectories/{repositoryId}" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
/**
* scan directories
* @since 1.4-M3
*/
RepositoryScanStatistics scanRepositoryDirectories( @PathParam( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
@Path( "alreadyScanning/{repositoryId}" ) @Path( "alreadyScanning/{repositoryId}" )
@GET @GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )

View File

@ -73,6 +73,10 @@
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId> <artifactId>archiva-repository-layer</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-scanner</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.redback</groupId> <groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-api</artifactId> <artifactId>redback-authorization-api</artifactId>

View File

@ -51,6 +51,9 @@ import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.metadata.RepositoryMetadataReader; import org.apache.archiva.repository.metadata.RepositoryMetadataReader;
import org.apache.archiva.repository.metadata.RepositoryMetadataWriter; import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
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.Artifact; import org.apache.archiva.rest.api.model.Artifact;
import org.apache.archiva.rest.api.model.ArtifactTransferRequest; import org.apache.archiva.rest.api.model.ArtifactTransferRequest;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
@ -146,6 +149,9 @@ public class DefaultRepositoriesService
@Inject @Inject
protected List<RepositoryListener> listeners = new ArrayList<RepositoryListener>(); protected List<RepositoryListener> listeners = new ArrayList<RepositoryListener>();
@Inject
private RepositoryScanner repoScanner;
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
public Boolean scanRepository( String repositoryId, boolean fullScan ) public Boolean scanRepository( String repositoryId, boolean fullScan )
@ -735,19 +741,19 @@ public class DefaultRepositoriesService
} }
catch ( RepositoryException e ) catch ( RepositoryException e )
{ {
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 ); throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500 );
} }
catch ( MetadataResolutionException e ) catch ( MetadataResolutionException e )
{ {
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 ); throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500 );
} }
catch ( MetadataRepositoryException e ) catch ( MetadataRepositoryException e )
{ {
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 ); throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500 );
} }
catch ( RepositoryAdminException e ) catch ( RepositoryAdminException e )
{ {
throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 400 ); throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 500 );
} }
finally finally
@ -757,6 +763,25 @@ public class DefaultRepositoriesService
return Boolean.TRUE; return Boolean.TRUE;
} }
public RepositoryScanStatistics scanRepositoryDirectories( String repositoryId )
throws ArchivaRestServiceException
{
long sinceWhen = RepositoryScanner.FRESH_SCAN;
try
{
return repoScanner.scan( getManagedRepositoryAdmin().getManagedRepository( repositoryId ), sinceWhen );
}
catch ( RepositoryScannerException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( "RepositoryScannerException exception: " + e.getMessage(), 500 );
}
catch ( RepositoryAdminException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( "RepositoryScannerException exception: " + e.getMessage(), 500 );
}
}
/** /**
* Update artifact level metadata. Creates one if metadata does not exist after artifact deletion. * Update artifact level metadata. Creates one if metadata does not exist after artifact deletion.