Search in sources :

Example 56 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class Repo method saveRepo.

// TODO add retry logic here as this can fail and as such should just trigger again
@Override
public synchronized boolean saveRepo(RepoResult repoResult) {
    RepoResult existing = this.getRepoByName(repoResult.getName());
    boolean isNew = false;
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    // Update with new details
    try {
        connection = this.dbConfig.getConnection();
        if (existing != null) {
            preparedStatement = connection.prepareStatement("UPDATE \"repo\" SET \"name\" = ?, \"scm\" = ?, \"url\" = ?, \"username\" = ?, \"password\" = ?, \"source\" = ?, \"branch\" = ?, \"data\" = ? WHERE  \"name\" = ?");
            preparedStatement.setString(9, repoResult.getName());
        } else {
            isNew = true;
            preparedStatement = connection.prepareStatement("INSERT INTO repo(\"name\",\"scm\",\"url\", \"username\", \"password\",\"source\",\"branch\",\"data\") VALUES (?,?,?,?,?,?,?,?)");
        }
        preparedStatement.setString(1, repoResult.getName());
        preparedStatement.setString(2, repoResult.getScm());
        preparedStatement.setString(3, repoResult.getUrl());
        preparedStatement.setString(4, repoResult.getUsername());
        preparedStatement.setString(5, repoResult.getPassword());
        preparedStatement.setString(6, repoResult.getSource());
        preparedStatement.setString(7, repoResult.getBranch());
        preparedStatement.setString(8, repoResult.getDataAsJson());
        preparedStatement.execute();
    } catch (SQLException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    } finally {
        Singleton.getHelpers().closeQuietly(preparedStatement);
    }
    return isNew;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) RepoResult(com.searchcode.app.model.RepoResult)

Example 57 with RepoResult

use of com.searchcode.app.model.RepoResult 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 58 with RepoResult

use of com.searchcode.app.model.RepoResult 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 59 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class IndexBaseRepoJob method execute.

/**
     * The main method used for finding jobs to index and actually doing the work
     */
public void execute(JobExecutionContext context) throws JobExecutionException {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    this.LOWMEMORY = Boolean.parseBoolean(jobDataMap.get("LOWMEMORY").toString());
    String repoLocations = jobDataMap.get("REPOLOCATIONS").toString();
    if (!isEnabled() || !this.sharedService.getBackgroundJobsEnabled()) {
        return;
    }
    if (this.codeIndexer.shouldPauseAdding()) {
        Singleton.getLogger().info("Pausing parser.");
        return;
    }
    // Pull the next repo to index from the queue
    RepoResult repoResult = this.getNextQueuedRepo().poll();
    if (repoResult != null && Singleton.getRunningIndexRepoJobs().containsKey(repoResult.getName()) == false) {
        this.haveRepoResult = true;
        Singleton.getLogger().info("Indexing " + repoResult.getName());
        repoResult.getData().indexStatus = "indexing";
        repoResult.getData().jobRunTime = Instant.now();
        Singleton.getRepo().saveRepo(repoResult);
        try {
            Singleton.getRunningIndexRepoJobs().put(repoResult.getName(), new RunningIndexJob("Indexing", Singleton.getHelpers().getCurrentTimeSeconds()));
            this.checkCloneSuccess(repoResult.getName(), repoLocations);
            String repoGitLocation = repoLocations + "/" + repoResult.getName() + "/.git/";
            File file = new File(repoGitLocation);
            boolean existingRepo = file.exists();
            boolean useCredentials = repoResult.getUsername() != null && !repoResult.getUsername().isEmpty();
            RepositoryChanged repositoryChanged;
            if (existingRepo) {
                repositoryChanged = this.updateExistingRepository(repoResult.getName(), repoResult.getUrl(), repoResult.getUsername(), repoResult.getPassword(), repoLocations, repoResult.getBranch(), useCredentials);
            } else {
                repositoryChanged = this.getNewRepository(repoResult.getName(), repoResult.getUrl(), repoResult.getUsername(), repoResult.getPassword(), repoLocations, repoResult.getBranch(), useCredentials);
            }
            // Write file indicating we have sucessfully cloned
            this.createCloneUpdateSuccess(repoLocations + "/" + repoResult.getName());
            this.triggerIndex(repoResult, repoResult.getName(), repoResult.getUrl(), repoLocations, repoGitLocation, existingRepo, repositoryChanged);
        } finally {
            // Clean up the job
            Singleton.getRunningIndexRepoJobs().remove(repoResult.getName());
        }
    }
}
Also used : RunningIndexJob(com.searchcode.app.dto.RunningIndexJob) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) JobDataMap(org.quartz.JobDataMap) File(java.io.File) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

RepoResult (com.searchcode.app.model.RepoResult)59 Repo (com.searchcode.app.dao.Repo)13 ApiResponse (com.searchcode.app.dto.api.ApiResponse)9 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)9 Request (spark.Request)9 ValidatorResult (com.searchcode.app.model.ValidatorResult)8 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)8 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 Data (com.searchcode.app.dao.Data)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1