mirror of https://github.com/apache/archiva.git
[MRM-1490] Expose Archiva services trough REST : search service add a method to scan repo now useful for tests
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1170258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0dacf0cb79
commit
915ef10186
|
@ -42,19 +42,30 @@ public interface RepositoriesService
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
||||||
Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
|
Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
|
||||||
@QueryParam( "fullScan" ) boolean fullScan );
|
@QueryParam( "fullScan" ) boolean fullScan )
|
||||||
|
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 } )
|
||||||
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
||||||
Boolean alreadyScanning( @PathParam( "repositoryId" ) String repositoryId );
|
Boolean alreadyScanning( @PathParam( "repositoryId" ) String repositoryId )
|
||||||
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
@Path( "removeScanningTaskFromQueue/{repositoryId}" )
|
@Path( "removeScanningTaskFromQueue/{repositoryId}" )
|
||||||
@GET
|
@GET
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
||||||
Boolean removeScanningTaskFromQueue( @PathParam( "repositoryId" ) String repositoryId );
|
Boolean removeScanningTaskFromQueue( @PathParam( "repositoryId" ) String repositoryId )
|
||||||
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
|
@Path( "scanRepositoryNow" )
|
||||||
|
@GET
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
|
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
||||||
|
Boolean scanRepositoryNow( @QueryParam( "repositoryId" ) String repositoryId,
|
||||||
|
@QueryParam( "fullScan" ) boolean fullScan )
|
||||||
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,10 @@
|
||||||
<artifactId>archiva-configuration</artifactId>
|
<artifactId>archiva-configuration</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>archiva-scheduler-indexing</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.apache.archiva</groupId>
|
||||||
<artifactId>audit</artifactId>
|
<artifactId>audit</artifactId>
|
||||||
|
|
|
@ -19,10 +19,19 @@ package org.apache.archiva.rest.services;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.archiva.admin.model.managed.ManagedRepository;
|
||||||
|
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.rest.api.services.ArchivaRestServiceException;
|
||||||
import org.apache.archiva.rest.api.services.RepositoriesService;
|
import org.apache.archiva.rest.api.services.RepositoriesService;
|
||||||
|
import org.apache.archiva.scheduler.indexing.ArchivaIndexingTaskExecutor;
|
||||||
|
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
|
||||||
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
|
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
|
||||||
import org.apache.archiva.scheduler.repository.RepositoryTask;
|
import org.apache.archiva.scheduler.repository.RepositoryTask;
|
||||||
import org.codehaus.plexus.redback.role.RoleManager;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
|
import org.apache.maven.index.context.IndexCreator;
|
||||||
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
import org.codehaus.plexus.taskqueue.TaskQueueException;
|
import org.codehaus.plexus.taskqueue.TaskQueueException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -31,6 +40,7 @@ import org.springframework.stereotype.Service;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -43,13 +53,22 @@ public class DefaultRepositoriesService
|
||||||
{
|
{
|
||||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected RoleManager roleManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "archivaTaskScheduler#repository" )
|
@Named( value = "archivaTaskScheduler#repository" )
|
||||||
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
|
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named( value = "taskExecutor#indexing" )
|
||||||
|
private ArchivaIndexingTaskExecutor archivaIndexingTaskExecutor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ManagedRepositoryAdmin managedRepositoryAdmin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PlexusSisuBridge plexusSisuBridge;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private MavenIndexerUtils mavenIndexerUtils;
|
||||||
|
|
||||||
// FIXME olamy move this to repository admin component !
|
// FIXME olamy move this to repository admin component !
|
||||||
public Boolean scanRepository( String repositoryId, boolean fullScan )
|
public Boolean scanRepository( String repositoryId, boolean fullScan )
|
||||||
|
@ -92,6 +111,32 @@ public class DefaultRepositoriesService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean scanRepositoryNow( String repositoryId, boolean fullScan )
|
||||||
|
throws ArchivaRestServiceException
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ManagedRepository repository = managedRepositoryAdmin.getManagedRepository( repositoryId );
|
||||||
|
|
||||||
|
IndexingContext context =
|
||||||
|
ArtifactIndexingTask.createContext( repository, plexusSisuBridge.lookup( NexusIndexer.class ),
|
||||||
|
new ArrayList<IndexCreator>(
|
||||||
|
mavenIndexerUtils.getAllIndexCreators() ) );
|
||||||
|
ArtifactIndexingTask task =
|
||||||
|
new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context );
|
||||||
|
task.setExecuteOnEntireRepo( true );
|
||||||
|
task.setOnlyUpdate( false );
|
||||||
|
|
||||||
|
archivaIndexingTaskExecutor.executeTask( task );
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
throw new ArchivaRestServiceException( e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,6 @@ public class SearchServiceTest
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
// olamy temporary disabled due to huge refactoring
|
|
||||||
if (true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String testRepoId = "test-repo";
|
String testRepoId = "test-repo";
|
||||||
// force guest user creation if not exists
|
// force guest user creation if not exists
|
||||||
if ( getUserService( authorizationHeader ).getGuestUser() == null )
|
if ( getUserService( authorizationHeader ).getGuestUser() == null )
|
||||||
|
@ -52,6 +46,22 @@ public class SearchServiceTest
|
||||||
assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
|
assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createAndIndexRepo( testRepoId );
|
||||||
|
|
||||||
|
SearchService searchService = getSearchService( authorizationHeader );
|
||||||
|
|
||||||
|
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
|
||||||
|
|
||||||
|
assertNotNull( artifacts );
|
||||||
|
assertTrue( " empty results for commons-logging search", artifacts.size() > 0 );
|
||||||
|
log.info( "artifacts for commons-logginf search {}", artifacts );
|
||||||
|
|
||||||
|
deleteTestRepo( testRepoId );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndIndexRepo( String testRepoId )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
|
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
|
||||||
|
|
||||||
if ( targetRepo.exists() )
|
if ( targetRepo.exists() )
|
||||||
|
@ -67,28 +77,14 @@ public class SearchServiceTest
|
||||||
managedRepository.setId( testRepoId );
|
managedRepository.setId( testRepoId );
|
||||||
managedRepository.setName( "test repo" );
|
managedRepository.setName( "test repo" );
|
||||||
managedRepository.setCronExpression( "* * * * * ?" );
|
managedRepository.setCronExpression( "* * * * * ?" );
|
||||||
|
managedRepository.setScanned( false );
|
||||||
|
|
||||||
managedRepository.setLocation( targetRepo.getPath() );
|
managedRepository.setLocation( targetRepo.getPath() );
|
||||||
|
|
||||||
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
||||||
service.addManagedRepository( managedRepository );
|
service.addManagedRepository( managedRepository );
|
||||||
|
|
||||||
getRepositoriesService( authorizationHeader ).scanRepository( testRepoId, true );
|
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
|
||||||
|
|
||||||
while ( getRepositoriesService( authorizationHeader ).alreadyScanning( testRepoId ) )
|
|
||||||
{
|
|
||||||
Thread.sleep( 1000 );
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchService searchService = getSearchService( authorizationHeader );
|
|
||||||
|
|
||||||
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
|
|
||||||
|
|
||||||
assertNotNull( artifacts );
|
|
||||||
assertTrue( " empty results for commons-logging search", artifacts.size() > 0 );
|
|
||||||
log.info( "artifacts for commons-logginf search {}", artifacts );
|
|
||||||
|
|
||||||
deleteTestRepo( testRepoId );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteTestRepo( String id )
|
private void deleteTestRepo( String id )
|
||||||
|
|
Loading…
Reference in New Issue