From f868ed2dda3e000241bab0ee58d91b4eec8b6441 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 22 Jan 2013 16:33:50 +0100 Subject: o Adding build count and last time timestamp to the Jenkins server view. --- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 14 ++++++++++++++ .../trygvis/esper/testing/util/sql/ResultSetF.java | 8 ++++++++ .../esper/testing/web/resource/JenkinsResource.java | 21 +++++++++++---------- .../resources/webapp/apps/jenkinsApp/server.html | 14 +++++++++++--- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java index 46fdc29..f8291b5 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -143,6 +143,20 @@ public class JenkinsDao { } } + public int selectBuildCountForServer(UUID uuid) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT count(1) FROM jenkins_job j, jenkins_build b WHERE j.server=? AND b.job = j.uuid")) { + s.setString(1, uuid.toString()); + return fromRs(s.executeQuery()).map(getInt).get(); + } + } + + public DateTime selectLastBuildForServer(UUID uuid) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT b.created_date FROM jenkins_job j, jenkins_build b WHERE j.server=? AND b.job = j.uuid ORDER BY b.created_date LIMIT 1")) { + s.setString(1, uuid.toString()); + return fromRs(s.executeQuery()).map(getDateTime).get(); + } + } + public UUID insertJob(UUID server, UUID file, URI url, JenkinsJobXml.JenkinsJobType type, Option displayName) throws SQLException { try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_job(" + JENKINS_JOB + ") VALUES(?, ?, ?, ?, ?, ?, ?)")) { UUID uuid = UUID.randomUUID(); diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java b/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java index 5c51e6f..e911230 100755 --- a/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java +++ b/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java @@ -1,6 +1,7 @@ package io.trygvis.esper.testing.util.sql; import io.trygvis.esper.testing.*; +import org.joda.time.*; import java.sql.*; import java.util.*; @@ -19,6 +20,13 @@ public class ResultSetF { } }; + public static final SqlF getDateTime = new SqlF() { + public DateTime apply(ResultSet rs) throws SQLException { + Timestamp i = rs.getTimestamp(1); + return rs.wasNull() ? null : new DateTime(i.getTime()); + } + }; + public static final SqlF getUUID = new SqlF() { public UUID apply(ResultSet rs) throws SQLException { return UUID.fromString(rs.getString(1)); diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java index ff6b085..fd8ea91 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java @@ -138,14 +138,12 @@ public class JenkinsResource extends AbstractResource { protected SqlF getJenkinsServerJson = new SqlF() { public JenkinsServerJson apply(JenkinsServerDto server) throws SQLException { - int count = daos.jenkinsDao.selectJobCountForServer(server.uuid); + int jobCount = daos.jenkinsDao.selectJobCountForServer(server.uuid); + int buildCount = daos.jenkinsDao.selectBuildCountForServer(server.uuid); + DateTime lastBuildTimestamp = daos.jenkinsDao.selectLastBuildForServer(server.uuid); - List jobs = new ArrayList<>(); - for (JenkinsJobDto jobDto : daos.jenkinsDao.selectJobsByServer(server.uuid, PageRequest.FIRST_PAGE)) { - jobs.add(getJenkinsJobJson.apply(jobDto)); - } - - return new JenkinsServerJson(server.uuid, server.createdDate, server.name, server.url, server.enabled, count, jobs); + return new JenkinsServerJson(server.uuid, server.createdDate, server.name, server.url, server.enabled, + jobCount, buildCount, lastBuildTimestamp); } }; @@ -208,16 +206,19 @@ class JenkinsServerJson { public final URI url; public final boolean enabled; public final int jobCount; - public final List recentJobs; + public final int buildCount; + public final DateTime lastBuildTimestamp; - JenkinsServerJson(UUID uuid, DateTime createdDate, String name, URI url, boolean enabled, int jobCount, List recentJobs) { + JenkinsServerJson(UUID uuid, DateTime createdDate, String name, URI url, boolean enabled, int jobCount, + int buildCount, DateTime lastBuildTimestamp) { this.uuid = uuid; this.createdDate = createdDate; this.name = name; this.url = url; this.enabled = enabled; this.jobCount = jobCount; - this.recentJobs = recentJobs; + this.buildCount = buildCount; + this.lastBuildTimestamp = lastBuildTimestamp; } } diff --git a/src/main/resources/webapp/apps/jenkinsApp/server.html b/src/main/resources/webapp/apps/jenkinsApp/server.html index fb821d3..88948b5 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/server.html +++ b/src/main/resources/webapp/apps/jenkinsApp/server.html @@ -4,7 +4,7 @@