From 5c8c3467906d996c04210cc8350edbd027ccc32a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 3 Jan 2013 17:10:30 +0100 Subject: o Skipping builds where the job is a . o Using the build's timestamp instead of createdDate in the UI. --- pom.xml | 2 +- .../io/trygvis/esper/testing/core/db/FileDao.java | 11 ++++++ .../testing/core/jenkins/JenkinsBuildPoller.java | 30 +++++++++++++-- .../esper/testing/jenkins/JenkinsClient.java | 22 +++-------- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 1 + .../esper/testing/jenkins/JenkinsJobDto.java | 4 +- .../esper/testing/jenkins/JenkinsServerDto.java | 2 +- .../esper/testing/jenkins/xml/JenkinsJobXml.java | 44 ++++++++++++++++++---- .../esper/testing/web/resource/CoreResource.java | 14 +++---- src/main/resources/queries.sql | 2 + src/main/webapp/apps/buildApp/build.html | 2 +- src/main/webapp/apps/jenkinsApp/job.html | 2 +- src/main/webapp/apps/personApp/person.html | 5 +-- 13 files changed, 100 insertions(+), 41 deletions(-) mode change 100644 => 100755 src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java create mode 100755 src/main/resources/queries.sql mode change 100644 => 100755 src/main/webapp/apps/buildApp/build.html mode change 100644 => 100755 src/main/webapp/apps/jenkinsApp/job.html mode change 100644 => 100755 src/main/webapp/apps/personApp/person.html diff --git a/pom.xml b/pom.xml index 9482a08..0224a0f 100755 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.trygvis.appsh booter-jetty - 8.1.7.v20120910+1 + 8.1.8.v20121106+2-SNAPSHOT com.sun.jersey diff --git a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java index affe1c8..a7d7199 100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java @@ -41,4 +41,15 @@ public class FileDao { return some(rs.getBinaryStream(1)); } } + + public SqlOption loadByUrl(URI uri) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT data FROM file WHERE url=?")) { + s.setString(1, uri.toASCIIString()); + ResultSet rs = s.executeQuery(); + if(!rs.next()) { + return none(); + } + return some(rs.getBinaryStream(1)); + } + } } diff --git a/src/main/java/io/trygvis/esper/testing/core/jenkins/JenkinsBuildPoller.java b/src/main/java/io/trygvis/esper/testing/core/jenkins/JenkinsBuildPoller.java index 3270db1..4689e4d 100755 --- a/src/main/java/io/trygvis/esper/testing/core/jenkins/JenkinsBuildPoller.java +++ b/src/main/java/io/trygvis/esper/testing/core/jenkins/JenkinsBuildPoller.java @@ -42,10 +42,35 @@ public class JenkinsBuildPoller implements TablePoller.NewRowCallback jobXmlFileO = daos.fileDao.load(jobDto.file); + + if (jobXmlFileO.isNone()) { + logger.warn("Job xml file unavailable: File.uuid={}", jobDto.file); + return; + } + + Option jobXmlO = xmlParser.parseDocument.f(jobXmlFileO.get()). + bind(JenkinsJobXml.parse); + + if (jobXmlO.isNone()) { + logger.warn("Could not parse job file: File.uuid={}", jobDto.file); + return; + } + + JenkinsJobXml jobXml = jobXmlO.some(); + + switch (jobXml.type) { + case MAVEN_MODULE: + logger.info("Skipping maven module, Job.uuid={}", jobDto.uuid); + return; + } + SqlOption file = daos.fileDao.load(jenkinsBuild.file); if (file.isNone()) { - logger.warn("File unavailable: " + jenkinsBuild.file); + logger.warn("Build file unavailable: " + jenkinsBuild.file); return; } @@ -78,6 +103,7 @@ public class JenkinsBuildPoller implements TablePoller.NewRowCallback xml = JenkinsJobXml.parse(root); - switch (name) { - case "freeStyleProject": - return some(p(JenkinsJobXml.parse(url, JenkinsJobType.FREE_STYLE, root), d.some()._2())); - case "mavenModuleSet": - return some(p(JenkinsJobXml.parse(url, JenkinsJobType.MAVEN_MODULE_SET, root), d.some()._2())); - case "mavenModule": - return some(p(JenkinsJobXml.parse(url, JenkinsJobType.MAVEN_MODULE, root), d.some()._2())); - case "matrixProject": - return some(p(JenkinsJobXml.parse(url, JenkinsJobType.MATRIX, root), d.some()._2())); - case "matrixConfiguration": - return some(p(JenkinsJobXml.parse(url, JenkinsJobType.MATRIX_CONFIGURATION, root), d.some()._2())); - default: - logger.warn("Unknown project type: " + name); - return Option.none(); + if(xml.isNone()) { + logger.warn("Unable to parse xml"); + return none(); } + + return some(p(xml.some(), d.some()._2())); } public Option> fetchBuild(URI url) { 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 aec9ab3..ee793fa 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -48,6 +48,7 @@ public class JenkinsDao { UUID.fromString(rs.getString(i++)), new DateTime(rs.getTimestamp(i++).getTime()), UUID.fromString(rs.getString(i++)), + UUID.fromString(rs.getString(i++)), URI.create(rs.getString(i++)), fromNull(rs.getString(i))); } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java old mode 100644 new mode 100755 index 2fb5b99..e540a2a --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java @@ -9,12 +9,14 @@ import java.util.*; public class JenkinsJobDto extends AbstractEntity { public final UUID server; + public final UUID file; public final URI url; public final Option displayName; - JenkinsJobDto(UUID uuid, DateTime createdDate, UUID server, URI url, Option displayName) { + public JenkinsJobDto(UUID uuid, DateTime createdDate, UUID server, UUID file, URI url, Option displayName) { super(uuid, createdDate); this.server = server; + this.file = file; this.url = url; this.displayName = displayName; } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerDto.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerDto.java index c603506..8195f01 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerDto.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerDto.java @@ -17,6 +17,6 @@ public class JenkinsServerDto extends AbstractEntity { } public URI userUrl(String id) { - return URI.create(url.toASCIIString() + "/users/" + id); + return URI.create(url.toASCIIString() + "/user/" + id); } } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/xml/JenkinsJobXml.java b/src/main/java/io/trygvis/esper/testing/jenkins/xml/JenkinsJobXml.java index eb4c874..8cbeb9d 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/xml/JenkinsJobXml.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/xml/JenkinsJobXml.java @@ -2,19 +2,36 @@ package io.trygvis.esper.testing.jenkins.xml; import java.net.URI; -import org.jdom2.Element; +import org.jdom2.*; import fj.F; import fj.data.Option; import io.trygvis.esper.testing.Util; -import static fj.data.Option.some; +import static fj.data.Option.*; import static io.trygvis.esper.testing.Util.child; import static io.trygvis.esper.testing.Util.childText; public class JenkinsJobXml { public enum JenkinsJobType { - FREE_STYLE, MAVEN_MODULE_SET, MAVEN_MODULE, MATRIX, MATRIX_CONFIGURATION + FREE_STYLE, MAVEN_MODULE_SET, MAVEN_MODULE, MATRIX, MATRIX_CONFIGURATION; + + public static Option fromElement(String name) { + switch (name) { + case "freeStyleProject": + return some(FREE_STYLE); + case "mavenModuleSet": + return some(MAVEN_MODULE_SET); + case "mavenModule": + return some(MAVEN_MODULE); + case "matrixProject": + return some(MATRIX); + case "matrixConfiguration": + return some(MATRIX_CONFIGURATION); + default: + return none(); + } + } } public final JenkinsJobType type; @@ -71,18 +88,31 @@ public class JenkinsJobXml { } } - public static JenkinsJobXml parse(URI url, JenkinsJobType type, Element root) { - return new JenkinsJobXml(type, + public static final F> parse = new F>() { + public Option f(Document document) { + return parse(document.getRootElement()); + } + }; + + public static Option parse(Element root) { + Option uri = childText(root, "url").bind(Util.parseUri); + Option typeO = JenkinsJobType.fromElement(root.getName()); + + if (uri.isNone() || typeO.isNone()) { + return none(); + } + + return some(new JenkinsJobXml(typeO.some(), childText(root, "description"), childText(root, "displayName"), childText(root, "name"), - childText(root, "url").bind(Util.parseUri).orSome(url), + uri.some(), childText(root, "color"), childText(root, "buildable").bind(Util.parseBoolean).orSome(false), child(root, "lastBuild").bind(BuildXml.buildXml), child(root, "lastCompletedBuild").bind(BuildXml.buildXml), child(root, "lastFailedBuild").bind(BuildXml.buildXml), child(root, "lastSuccessfulBuild").bind(BuildXml.buildXml), - child(root, "lastUnsuccessfulBuild").bind(BuildXml.buildXml)); + child(root, "lastUnsuccessfulBuild").bind(BuildXml.buildXml))); } } 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 7548a32..f006261 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java @@ -107,7 +107,7 @@ public class CoreResource extends AbstractResource { List list = new ArrayList<>(); for (BuildDto build : buildDtos) { - list.add(getBuildJson(daos, build)); + list.add(getBuildJson(build)); } return list; } @@ -138,23 +138,23 @@ public class CoreResource extends AbstractResource { return Option.none(); } - return Option.some(getBuildJson(daos, o.get())); + return Option.some(getBuildJson(o.get())); } }); } - private BuildJson getBuildJson(Daos daos, BuildDto build) { - return new BuildJson(build.uuid, build.createdDate, build.success); + private BuildJson getBuildJson(BuildDto build) { + return new BuildJson(build.uuid, build.timestamp, build.success); } public static class BuildJson { public final UUID uuid; - public final DateTime date; + public final DateTime timestamp; public final boolean success; - public BuildJson(UUID uuid, DateTime date, boolean success) { + public BuildJson(UUID uuid, DateTime timestamp, boolean success) { this.uuid = uuid; - this.date = date; + this.timestamp = timestamp; this.success = success; } } diff --git a/src/main/resources/queries.sql b/src/main/resources/queries.sql new file mode 100755 index 0000000..66bdb38 --- /dev/null +++ b/src/main/resources/queries.sql @@ -0,0 +1,2 @@ +-- All unclaimed jenkins users +select absolute_url from jenkins_user where uuid not in (select jenkins_user from person_jenkins_user); diff --git a/src/main/webapp/apps/buildApp/build.html b/src/main/webapp/apps/buildApp/build.html old mode 100644 new mode 100755 index b2d4bd9..2feee28 --- a/src/main/webapp/apps/buildApp/build.html +++ b/src/main/webapp/apps/buildApp/build.html @@ -9,7 +9,7 @@ - + diff --git a/src/main/webapp/apps/jenkinsApp/job.html b/src/main/webapp/apps/jenkinsApp/job.html old mode 100644 new mode 100755 index 5113d2e..6ee7af0 --- a/src/main/webapp/apps/jenkinsApp/job.html +++ b/src/main/webapp/apps/jenkinsApp/job.html @@ -36,7 +36,7 @@ - + diff --git a/src/main/webapp/apps/personApp/person.html b/src/main/webapp/apps/personApp/person.html old mode 100644 new mode 100755 index 83aea0a..056545f --- a/src/main/webapp/apps/personApp/person.html +++ b/src/main/webapp/apps/personApp/person.html @@ -33,7 +33,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -72,5 +72,4 @@
Date{{build.date | date:'medium'}}{{build.timestamp | date:'medium'}}
Status
{{build.createdDate | date:'medium'}}{{build.timestamp | date:'medium'}} {{build.result}}
{{build.date | date:'medium'}}{{build.timestamp | date:'medium'}} {{build.success}} Details
{{build.date | date:'medium'}}{{build.timestamp | date:'medium'}} {{build.success}}
- -- cgit v1.2.3