Search in sources :

Example 1 with JobInstancesModel

use of com.thoughtworks.go.server.ui.JobInstancesModel in project gocd by gocd.

the class AgentJobHistoryControllerV1 method index.

public String index(Request request, Response response) throws IOException {
    String uuid = request.params(":uuid");
    Integer offset = getOffset(request);
    Integer pageSize = getPageSize(request);
    JobInstanceService.JobHistoryColumns column = getSortColumn(request);
    SortOrder sortOrder = getSortOrder(request);
    Integer total = jobInstanceService.totalCompletedJobsCountOn(uuid);
    Pagination pagination = Pagination.pageStartingAt(offset, total, pageSize);
    AgentInstance agent = agentService.findAgent(uuid);
    if (agent.isNullAgent()) {
        throw new RecordNotFoundException(EntityType.Agent, uuid);
    }
    JobInstancesModel jobInstances = jobInstanceService.completedJobsOnAgent(uuid, column, sortOrder, pagination);
    return writerForTopLevelObject(request, response, outputWriter -> AgentJobHistoryRepresenter.toJSON(outputWriter, uuid, jobInstances));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) JobInstanceService(com.thoughtworks.go.server.service.JobInstanceService) Pagination(com.thoughtworks.go.server.util.Pagination) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) SortOrder(com.thoughtworks.go.server.ui.SortOrder) JobInstancesModel(com.thoughtworks.go.server.ui.JobInstancesModel)

Example 2 with JobInstancesModel

use of com.thoughtworks.go.server.ui.JobInstancesModel in project gocd by gocd.

the class JobInstanceServiceTest method shouldGetCompletedJobsOnAgentOnTheGivenPage.

@Test
public void shouldGetCompletedJobsOnAgentOnTheGivenPage() {
    JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, serverHealthService);
    ArrayList<JobInstance> expected = new ArrayList<>();
    when(jobInstanceDao.totalCompletedJobsOnAgent("uuid")).thenReturn(500);
    when(jobInstanceDao.completedJobsOnAgent("uuid", JobInstanceService.JobHistoryColumns.pipeline, SortOrder.ASC, 50, 50)).thenReturn(expected);
    JobInstancesModel actualModel = jobService.completedJobsOnAgent("uuid", JobInstanceService.JobHistoryColumns.pipeline, SortOrder.ASC, 2, 50);
    assertThat(actualModel, is(new JobInstancesModel(new JobInstances(expected), Pagination.pageByNumber(2, 500, 50))));
    verify(jobInstanceDao).totalCompletedJobsOnAgent("uuid");
    verify(jobInstanceDao).completedJobsOnAgent("uuid", JobInstanceService.JobHistoryColumns.pipeline, SortOrder.ASC, 50, 50);
}
Also used : ArrayList(java.util.ArrayList) JobInstancesModel(com.thoughtworks.go.server.ui.JobInstancesModel) Test(org.junit.jupiter.api.Test)

Aggregations

JobInstancesModel (com.thoughtworks.go.server.ui.JobInstancesModel)2 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 JobInstanceService (com.thoughtworks.go.server.service.JobInstanceService)1 SortOrder (com.thoughtworks.go.server.ui.SortOrder)1 Pagination (com.thoughtworks.go.server.util.Pagination)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1