Search in sources :

Example 6 with UniqueRepoQueue

use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.

the class IndexBaseRepoJobTest method testExecuteNothingInQueue.

public void testExecuteNothingInQueue() throws JobExecutionException {
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    IndexGitRepoJob spy = spy(indexGitRepoJob);
    spy.haveRepoResult = false;
    when(spy.getNextQueuedRepo()).thenReturn(new UniqueRepoQueue());
    spy.codeIndexer = mockCodeIndexer;
    spy.execute(this.mockContext);
    assertThat(spy.haveRepoResult).isFalse();
}
Also used : IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue)

Example 7 with UniqueRepoQueue

use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.

the class EnqueueFileRepositoryJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
        return;
    }
    try {
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
        UniqueRepoQueue repoQueue = Singleton.getUniqueFileRepoQueue();
        // Get all of the repositories and enqueue them
        List<RepoResult> repoResultList = Singleton.getRepo().getAllRepo();
        Singleton.getLogger().info("Adding repositories to be indexed. " + repoResultList.size());
        for (RepoResult rr : repoResultList) {
            switch(rr.getScm().toLowerCase()) {
                case "file":
                    Singleton.getLogger().info("Adding to FILE queue " + rr.getName() + " " + rr.getScm());
                    repoQueue.add(rr);
                    break;
                default:
                    Singleton.getLogger().info("Unable to determine job type for " + rr.getName());
                    break;
            }
        }
    } catch (Exception ex) {
    }
}
Also used : UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 8 with UniqueRepoQueue

use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.

the class EnqueueRepositoryJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
        return;
    }
    try {
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
        UniqueRepoQueue repoGitQueue = Singleton.getUniqueGitRepoQueue();
        UniqueRepoQueue repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
        // Get all of the repositories and enqueue them
        List<RepoResult> repoResultList = Singleton.getRepo().getAllRepo();
        Singleton.getLogger().info("Adding repositories to be indexed. " + repoResultList.size());
        // Filter out those queued to be deleted
        List<String> persistentDelete = Singleton.getDataService().getPersistentDelete();
        List<RepoResult> collect = repoResultList.stream().filter(x -> !persistentDelete.contains(x.getName())).collect(Collectors.toList());
        for (RepoResult rr : collect) {
            switch(rr.getScm().toLowerCase()) {
                case "git":
                    Singleton.getLogger().info("Adding to GIT queue " + rr.getName() + " " + rr.getScm());
                    repoGitQueue.add(rr);
                    break;
                case "svn":
                    Singleton.getLogger().info("Adding to SVN queue " + rr.getName() + " " + rr.getScm());
                    repoSvnQueue.add(rr);
                    break;
                default:
                    Singleton.getLogger().info("Unable to determine SCM type for " + rr.getName() + " " + rr.getScm());
                    break;
            }
        }
    } catch (Exception ex) {
    }
}
Also used : List(java.util.List) Singleton(com.searchcode.app.service.Singleton) RepoResult(com.searchcode.app.model.RepoResult) Collectors(java.util.stream.Collectors) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) org.quartz(org.quartz) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 9 with UniqueRepoQueue

use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.

the class JobService method enqueueRepository.

private void enqueueRepository(RepoResult rr) {
    UniqueRepoQueue repoGitQueue = Singleton.getUniqueGitRepoQueue();
    UniqueRepoQueue repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
    UniqueRepoQueue repoFileQueue = Singleton.getUniqueFileRepoQueue();
    switch(rr.getScm().toLowerCase()) {
        case "git":
            Singleton.getLogger().info("Adding to GIT queue " + rr.getName() + " " + rr.getScm());
            repoGitQueue.add(rr);
            break;
        case "svn":
            Singleton.getLogger().info("Adding to SVN queue " + rr.getName() + " " + rr.getScm());
            repoSvnQueue.add(rr);
            break;
        case "file":
            Singleton.getLogger().info("Adding to FILE queue " + rr.getName() + " " + rr.getScm());
            repoFileQueue.add(rr);
            break;
        default:
            Singleton.getLogger().info("Unknown SCM type " + rr.getName() + " " + rr.getScm());
            break;
    }
}
Also used : UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue)

Example 10 with UniqueRepoQueue

use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoDeleteAuthReponameFailedAuth.

public void testRepoDeleteAuthReponameFailedAuth() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue(new ConcurrentLinkedQueue<>());
    ApiService mockApiService = Mockito.mock(ApiService.class);
    when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(false);
    when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, null, null);
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
    ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
    assertThat(apiResponse.isSucessful()).isFalse();
    assertThat(uniqueRepoQueue.size()).isEqualTo(0);
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)10 RepoResult (com.searchcode.app.model.RepoResult)8 Repo (com.searchcode.app.dao.Repo)3 ApiResponse (com.searchcode.app.dto.api.ApiResponse)3 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)3 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)3 Request (spark.Request)3 IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)2 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)1 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)1 SharedService (com.searchcode.app.service.SharedService)1 Singleton (com.searchcode.app.service.Singleton)1 Path (java.nio.file.Path)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 org.quartz (org.quartz)1