diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-23 12:00:04 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-23 12:00:04 +0100 |
commit | afbfd905b8f5326d149ba7fdfd784af50d85e5ee (patch) | |
tree | 7ebdb883ce69d697af278780bdf67362ce164c2d /src/main | |
parent | a057cf0cb5b855d1fedd58d702bd06bb22e938f5 (diff) | |
download | esper-testing-afbfd905b8f5326d149ba7fdfd784af50d85e5ee.tar.gz esper-testing-afbfd905b8f5326d149ba7fdfd784af50d85e5ee.tar.bz2 esper-testing-afbfd905b8f5326d149ba7fdfd784af50d85e5ee.tar.xz esper-testing-afbfd905b8f5326d149ba7fdfd784af50d85e5ee.zip |
o Storing the file file reference on the jenkins build and job.
Diffstat (limited to 'src/main')
5 files changed, 24 insertions, 13 deletions
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 0878f63..c418970 100644 --- a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java @@ -14,7 +14,7 @@ public class FileDao { this.c = c; } - public void store(URI url, String contentType, byte[] data) throws SQLException { + public UUID store(URI url, String contentType, byte[] data) throws SQLException { try (PreparedStatement s = c.prepareStatement("INSERT INTO file(uuid, created_date, url, content_type, data) VALUES(?, ?, ?, ?, ?)")) { UUID uuid = UUID.randomUUID(); int i = 1; @@ -24,6 +24,7 @@ public class FileDao { s.setString(i++, contentType); s.setBinaryStream(i, new ByteArrayInputStream(data), data.length); s.executeUpdate(); + return uuid; } } } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java index 41d90ae..5c7249f 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java @@ -8,6 +8,7 @@ import java.util.*; public class JenkinsBuildDto extends AbstractEntity { public final UUID job; + public final UUID file; public final String entryId; public final URI url; public final String result; @@ -16,9 +17,10 @@ public class JenkinsBuildDto extends AbstractEntity { public final DateTime timestamp; public final UUID[] users; - public JenkinsBuildDto(UUID uuid, DateTime createdDate, UUID job, String entryId, URI url, String result, int number, int duration, DateTime timestamp, UUID[] users) { + public JenkinsBuildDto(UUID uuid, DateTime createdDate, UUID job, UUID file, String entryId, URI url, String result, int number, int duration, DateTime timestamp, UUID[] users) { super(uuid, createdDate); this.job = job; + this.file = file; this.entryId = entryId; this.url = url; this.result = result; 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 a31c6a0..8d32dbe 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -20,9 +20,7 @@ public class JenkinsDao { public static final String JENKINS_SERVER = "uuid, created_date, url, enabled"; - public static final String JENKINS_JOB = "uuid, created_date, server, url, job_type, display_name"; - - public static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp, users"; + public static final String JENKINS_JOB = "uuid, created_date, server, file, url, job_type, display_name"; public static final String JENKINS_USER = "uuid, created_date, server, absolute_url"; @@ -67,6 +65,8 @@ public class JenkinsDao { return list; } + public static final String JENKINS_BUILD = "uuid, created_date, job, file, entry_id, url, result, number, duration, timestamp, users"; + public static final SqlF<ResultSet, JenkinsBuildDto> jenkinsBuild = new SqlF<ResultSet, JenkinsBuildDto>() { public JenkinsBuildDto apply(ResultSet rs) throws SQLException { int i = 1; @@ -74,6 +74,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++)), rs.getString(i++), URI.create(rs.getString(i++)), rs.getString(i++), @@ -143,13 +144,14 @@ public class JenkinsDao { } } - public UUID insertJob(UUID server, URI url, JenkinsJobXml.JenkinsJobType type, Option<String> displayName) throws SQLException { - try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_job(" + JENKINS_JOB + ") VALUES(?, ?, ?, ?, ?, ?)")) { + public UUID insertJob(UUID server, UUID file, URI url, JenkinsJobXml.JenkinsJobType type, Option<String> 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++, file.toString()); s.setString(i++, url.toASCIIString()); s.setString(i++, type.name()); s.setString(i, displayName.toNull()); @@ -167,13 +169,14 @@ public class JenkinsDao { } } - public UUID insertBuild(UUID server, String entryId, URI url, String result, int number, int duration, long timestamp, UUID[] users) throws SQLException { - try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_build(" + JENKINS_BUILD + ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { + public UUID insertBuild(UUID job, UUID file, String entryId, URI url, String result, int number, int duration, long timestamp, UUID[] users) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_build(" + JENKINS_BUILD + ") 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++, job.toString()); + s.setString(i++, file.toString()); s.setString(i++, entryId); s.setString(i++, url.toASCIIString()); s.setString(i++, result); 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 32728a6..c34f422 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -76,7 +76,7 @@ public class JenkinsServerActor implements TransactionalActor { continue; } - fileDao.store(buildUrl, "application/xml", buildXmlOption.some()._2()); + UUID buildXmlFile = fileDao.store(buildUrl, "application/xml", buildXmlOption.some()._2()); String result = build.result.some(); @@ -137,11 +137,11 @@ public class JenkinsServerActor implements TransactionalActor { continue; } - fileDao.store(uri, "application/xml", jobXmlOption.some()._2()); + UUID jobXmlFile = fileDao.store(uri, "application/xml", jobXmlOption.some()._2()); JenkinsJobXml xml = jobXmlOption.some()._1(); - job = dao.insertJob(server.uuid, xml.url, xml.type, xml.displayName); + job = dao.insertJob(server.uuid, jobXmlFile, xml.url, xml.type, xml.displayName); logger.info("New job: {}, uuid={}", xml.displayName.orSome(xml.url.toASCIIString()), job); } @@ -150,6 +150,7 @@ public class JenkinsServerActor implements TransactionalActor { UUID uuid = dao.insertBuild( job, + buildXmlFile, entry.id, build.url, result, diff --git a/src/main/resources/ddl-jenkins.sql b/src/main/resources/ddl-jenkins.sql index 2a57ad6..c75f836 100644 --- a/src/main/resources/ddl-jenkins.sql +++ b/src/main/resources/ddl-jenkins.sql @@ -21,12 +21,14 @@ CREATE TABLE jenkins_job ( server CHAR(36) NOT NULL, + file 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), CONSTRAINT fk_jenkins_job__server FOREIGN KEY (server) REFERENCES jenkins_server (uuid), + CONSTRAINT fk_jenkins_job__file FOREIGN KEY (file) REFERENCES file (uuid), CONSTRAINT uq_jenkins_job__url UNIQUE (url) ); @@ -39,6 +41,7 @@ CREATE TABLE jenkins_build ( job CHAR(36) NOT NULL, + file CHAR(36) NOT NULL, entry_id VARCHAR(1000) NOT NULL, url VARCHAR(1000) NOT NULL, result VARCHAR(100) NOT NULL, @@ -49,6 +52,7 @@ CREATE TABLE jenkins_build ( CONSTRAINT pk_jenkins_build PRIMARY KEY (UUID), CONSTRAINT fk_jenkins_build__job FOREIGN KEY (job) REFERENCES jenkins_job (uuid), + CONSTRAINT fk_jenkins_build__file FOREIGN KEY (file) REFERENCES file (uuid), CONSTRAINT uq_jenkins_build__id UNIQUE (entry_id), CONSTRAINT uq_jenkins_build__seq UNIQUE (seq) ); |