From 5ec81d9e77fcb56ddf5953989e23b6cafe4772a3 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 29 Dec 2012 18:59:32 +0100 Subject: o Adding build view for jenkins app. --- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 15 ++- .../testing/web/resource/JenkinsResource.java | 102 ++++++++++++++++----- src/main/webapp/apps/jenkinsApp/build.html | 41 +++++++++ src/main/webapp/apps/jenkinsApp/jenkinsApp.js | 22 ++++- src/main/webapp/apps/jenkinsApp/job.html | 4 +- 5 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 src/main/webapp/apps/jenkinsApp/build.html 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 ee793fa..0ed0d5f 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -180,6 +180,14 @@ public class JenkinsDao { } } + public SqlOption selectBuild(UUID uuid) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_BUILD + " FROM jenkins_build WHERE uuid=?")) { + int i = 1; + s.setString(i, uuid.toString()); + return fromRs(s.executeQuery()).map(jenkinsBuild); + } + } + public int selectBuildCountByJob(UUID job) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT count(1) FROM jenkins_build WHERE job=?")) { int i = 1; @@ -223,11 +231,10 @@ public class JenkinsDao { } } - public SqlOption selectUser(UUID uuid, UUID server) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_USER + " FROM jenkins_user WHERE uuid=? AND server=?")) { + public SqlOption selectUser(UUID uuid) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_USER + " FROM jenkins_user WHERE uuid=?")) { int i = 1; - s.setString(i++, uuid.toString()); - s.setString(i, server.toString()); + s.setString(i, uuid.toString()); return fromRs(s.executeQuery()).map(jenkinsUser); } } diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java index aab108b..bd0c613 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java @@ -1,7 +1,5 @@ package io.trygvis.esper.testing.web.resource; -import fj.*; -import fj.data.*; import io.trygvis.esper.testing.*; import io.trygvis.esper.testing.jenkins.*; import io.trygvis.esper.testing.jenkins.xml.*; @@ -70,9 +68,9 @@ public class JenkinsResource extends AbstractResource { @GET @Path("/job/{uuid}") @Produces(MediaType.APPLICATION_JSON) - public JenkinsJobJson getJob(@MagicParam final UUID uuid) throws Exception { - return sql(new JenkinsDaosCallback>() { - protected SqlOption run() throws SQLException { + public JenkinsJobJsonDetail getJob(@MagicParam final UUID uuid) throws Exception { + return sql(new JenkinsDaosCallback>() { + protected SqlOption run() throws SQLException { return daos.jenkinsDao.selectJob(uuid).map(getJenkinsJobJsonDetail); } }); @@ -93,6 +91,17 @@ public class JenkinsResource extends AbstractResource { }); } + @GET + @Path("/build/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + public JenkinsBuildJsonDetail getBuild(@MagicParam final UUID build) throws Exception { + return sql(new JenkinsDaosCallback>() { + protected SqlOption run() throws SQLException { + return daos.jenkinsDao.selectBuild(build).map(getJenkinsBuildJsonDetail); + } + }); + } + public static UUID parseUuid(String s) { try { return UUID.fromString(s); @@ -132,24 +141,40 @@ public class JenkinsResource extends AbstractResource { } }; - protected SqlF getJenkinsJobJsonDetail = new SqlF() { - public JenkinsJobJson apply(JenkinsJobDto job) throws SQLException { - int buildCount = daos.jenkinsDao.selectBuildCountByJob(job.uuid); - return new JenkinsJobJson(job.uuid, job.createdDate, job.server, job.displayName.toNull(), buildCount); + protected SqlF getJenkinsJobJsonDetail = new SqlF() { + public JenkinsJobJsonDetail apply(JenkinsJobDto dto) throws SQLException { + return new JenkinsJobJsonDetail( + getJenkinsJobJson.apply(dto), + daos.jenkinsDao.selectBuildCountByJob(dto.uuid)); } }; protected SqlF getJenkinsBuildJson = new SqlF() { public JenkinsBuildJson apply(JenkinsBuildDto dto) throws SQLException { - Option result = daos.fileDao.load(dto.file).toFj(). + JenkinsBuildXml xml = daos.fileDao.load(dto.file).toFj(). bind(xmlParser.parseDocument). - bind(JenkinsBuildXml.parse).map(new F() { - public String f(JenkinsBuildXml xml) { - return xml.result.orSome("unknown"); - } - }); + bind(JenkinsBuildXml.parse).some(); + + return new JenkinsBuildJson(dto.uuid, dto.createdDate, new DateTime(xml.timestamp), + xml.result.orSome("unknown"), xml.number, xml.duration); + } + }; + + protected SqlF getJenkinsBuildJsonDetail = new SqlF() { + public JenkinsBuildJsonDetail apply(JenkinsBuildDto dto) throws SQLException { + List users = new ArrayList<>(); + for (UUID user : dto.users) { + users.add(daos.jenkinsDao.selectUser(user).map(getJenkinsUserJson).get()); + } + return new JenkinsBuildJsonDetail( + getJenkinsBuildJson.apply(dto), + users); + } + }; - return new JenkinsBuildJson(dto.uuid, dto.createdDate, result.orSome("unknown")); + protected SqlF getJenkinsUserJson = new SqlF() { + public JenkinsUserJson apply(JenkinsUserDto dto) throws SQLException { + return new JenkinsUserJson(dto.uuid, dto.createdDate, dto.absoluteUrl); } }; } @@ -179,21 +204,20 @@ class JenkinsJobJson { public final UUID server; public final String displayName; - public final Integer buildCount; - JenkinsJobJson(UUID uuid, DateTime createdDate, UUID server, String displayName) { this.uuid = uuid; this.createdDate = createdDate; this.server = server; this.displayName = displayName; - this.buildCount = null; } +} - JenkinsJobJson(UUID uuid, DateTime createdDate, UUID server, String displayName, int buildCount) { - this.uuid = uuid; - this.createdDate = createdDate; - this.server = server; - this.displayName = displayName; +class JenkinsJobJsonDetail { + public final JenkinsJobJson job; + public final Integer buildCount; + + JenkinsJobJsonDetail(JenkinsJobJson job, Integer buildCount) { + this.job = job; this.buildCount = buildCount; } } @@ -201,11 +225,39 @@ class JenkinsJobJson { class JenkinsBuildJson { public final UUID uuid; public final DateTime createdDate; + public final DateTime timestamp; public final String result; + public final int number; + public final int duration; - JenkinsBuildJson(UUID uuid, DateTime createdDate, String result) { + JenkinsBuildJson(UUID uuid, DateTime createdDate, DateTime timestamp, String result, int number, int duration) { this.uuid = uuid; this.createdDate = createdDate; + this.timestamp = timestamp; this.result = result; + this.number = number; + this.duration = duration; + } +} + +class JenkinsBuildJsonDetail { + public final JenkinsBuildJson build; + public final List participants; + + JenkinsBuildJsonDetail(JenkinsBuildJson build, List participants) { + this.build = build; + this.participants = participants; + } +} + +class JenkinsUserJson { + public final UUID uuid; + public final DateTime createdDate; + public final String absoluteUrl; + + JenkinsUserJson(UUID uuid, DateTime createdDate, String absoluteUrl) { + this.uuid = uuid; + this.createdDate = createdDate; + this.absoluteUrl = absoluteUrl; } } diff --git a/src/main/webapp/apps/jenkinsApp/build.html b/src/main/webapp/apps/jenkinsApp/build.html new file mode 100644 index 0000000..02fa60b --- /dev/null +++ b/src/main/webapp/apps/jenkinsApp/build.html @@ -0,0 +1,41 @@ +
+ + + + + +

Overview

+ + + + + + + + + + + + + + + +
Timestamp{{details.build.timestamp | date:'medium'}}
Number{{details.build.number}}
Duration{{details.build.duration / 1000 | number:0}}s
+ +

Users

+ + + + + + +
{{user.uuid}}
+ +
diff --git a/src/main/webapp/apps/jenkinsApp/jenkinsApp.js b/src/main/webapp/apps/jenkinsApp/jenkinsApp.js index 19d107d..1cd2d2a 100644 --- a/src/main/webapp/apps/jenkinsApp/jenkinsApp.js +++ b/src/main/webapp/apps/jenkinsApp/jenkinsApp.js @@ -4,7 +4,8 @@ var jenkinsApp = angular.module('jenkinsApp', ['jenkinsServer', 'jenkinsJob', 'j $routeProvider. when('/', {controller: ServerListCtrl, templateUrl: '/apps/jenkinsApp/server-list.html?noCache=' + noCache}). when('/server/:uuid', {controller: ServerCtrl, templateUrl: '/apps/jenkinsApp/server.html?noCache=' + noCache}). - when('/job/:uuid', {controller: JobCtrl, templateUrl: '/apps/jenkinsApp/job.html?noCache=' + noCache}); + when('/job/:uuid', {controller: JobCtrl, templateUrl: '/apps/jenkinsApp/job.html?noCache=' + noCache}). + when('/build/:uuid', {controller: BuildCtrl, templateUrl: '/apps/jenkinsApp/build.html?noCache=' + noCache}); }); function ServerListCtrl($scope, $location, JenkinsServer) { @@ -32,12 +33,25 @@ function ServerCtrl($scope, $location, $routeParams, JenkinsServer, JenkinsJob, function JobCtrl($scope, $location, $routeParams, JenkinsJob, JenkinsBuild, PagingTableService) { var jobUuid = $routeParams.uuid; - JenkinsJob.get({uuid: jobUuid}, function (job) { - $scope.job = job; + JenkinsJob.get({uuid: jobUuid}, function (details) { + $scope.details = details; }); $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsBuild, {job: jobUuid})); $scope.showServers = function () { $location.path('/'); }; - $scope.showServer = function (uuid) { $location.path('/server/' + $scope.job.server); }; + $scope.showServer = function () { $location.path('/server/' + $scope.job.server); }; + $scope.showBuild = function (uuid) { $location.path('/build/' + uuid); }; +} + +function BuildCtrl($scope, $location, $routeParams, JenkinsBuild) { + var buildUuid = $routeParams.uuid; + + JenkinsBuild.get({uuid: buildUuid}, function (details) { + $scope.details = details; + }); + + $scope.showServers = function () { $location.path('/'); }; + $scope.showServer = function (uuid) { $location.path('/server/' + $scope.server.uuid); }; + $scope.showJob = function (uuid) { $location.path('/job/' + $scope.build.job); }; } diff --git a/src/main/webapp/apps/jenkinsApp/job.html b/src/main/webapp/apps/jenkinsApp/job.html index 6ee7af0..027748a 100755 --- a/src/main/webapp/apps/jenkinsApp/job.html +++ b/src/main/webapp/apps/jenkinsApp/job.html @@ -16,11 +16,11 @@ URL - {{job.displayName}} + {{details.job.displayName}} Build count - {{job.buildCount}} + {{details.buildCount}} -- cgit v1.2.3