diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-08 21:52:51 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-08 21:52:51 +0100 |
commit | 906019004f1cd50cdfe4f72c7aff234ea3577b8e (patch) | |
tree | 1afda282d47c5f8a0b0e0493ebefb6ae78b65535 | |
parent | 953ddf830be3ec5188762c2471d007478e6573a1 (diff) | |
download | esper-testing-906019004f1cd50cdfe4f72c7aff234ea3577b8e.tar.gz esper-testing-906019004f1cd50cdfe4f72c7aff234ea3577b8e.tar.bz2 esper-testing-906019004f1cd50cdfe4f72c7aff234ea3577b8e.tar.xz esper-testing-906019004f1cd50cdfe4f72c7aff234ea3577b8e.zip |
o Supporting Maven builds in jenkins.
6 files changed, 83 insertions, 44 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java index bd7c82b..0b2883f 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java @@ -22,6 +22,7 @@ import java.util.List; import static fj.data.Option.*; import static io.trygvis.esper.testing.Util.*; import static io.trygvis.esper.testing.util.HttpClient.inputStreamOnly; +import static java.lang.System.currentTimeMillis; import static org.apache.commons.lang.StringUtils.*; public class JenkinsClient { @@ -36,7 +37,10 @@ public class JenkinsClient { jenkinsEntryXmlClient = new HttpClient<>(http, inputStreamOnly(new F<InputStream, Option<List<JenkinsEntryXml>>>() { public Option<List<JenkinsEntryXml>> f(InputStream inputStream) { + long start = currentTimeMillis(); Feed feed = (Feed) parser.parse(inputStream).getRoot(); + long end = currentTimeMillis(); + logger.info("Parsed document in " + (end - start) + "ms."); List<JenkinsEntryXml> list = new ArrayList<>(); @@ -47,6 +51,10 @@ public class JenkinsClient { } } + long end2 = currentTimeMillis(); + + logger.info("Converted document to JenkinsEntryXml in " + (end2 - end) + "ms."); + return some(list); } })); @@ -133,8 +141,8 @@ public class JenkinsClient { switch (name) { case "matrixBuild": - case "matrixRun": case "mavenModuleSetBuild": + case "mavenBuild": case "freeStyleBuild": return JenkinsBuildXml.parse(root); default: @@ -166,8 +174,24 @@ public class JenkinsClient { Option<Integer> duration = childText(root, "duration").bind(Util.parseInt); Option<Long> timestamp = childText(root, "timestamp").bind(Util.parseLong); - if(url.isNone() || number.isNone() || result.isNone() || duration.isNone() || timestamp.isNone()) { - logger.warn("Missing required fields."); + if(url.isNone()) { + logger.warn("Missing required field: <url>"); + return none(); + } + if(number.isNone()) { + logger.warn("Missing required field: <number>"); + return none(); + } + if(result.isNone()) { + logger.warn("Missing required field: <result>"); + return none(); + } + if(duration.isNone()) { + logger.warn("Missing required field: <duration>"); + return none(); + } + if(timestamp.isNone()) { + logger.warn("Missing required field: <timestamp>"); return none(); } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java index a913b63..1d11aa8 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java @@ -9,8 +9,8 @@ import java.sql.*; import java.util.List; import java.util.*; -import static fj.data.Option.*; import static io.trygvis.esper.testing.jenkins.JenkinsClient.*; +import static java.lang.System.*; public class JenkinsServer implements TransactionalActor { private static final Logger logger = LoggerFactory.getLogger(JenkinsServer.class); @@ -23,8 +23,10 @@ public class JenkinsServer implements TransactionalActor { } public void act(Connection c) throws Exception { + long start = currentTimeMillis(); + JenkinsDao dao = new JenkinsDao(c); - Option<List<JenkinsEntryXml>> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssAll")); + Option<List<JenkinsEntryXml>> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssLatest")); if (option.isNone()) { return; @@ -46,24 +48,42 @@ public class JenkinsServer implements TransactionalActor { logger.info("New build: " + entry.id + ", fetching info"); - i++; - - Option<JenkinsBuildXml> o2 = client.fetchBuild(apiXml(entry.url)); + Option<JenkinsBuildXml> buildXmlOption = client.fetchBuild(apiXml(entry.url)); - if (o2.isNone()) { + if (buildXmlOption.isNone()) { continue; } - JenkinsBuildXml build = o2.some(); + JenkinsBuildXml build = buildXmlOption.some(); - Option<UUID> job = findJob(dao, server, build); + URI jobUrl = createJobUrl(build.url.toASCIIString()); - if (job.isNone()) { - continue; + Option<JenkinsJobDto> jobDtoOption = dao.selectJobByUrl(jobUrl); + + UUID job; + + if (jobDtoOption.isSome()) { + job = jobDtoOption.some().uuid; + } else { + logger.info("New job: " + jobUrl + ", fetching info"); + + Option<JenkinsJobXml> jobXmlOption = client.fetchJob(apiXml(jobUrl)); + + if (jobXmlOption.isNone()) { + continue; + } + + JenkinsJobXml xml = jobXmlOption.some(); + + job = dao.insertJob(server.uuid, xml.url, xml.displayName); + + logger.info("New job: " + xml.displayName.orSome(xml.url.toASCIIString()) + ", uuid=" + job); } + i++; + UUID uuid = dao.insertBuild( - job.some(), + job, entry.id, build.url, build.result, @@ -74,33 +94,9 @@ public class JenkinsServer implements TransactionalActor { logger.info("Build inserted: " + uuid + ", i=" + i); } - logger.info("Inserted " + i + " new events."); - } - - private Option<UUID> findJob(JenkinsDao dao, JenkinsServerDto server, JenkinsBuildXml build) throws SQLException { - URI jobUrl = createJobUrl(build.url.toASCIIString()); - - Option<JenkinsJobDto> o2 = dao.selectJobByUrl(jobUrl); - - if (o2.isSome()) { - return some(o2.some().uuid); - } - - logger.info("New job: " + jobUrl + ", fetching info"); - - Option<JenkinsJobXml> o = client.fetchJob(apiXml(jobUrl)); - - if (o.isNone()) { - return none(); - } - - JenkinsJobXml xml = o.some(); - - UUID uuid = dao.insertJob(server.uuid, xml.url, xml.displayName); + long end = currentTimeMillis(); - logger.info("New job: " + xml.displayName.orSome(xml.url.toASCIIString()) + ", uuid=" + uuid); - - return some(uuid); + logger.info("Inserted " + i + " new builds in " + (end - start) + "ms."); } /** @@ -115,6 +111,14 @@ public class JenkinsServer implements TransactionalActor { return URI.create(u); } + if (u.matches(".*/[.-_a-zA-Z]*\\$.*/[0-9]*/")) { + u = u.substring(0, u.lastIndexOf("/")); + u = u.substring(0, u.lastIndexOf("/")); + u = u.substring(0, u.lastIndexOf("/") + 1); + + return URI.create(u); + } + if (u.endsWith("/")) { u = u.substring(0, u.length() - 1); } diff --git a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java index 5ac7d13..a194cd1 100755 --- a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java +++ b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java @@ -16,7 +16,7 @@ import org.slf4j.*; import java.io.*; import java.net.*; -import static fj.data.Option.none; +import static fj.data.Option.*; import static java.lang.System.*; public class HttpClient<A> { diff --git a/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java b/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java index 7e5e298..8018428 100755 --- a/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java +++ b/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java @@ -4,17 +4,26 @@ import fj.*; import fj.data.*; import org.codehaus.httpcache4j.cache.*; import org.jdom2.*; +import org.slf4j.*; import java.io.*; +import static java.lang.System.currentTimeMillis; + public class XmlHttpClient extends HttpClient<Document> { + private static final Logger logger = LoggerFactory.getLogger(HttpClient.class); + public XmlHttpClient(HTTPCache http) { super(http, HttpClient.inputStreamOnly(new F<InputStream, Option<Document>>() { final XmlParser parser = new XmlParser(); public Option<Document> f(InputStream inputStream) { - return parser.parseDocument(inputStream); + long start = currentTimeMillis(); + Option<Document> documents = parser.parseDocument(inputStream); + long end = currentTimeMillis(); + logger.info("Parsed document in " + (end - start) + "ms."); + return documents; } })); } diff --git a/src/main/resources/logback-test.xml b/src/main/resources/logback-test.xml index a865432..1a63a5f 100755 --- a/src/main/resources/logback-test.xml +++ b/src/main/resources/logback-test.xml @@ -6,13 +6,13 @@ </encoder> </appender> - <logger name="org.apache.http.headers" level="DEBUG"/> + <logger name="org.apache.http.headers" level="INFO"/> <logger name="org.apache.http.wire" level="INFO"/> <logger name="org.apache.http" level="INFO"/> <!-- Gitorious spews out a few invalid cookies --> <logger name="org.apache.http.client.protocol.ResponseProcessCookies" level="ERROR"/> - <logger name="io.trygvis.esper.testing.util.HttpClient" level="DEBUG"/> + <logger name="io.trygvis.esper.testing.util.HttpClient" level="INFO"/> <root level="INFO"> <appender-ref ref="STDOUT"/> diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java index 8b6f191..cf3a84a 100644 --- a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java +++ b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java @@ -6,6 +6,8 @@ import static io.trygvis.esper.testing.jenkins.JenkinsServer.*; public class JenkinsServerTest extends TestCase { public void testUrlGeneration() { + assertEquals("https://builds.apache.org/job/james-server-trunk/", createJobUrl("https://builds.apache.org/job/james-server-trunk/org.apache.james$james-server-dnsservice-library/3417/").toASCIIString()); + assertEquals("http://ci.jruby.org/job/rails-master/", createJobUrl("http://ci.jruby.org/job/rails-master/component=activeresource,label=master/3577/").toASCIIString()); assertEquals("http://ci.jruby.org/job/rails-master/", createJobUrl("http://ci.jruby.org/job/rails-master/3577/").toASCIIString()); |