|
|
@ -23,6 +23,8 @@ import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class IndexService {
|
|
|
|
public class IndexService {
|
|
|
@ -32,6 +34,7 @@ public class IndexService {
|
|
|
|
private final GitRepositoryRepository gitRepositoryRepository;
|
|
|
|
private final GitRepositoryRepository gitRepositoryRepository;
|
|
|
|
private final BranchService branchService;
|
|
|
|
private final BranchService branchService;
|
|
|
|
private final List<AbstractTimeSeriesCreator> timeSeriesCreators;
|
|
|
|
private final List<AbstractTimeSeriesCreator> timeSeriesCreators;
|
|
|
|
|
|
|
|
private final static ExecutorService EXECUTOR = Executors.newFixedThreadPool(10);
|
|
|
|
|
|
|
|
|
|
|
|
public IndexService(GitRepositoryService gitRepositoryService,
|
|
|
|
public IndexService(GitRepositoryService gitRepositoryService,
|
|
|
|
GitRepositoryRepository gitRepositoryRepository,
|
|
|
|
GitRepositoryRepository gitRepositoryRepository,
|
|
|
@ -43,38 +46,43 @@ public class IndexService {
|
|
|
|
this.timeSeriesCreators = timeSeriesCreators;
|
|
|
|
this.timeSeriesCreators = timeSeriesCreators;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
@Async
|
|
|
|
public void index(@NotNull Integer branchId) throws GitAPIException, IOException {
|
|
|
|
public void index(@NotNull Integer branchId) throws GitAPIException, IOException {
|
|
|
|
Branch branch = branchService.findByBranchId(branchId).orElseThrow(() -> new RuntimeException("Ветка репозитория не найдена по id"));
|
|
|
|
Branch branch = branchService.findByBranchId(branchId).orElseThrow(() -> new RuntimeException("Ветка репозитория не найдена по id"));
|
|
|
|
index(branch.getGitRepository().getUrl(), branch.getName());
|
|
|
|
index(branch.getGitRepository(), branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
|
|
|
|
@Transactional
|
|
|
|
GitRepository gitRepository = gitRepositoryRepository.findByUrl(repositoryUrl);
|
|
|
|
@Async
|
|
|
|
if (gitRepository == null) {
|
|
|
|
public void index(String gitRepositoryUrl, String branchName) throws GitAPIException, IOException {
|
|
|
|
gitRepository = gitRepositoryRepository.save(new GitRepository(repositoryUrl));
|
|
|
|
GitRepository gitRepository = gitRepositoryService.findByUrlOrCreate(gitRepositoryUrl);
|
|
|
|
}
|
|
|
|
Branch branch = branchService.findByRepositoryAndNameOrCreate(gitRepository, branchName);
|
|
|
|
Branch branch = branchService.findByRepositoryAndName(gitRepository, branchName);
|
|
|
|
branch = branchService.updateStatus(branch, IndexingStatus.INDEXING);
|
|
|
|
if (branch == null) {
|
|
|
|
index(gitRepository, branch);
|
|
|
|
branch = new Branch(gitRepository, branchName);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
|
|
|
public void index(GitRepository gitRepository, Branch branch) throws GitAPIException, IOException {
|
|
|
|
branchService.save(branch, Collections.emptyList());
|
|
|
|
branchService.save(branch, Collections.emptyList());
|
|
|
|
branch = branchService.updateStatus(branch, IndexingStatus.INDEXING);
|
|
|
|
branch = branchService.updateStatus(branch, IndexingStatus.INDEXING);
|
|
|
|
int commitsFrom = 0;
|
|
|
|
int commitsFrom = 0;
|
|
|
|
int commitsTo = COMMITS_PAGE_SIZE;
|
|
|
|
int commitsTo = COMMITS_PAGE_SIZE;
|
|
|
|
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, true);
|
|
|
|
List<Commit> commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, true);
|
|
|
|
while (!commits.isEmpty()) {
|
|
|
|
while (!commits.isEmpty()) {
|
|
|
|
LOG.debug("{} commits loaded.", commits.size());
|
|
|
|
LOG.debug("{} commits loaded.", commits.size());
|
|
|
|
branchService.addCommits(branch, commits);
|
|
|
|
branchService.addCommits(branch, commits);
|
|
|
|
LOG.debug("{} commits successfully saved. {} {}", commits.size(), repositoryUrl, branchName);
|
|
|
|
LOG.debug("{} commits successfully saved. {} {}", commits.size(), gitRepository.getUrl(), branch.getName());
|
|
|
|
commitsFrom += COMMITS_PAGE_SIZE;
|
|
|
|
commitsFrom += COMMITS_PAGE_SIZE;
|
|
|
|
commitsTo += COMMITS_PAGE_SIZE;
|
|
|
|
commitsTo += COMMITS_PAGE_SIZE;
|
|
|
|
commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, false);
|
|
|
|
commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Integer repositoryId = gitRepository.getId();
|
|
|
|
Integer repositoryId = gitRepository.getId();
|
|
|
|
final Branch branchForSave = branch;
|
|
|
|
final Branch branchForSave = branch;
|
|
|
|
timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchForSave));
|
|
|
|
timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchForSave));
|
|
|
|
branchService.updateStatus(branch, IndexingStatus.FINISHED);
|
|
|
|
branchService.updateStatus(branch, IndexingStatus.FINISHED);
|
|
|
|
LOG.debug("Complete indexing {} branch", branchName);
|
|
|
|
LOG.debug("Complete indexing {} branch", branch.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
@ -89,7 +97,6 @@ public class IndexService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
index(failedBranch.getId());
|
|
|
|
index(failedBranch.getId());
|
|
|
|
LOG.info("Завершено индексирование ветки {}", failedBranch.getName());
|
|
|
|
LOG.info("Завершено индексирование ветки {}", failedBranch.getName());
|
|
|
|
branchService.updateStatus(failedBranch, IndexingStatus.FINISHED);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
LOG.warn(ex.getMessage());
|
|
|
|
LOG.warn(ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|