From 1b83af30a4e935f2037a6e9153cb438c29adfbfc Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 29 Dec 2012 15:56:48 +0100 Subject: o Starting on a generic paging component. o Showing recent jobs on the jenkins server page. --- .../testing/core/badge/UnbreakablePoller.java | 2 +- .../io/trygvis/esper/testing/core/db/BuildDao.java | 10 ++++- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 27 +++++++++++++ .../esper/testing/util/sql/PageRequest.java | 1 + .../esper/testing/web/resource/CoreResource.java | 14 +++++++ .../testing/web/resource/JenkinsResource.java | 45 +++++++++++++++++++++- 6 files changed, 95 insertions(+), 4 deletions(-) (limited to 'src/main/java/io/trygvis/esper/testing') diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java index 05d4976..3183304 100644 --- a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java +++ b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java @@ -40,7 +40,7 @@ public class UnbreakablePoller implements TablePoller.NewRowCallback { public void process(Connection c, BuildDto build) throws SQLException { Daos daos = new Daos(c); - List persons = daos.buildDao.selectPersonsFromBuildParticipant(build.uuid); + List persons = daos.buildDao.selectBuildParticipantByBuild(build.uuid); logger.info("Processing build={}, success={}, #persons={}", build.uuid, build.success, persons.size()); for (UUID person : persons) { diff --git a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java index e498017..416faf6 100644 --- a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java @@ -57,7 +57,7 @@ public class BuildDao { } } - public List selectPersonsFromBuildParticipant(UUID build) throws SQLException { + public List selectBuildParticipantByBuild(UUID build) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT person FROM build_participant WHERE build=?")) { int i = 1; s.setString(i, build.toString()); @@ -65,6 +65,14 @@ public class BuildDao { } } + public List selectPersonsFromBuildParticipant(UUID build) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT " + PersonDao.PERSON + " FROM person p, build_participant bp WHERE bp.person = p.uuid AND build=?")) { + int i = 1; + s.setString(i, build.toString()); + return toList(s, PersonDao.person); + } + } + public SqlOption selectBuild(UUID uuid) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + BUILD + " FROM build WHERE uuid=?")) { int i = 1; 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 8d32dbe..117d91d 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -10,6 +10,7 @@ import java.util.*; import java.util.List; import static fj.data.Option.*; +import static io.trygvis.esper.testing.Util.toList; import static io.trygvis.esper.testing.Util.toUuidArray; import static io.trygvis.esper.testing.util.sql.SqlOption.fromRs; import static java.lang.System.*; @@ -96,6 +97,10 @@ public class JenkinsDao { } }; + // ----------------------------------------------------------------------- + // Server + // ----------------------------------------------------------------------- + public List selectServers(boolean enabledOnly) throws SQLException { String sql = "SELECT " + JENKINS_SERVER + " FROM jenkins_server"; @@ -121,6 +126,10 @@ public class JenkinsDao { } } + // ----------------------------------------------------------------------- + // Job + // ----------------------------------------------------------------------- + public SqlOption selectJob(UUID uuid) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE uuid=?")) { s.setString(1, uuid.toString()); @@ -128,6 +137,16 @@ public class JenkinsDao { } } + public List selectJobsByServer(UUID server, PageRequest page) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE server=? ORDER BY created_date LIMIT ? OFFSET ?")) { + int i = 1; + s.setString(i++, server.toString()); + s.setInt(i++, page.count.orSome(10)); + s.setInt(i, page.startIndex.orSome(0)); + return toList(s, jenkinsJob); + } + } + public SqlOption selectJobByUrl(URI url) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE url=?")) { s.setString(1, url.toASCIIString()); @@ -161,6 +180,10 @@ public class JenkinsDao { } } + // ----------------------------------------------------------------------- + // Build + // ----------------------------------------------------------------------- + public SqlOption selectBuildByEntryId(String id) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_BUILD + " FROM jenkins_build WHERE entry_id=?")) { int i = 1; @@ -190,6 +213,10 @@ public class JenkinsDao { } } + // ----------------------------------------------------------------------- + // User + // ----------------------------------------------------------------------- + public UUID insertUser(UUID server, String absoluteUrl) throws SQLException { try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_user(" + JENKINS_USER + ") VALUES(?, ?, ?, ?)")) { UUID uuid = UUID.randomUUID(); diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java index 824291c..38d417d 100644 --- a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java +++ b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java @@ -9,6 +9,7 @@ import javax.servlet.http.*; public class PageRequest { public final Option startIndex; public final Option count; + public static final PageRequest FIRST_PAGE = new PageRequest(Option.none(), Option.none()); public PageRequest(Option startIndex, Option count) { this.startIndex = startIndex; diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java index 2f4b77b..9b22674 100644 --- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java @@ -114,6 +114,20 @@ public class CoreResource extends AbstractResource { }); } + @GET + @Path("/build-participant/{uuid}") + public List getBuildParticipants(@MagicParam final UUID build) throws Exception { + return da.inTransaction(new DatabaseAccess.DaosCallback>() { + public List run(Daos daos) throws SQLException { + List list = new ArrayList<>(); + for (PersonDto person : daos.buildDao.selectPersonsFromBuildParticipant(build)) { + list.add(getPersonJson(daos, person)); + } + return list; + } + }); + } + @GET @Path("/build/{uuid}") public BuildJson getBuild(@MagicParam final UUID uuid) throws Exception { 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 284d90e..33b3f88 100644 --- a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java @@ -3,6 +3,8 @@ package io.trygvis.esper.testing.web.resource; import fj.data.*; import io.trygvis.esper.testing.*; import io.trygvis.esper.testing.jenkins.*; +import io.trygvis.esper.testing.util.sql.*; +import io.trygvis.esper.testing.web.*; import org.joda.time.*; import javax.ws.rs.*; @@ -55,9 +57,34 @@ public class JenkinsResource extends AbstractResource { }); } + @GET + @Path("/job") + @Produces(MediaType.APPLICATION_JSON) + public List getJobs(@MagicParam(query = "server") final UUID server, @MagicParam final PageRequest page) throws Exception { + return da.inTransaction(new DatabaseAccess.DaosCallback>() { + public List run(final Daos daos) throws SQLException { + List jobs = new ArrayList<>(); + for (JenkinsJobDto job : daos.jenkinsDao.selectJobsByServer(server, page)) { + jobs.add(getJenkinsJobJson(job)); + } + return jobs; + } + }); + } + private JenkinsServerJson getJenkinsServerJson(Daos daos, JenkinsServerDto server) throws SQLException { int count = daos.jenkinsDao.selectJobCountForServer(server.uuid); - return new JenkinsServerJson(server.uuid, server.createdDate, server.url, server.enabled, count); + + List jobs = new ArrayList<>(); + for (JenkinsJobDto jobDto : daos.jenkinsDao.selectJobsByServer(server.uuid, PageRequest.FIRST_PAGE)) { + jobs.add(getJenkinsJobJson(jobDto)); + } + + return new JenkinsServerJson(server.uuid, server.createdDate, server.url, server.enabled, count, jobs); + } + + private JenkinsJobJson getJenkinsJobJson(JenkinsJobDto job) { + return new JenkinsJobJson(job.uuid, job.createdDate, job.displayName.toNull()); } public static UUID parseUuid(String s) { @@ -75,12 +102,26 @@ class JenkinsServerJson { public final URI url; public final boolean enabled; public final int jobCount; + public final List recentJobs; - JenkinsServerJson(UUID uuid, DateTime createdDate, URI url, boolean enabled, int jobCount) { + JenkinsServerJson(UUID uuid, DateTime createdDate, URI url, boolean enabled, int jobCount, List recentJobs) { this.uuid = uuid; this.createdDate = createdDate; this.url = url; this.enabled = enabled; this.jobCount = jobCount; + this.recentJobs = recentJobs; + } +} + +class JenkinsJobJson { + public final UUID uuid; + public final DateTime createdDate; + public final String displayName; + + JenkinsJobJson(UUID uuid, DateTime createdDate, String displayName) { + this.uuid = uuid; + this.createdDate = createdDate; + this.displayName = displayName; } } -- cgit v1.2.3