Search in sources :

Example 21 with JobInstance

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));
}
Also used : Expectations(org.jmock.Expectations) LogFile(com.thoughtworks.go.server.domain.LogFile) JobInstance(com.thoughtworks.go.domain.JobInstance) HashMap(java.util.HashMap) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) LogFile(com.thoughtworks.go.server.domain.LogFile) File(java.io.File) Test(org.junit.Test)

Example 22 with JobInstance

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);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) JobInstance(com.thoughtworks.go.domain.JobInstance) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.Test)

Example 23 with JobInstance

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"));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.Test)

Example 24 with JobInstance

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);
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance)

Example 25 with JobInstance

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;
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) JobInstance(com.thoughtworks.go.domain.JobInstance)

Aggregations

JobInstance (com.thoughtworks.go.domain.JobInstance)90 Test (org.junit.Test)65 Stage (com.thoughtworks.go.domain.Stage)23 Pipeline (com.thoughtworks.go.domain.Pipeline)22 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)16 JobInstances (com.thoughtworks.go.domain.JobInstances)11 JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)10 Stages (com.thoughtworks.go.domain.Stages)5 JsonTester (com.thoughtworks.go.util.JsonTester)5 Map (java.util.Map)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 AgentConfig (com.thoughtworks.go.config.AgentConfig)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 Date (java.util.Date)4 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)3 Resource (com.thoughtworks.go.config.Resource)3 DirectoryEntries (com.thoughtworks.go.domain.DirectoryEntries)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)3 StageDao (com.thoughtworks.go.server.dao.StageDao)3