diff options
Diffstat (limited to 'src')
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<String> 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<ResultSet, DateTime> getDateTime = new SqlF<ResultSet, DateTime>() { + public DateTime apply(ResultSet rs) throws SQLException { + Timestamp i = rs.getTimestamp(1); + return rs.wasNull() ? null : new DateTime(i.getTime()); + } + }; + public static final SqlF<ResultSet, UUID> getUUID = new SqlF<ResultSet, UUID>() { 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<JenkinsServerDto, JenkinsServerJson> getJenkinsServerJson = new SqlF<JenkinsServerDto, JenkinsServerJson>() { 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<JenkinsJobJson> 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<JenkinsJobJson> recentJobs; + public final int buildCount; + public final DateTime lastBuildTimestamp; - JenkinsServerJson(UUID uuid, DateTime createdDate, String name, URI url, boolean enabled, int jobCount, List<JenkinsJobJson> 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 @@ <div class="page-header"> - <h1>Jenkins Server</h1> + <h1>Jenkins Server: {{server.name}}</h1> </div> <ul class="breadcrumb"> @@ -24,8 +24,16 @@ <td>{{server.enabled}}</td> </tr> <tr> - <th>Stats</th> - <td>{{server.jobCount}} jobs</td> + <th>Number of jobs</th> + <td>{{server.jobCount}}</td> + </tr> + <tr> + <th>Number of builds</th> + <td>{{server.buildCount}}</td> + </tr> + <tr> + <th>Most recent build</th> + <td>{{server.lastBuildTimestamp | date:'medium'}}</td> </tr> </tbody> </table> |