aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-08 10:52:00 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-08 10:52:00 +0100
commit164ce072f94a0820d6c2256aab8c6ee8d90d8eee (patch)
tree3c2a5b6ef68625393368d2fba444565b0bd2ed09 /src/main
parent5d56a80555ebe5a419dae3b1b849ffa78449b410 (diff)
downloadesper-testing-164ce072f94a0820d6c2256aab8c6ee8d90d8eee.tar.gz
esper-testing-164ce072f94a0820d6c2256aab8c6ee8d90d8eee.tar.bz2
esper-testing-164ce072f94a0820d6c2256aab8c6ee8d90d8eee.tar.xz
esper-testing-164ce072f94a0820d6c2256aab8c6ee8d90d8eee.zip
o Creating a flag to disable jenkins servers from being polled.
o Using proper logging.
Diffstat (limited to 'src/main')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/Daos.java4
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java72
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java7
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java2
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java16
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/object/ObjectManager.java10
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/object/ObjectUtil.java6
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/util/HttpClient.java21
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java16
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/util/XmlParser.java17
-rwxr-xr-xsrc/main/resources/ddl-jenkins.sql7
11 files changed, 97 insertions, 81 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/Daos.java b/src/main/java/io/trygvis/esper/testing/Daos.java
index 0a7a5da..e7faeca 100755
--- a/src/main/java/io/trygvis/esper/testing/Daos.java
+++ b/src/main/java/io/trygvis/esper/testing/Daos.java
@@ -51,8 +51,4 @@ public class Daos implements Closeable {
public void commit() throws SQLException {
connection.commit();
}
-
- public static Daos lookup(DataSource dataSource) throws SQLException {
- return new Daos(dataSource.getConnection());
- }
}
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 40d7618..ecd8288 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java
@@ -13,6 +13,7 @@ import org.codehaus.httpcache4j.cache.*;
import org.jdom2.Document;
import org.jdom2.Element;
import org.joda.time.DateTime;
+import org.slf4j.*;
import java.io.*;
import java.net.*;
@@ -24,6 +25,7 @@ import static io.trygvis.esper.testing.Util.*;
import static org.apache.commons.lang.StringUtils.*;
public class JenkinsClient {
+ private static final Logger logger = LoggerFactory.getLogger(JenkinsClient.class);
private final XmlHttpClient xmlHttpClient;
private final HttpClient<List<JenkinsEntryXml>> jenkinsEntryXmlClient;
private final Parser parser;
@@ -101,7 +103,7 @@ public class JenkinsClient {
case "mavenModuleSet":
return some(JenkinsJobXml.parse(uri, JenkinsJobType.MAVEN, root));
default:
- System.out.println("Unknown project type: " + name);
+ logger.warn("Unknown project type: " + name);
return Option.none();
}
}
@@ -124,11 +126,43 @@ public class JenkinsClient {
case "freeStyleBuild":
return JenkinsBuildXml.parse(root);
default:
- System.out.println("Unknown build type: " + name);
+ logger.warn("Unknown build type: " + name);
return Option.none();
}
}
-}
+
+ public static class JenkinsBuildXml {
+
+ public final URI uri;
+ public final int number;
+ public final String result;
+ public final int duration;
+ public final long timestamp;
+
+ JenkinsBuildXml(URI uri, int number, String result, int duration, long timestamp) {
+ this.uri = uri;
+ this.number = number;
+ this.result = result;
+ this.duration = duration;
+ this.timestamp = timestamp;
+ }
+
+ public static Option<JenkinsBuildXml> parse(Element root) {
+
+ Option<URI> uri = childText(root, "url").bind(Util.parseUri);
+ Option<Integer> number = childText(root, "number").bind(Util.parseInt);
+ Option<String> result = childText(root, "result");
+ Option<Integer> duration = childText(root, "duration").bind(Util.parseInt);
+ Option<Long> timestamp = childText(root, "timestamp").bind(Util.parseLong);
+
+ if(uri.isNone() || number.isNone() || result.isNone() || duration.isNone() || timestamp.isNone()) {
+ logger.warn("Missing required fields.");
+ return none();
+ }
+
+ return some(new JenkinsBuildXml(uri.some(), number.some(), result.some(), duration.some(), timestamp.some()));
+ }
+ }}
class JenkinsEntryXml {
public final String id;
@@ -243,35 +277,3 @@ class JenkinsJobXml {
}
}
-class JenkinsBuildXml {
-
- public final URI uri;
- public final int number;
- public final String result;
- public final int duration;
- public final long timestamp;
-
- JenkinsBuildXml(URI uri, int number, String result, int duration, long timestamp) {
- this.uri = uri;
- this.number = number;
- this.result = result;
- this.duration = duration;
- this.timestamp = timestamp;
- }
-
- public static Option<JenkinsBuildXml> parse(Element root) {
-
- Option<URI> uri = childText(root, "url").bind(Util.parseUri);
- Option<Integer> number = childText(root, "number").bind(Util.parseInt);
- Option<String> result = childText(root, "result");
- Option<Integer> duration = childText(root, "duration").bind(Util.parseInt);
- Option<Long> timestamp = childText(root, "timestamp").bind(Util.parseLong);
-
- if(uri.isNone() || number.isNone() || result.isNone() || duration.isNone() || timestamp.isNone()) {
- System.out.println("Missing required fields.");
- return none();
- }
-
- return some(new JenkinsBuildXml(uri.some(), number.some(), result.some(), duration.some(), timestamp.some()));
- }
-}
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 05ed567..a063180 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
@@ -54,8 +54,11 @@ public class JenkinsDao {
new DateTime(rs.getTimestamp(i).getTime()));
}
- public List<JenkinsServerDto> selectServer() throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_SERVER + " FROM jenkins_server")) {
+ public List<JenkinsServerDto> selectServer(boolean enabledOnly) throws SQLException {
+ String where = "WHERE ";
+ 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<>();
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 c273d8a..ffe1421 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java
@@ -41,7 +41,7 @@ public class JenkinsImporter {
java.util.List<JenkinsServerDto> newKeys;
try (Connection c = boneCp.getConnection()) {
- newKeys = new JenkinsDao(c).selectServer();
+ newKeys = new JenkinsDao(c).selectServer(true);
}
serverManager.update(newKeys);
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 9d12456..a89288d 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java
@@ -2,13 +2,17 @@ package io.trygvis.esper.testing.jenkins;
import fj.data.*;
import io.trygvis.esper.testing.object.*;
+import org.slf4j.*;
import java.net.*;
import java.sql.*;
-import java.util.*;
import java.util.List;
+import java.util.*;
+
+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;
@@ -27,7 +31,7 @@ public class JenkinsServer implements TransactionalActor {
List<JenkinsEntryXml> list = option.some();
- System.out.println("Got " + list.size() + " entries.");
+ logger.info("Got " + list.size() + " entries.");
int i = 0;
@@ -35,11 +39,11 @@ public class JenkinsServer implements TransactionalActor {
Option<JenkinsBuildDto> o = dao.selectBuildByEntryId(entry.id);
if(o.isSome()) {
- System.out.println("Old event: " + entry.id);
+ logger.info("Old event: " + entry.id);
continue;
}
- System.out.println("New event: " + entry.id + ", fetching build info");
+ logger.info("New event: " + entry.id + ", fetching build info");
i++;
@@ -53,13 +57,13 @@ public class JenkinsServer implements TransactionalActor {
UUID uuid = dao.insertBuild(entry.id, build.uri, build.result, build.number, build.duration, build.timestamp);
- System.out.println("Build inserted: " + uuid + ", i=" + i);
+ logger.info("Build inserted: " + uuid + ", i=" + i);
// if(i == 1) {
// break;
// }
}
- System.out.println("Inserted " + i + " new events.");
+ logger.info("Inserted " + i + " new events.");
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/object/ObjectManager.java b/src/main/java/io/trygvis/esper/testing/object/ObjectManager.java
index e850c61..a4fbc60 100755
--- a/src/main/java/io/trygvis/esper/testing/object/ObjectManager.java
+++ b/src/main/java/io/trygvis/esper/testing/object/ObjectManager.java
@@ -1,9 +1,13 @@
package io.trygvis.esper.testing.object;
+import org.slf4j.*;
+
import java.io.*;
import java.util.*;
public class ObjectManager<K, V extends Closeable> implements Closeable {
+ private static final Logger logger = LoggerFactory.getLogger(ObjectManager.class);
+
private final String type;
private final ObjectFactory<K, V> objectFactory;
private Map<K, V> objects = new HashMap<>();
@@ -28,7 +32,7 @@ public class ObjectManager<K, V extends Closeable> implements Closeable {
for (K k : gone) {
try {
- System.out.println("Removing " + type + " with id=" + k);
+ logger.debug("Removing " + type + " with id=" + k);
objects.remove(k).close();
} catch (IOException e) {
e.printStackTrace(System.out);
@@ -36,14 +40,14 @@ public class ObjectManager<K, V extends Closeable> implements Closeable {
}
for (K k : found) {
- System.out.println("Adding " + type + " with id=" + k);
+ logger.debug("Adding " + type + " with id=" + k);
objects.put(k, objectFactory.create(k));
}
}
public synchronized void close() throws IOException {
if (closed) {
- System.out.println("Already closed: type=" + type);
+ logger.warn("Already closed: type=" + type);
return;
}
update(Collections.<K>emptyList());
diff --git a/src/main/java/io/trygvis/esper/testing/object/ObjectUtil.java b/src/main/java/io/trygvis/esper/testing/object/ObjectUtil.java
index f421acf..d70e074 100755
--- a/src/main/java/io/trygvis/esper/testing/object/ObjectUtil.java
+++ b/src/main/java/io/trygvis/esper/testing/object/ObjectUtil.java
@@ -1,5 +1,7 @@
package io.trygvis.esper.testing.object;
+import org.slf4j.*;
+
import javax.sql.*;
import java.io.*;
import java.sql.*;
@@ -16,6 +18,8 @@ public class ObjectUtil {
}
private static class TransactionalActorWrapper<A extends TransactionalActor> implements Runnable {
+ private static final Logger logger = LoggerFactory.getLogger(TransactionalActorWrapper.class);
+
private final DataSource dataSource;
private final String name;
private final A actor;
@@ -47,7 +51,7 @@ public class ObjectUtil {
c.close();
}
} catch (Throwable e) {
- System.out.println("Exception in thread " + Thread.currentThread().getName());
+ logger.warn("Exception in thread " + Thread.currentThread().getName());
e.printStackTrace(System.out);
}
}
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 420a949..9596fd1 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.slf4j.*;
import java.io.*;
import java.net.*;
@@ -18,6 +19,8 @@ import static java.lang.System.*;
public class HttpClient<A> {
+ private static final Logger logger = LoggerFactory.getLogger(HttpClient.class);
+
private final HTTPCache http;
private final F<HTTPResponse, Option<A>> f;
@@ -26,25 +29,25 @@ public class HttpClient<A> {
this.f = f;
}
- public static <A> HttpClient<A> httpClient(HTTPCache http, final F<InputStream, Option<A>> f) {
- return new HttpClient<>(http, new F<HTTPResponse, Option<A>>() {
+ public static <A> F<HTTPResponse, Option<A>> inputStreamOnly(final F<InputStream, Option<A>> f) {
+ return new F<HTTPResponse, Option<A>>() {
@Override
public Option<A> f(HTTPResponse response) {
return f.f(response.getPayload().getInputStream());
}
- });
+ };
}
public Option<A> fetch(URI uri) throws IOException {
HTTPResponse response = null;
try {
- System.out.println("Fetching " + uri);
- long start = currentTimeMillis();
+// logger.debug("Fetching " + uri);
+// long start = currentTimeMillis();
response = http.execute(new HTTPRequest(uri));
- long end = currentTimeMillis();
+// long end = currentTimeMillis();
int code = response.getStatus().getCode();
- System.out.println("Fetched in " + (end - start) + "ms. Status: " + code);
+// logger.debug("Fetched in " + (end - start) + "ms. Status: " + code);
if (code != 200) {
throw new IOException("Did not get 200 back, got " + code);
@@ -88,7 +91,7 @@ public class HttpClient<A> {
}
public HTTPResponse resolve(HTTPRequest request) throws IOException {
- System.out.println(request.getRequestURI() + ": Executing");
+ logger.debug(request.getRequestURI() + ": Executing");
long start = currentTimeMillis();
Status status = null;
try {
@@ -106,7 +109,7 @@ public class HttpClient<A> {
s += "with exception";
}
- System.out.println(s);
+ logger.debug(s);
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java b/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java
index dc3b46f..7e5e298 100755
--- a/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java
+++ b/src/main/java/io/trygvis/esper/testing/util/XmlHttpClient.java
@@ -6,22 +6,16 @@ import org.codehaus.httpcache4j.cache.*;
import org.jdom2.*;
import java.io.*;
-import java.net.*;
-public class XmlHttpClient {
-
- private final HttpClient<Document> httpClient;
+public class XmlHttpClient extends HttpClient<Document> {
public XmlHttpClient(HTTPCache http) {
- final XmlParser parser = new XmlParser();
- httpClient = HttpClient.httpClient(http, new F<InputStream, Option<Document>>() {
+ super(http, HttpClient.inputStreamOnly(new F<InputStream, Option<Document>>() {
+ final XmlParser parser = new XmlParser();
+
public Option<Document> f(InputStream inputStream) {
return parser.parseDocument(inputStream);
}
- });
- }
-
- public Option<Document> fetch(URI uri) throws IOException {
- return httpClient.fetch(uri);
+ }));
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/util/XmlParser.java b/src/main/java/io/trygvis/esper/testing/util/XmlParser.java
index e1b463f..9c585fc 100755
--- a/src/main/java/io/trygvis/esper/testing/util/XmlParser.java
+++ b/src/main/java/io/trygvis/esper/testing/util/XmlParser.java
@@ -1,16 +1,20 @@
package io.trygvis.esper.testing.util;
import fj.data.*;
-import static fj.data.Option.*;
-import static javax.xml.stream.XMLStreamConstants.*;
import org.h2.util.*;
import org.jdom2.*;
import org.jdom2.input.*;
+import org.slf4j.*;
-import java.io.*;
import javax.xml.stream.*;
+import java.io.*;
+
+import static fj.data.Option.*;
+import static javax.xml.stream.XMLStreamConstants.*;
public class XmlParser {
+ private static final Logger logger = LoggerFactory.getLogger(XmlParser.class);
+
public static boolean debugXml;
private final XMLInputFactory xmlInputFactory;
@@ -29,10 +33,9 @@ public class XmlParser {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
IOUtils.copy(stream, buffer);
byte[] bytes = buffer.toByteArray();
- System.out.println("------------------------------------------------");
- System.out.write(bytes);
- System.out.println();
- System.out.println("------------------------------------------------");
+ logger.debug("------------------------------------------------");
+ logger.debug(new String(bytes, "utf-8"));
+ logger.debug("------------------------------------------------");
stream = new ByteArrayInputStream(bytes);
}
diff --git a/src/main/resources/ddl-jenkins.sql b/src/main/resources/ddl-jenkins.sql
index 00af6ee..c34e8cb 100755
--- a/src/main/resources/ddl-jenkins.sql
+++ b/src/main/resources/ddl-jenkins.sql
@@ -7,6 +7,7 @@ CREATE TABLE jenkins_server (
uuid CHAR(36) NOT NULL,
created_date TIMESTAMP NOT NULL,
url VARCHAR(1000) NOT NULL,
+ enabled BOOLEAN NOT NULL,
CONSTRAINT pk_jenkins_server PRIMARY KEY (uuid),
CONSTRAINT uq_jenkins_server__url UNIQUE (url)
);
@@ -26,7 +27,9 @@ CREATE TABLE jenkins_build (
CONSTRAINT uq_jenkins_build__id UNIQUE (entry_id)
);
--- INSERT INTO jenkins_server (uuid, url) VALUES ('782a75f6-40a4-11e2-aca6-20cf30557fa0', 'https://builds.apache.org');
-INSERT INTO jenkins_server (uuid, created_date, url) VALUES ('4c473c86-40ad-11e2-ae61-20cf30557fa0', current_timestamp, 'http://ci.jruby.org');
+INSERT INTO jenkins_server (uuid, created_date, url, enabled) VALUES
+('782a75f6-40a4-11e2-aca6-20cf30557fa0', CURRENT_TIMESTAMP, 'https://builds.apache.org', FALSE),
+('4c473c86-40ad-11e2-ae61-20cf30557fa0', CURRENT_TIMESTAMP, 'http://ci.jruby.org', FALSE),
+('518c6162-411b-11e2-b63c-20cf30557fa0', CURRENT_TIMESTAMP, 'http://www.simantics.org/jenkins', FALSE);
COMMIT;