use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class IndexFileRepoJob method execute.
/**
* The main method used for finding jobs to index and actually doing the work
*/
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (!isEnabled()) {
return;
}
if (!this.sharedService.getBackgroundJobsEnabled()) {
return;
}
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (Singleton.getCodeIndexer().shouldPauseAdding()) {
Singleton.getLogger().info("Pausing parser.");
return;
}
// Pull the next repo to index from the queue
UniqueRepoQueue repoQueue = this.getNextQueuedRepo();
RepoResult repoResult = repoQueue.poll();
if (repoResult != null && !Singleton.getRunningIndexRepoJobs().containsKey(repoResult.getName())) {
Singleton.getLogger().info("File Indexer 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()));
JobDataMap data = context.getJobDetail().getJobDataMap();
String repoName = repoResult.getName();
this.repoName = repoName;
String repoRemoteLocation = repoResult.getUrl();
String repoLocations = data.get("REPOLOCATIONS").toString();
this.LOWMEMORY = Boolean.parseBoolean(data.get("LOWMEMORY").toString());
Path docDir = Paths.get(repoRemoteLocation);
this.indexDocsByPath(docDir, repoName, repoLocations, repoRemoteLocation, true);
int runningTime = Singleton.getHelpers().getCurrentTimeSeconds() - Singleton.getRunningIndexRepoJobs().get(repoResult.getName()).startTime;
repoResult.getData().averageIndexTimeSeconds = (repoResult.getData().averageIndexTimeSeconds + runningTime) / 2;
repoResult.getData().indexStatus = "success";
repoResult.getData().jobRunTime = Instant.now();
Singleton.getRepo().saveRepo(repoResult);
} finally {
// Clean up the job
Singleton.getRunningIndexRepoJobs().remove(repoResult.getName());
}
}
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class Repo method getRepoByUrl.
@Override
public synchronized RepoResult getRepoByUrl(String repositoryUrl) {
if (repositoryUrl == null) {
return null;
}
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
RepoResult result = null;
try {
connection = this.dbConfig.getConnection();
preparedStatement = connection.prepareStatement("select rowid,name,scm,url,username,password,source,branch,data from repo where url=?;");
preparedStatement.setString(1, repositoryUrl);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
int rowId = resultSet.getInt("rowid");
String repoName = resultSet.getString("name");
String repoScm = resultSet.getString("scm");
String repoUrl = resultSet.getString("url");
String repoUsername = resultSet.getString("username");
String repoPassword = resultSet.getString("password");
String repoSource = resultSet.getString("source");
String repoBranch = resultSet.getString("branch");
String repoData = resultSet.getString("data");
result = new RepoResult(rowId, repoName, repoScm, repoUrl, repoUsername, repoPassword, repoSource, repoBranch, repoData);
}
} catch (SQLException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} finally {
Singleton.getHelpers().closeQuietly(resultSet);
Singleton.getHelpers().closeQuietly(preparedStatement);
}
return result;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class DeleteRepositoryJob method execute.
public void execute(JobExecutionContext context) throws JobExecutionException {
if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
return;
}
List<String> persistentDelete = Singleton.getDataService().getPersistentDelete();
if (persistentDelete.isEmpty()) {
return;
}
RepoResult rr = Singleton.getRepo().getRepoByName(persistentDelete.get(0));
if (rr == null) {
Singleton.getDataService().removeFromPersistentDelete(persistentDelete.get(0));
return;
}
try {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
Singleton.getUniqueGitRepoQueue().delete(rr);
if (Singleton.getRunningIndexRepoJobs().containsKey(rr.getName())) {
return;
}
Singleton.getLogger().info("Deleting repository. " + rr.getName());
Singleton.getCodeIndexer().deleteByReponame(rr.getName());
// remove the directory
String repoLocations = Properties.getProperties().getProperty(Values.REPOSITORYLOCATION, Values.DEFAULTREPOSITORYLOCATION);
FileUtils.deleteDirectory(new File(repoLocations + rr.getName() + "/"));
// Remove from the database
Singleton.getRepo().deleteRepoByName(rr.getName());
// Remove from the persistent queue
Singleton.getDataService().removeFromPersistentDelete(rr.getName());
} catch (Exception ignored) {
}
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoDeleteAuthReponameNoPub.
public void testRepoDeleteAuthReponameNoPub() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue(new ConcurrentLinkedQueue<>());
when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("pub is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
assertThat(uniqueRepoQueue.size()).isEqualTo(0);
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoDeleteNoAuthReponame.
public void testRepoDeleteNoAuthReponame() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
DataService dataServiceMock = Mockito.mock(DataService.class);
when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, dataServiceMock, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = false;
when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("repository queued for deletion");
assertThat(apiResponse.isSucessful()).isTrue();
verify(dataServiceMock, times(1)).addToPersistentDelete("");
}
Aggregations