aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-22 22:29:13 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-22 22:29:13 +0100
commit498fd62e043e31bf5beddfff0e9b5f7f889b884c (patch)
tree72577f37224449b39bcbb3a877567e19ca24b215 /src/main/java
parent7e05c42378c79752c5f9b5bc4c0c8d59da97b47c (diff)
downloadesper-testing-498fd62e043e31bf5beddfff0e9b5f7f889b884c.tar.gz
esper-testing-498fd62e043e31bf5beddfff0e9b5f7f889b884c.tar.bz2
esper-testing-498fd62e043e31bf5beddfff0e9b5f7f889b884c.tar.xz
esper-testing-498fd62e043e31bf5beddfff0e9b5f7f889b884c.zip
JenkinsServerActor:
o Adding a check to see if we're missing builds based on the previous build number.
Diffstat (limited to 'src/main/java')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java4
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java50
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java9
3 files changed, 56 insertions, 7 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java
index 2092d89..af3f9ed 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java
@@ -22,4 +22,8 @@ public class JenkinsJobDto extends AbstractEntity {
this.jobType = jobType;
this.displayName = displayName;
}
+
+ public String displayName() {
+ return displayName.orSome("<no name>");
+ }
}
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 66fd5ff..f573b23 100755
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java
@@ -4,6 +4,7 @@ import fj.*;
import fj.data.*;
import io.trygvis.esper.testing.core.db.*;
import io.trygvis.esper.testing.jenkins.xml.*;
+import io.trygvis.esper.testing.util.*;
import io.trygvis.esper.testing.util.object.*;
import io.trygvis.esper.testing.util.sql.*;
import org.slf4j.*;
@@ -21,6 +22,7 @@ import static java.lang.System.*;
public class JenkinsServerActor implements TransactionalActor {
private static final Logger logger = LoggerFactory.getLogger(JenkinsServerActor.class);
+ private static final XmlParser xmlParser = new XmlParser();
private final JenkinsClient client;
public final JenkinsServerDto server;
@@ -121,10 +123,12 @@ public class JenkinsServerActor implements TransactionalActor {
SqlOption<JenkinsJobDto> jobDtoOption = dao.selectJobByUrl(jobUrl);
- UUID job;
+ JenkinsJobDto job;
if (jobDtoOption.isSome()) {
- job = jobDtoOption.get().uuid;
+ job = jobDtoOption.get();
+
+ logger.info("New build for job '{}'/{}", job.displayName(), job.uuid);
} else {
logger.info("New job: {}, fetching info", jobUrl);
@@ -140,21 +144,25 @@ public class JenkinsServerActor implements TransactionalActor {
JenkinsJobXml xml = jobXmlOption.some()._1();
- job = dao.insertJob(server.uuid, jobXmlFile, xml.url, xml.type, xml.displayName);
+ UUID uuid = dao.insertJob(server.uuid, jobXmlFile, xml.url, xml.type, xml.displayName);
+
+ job = dao.selectJob(uuid).get();
- logger.info("New job: {}, uuid={}", xml.displayName.orSome(xml.url.toASCIIString()), job);
+ logger.info("New job: '{}'/{}", xml.displayName.orSome(xml.url.toASCIIString()), uuid);
}
i++;
+ checkForMissingBuilds(dao, fileDao, build, job);
+
UUID uuid = dao.insertBuild(
- job,
+ job.uuid,
buildXmlFile,
entry.id,
build.url,
users.toArray(new UUID[users.size()]));
- logger.info("Build inserted: {}, #users={} item #{}/{}", uuid, users.size(), i, list.size());
+ logger.info("Build inserted: {}, name={}, number={}, #users={} item #{}/{}", uuid, job.displayName(), build.number, users.size(), i, list.size());
}
long end = currentTimeMillis();
@@ -162,6 +170,36 @@ public class JenkinsServerActor implements TransactionalActor {
logger.info("Inserted " + i + " of " + list.size() + " builds in " + (end - start) + "ms.");
}
+ private void checkForMissingBuilds(JenkinsDao dao, FileDao fileDao, JenkinsBuildXml build, JenkinsJobDto job) throws SQLException {
+ if (build.number <= 1) {
+ return;
+ }
+
+ List<JenkinsBuildDto> builds = dao.selectBuildByJob(job.uuid, PageRequest.one());
+
+ if (builds.isEmpty()) {
+ return;
+ }
+
+ JenkinsBuildDto previousJob = builds.get(0);
+
+ Option<JenkinsBuildXml> previousXmlO = fileDao.load(previousJob.file).toFj().
+ bind(xmlParser.parseDocument).
+ bind(JenkinsBuildXml.parse);
+
+ if (previousXmlO.isNone()) {
+ logger.warn("Unable to load/parse XML file from previous build, file={}", previousJob.file);
+ return;
+ }
+
+ JenkinsBuildXml previousBuildXml = previousXmlO.some();
+
+ if (build.number != previousBuildXml.number + 1) {
+ logger.warn("MISSED BUILD. The build number for job={} ({}) was {}, but the previous build was {}",
+ job.displayName(), job.uuid, build.number, previousBuildXml.number);
+ }
+ }
+
/**
* This sucks, a build should really include the URL to the job.
*/
diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java
index 7773e50..deeedcc 100755
--- a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java
+++ b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java
@@ -1,8 +1,11 @@
package io.trygvis.esper.testing.util.sql;
-import fj.data.Option;
+import fj.data.*;
import java.util.*;
+import java.util.List;
+
+import static fj.data.Option.*;
public class PageRequest {
public final Option<Integer> startIndex;
@@ -19,4 +22,8 @@ public class PageRequest {
public String toString() {
return "PageRequest{startIndex=" + startIndex + ", count=" + count + '}';
}
+
+ public static PageRequest one(String... orderBy) {
+ return new PageRequest(some(0), some(1), Arrays.asList(orderBy));
+ }
}