From 34f5ac99c81dfe39f986e8133fb7fff22c0d30bc Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 10 Dec 2012 14:27:04 +0100 Subject: o Adding Maven module as a build type. --- .../esper/testing/jenkins/JenkinsClient.java | 7 +- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 7 +- .../esper/testing/jenkins/JenkinsImporter.java | 6 +- .../esper/testing/jenkins/JenkinsServer.java | 130 --------------------- .../esper/testing/jenkins/JenkinsServerActor.java | 115 ++++++++++++++++++ src/main/resources/ddl-jenkins.sql | 1 + .../testing/jenkins/JenkinsServerActorTest.java | 17 +++ .../esper/testing/jenkins/JenkinsServerTest.java | 17 --- 8 files changed, 144 insertions(+), 156 deletions(-) mode change 100644 => 100755 src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java delete mode 100644 src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java create mode 100755 src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java create mode 100755 src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java delete mode 100644 src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java (limited to 'src') 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 2b3ca13..0aa63c1 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java @@ -119,7 +119,9 @@ public class JenkinsClient { case "freeStyleProject": return some(JenkinsJobXml.parse(url, JenkinsJobType.FREE_STYLE, root)); case "mavenModuleSet": - return some(JenkinsJobXml.parse(url, JenkinsJobType.MAVEN, root)); + return some(JenkinsJobXml.parse(url, JenkinsJobType.MAVEN_MODULE_SET, root)); + case "mavenModule": + return some(JenkinsJobXml.parse(url, JenkinsJobType.MAVEN_MODULE, root)); case "matrixProject": return some(JenkinsJobXml.parse(url, JenkinsJobType.MATRIX, root)); default: @@ -241,7 +243,7 @@ class JenkinsJobEntryXml { class JenkinsJobXml { enum JenkinsJobType { - MAVEN, FREE_STYLE, MATRIX + FREE_STYLE, MAVEN_MODULE_SET, MAVEN_MODULE, MATRIX } public final JenkinsJobType type; @@ -313,4 +315,3 @@ class JenkinsJobXml { child(root, "lastUnsuccessfulBuild").bind(BuildXml.buildXml)); } } - diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java old mode 100644 new mode 100755 index 9f3c752..bd99768 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -20,7 +20,7 @@ public class JenkinsDao { private static final String JENKINS_SERVER = "uuid, created_date, url"; - private static final String JENKINS_JOB = "uuid, created_date, server, url, display_name"; + private static final String JENKINS_JOB = "uuid, created_date, server, url, job_type, display_name"; private static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp"; @@ -88,14 +88,15 @@ public class JenkinsDao { } } - public UUID insertJob(UUID server, URI url, Option displayName) throws SQLException { - try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_job(" + JENKINS_JOB + ") VALUES(?, ?, ?, ?, ?)")) { + public UUID insertJob(UUID server, 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(); int i = 1; s.setString(i++, uuid.toString()); s.setTimestamp(i++, new Timestamp(currentTimeMillis())); s.setString(i++, server.toString()); s.setString(i++, url.toASCIIString()); + s.setString(i++, type.name()); s.setString(i, displayName.toNull()); s.executeUpdate(); diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java index 713982f..680e593 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java @@ -26,10 +26,10 @@ public class JenkinsImporter { HashSet servers = new HashSet<>(); - ObjectManager> serverManager = new ObjectManager<>("JenkinsServerOld", servers, new ObjectFactory>() { - public ActorRef create(JenkinsServerDto server) { + ObjectManager> serverManager = new ObjectManager<>("JenkinsServerOld", servers, new ObjectFactory>() { + public ActorRef create(JenkinsServerDto server) { String name = "Jenkins: " + server.url; - return threadedActor(name, config.jenkinsUpdateInterval, boneCp, name, new JenkinsServer(jenkinsClient, server)); + return threadedActor(name, config.jenkinsUpdateInterval, boneCp, name, new JenkinsServerActor(jenkinsClient, server)); } }); diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java deleted file mode 100644 index 089c7d0..0000000 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java +++ /dev/null @@ -1,130 +0,0 @@ -package io.trygvis.esper.testing.jenkins; - -import fj.data.*; -import io.trygvis.esper.testing.object.*; -import org.slf4j.*; - -import java.net.*; -import java.sql.*; -import java.util.List; -import java.util.*; - -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); - private final JenkinsClient client; - public final JenkinsServerDto server; - - public JenkinsServer(JenkinsClient client, JenkinsServerDto server) { - this.client = client; - this.server = server; - } - - public void act(Connection c) throws Exception { - long start = currentTimeMillis(); - - JenkinsDao dao = new JenkinsDao(c); - Option> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssAll")); - - if (option.isNone()) { - return; - } - - List list = option.some(); - - logger.info("Got " + list.size() + " entries."); - - int i = 0; - - for (JenkinsEntryXml entry : list) { - Option o = dao.selectBuildByEntryId(entry.id); - - if (o.isSome()) { - logger.debug("Old event: " + entry.id); - continue; - } - - logger.info("New build: " + entry.id + ", fetching info"); - - Option buildXmlOption = client.fetchBuild(apiXml(entry.url)); - - if (buildXmlOption.isNone()) { - continue; - } - - JenkinsBuildXml build = buildXmlOption.some(); - - URI jobUrl = createJobUrl(build.url.toASCIIString()); - - Option jobDtoOption = dao.selectJobByUrl(jobUrl); - - UUID job; - - if (jobDtoOption.isSome()) { - job = jobDtoOption.some().uuid; - } else { - logger.info("New job: " + jobUrl + ", fetching info"); - - Option 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, - entry.id, - build.url, - build.result, - build.number, - build.duration, - build.timestamp); - - logger.info("Build inserted: " + uuid + ", i=" + i); - } - - long end = currentTimeMillis(); - - logger.info("Inserted " + i + " new builds in " + (end - start) + "ms."); - } - - /** - * This sucks, a build should really include the URL to the job. - */ - public static URI createJobUrl(String 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.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); - } - int i = u.lastIndexOf("/"); - u = u.substring(0, i); - - return URI.create(u + "/"); - } -} diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java new file mode 100755 index 0000000..fa30f14 --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -0,0 +1,115 @@ +package io.trygvis.esper.testing.jenkins; + +import fj.data.*; +import io.trygvis.esper.testing.object.*; +import org.slf4j.*; + +import java.net.*; +import java.sql.*; +import java.util.List; +import java.util.*; + +import static io.trygvis.esper.testing.jenkins.JenkinsClient.*; +import static java.lang.System.*; + +public class JenkinsServerActor implements TransactionalActor { + private static final Logger logger = LoggerFactory.getLogger(JenkinsServerActor.class); + private final JenkinsClient client; + public final JenkinsServerDto server; + + public JenkinsServerActor(JenkinsClient client, JenkinsServerDto server) { + this.client = client; + this.server = server; + } + + public void act(Connection c) throws Exception { + long start = currentTimeMillis(); + + JenkinsDao dao = new JenkinsDao(c); + Option> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssAll")); + + if (option.isNone()) { + return; + } + + List list = option.some(); + + logger.info("Got " + list.size() + " entries."); + + int i = 0; + + for (JenkinsEntryXml entry : list) { + Option o = dao.selectBuildByEntryId(entry.id); + + if (o.isSome()) { + logger.debug("Old build: " + entry.id); + continue; + } + + logger.info("New build: " + entry.id + ", fetching info"); + + Option buildXmlOption = client.fetchBuild(apiXml(entry.url)); + + if (buildXmlOption.isNone()) { + continue; + } + + JenkinsBuildXml build = buildXmlOption.some(); + + URI jobUrl = createJobUrl(build.url.toASCIIString()); + + Option jobDtoOption = dao.selectJobByUrl(jobUrl); + + UUID job; + + if (jobDtoOption.isSome()) { + job = jobDtoOption.some().uuid; + } else { + logger.info("New job: " + jobUrl + ", fetching info"); + + Option jobXmlOption = client.fetchJob(apiXml(jobUrl)); + + if (jobXmlOption.isNone()) { + continue; + } + + JenkinsJobXml xml = jobXmlOption.some(); + + job = dao.insertJob(server.uuid, xml.url, xml.type, xml.displayName); + + logger.info("New job: " + xml.displayName.orSome(xml.url.toASCIIString()) + ", uuid=" + job); + } + + i++; + + UUID uuid = dao.insertBuild( + job, + entry.id, + build.url, + build.result, + build.number, + build.duration, + build.timestamp); + + logger.info("Build inserted: " + uuid + ", item #" + i + "/" + list.size()); + } + + long end = currentTimeMillis(); + + logger.info("Inserted " + i + " of " + list.size() + " builds in " + (end - start) + "ms."); + } + + /** + * This sucks, a build should really include the URL to the job. + */ + public static URI createJobUrl(String u) { + if (!u.matches(".*/[0-9]*/")) { + throw new RuntimeException("Not a valid build url: " + u); + } + + u = u.substring(0, u.lastIndexOf("/")); + u = u.substring(0, u.lastIndexOf("/") + 1); + + return URI.create(u); + } +} diff --git a/src/main/resources/ddl-jenkins.sql b/src/main/resources/ddl-jenkins.sql index 70db7f9..01275eb 100755 --- a/src/main/resources/ddl-jenkins.sql +++ b/src/main/resources/ddl-jenkins.sql @@ -20,6 +20,7 @@ CREATE TABLE jenkins_job ( server CHAR(36) NOT NULL, url VARCHAR(1000) NOT NULL, + job_type VARCHAR(100) NOT NULL, display_name VARCHAR(100), CONSTRAINT pk_jenkins_job PRIMARY KEY (UUID), diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java new file mode 100755 index 0000000..9a673e9 --- /dev/null +++ b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java @@ -0,0 +1,17 @@ +package io.trygvis.esper.testing.jenkins; + +import junit.framework.*; + +import static io.trygvis.esper.testing.jenkins.JenkinsServerActor.*; + +public class JenkinsServerActorTest extends TestCase { + public void testUrlGeneration() { +// assertEquals("https://jenkins.puppetlabs.com/job/Hiera%20%28master%29/74/api/xml", createJobUrl("https://jenkins.puppetlabs.com/job/Hiera%20%28master%29/facter=1.6.x,puppet=2.7.x,ruby=ruby-1.8.7,rvm=%23rvm/74/api/xml").toASCIIString()); + + assertEquals("https://builds.apache.org/job/james-server-trunk/org.apache.james$james-server-dnsservice-library/", 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/component=activeresource,label=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()); + } +} diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java deleted file mode 100644 index d0630b8..0000000 --- a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.trygvis.esper.testing.jenkins; - -import junit.framework.*; - -import static io.trygvis.esper.testing.jenkins.JenkinsServer.*; - -public class JenkinsServerTest extends TestCase { - public void testUrlGeneration() { -// assertEquals("https://jenkins.puppetlabs.com/job/Hiera%20%28master%29/74/api/xml", createJobUrl("https://jenkins.puppetlabs.com/job/Hiera%20%28master%29/facter=1.6.x,puppet=2.7.x,ruby=ruby-1.8.7,rvm=%23rvm/74/api/xml").toASCIIString()); - - 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()); - } -} -- cgit v1.2.3