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);
}
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())));
}
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);
}
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));
}
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)));
}
Aggregations