use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class JobDetailServiceTest method shouldCreateBuildInstanceDetailFromLogFileForCompletedBuild.
@Test
public void shouldCreateBuildInstanceDetailFromLogFileForCompletedBuild() throws Exception {
final String jobConfigName = "jobConfig1";
final int id = 1;
final JobInstance completed = JobInstanceMother.completed(jobConfigName, JobResult.Failed);
completed.setId(id);
completed.setIdentifier(new JobIdentifier("pipeline", "1", "stage", "1", jobConfigName));
final HashMap properties = new HashMap();
final File artifactsRoot = new File("artifacts");
context.checking(new Expectations() {
{
one(artifactsService).getInstanceLogFile(completed.getIdentifier());
LogFile buildLogFile = new LogFile(DataUtils.getFailedBuildLbuildAsFile().getFile());
will(returnValue(buildLogFile));
one(artifactsService).parseLogFile(buildLogFile, completed.isPassed());
will(returnValue(properties));
one(artifactsService).findArtifact(completed.getIdentifier(), "");
will(returnValue(artifactsRoot));
}
});
jobDetailService.loadBuildInstanceLog(completed);
assertThat(completed.getName(), is(jobConfigName));
assertThat(properties.get("artifactfolder"), is(artifactsRoot));
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class JobPresentationServiceTest method shouldReturnJobModel.
@Test
public void shouldReturnJobModel() throws Exception {
JobInstance dev = assignedWithAgentId("dev", "agent1");
JobInstance DEv = assignedWithAgentId("DEv", "agent1");
JobInstance bev = assignedWithAgentId("bev", "agent2");
JobInstance tev = scheduled("tev");
JobInstance lev = assignAgent(passed("lev"), "agent3");
JobInstance kev = assignAgent(failed("kev"), "agent3");
AgentInstance agent = building();
when(agentService.findAgentAndRefreshStatus(any(String.class))).thenReturn(agent);
List<JobInstanceModel> models = new JobPresentationService(jobDurationStrategy, agentService).jobInstanceModelFor(new JobInstances(dev, bev, tev, lev, kev, DEv));
assertThat(models.size(), is(6));
//failed
assertThat(models.get(0), is(new JobInstanceModel(kev, jobDurationStrategy, agent)));
//in progress. sort by name (case insensitive)
assertThat(models.get(1), is(new JobInstanceModel(bev, jobDurationStrategy, agent)));
assertThat(models.get(2), is(new JobInstanceModel(dev, jobDurationStrategy, agent)));
assertThat(models.get(3), is(new JobInstanceModel(DEv, jobDurationStrategy, agent)));
assertThat(models.get(4), is(new JobInstanceModel(tev, jobDurationStrategy)));
//passed
assertThat(models.get(5), is(new JobInstanceModel(lev, jobDurationStrategy, agent)));
//assert agent info
verify(agentService, times(2)).findAgentAndRefreshStatus("agent1");
verify(agentService).findAgentAndRefreshStatus("agent2");
verify(agentService, times(2)).findAgentAndRefreshStatus("agent3");
verifyNoMoreInteractions(agentService);
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class ScheduleServiceRescheduleHungJobsTest method shouldRescheduleHungBuildForDeadAgent.
@Test
public void shouldRescheduleHungBuildForDeadAgent() {
final JobInstance jobInstance = JobInstanceMother.assigned("dev");
when(agentService.findRegisteredAgents()).thenReturn(activities());
when(jobInstanceService.findHungJobs(Arrays.asList("uuid1", "uuid2"))).thenReturn(new JobInstances(jobInstance));
scheduleService.rescheduleHungJobs();
verify(agentService).findRegisteredAgents();
verify(jobInstanceService).findHungJobs(Arrays.asList("uuid1", "uuid2"));
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class AgentAssignment method latestActiveJobOnAgent.
public JobInstance latestActiveJobOnAgent(String agentUuid) {
if (!map.containsKey(agentUuid)) {
JobInstance job = jobInstanceDao.getLatestInProgressBuildByAgentUuid(agentUuid);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Getting AgentAssignment for agent with UUID [%s], got: %s", agentUuid, job));
}
map.put(agentUuid, job);
}
return map.get(agentUuid);
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class CcTrayStageStatusChangeHandler method statusesOfStageAndItsJobsFor.
public List<ProjectStatus> statusesOfStageAndItsJobsFor(Stage stage) {
ArrayList<ProjectStatus> statuses = new ArrayList<>();
String projectName = stage.getIdentifier().ccProjectName();
Set<String> breakers = breakersCalculator.calculateFor(stage);
statuses.add(getStageStatus(stage, projectName, breakers));
for (JobInstance jobInstance : stage.getJobInstances()) {
Set<String> jobBreakers = jobInstance.getResult() == JobResult.Failed ? breakers : new HashSet<>();
statuses.add(jobStatusChangeHandler.statusFor(jobInstance, jobBreakers));
}
return statuses;
}
Aggregations