From e16e32c653cda7e47a6b9dc8515f187658549921 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 10 Dec 2012 15:16:36 +0100 Subject: o Adding some utilities. --- .../jenkins/CreateMissingMavenModuleJobsApp.java | 73 ++++++++++++++++++++++ .../testing/jenkins/JenkinsServerActorTest.java | 12 ++-- .../esper/testing/jenkins/SetJobTypeApp.java | 62 ++++++++++++++++++ 3 files changed, 143 insertions(+), 4 deletions(-) create mode 100755 src/test/java/io/trygvis/esper/testing/jenkins/CreateMissingMavenModuleJobsApp.java create mode 100755 src/test/java/io/trygvis/esper/testing/jenkins/SetJobTypeApp.java (limited to 'src/test') 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 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 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 jobs = dao.toJobList(rs); + + System.out.println("jobs.size() = " + jobs.size()); + + for (JenkinsJobDto jobDto : jobs) { + System.out.println("job = " + jobDto.url); + + Option 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(); + } + } +} -- cgit v1.2.3