use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class ConsoleActivityMonitorTest method shouldClearServerHealthMessageForAnyJobCancelledExternally.
@Test
public void shouldClearServerHealthMessageForAnyJobCancelledExternally() {
DateTime now = new DateTime();
when(timeProvider.currentTimeMillis()).thenReturn(now.getMillis());
JobIdentifier unresponsiveJob = new JobIdentifier("foo", 12, "foo-10", "stage", "2", "job", 20l);
JobInstance job = buildingInstance(unresponsiveJob);
listener.jobStatusChanged(job);
job.cancel();
listener.jobStatusChanged(job);
verify(serverHealthService).removeByScope(HealthStateScope.forJob("foo", "stage", "job"));
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class BuildRepositoryService method isCancelledOrRescheduled.
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;
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class ScheduledPipelineLoader method pipelineWithPasswordAwareBuildCauseByBuildId.
// TODO: Do we need to do this differently than PipelineService#fullPipeline?
public Pipeline pipelineWithPasswordAwareBuildCauseByBuildId(final long buildId) {
Pipeline pipeline = pipelineDao.pipelineWithMaterialsAndModsByBuildId(buildId);
MaterialRevisions scheduledRevs = pipeline.getBuildCause().getMaterialRevisions();
MaterialConfigs knownMaterials = knownMaterials(pipeline, scheduledRevs);
for (MaterialRevision materialRevision : scheduledRevs) {
MaterialConfig materialConfig = materialFrom(knownMaterials, materialRevision);
Material usedMaterial = materialRevision.getMaterial();
if (materialConfig == null) {
final JobInstance jobInstance = jobInstanceService.buildByIdWithTransitions(buildId);
scheduleService.failJob(jobInstance);
final String message = "Cannot load job '" + jobInstance.buildLocator() + "' because material " + usedMaterial.config() + " was not found in config.";
final String description = "Job for pipeline '" + jobInstance.buildLocator() + "' has been failed as one or more material configurations were either changed or removed.";
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
final ServerHealthState error = ServerHealthState.error(message, description, HealthStateType.general(HealthStateScope.forJob(jobInstance.getPipelineName(), jobInstance.getStageName(), jobInstance.getName())));
error.setTimeout(Timeout.FIVE_MINUTES);
serverHealthService.update(error);
appendToConsoleLog(jobInstance, message);
appendToConsoleLog(jobInstance, description);
}
});
throw new StaleMaterialsOnBuildCause(message);
}
usedMaterial.updateFromConfig(materialConfig);
}
return pipeline;
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class JobPresentationService method jobInstanceModelFor.
public List<JobInstanceModel> jobInstanceModelFor(JobInstances jobInstances) {
ArrayList<JobInstanceModel> models = new ArrayList<>();
for (JobInstance jobInstance : jobInstances) {
AgentInstance agentInstance = jobInstance.isAssignedToAgent() ? agentService.findAgentAndRefreshStatus(jobInstance.getAgentUuid()) : null;
JobInstanceModel model;
if (null != agentInstance && !agentInstance.isNullAgent()) {
model = new JobInstanceModel(jobInstance, jobDurationStrategy, agentInstance);
} else if (jobInstance.getAgentUuid() != null) {
Agent agent = agentService.findAgentObjectByUuid(jobInstance.getAgentUuid());
model = new JobInstanceModel(jobInstance, jobDurationStrategy, agent);
} else {
model = new JobInstanceModel(jobInstance, jobDurationStrategy);
}
models.add(model);
}
sort(models, JobInstanceModel.JOB_MODEL_COMPARATOR);
return models;
}
use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.
the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsRescheduled.
@Test
public void shouldSendCancelMessageIfJobIsRescheduled() 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));
assertThat(MessageEncoding.decodeWork(agent.messages.get(0).getData()), instanceOf(BuildWork.class));
BuildWork work = (BuildWork) MessageEncoding.decodeWork(agent.messages.get(0).getData());
BuildAssignment assignment = work.getAssignment();
final JobInstance instance = jobInstanceService.buildByIdWithTransitions(assignment.getJobIdentifier().getBuildId());
scheduleService.rescheduleJob(instance);
assertThat(agent.messages.size(), is(2));
assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Aggregations