private boolean areAllJobsInScheduledState() { for (JobInstance instance : jobInstances) { if (instance.getState() != JobState.Scheduled) { return false; } } return true; }
public void jobStatusChanged(JobInstance job) { if (job.getState() == JobState.Rescheduled || job.getState() == JobState.Completed) { map.remove(job.getAgentUuid()); LOGGER.debug("Removed agent assignment for job [{}]", job); } if (job.getState().isActiveOnAgent()) { map.put(job.getAgentUuid(), job); LOGGER.debug("Agent assignment added for job [{}]", job); } }
private boolean areAllReRunJobsInScheduledState() { for (JobInstance instance : jobInstances) { if (instance.isRerun() && instance.getState() != JobState.Scheduled) { return false; } } return true; }
public JobInstances filterByState(JobState state) { JobInstances filtered = new JobInstances(); for (JobInstance instance : this) { if (state == instance.getState()) { filtered.add(instance); } } return filtered; }
private void logIfJobIsCompleted(JobInstance jobInstance) { JobState currentState = getCurrentState(jobInstance.getId()); if (currentState.isCompleted() && !jobInstance.isCopy()) { String message = String.format( "State change for a completed Job is not allowed. Job %s is currently State=%s, Result=%s", jobInstance.getIdentifier(), jobInstance.getState(), jobInstance.getResult()); LOG.warn(message, new Exception().fillInStackTrace()); } }
public boolean isCancelledOrRescheduled(Long buildInstanceId) { JobInstance instance = jobInstanceService.buildByIdWithTransitions(buildInstanceId); if (instance.isNull()) { return false; } boolean cancelled = instance.getResult() == JobResult.Cancelled; boolean rescheduled = instance.getState() == JobState.Rescheduled; return cancelled || rescheduled; } }
public void jobStatusChanged(JobInstance job) { JobIdentifier identifier = job.getIdentifier(); if (job.getState().isBuilding()) { consoleActivityMonitor.jobLastActivityMap.putIfAbsent(identifier, consoleActivityMonitor.timeProvider.currentTimeMillis()); } else if (job.isCompleted() || job.isRescheduled()) { consoleActivityMonitor.jobLastActivityMap.remove(identifier); consoleActivityMonitor.removeHungJobWarning(identifier); } } }
private String lastBuildStatus(ProjectStatus existingStatus, JobInstance job) { return job.getState().isCompleted() ? job.getResult().toCctrayStatus() : existingStatus.getLastBuildStatus(); }
@Test public void shouldSetCompletingTimeAndResult() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); final Date completionDate = new Date(); instance.completing(JobResult.Passed, completionDate); assertThat(instance.getResult(), is(JobResult.Passed)); assertThat(instance.getState(), is(JobState.Completing)); }
@Test public void shouldCleanAgentIdAndResultAfterRescheduled() throws Exception { JobInstance instance = JobInstanceMother.assignedWithAgentId("testBuild", "uuid"); instance.completing(JobResult.Failed); instance.reschedule(); assertThat(instance.getState(), is(JobState.Scheduled)); assertThat(instance.getAgentUuid(), is(nullValue())); assertThat(instance.getResult(), is(JobResult.Unknown)); }
@Test public void shouldCancelBuild() { final JobInstance instance = JobInstanceMother.scheduled("plan1"); instance.cancel(); assertThat(instance.getState(), is(JobState.Completed)); assertThat(instance.getResult(), is(JobResult.Cancelled)); }
@Test public void shouldSetCompletedTimeOnComplete() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); final Date completionDate = new Date(); instance.completing(JobResult.Passed, completionDate); instance.completed(completionDate); assertThat(instance.getResult(), is(JobResult.Passed)); assertThat(instance.getStartedDateFor(JobState.Completed), is(completionDate)); assertThat(instance.getState(), is(JobState.Completed)); }
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.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); }
@Test public void shouldChangeStatus() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); instance.assign("1234", timeProvider.currentTime()); assertThat(instance.getState(), is(JobState.Assigned)); assertThat(instance.getTransitions().byState(JobState.Assigned), not(nullValue())); }
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); }
private void assertCopiedJob(JobInstance newJava, final long originalId) { assertThat(newJava.getId(), is(-1l)); assertThat(newJava.getTransitions().isEmpty(), is(false)); assertThat(newJava.getResult(), is(Passed)); assertThat(newJava.getState(), is(Completed)); assertThat(newJava.getTransitions().byState(Scheduled).getId(), is(-1l)); assertThat(newJava.getTransitions().byState(Completed).getId(), is(-1l)); assertThat(newJava.getOriginalJobId(), is(originalId)); assertThat(newJava.isRerun(), is(false)); assertThat(newJava.isCopy(), is(true)); }
private StageNotificationDTO.StageDTO createStageDTO() { ArrayList<StageNotificationDTO.JobDTO> jobs = new ArrayList<>(); for (JobInstance job : stage.getJobInstances()) { StageNotificationDTO.JobDTO jobDTO = new StageNotificationDTO.JobDTO(job.getName(), DateUtil.dateToString(job.getScheduledDate()), DateUtil.dateToString(job.getAssignedDate()), DateUtil.dateToString(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(), DateUtil.dateToString(stage.getCreatedTime()), DateUtil.dateToString(stage.getLastTransitionedTime()), jobs); }
@Test public void shouldFilterByStatus() { final JobInstance instance1 = new JobInstance("test" ); final JobInstance instance2 = new JobInstance("test2" ); instance2.setState(JobState.Assigned); JobInstances instances = new JobInstances(instance1, instance2); JobInstances actual = instances.filterByState(JobState.Assigned); assertThat(actual.size(), is(1)); assertThat(actual.get(0).getState(), is(JobState.Assigned)); }
private StageNotificationDTO.StageDTO createStageDTO() { ArrayList<StageNotificationDTO.JobDTO> jobs = new ArrayList<>(); for (JobInstance job : stage.getJobInstances()) { StageNotificationDTO.JobDTO jobDTO = new StageNotificationDTO.JobDTO(job.getName(), DateUtil.dateToString(job.getScheduledDate()), DateUtil.dateToString(job.getAssignedDate()), DateUtil.dateToString(job.getCompletedDate()), job.getState(), job.getResult(), job.getAgentUuid()); jobs.add(jobDTO); } return new StageNotificationDTO.StageDTO(stage.getName(), stage.getCounter(), stage.getApprovalType(), stage.getApprovedBy(), stage.getPreviousStage(), stage.getState(), stage.getResult(), DateUtil.dateToString(stage.getCreatedTime()), DateUtil.dateToString(stage.getLastTransitionedTime()), jobs); }
public static StageInstanceModel toStageInstanceModel(Stage stage) { StageInstanceModel stageInstanceModel = new StageInstanceModel(stage.getName(), String.valueOf(stage.getCounter()), stage.getResult(), stage.getIdentifier()); stageInstanceModel.setApprovalType(stage.getApprovalType()); stageInstanceModel.setApprovedBy(stage.getApprovedBy()); stageInstanceModel.setRerunOfCounter(stage.getRerunOfCounter()); JobHistory jobHistory = new JobHistory(); for (JobInstance jobInstance : stage.getJobInstances()) { jobHistory.addJob(jobInstance.getName(), jobInstance.getState(), jobInstance.getResult(), jobInstance.getScheduledDate()); } stageInstanceModel.setBuildHistory(jobHistory); return stageInstanceModel; }