use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class PipelineHistoryService method findPipelineInstancesByPageNumber.
public PipelineInstanceModels findPipelineInstancesByPageNumber(String pipelineName, int pageNumber, int limit, String userName) {
Pagination pagination = Pagination.pageByNumber(pageNumber, totalCount(pipelineName), limit);
PipelineInstanceModels instanceModels = load(pipelineName, pagination, userName, false);
instanceModels.setPagination(pagination);
return instanceModels;
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class DependencyMaterialUpdater method insertRevisionsForAllParentStageInstances.
private void insertRevisionsForAllParentStageInstances(DependencyMaterial dependencyMaterial) {
Pagination pagination = Pagination.pageStartingAt(0, null, MaterialDatabaseUpdater.STAGES_PER_PAGE);
List<Modification> modifications;
do {
modifications = dependencyMaterialSourceDao.getPassedStagesByName(dependencyMaterial, pagination);
for (Modification modification : modifications) {
MaterialRevision revision = new MaterialRevision(dependencyMaterial, modification);
materialRepository.saveMaterialRevision(revision);
}
pagination = Pagination.pageStartingAt(pagination.getOffset() + pagination.getPageSize(), null, pagination.getPageSize());
} while (!modifications.isEmpty());
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDao method findStageHistoryPage.
public StageHistoryPage findStageHistoryPage(String pipelineName, String stageName, FuncVarArg<Pagination, Object> function) {
// IMPORTANT: wire cache clearing on job-state-change for me, the day StageHistoryEntry gets jobs - Sachin & JJ
String mutex = mutexForStageHistory(pipelineName, stageName);
readWriteLock.acquireReadLock(mutex);
try {
Pagination pagination = function.call();
String subKey = String.format("%s-%s", pagination.getCurrentPage(), pagination.getPageSize());
String key = cacheKeyForStageHistories(pipelineName, stageName);
StageHistoryPage stageHistoryPage = (StageHistoryPage) goCache.get(key, subKey);
if (stageHistoryPage == null) {
List<StageHistoryEntry> stageHistoryEntries = findStages(pagination, pipelineName, stageName);
stageHistoryPage = new StageHistoryPage(stageHistoryEntries, pagination, findImmediateChronologicallyForwardStageHistoryEntry(stageHistoryEntries.get(0)));
goCache.put(key, subKey, stageHistoryPage);
}
return cloner.deepClone(stageHistoryPage);
} finally {
readWriteLock.releaseReadLock(mutex);
}
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldCachePaginatedModificationsForMaterialCorrectly.
@Test
public void shouldCachePaginatedModificationsForMaterialCorrectly() throws Exception {
final ScmMaterial material = material();
MaterialInstance materialInstance = material.createMaterialInstance();
repo.saveOrUpdate(materialInstance);
MaterialRevision first = saveOneScmModification("1", material, "user1", "1.txt", "comment1");
MaterialRevision second = saveOneScmModification("2", material, "user2", "2.txt", "comment2");
MaterialRevision third = saveOneScmModification("3", material, "user3", "3.txt", "comment3");
MaterialRevision fourth = saveOneScmModification("4", material, "user4", "4.txt", "comment4");
MaterialRevision fifth = saveOneScmModification("5", material, "user5", "5.txt", "comment5");
Pagination page = Pagination.pageStartingAt(0, 5, 3);
repo.getModificationsFor(materialInstance, page);
Modifications modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(page));
assertThat(modificationsFromCache.size(), is(3));
assertThat(modificationsFromCache.get(0).getRevision(), is(fifth.getLatestRevisionString()));
assertThat(modificationsFromCache.get(1).getRevision(), is(fourth.getLatestRevisionString()));
assertThat(modificationsFromCache.get(2).getRevision(), is(third.getLatestRevisionString()));
page = Pagination.pageStartingAt(1, 5, 3);
repo.getModificationsFor(materialInstance, page);
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(page));
assertThat(modificationsFromCache.size(), is(3));
assertThat(modificationsFromCache.get(0).getRevision(), is(fourth.getLatestRevisionString()));
assertThat(modificationsFromCache.get(1).getRevision(), is(third.getLatestRevisionString()));
assertThat(modificationsFromCache.get(2).getRevision(), is(second.getLatestRevisionString()));
page = Pagination.pageStartingAt(3, 5, 3);
repo.getModificationsFor(materialInstance, page);
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(page));
assertThat(modificationsFromCache.size(), is(2));
assertThat(modificationsFromCache.get(0).getRevision(), is(second.getLatestRevisionString()));
assertThat(modificationsFromCache.get(1).getRevision(), is(first.getLatestRevisionString()));
final Modification modOne = new Modification("user", "comment", "email@gmail.com", new Date(), "123");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
MaterialInstance foo = repo.findOrCreateFrom(material);
repo.saveModifications(foo, asList(modOne));
}
});
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(Pagination.pageStartingAt(0, 5, 3)));
assertThat(modificationsFromCache, is(nullValue()));
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(Pagination.pageStartingAt(3, 5, 3)));
assertThat(modificationsFromCache, is(nullValue()));
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldGetDetailedStageHistory.
@Test
public void shouldGetDetailedStageHistory() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1", "h2", "h3" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg), new String[] { "job1", "job2" });
scheduleUtil.runAndPass(p1, "h1");
scheduleUtil.runAndPass(p1, "h2");
scheduleUtil.runAndPass(p1, "h3");
Pagination pagination = Pagination.pageStartingAt(0, 3, 2);
StageInstanceModels stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertThat(stageInstanceModels.size(), is(2));
assertThat(stageInstanceModels.get(0).getResult(), is(StageResult.Passed));
assertThat(stageInstanceModels.get(0).getIdentifier().getPipelineName(), is(pipelineName));
assertThat(stageInstanceModels.get(0).getIdentifier().getPipelineCounter(), is(3));
assertThat(stageInstanceModels.get(0).getIdentifier().getStageName(), is(stageName));
assertThat(stageInstanceModels.get(0).getIdentifier().getStageCounter(), is("1"));
assertJobDetails(stageInstanceModels.get(0).getBuildHistory());
assertThat(stageInstanceModels.get(1).getResult(), is(StageResult.Passed));
assertThat(stageInstanceModels.get(1).getIdentifier().getPipelineName(), is(pipelineName));
assertThat(stageInstanceModels.get(1).getIdentifier().getPipelineCounter(), is(2));
assertThat(stageInstanceModels.get(1).getIdentifier().getStageName(), is(stageName));
assertThat(stageInstanceModels.get(1).getIdentifier().getStageCounter(), is("1"));
assertJobDetails(stageInstanceModels.get(1).getBuildHistory());
pagination = Pagination.pageStartingAt(2, 3, 2);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertThat(stageInstanceModels.size(), is(1));
assertThat(stageInstanceModels.get(0).getResult(), is(StageResult.Passed));
assertThat(stageInstanceModels.get(0).getIdentifier().getPipelineName(), is(pipelineName));
assertThat(stageInstanceModels.get(0).getIdentifier().getPipelineCounter(), is(1));
assertThat(stageInstanceModels.get(0).getIdentifier().getStageName(), is(stageName));
assertThat(stageInstanceModels.get(0).getIdentifier().getStageCounter(), is("1"));
assertJobDetails(stageInstanceModels.get(0).getBuildHistory());
}
Aggregations