aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-20 23:18:24 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-20 23:18:24 +0100
commitd25d523d2a7f7e4c3446d81740e09e487ad807d0 (patch)
tree228ecb562647445a08a441e24d74fc02c27e7503 /src
parent0cbc9933db10938a1e9c7f330188e40caec9550d (diff)
downloadesper-testing-d25d523d2a7f7e4c3446d81740e09e487ad807d0.tar.gz
esper-testing-d25d523d2a7f7e4c3446d81740e09e487ad807d0.tar.bz2
esper-testing-d25d523d2a7f7e4c3446d81740e09e487ad807d0.tar.xz
esper-testing-d25d523d2a7f7e4c3446d81740e09e487ad807d0.zip
o Storing the users that had a commit in the build as a part of the build.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java4
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java26
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java34
-rw-r--r--src/main/resources/ddl-jenkins.sql1
4 files changed, 52 insertions, 13 deletions
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 8076eaa..04c21c0 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java
@@ -14,8 +14,9 @@ public class JenkinsBuildDto extends AbstractDto {
public final int number;
public final int duration;
public final DateTime timestamp;
+ public final UUID[] users;
- JenkinsBuildDto(UUID uuid, DateTime createdDate, UUID job, String entryId, URI url, String result, int number, int duration, DateTime timestamp) {
+ public JenkinsBuildDto(UUID uuid, DateTime createdDate, UUID job, String entryId, URI url, String result, int number, int duration, DateTime timestamp, UUID[] users) {
super(uuid, createdDate);
this.job = job;
this.entryId = entryId;
@@ -24,5 +25,6 @@ public class JenkinsBuildDto extends AbstractDto {
this.number = number;
this.duration = duration;
this.timestamp = timestamp;
+ this.users = users;
}
}
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 2cfff80..2cd71c0 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
@@ -6,6 +6,7 @@ import org.joda.time.*;
import java.net.*;
import java.sql.*;
+import java.sql.Array;
import java.util.*;
import java.util.List;
@@ -21,7 +22,7 @@ public class JenkinsDao {
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";
+ public static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp, users";
public static final String JENKINS_USER = "uuid, created_date, server, absolute_url";
@@ -76,7 +77,8 @@ public class JenkinsDao {
rs.getString(i++),
rs.getInt(i++),
rs.getInt(i++),
- new DateTime(rs.getTimestamp(i).getTime()));
+ new DateTime(rs.getTimestamp(i++).getTime()),
+ toUuidArray(rs, i));
}
};
@@ -91,6 +93,19 @@ public class JenkinsDao {
}
};
+ private static UUID[] toUuidArray(ResultSet rs, int index) throws SQLException {
+ Array array = rs.getArray(index);
+ if(array == null) {
+ return new UUID[0];
+ }
+ String[] strings = (String[]) array.getArray();
+ UUID[] uuids = new UUID[strings.length];
+ for (int i = 0; i < strings.length; i++) {
+ uuids[i] = UUID.fromString(strings[i]);
+ }
+ return uuids;
+ }
+
public List<JenkinsServerDto> selectServers(boolean enabledOnly) throws SQLException {
String sql = "SELECT " + JENKINS_SERVER + " FROM jenkins_server";
@@ -162,8 +177,8 @@ public class JenkinsDao {
}
}
- public UUID insertBuild(UUID server, String entryId, URI url, String result, int number, int duration, long timestamp) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_build(" + JENKINS_BUILD + ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
+ 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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
UUID uuid = UUID.randomUUID();
int i = 1;
s.setString(i++, uuid.toString());
@@ -174,7 +189,8 @@ public class JenkinsDao {
s.setString(i++, result);
s.setInt(i++, number);
s.setInt(i++, duration);
- s.setTimestamp(i, new Timestamp(timestamp));
+ s.setTimestamp(i++, new Timestamp(timestamp));
+ s.setArray(i, c.createArrayOf("varchar", users));
s.executeUpdate();
return uuid;
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 ad22157..9f2969a 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
@@ -7,6 +7,8 @@ import org.slf4j.*;
import java.net.*;
import java.sql.*;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.*;
import java.util.Set;
@@ -40,7 +42,7 @@ public class JenkinsServerActor implements TransactionalActor {
int i = 0;
- Set<String> authorUrls = new TreeSet<>();
+ Map<String, UUID> authors = new HashMap<>();
for (JenkinsEntryXml entry : list) {
SqlOption<JenkinsBuildDto> o = dao.selectBuildByEntryId(entry.id);
@@ -66,6 +68,12 @@ public class JenkinsServerActor implements TransactionalActor {
}
String result = build.result.some();
+ // -----------------------------------------------------------------------
+ // Users
+ // -----------------------------------------------------------------------
+
+ Set<UUID> users = new HashSet<>();
+
if(build.changeSet.isSome()) {
JenkinsBuildXml.ChangeSetXml changeSetXml = build.changeSet.some();
@@ -76,15 +84,26 @@ public class JenkinsServerActor implements TransactionalActor {
String url = item.author.some().absoluteUrl;
- boolean newUser = authorUrls.add(url);
+ UUID uuid = authors.get(url);
- if(newUser && dao.selectUser(server.uuid, url).isNone()) {
- logger.info("New user: {}", url);
- dao.insertUser(server.uuid, url);
+ if(uuid == null) {
+ SqlOption<JenkinsUserDto> userO = dao.selectUser(server.uuid, url);
+ if (userO.isNone()) {
+ logger.info("New user: {}", url);
+ uuid = dao.insertUser(server.uuid, url);
+ } else {
+ uuid = userO.get().uuid;
+ }
}
+
+ users.add(uuid);
}
}
+ // -----------------------------------------------------------------------
+ // Job
+ // -----------------------------------------------------------------------
+
URI jobUrl = extrapolateJobUrlFromBuildUrl(build.url.toASCIIString());
Option<JenkinsJobDto> jobDtoOption = dao.selectJobByUrl(jobUrl);
@@ -118,9 +137,10 @@ public class JenkinsServerActor implements TransactionalActor {
result,
build.number,
build.duration,
- build.timestamp);
+ build.timestamp,
+ users.toArray(new UUID[users.size()]));
- logger.info("Build inserted: " + uuid + ", item #" + i + "/" + list.size());
+ logger.info("Build inserted: {}, #users={} item #{}/{}", uuid, users.size(), i, list.size());
}
long end = currentTimeMillis();
diff --git a/src/main/resources/ddl-jenkins.sql b/src/main/resources/ddl-jenkins.sql
index 65b3e35..45de998 100644
--- a/src/main/resources/ddl-jenkins.sql
+++ b/src/main/resources/ddl-jenkins.sql
@@ -40,6 +40,7 @@ CREATE TABLE jenkins_build (
number INT NOT NULL,
duration INT NOT NULL,
timestamp TIMESTAMP NOT NULL,
+ users CHAR(36) [],
CONSTRAINT pk_jenkins_build PRIMARY KEY (UUID),
CONSTRAINT fk_jenkins_build__job FOREIGN KEY (job) REFERENCES jenkins_job (uuid),