@RequestMapping(value = "/**/jobStatus.json", method = RequestMethod.GET) public ModelAndView handleRequest(@RequestParam(value = "pipelineName") String pipelineName, @RequestParam(value = "stageName") String stageName, @RequestParam(value = "jobId") long jobId, HttpServletResponse response) { Object json; try { JobInstance requestedInstance = jobInstanceService.buildByIdWithTransitions(jobId); JobInstance mostRecentJobInstance = jobInstanceDao.mostRecentJobWithTransitions(requestedInstance.getIdentifier()); JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(mostRecentJobInstance, agentService.findAgentObjectByUuid(mostRecentJobInstance.getAgentUuid()), stageService.getBuildDuration(pipelineName, stageName, mostRecentJobInstance)); json = createBuildInfo(presenter); } catch (Exception e) { LOGGER.warn(null, e); json = errorJsonMap(e); } return jsonFound(json).respond(response); }
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); } models.sort(JobInstanceModel.JOB_MODEL_COMPARATOR); return models; } }