aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/trygvis/esper')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/Config.java2
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java9
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java13
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java2
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java17
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/util/HttpClient.java12
6 files changed, 36 insertions, 19 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/Config.java b/src/main/java/io/trygvis/esper/testing/Config.java
index 95e5a99..4ff034a 100755
--- a/src/main/java/io/trygvis/esper/testing/Config.java
+++ b/src/main/java/io/trygvis/esper/testing/Config.java
@@ -1,5 +1,7 @@
package io.trygvis.esper.testing;
+import ch.qos.logback.classic.*;
+import ch.qos.logback.core.util.*;
import com.jolbox.bonecp.*;
import fj.data.*;
import static fj.data.Option.*;
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 ecd8288..59c4f30 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java
@@ -22,6 +22,7 @@ import java.util.List;
import static fj.data.Option.*;
import static io.trygvis.esper.testing.Util.*;
+import static io.trygvis.esper.testing.util.HttpClient.inputStreamOnly;
import static org.apache.commons.lang.StringUtils.*;
public class JenkinsClient {
@@ -34,9 +35,9 @@ public class JenkinsClient {
this.xmlHttpClient = new XmlHttpClient(http);
this.parser = abdera.getParser();
- jenkinsEntryXmlClient = new HttpClient<>(http, new F<HTTPResponse, Option<List<JenkinsEntryXml>>>() {
- public Option<List<JenkinsEntryXml>> f(HTTPResponse response) {
- Feed feed = (Feed) parser.parse(response.getPayload().getInputStream()).getRoot();
+ jenkinsEntryXmlClient = new HttpClient<>(http, inputStreamOnly(new F<InputStream, Option<List<JenkinsEntryXml>>>() {
+ public Option<List<JenkinsEntryXml>> f(InputStream inputStream) {
+ Feed feed = (Feed) parser.parse(inputStream).getRoot();
List<JenkinsEntryXml> list = new ArrayList<>();
@@ -49,7 +50,7 @@ public class JenkinsClient {
return some(list);
}
- });
+ }));
}
public Option<List<JenkinsEntryXml>> fetchRss(URI uri) throws IOException {
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 a063180..8a7480b 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
@@ -19,7 +19,7 @@ public class JenkinsDao {
private static final String JENKINS_SERVER = "uuid, created_date, url";
- private static final String JENKINS_BUILD = "uuid, created_date, entry_id, url, result, number, duration, timestamp";
+ private static final String JENKINS_BUILD = "uuid, created_date, server, entry_id, url, result, number, duration, timestamp";
public JenkinsDao(Connection c) {
this.c = c;
@@ -46,6 +46,7 @@ public class JenkinsDao {
return new JenkinsBuildDto(
UUID.fromString(rs.getString(i++)),
new DateTime(rs.getTimestamp(i++).getTime()),
+ UUID.fromString(rs.getString(i++)),
rs.getString(i++),
URI.create(rs.getString(i++)),
rs.getString(i++),
@@ -83,12 +84,13 @@ public class JenkinsDao {
}
}
- public UUID insertBuild(String entryId, URI uri, 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 uri, String result, int number, int duration, long timestamp) 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++, entryId);
s.setString(i++, uri.toASCIIString());
s.setString(i++, result);
@@ -146,6 +148,8 @@ class JenkinsJobDto {
class JenkinsBuildDto {
public final UUID uuid;
public final DateTime created_date;
+ // TODO: should be job
+ public final UUID server;
public final String entryId;
public final URI uri;
public final String result;
@@ -153,9 +157,10 @@ class JenkinsBuildDto {
public final int duration;
public final DateTime timestamp;
- JenkinsBuildDto(UUID uuid, DateTime created_date, String entryId, URI uri, String result, int number, int duration, DateTime timestamp) {
+ JenkinsBuildDto(UUID uuid, DateTime created_date, UUID server, String entryId, URI uri, String result, int number, int duration, DateTime timestamp) {
this.uuid = uuid;
this.created_date = created_date;
+ this.server = server;
this.entryId = entryId;
this.uri = uri;
this.result = result;
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 ffe1421..c9a28b2 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java
@@ -29,7 +29,7 @@ public class JenkinsImporter {
ObjectManager<JenkinsServerDto, ActorRef<JenkinsServer>> serverManager = new ObjectManager<>("JenkinsServerOld", servers, new ObjectFactory<JenkinsServerDto, ActorRef<JenkinsServer>>() {
public ActorRef<JenkinsServer> create(JenkinsServerDto server) {
String name = "Jenkins: " + server.uri;
- return threadedActor(name, config.jenkinsUpdateInterval, boneCp, name, new JenkinsServer(jenkinsClient, server.uri));
+ return threadedActor(name, config.jenkinsUpdateInterval, boneCp, name, new JenkinsServer(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
index a89288d..92c0569 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java
@@ -14,16 +14,16 @@ import static io.trygvis.esper.testing.jenkins.JenkinsClient.*;
public class JenkinsServer implements TransactionalActor {
private static final Logger logger = LoggerFactory.getLogger(JenkinsServer.class);
private final JenkinsClient client;
- public final URI uri;
+ public final JenkinsServerDto server;
- public JenkinsServer(JenkinsClient client, URI uri) {
+ public JenkinsServer(JenkinsClient client, JenkinsServerDto server) {
this.client = client;
- this.uri = uri;
+ this.server = server;
}
public void act(Connection c) throws Exception {
JenkinsDao dao = new JenkinsDao(c);
- Option<List<JenkinsEntryXml>> option = client.fetchRss(URI.create(uri.toASCIIString() + "/rssAll"));
+ Option<List<JenkinsEntryXml>> option = client.fetchRss(URI.create(server.uri.toASCIIString() + "/rssAll"));
if(option.isNone()) {
return;
@@ -55,7 +55,14 @@ public class JenkinsServer implements TransactionalActor {
JenkinsBuildXml build = o2.some();
- UUID uuid = dao.insertBuild(entry.id, build.uri, build.result, build.number, build.duration, build.timestamp);
+ UUID uuid = dao.insertBuild(
+ server.uuid,
+ entry.id,
+ build.uri,
+ build.result,
+ build.number,
+ build.duration,
+ build.timestamp);
logger.info("Build inserted: " + uuid + ", i=" + i);
diff --git a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java
index 9596fd1..79159ac 100755
--- a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java
+++ b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java
@@ -10,6 +10,7 @@ import org.apache.http.params.*;
import org.codehaus.httpcache4j.*;
import org.codehaus.httpcache4j.cache.*;
import org.codehaus.httpcache4j.resolver.*;
+import org.h2.util.*;
import org.slf4j.*;
import java.io.*;
@@ -33,7 +34,12 @@ public class HttpClient<A> {
return new F<HTTPResponse, Option<A>>() {
@Override
public Option<A> f(HTTPResponse response) {
- return f.f(response.getPayload().getInputStream());
+ InputStream inputStream = response.getPayload().getInputStream();
+ try {
+ return f.f(inputStream);
+ } finally {
+ IOUtils.closeSilently(inputStream);
+ }
}
};
}
@@ -42,12 +48,8 @@ public class HttpClient<A> {
HTTPResponse response = null;
try {
-// logger.debug("Fetching " + uri);
-// long start = currentTimeMillis();
response = http.execute(new HTTPRequest(uri));
-// long end = currentTimeMillis();
int code = response.getStatus().getCode();
-// logger.debug("Fetched in " + (end - start) + "ms. Status: " + code);
if (code != 200) {
throw new IOException("Did not get 200 back, got " + code);