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;
}
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) {
}
}
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) {
}
}
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());
}
}
}
Aggregations