aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-10 15:16:36 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-10 15:16:36 +0100
commite16e32c653cda7e47a6b9dc8515f187658549921 (patch)
treebebfb7c15bbf7b5ab39dfdcd6627bf79d765b256
parent34f5ac99c81dfe39f986e8133fb7fff22c0d30bc (diff)
downloadesper-testing-e16e32c653cda7e47a6b9dc8515f187658549921.tar.gz
esper-testing-e16e32c653cda7e47a6b9dc8515f187658549921.tar.bz2
esper-testing-e16e32c653cda7e47a6b9dc8515f187658549921.tar.xz
esper-testing-e16e32c653cda7e47a6b9dc8515f187658549921.zip
o Adding some utilities.
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java30
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java17
-rwxr-xr-xsrc/test/java/io/trygvis/esper/testing/jenkins/CreateMissingMavenModuleJobsApp.java73
-rwxr-xr-xsrc/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java12
-rwxr-xr-xsrc/test/java/io/trygvis/esper/testing/jenkins/SetJobTypeApp.java62
5 files changed, 178 insertions, 16 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 bd99768..0195900 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
@@ -18,11 +18,11 @@ public class JenkinsDao {
private final Connection c;
- private static final String JENKINS_SERVER = "uuid, created_date, url";
+ public static final String JENKINS_SERVER = "uuid, created_date, url";
- private static final String JENKINS_JOB = "uuid, created_date, server, url, job_type, display_name";
+ public 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";
+ public static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp";
public JenkinsDao(Connection c) {
this.c = c;
@@ -36,6 +36,14 @@ public class JenkinsDao {
URI.create(rs.getString(i)));
}
+ public List<JenkinsServerDto> toServerList(ResultSet rs) throws SQLException {
+ List<JenkinsServerDto> list = new ArrayList<>();
+ while (rs.next()) {
+ list.add(jenkinsServer(rs));
+ }
+ return list;
+ }
+
private JenkinsJobDto jenkinsJob(ResultSet rs) throws SQLException {
int i = 1;
return new JenkinsJobDto(
@@ -46,6 +54,14 @@ public class JenkinsDao {
fromNull(rs.getString(i)));
}
+ public List<JenkinsJobDto> toJobList(ResultSet rs) throws SQLException {
+ List<JenkinsJobDto> list = new ArrayList<>();
+ while (rs.next()) {
+ list.add(jenkinsJob(rs));
+ }
+ return list;
+ }
+
private JenkinsBuildDto jenkinsBuild(ResultSet rs) throws SQLException {
int i = 1;
return new JenkinsBuildDto(
@@ -65,13 +81,7 @@ public class JenkinsDao {
where += enabledOnly ? "enabled=true" : "";
try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_SERVER + " FROM jenkins_server " + where)) {
- ResultSet rs = s.executeQuery();
-
- List<JenkinsServerDto> servers = new ArrayList<>();
- while (rs.next()) {
- servers.add(jenkinsServer(rs));
- }
- return servers;
+ return toServerList(s.executeQuery());
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
index fa30f14..4bbc007 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
@@ -56,7 +56,7 @@ public class JenkinsServerActor implements TransactionalActor {
JenkinsBuildXml build = buildXmlOption.some();
- URI jobUrl = createJobUrl(build.url.toASCIIString());
+ URI jobUrl = extrapolateJobUrlFromBuildUrl(build.url.toASCIIString());
Option<JenkinsJobDto> jobDtoOption = dao.selectJobByUrl(jobUrl);
@@ -102,7 +102,7 @@ public class JenkinsServerActor implements TransactionalActor {
/**
* This sucks, a build should really include the URL to the job.
*/
- public static URI createJobUrl(String u) {
+ public static URI extrapolateJobUrlFromBuildUrl(String u) {
if (!u.matches(".*/[0-9]*/")) {
throw new RuntimeException("Not a valid build url: " + u);
}
@@ -112,4 +112,17 @@ public class JenkinsServerActor implements TransactionalActor {
return URI.create(u);
}
+
+ public static String extrapolateMavenModuleFromMavenModuleSetUrl(String u) {
+ int i = u.lastIndexOf("/");
+ if (i == -1) {
+ throw new RuntimeException("Illegal URL");
+ }
+ u = u.substring(0, i);
+ i = u.lastIndexOf("/");
+ if (i == -1) {
+ throw new RuntimeException("Illegal URL");
+ }
+ return u.substring(0, i + 1);
+ }
}
diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/CreateMissingMavenModuleJobsApp.java b/src/test/java/io/trygvis/esper/testing/jenkins/CreateMissingMavenModuleJobsApp.java
new file mode 100755
index 0000000..9cc47ad
--- /dev/null
+++ b/src/test/java/io/trygvis/esper/testing/jenkins/CreateMissingMavenModuleJobsApp.java
@@ -0,0 +1,73 @@
+package io.trygvis.esper.testing.jenkins;
+
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.abdera.Abdera;
+import org.codehaus.httpcache4j.cache.HTTPCache;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+
+import fj.data.Option;
+import io.trygvis.esper.testing.Config;
+import io.trygvis.esper.testing.util.HttpClient;
+
+import static io.trygvis.esper.testing.jenkins.JenkinsClient.apiXml;
+
+public class CreateMissingMavenModuleJobsApp {
+ public static void main(String[] args) throws Exception {
+ final Config config = Config.loadFromDisk();
+ final BoneCPDataSource boneCp = config.createBoneCp();
+ HTTPCache httpCache = HttpClient.createHttpCache(config);
+ Abdera abdera = config.createAbdera();
+ final JenkinsClient client = new JenkinsClient(httpCache, abdera);
+
+ try (Connection c = boneCp.getConnection()) {
+
+// PreparedStatement s2 = c.prepareStatement("UPDATE jenkins_job SET job_type=? WHERE uuid=?");
+
+ PreparedStatement s = c.prepareStatement("SELECT " + JenkinsDao.JENKINS_JOB + " FROM jenkins_job WHERE job_type='MAVEN_MODULE'");
+ ResultSet rs = s.executeQuery();
+
+ JenkinsDao dao = new JenkinsDao(c);
+
+ List<JenkinsJobDto> jobs = dao.toJobList(rs);
+
+ System.out.println("jobs.size() = " + jobs.size());
+
+ for (JenkinsJobDto jobDto : jobs) {
+ System.out.println("job = " + jobDto.url);
+
+ String u = JenkinsServerActor.extrapolateMavenModuleFromMavenModuleSetUrl(jobDto.url.toASCIIString());
+
+ System.out.println("u = " + u);
+
+ URI url = URI.create(u);
+
+ Option<JenkinsJobXml> xmlOption = client.fetchJob(apiXml(url));
+
+ if(xmlOption.isNone()) {
+ System.out.println("None");
+ continue;
+ }
+
+ JenkinsJobXml jobXml = xmlOption.some();
+
+ if(dao.selectJobByUrl(jobXml.url).isSome()) {
+ System.out.println("Duplicate");
+ continue;
+ }
+
+ UUID uuid = dao.insertJob(jobDto.server, url, jobXml.type, jobXml.displayName);
+
+ System.out.println("New job: " + uuid);
+ }
+
+ c.commit();
+ }
+ }
+}
diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java
index 9a673e9..8b1eacc 100755
--- a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java
+++ b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerActorTest.java
@@ -6,12 +6,16 @@ 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://jenkins.puppetlabs.com/job/Hiera%20%28master%29/74/api/xml", extrapolateJobUrlFromBuildUrl("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("https://builds.apache.org/job/james-server-trunk/org.apache.james$james-server-dnsservice-library/", extrapolateJobUrlFromBuildUrl("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/component=activeresource,label=master/", extrapolateJobUrlFromBuildUrl("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());
+ assertEquals("http://ci.jruby.org/job/rails-master/", extrapolateJobUrlFromBuildUrl("http://ci.jruby.org/job/rails-master/3577/").toASCIIString());
+ }
+
+ public void test2() {
+ assertEquals("http://vm-pbuild-4:8080/job/admin-web/", extrapolateMavenModuleFromMavenModuleSetUrl("http://vm-pbuild-4:8080/job/admin-web/eu.nets.efaktura.adminweb$efaktura-admin-web-wsclient/"));
}
}
diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/SetJobTypeApp.java b/src/test/java/io/trygvis/esper/testing/jenkins/SetJobTypeApp.java
new file mode 100755
index 0000000..46060a9
--- /dev/null
+++ b/src/test/java/io/trygvis/esper/testing/jenkins/SetJobTypeApp.java
@@ -0,0 +1,62 @@
+package io.trygvis.esper.testing.jenkins;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.codehaus.httpcache4j.cache.HTTPCache;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+
+import fj.data.Option;
+import io.trygvis.esper.testing.Config;
+import io.trygvis.esper.testing.util.HttpClient;
+
+import static io.trygvis.esper.testing.jenkins.JenkinsClient.apiXml;
+
+public class SetJobTypeApp {
+ public static void main(String[] args) throws Exception {
+ final Config config = Config.loadFromDisk();
+ final BoneCPDataSource boneCp = config.createBoneCp();
+ HTTPCache httpCache = HttpClient.createHttpCache(config);
+ Abdera abdera = config.createAbdera();
+ final JenkinsClient jenkinsClient = new JenkinsClient(httpCache, abdera);
+
+ try (Connection c = boneCp.getConnection()) {
+
+ PreparedStatement s2 = c.prepareStatement("UPDATE jenkins_job SET job_type=? WHERE uuid=?");
+
+ PreparedStatement s = c.prepareStatement("SELECT " + JenkinsDao.JENKINS_JOB + " FROM jenkins_job WHERE job_type IS NULL");
+ ResultSet rs = s.executeQuery();
+
+ JenkinsDao dao = new JenkinsDao(c);
+
+ List<JenkinsJobDto> jobs = dao.toJobList(rs);
+
+ System.out.println("jobs.size() = " + jobs.size());
+
+ for (JenkinsJobDto jobDto : jobs) {
+ System.out.println("job = " + jobDto.url);
+
+ Option<JenkinsJobXml> xmlOption = jenkinsClient.fetchJob(apiXml(jobDto.url));
+
+ if(xmlOption.isNone()) {
+ System.out.println("None");
+ continue;
+ }
+
+ JenkinsJobXml jobXml = xmlOption.some();
+
+ System.out.println("jobXml.type = " + jobXml.type);
+
+ s2.setString(1, jobXml.type.name());
+ s2.setString(2, jobDto.uuid.toString());
+ s2.executeUpdate();
+ }
+
+ c.commit();
+ }
+ }
+}