Search in sources :

Example 16 with Pagination

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;
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination)

Example 17 with Pagination

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());
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision)

Example 18 with Pagination

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);
    }
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)

Example 19 with Pagination

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()));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 20 with Pagination

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());
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) Test(org.junit.Test)

Aggregations

Pagination (com.thoughtworks.go.server.util.Pagination)24 Test (org.junit.Test)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)7 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)7 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)5 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)5 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)4 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)3 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Method (java.lang.reflect.Method)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 PipelineNotFoundException (com.thoughtworks.go.config.PipelineNotFoundException)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1 GitMaterialInstance (com.thoughtworks.go.domain.materials.git.GitMaterialInstance)1