Search in sources :

Example 16 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class StageConverter method createStageDTO.

private StageNotificationDTO.StageDTO createStageDTO() {
    ArrayList<StageNotificationDTO.JobDTO> jobs = new ArrayList<>();
    for (JobInstance job : stage.getJobInstances()) {
        StageNotificationDTO.JobDTO jobDTO = new StageNotificationDTO.JobDTO(job.getName(), job.getScheduledDate(), job.getAssignedDate(), job.getCompletedDate(), job.getState(), job.getResult(), job.getAgentUuid());
        jobs.add(jobDTO);
    }
    return new StageNotificationDTO.StageDTO(stage.getName(), stage.getCounter(), stage.getApprovalType(), stage.getApprovedBy(), stage.getState(), stage.getResult(), stage.getCreatedTime(), stage.getLastTransitionedTime(), jobs);
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) ArrayList(java.util.ArrayList)

Example 17 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class ArtifactPropertiesGeneratorRepositoryIntegrationTest method shouldSaveACopyOfAnArtifactPropertiesGenerator.

@Test
public void shouldSaveACopyOfAnArtifactPropertiesGenerator() {
    // Arrange
    JobInstance firstJobInstance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME + "1"));
    JobInstance secondJobInstance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME + "2"));
    ArtifactPropertiesGenerator generator = new ArtifactPropertiesGenerator("test", "src", "//xpath");
    // Act
    ArtifactPropertiesGenerator generatorOfFirstJob = artifactPropertiesGeneratorRepository.saveCopyOf(firstJobInstance.getId(), generator);
    ArtifactPropertiesGenerator generatorOfSecondJob = artifactPropertiesGeneratorRepository.saveCopyOf(secondJobInstance.getId(), generator);
    // Assert
    List<ArtifactPropertiesGenerator> firstJobGenerators = artifactPropertiesGeneratorRepository.findByBuildId(firstJobInstance.getId());
    assertThat(firstJobGenerators.size(), is(1));
    assertThat(firstJobGenerators.get(0).getId(), equalTo(generatorOfFirstJob.getId()));
    assertThat(firstJobGenerators, hasItem(generatorOfFirstJob));
    List<ArtifactPropertiesGenerator> secondJobGenerators = artifactPropertiesGeneratorRepository.findByBuildId(secondJobInstance.getId());
    assertThat(secondJobGenerators.size(), is(1));
    assertThat(secondJobGenerators, hasItem(generatorOfSecondJob));
    assertThat(generatorOfFirstJob.getId(), not(equalTo(generatorOfSecondJob.getId())));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) ArtifactPropertiesGenerator(com.thoughtworks.go.config.ArtifactPropertiesGenerator) Test(org.junit.Test)

Example 18 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobStatusListenerTest method setUp.

@Before
public void setUp() throws Exception {
    goCache.clear();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    PipelineConfig pipelineConfig = withSingleStageWithMaterials(PIPELINE_NAME, STAGE_NAME, withBuildPlans(JOB_NAME));
    configHelper.addPipeline(PIPELINE_NAME, STAGE_NAME);
    savedPipeline = scheduleHelper.schedule(pipelineConfig, BuildCause.createWithModifications(modifyOneFile(pipelineConfig), ""), GoConstants.DEFAULT_APPROVED_BY);
    JobInstance job = savedPipeline.getStages().first().getJobInstances().first();
    job.setAgentUuid(UUID);
    mockery = new ClassMockery();
    stageStatusTopic = mockery.mock(StageStatusTopic.class);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) JobInstance(com.thoughtworks.go.domain.JobInstance) ClassMockery(com.thoughtworks.go.util.ClassMockery) Before(org.junit.Before)

Example 19 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsCancelled.

@Test
public void shouldSendCancelMessageIfJobIsCancelled() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    configHelper.addAgent(agentConfig);
    fixture.createPipelineWithFirstStageScheduled();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    buildAssignmentService.onTimer();
    assertThat(agent.messages.size(), is(1));
    Work work = MessageEncoding.decodeWork(agent.messages.get(0).getData());
    assertThat(work, instanceOf(BuildWork.class));
    JobPlan jobPlan = ((BuildWork) work).getAssignment().getPlan();
    final JobInstance instance = jobInstanceService.buildByIdWithTransitions(jobPlan.getJobId());
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            jobInstanceService.cancelJob(instance);
        }
    });
    assertThat(agent.messages.size(), is(2));
    assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobPlan(com.thoughtworks.go.domain.JobPlan) JobInstance(com.thoughtworks.go.domain.JobInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionStatus(org.springframework.transaction.TransactionStatus) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 20 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class CcTrayJobStatusChangeHandlerTest method shouldUpdateValueInCacheWhenJobHasChanged.

@Test
public void shouldUpdateValueInCacheWhenJobHasChanged() throws Exception {
    String jobName = "job1";
    ProjectStatus existingStatusInCache = new ProjectStatus(projectNameFor(jobName), "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor(jobName));
    when(cache.get(projectNameFor(jobName))).thenReturn(existingStatusInCache);
    CcTrayJobStatusChangeHandler handler = new CcTrayJobStatusChangeHandler(cache);
    JobInstance completedJob = JobInstanceMother.completed(jobName);
    handler.call(completedJob);
    verify(cache).put(statusCaptor.capture());
    ProjectStatus newStatusInCache = statusCaptor.getValue();
    assertThat(newStatusInCache.name(), is(projectNameFor(jobName)));
    assertThat(newStatusInCache.getLastBuildStatus(), is("Success"));
    assertThat(newStatusInCache.getLastBuildLabel(), is("label-1"));
    assertThat(newStatusInCache.getLastBuildTime(), is(completedJob.getCompletedDate()));
    assertThat(newStatusInCache.getBreakers(), is(Collections.<String>emptySet()));
    assertThat(activityOf(newStatusInCache), is("Sleeping"));
    assertThat(webUrlOf(newStatusInCache), is(webUrlFor(jobName)));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) JobInstance(com.thoughtworks.go.domain.JobInstance) Date(java.util.Date) Test(org.junit.Test)

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