From d8a7ca67f49f1e0d6c7e0504312f7fbac06a592c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Sep 2011 08:27:17 +0000 Subject: [PATCH] * Start of a JSON API to get information about a specific build. E.g. http://server/build/1341335/api/get-info returns a JSON record containing information about the build. --- deps.nix | 1 + src/lib/Hydra.pm | 8 +++++++- src/lib/Hydra/Controller/API.pm | 12 ++---------- src/lib/Hydra/Controller/Build.pm | 15 +++++++++++++++ src/lib/Hydra/View/JSON.pm | 3 +++ 5 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 src/lib/Hydra/View/JSON.pm diff --git a/deps.nix b/deps.nix index 81b08f11..dce08733 100644 --- a/deps.nix +++ b/deps.nix @@ -11,6 +11,7 @@ with pkgs; perlPackages.CatalystViewTT perlPackages.CatalystEngineHTTPPrefork perlPackages.CatalystViewDownload + perlPackages.CatalystViewJSON perlPackages.XMLSimple perlPackages.IPCRun perlPackages.IOCompressBzip2 diff --git a/src/lib/Hydra.pm b/src/lib/Hydra.pm index ec727a86..3e6d54dd 100644 --- a/src/lib/Hydra.pm +++ b/src/lib/Hydra.pm @@ -43,7 +43,13 @@ __PACKAGE__->config( }, }, }, - } + }, + 'View::JSON' => { + expose_stash => qr/^json/, + }, + 'Plugin::Session' => { + expires => 3600 * 24 * 2, + }, ); __PACKAGE__->setup(); diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index 664cdd4d..630dfbda 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -11,6 +11,8 @@ use JSON::Any; use DateTime; use Digest::SHA qw(sha256_hex); +# !!! Rewrite this to use View::JSON. + sub api : Chained('/') PathPart('api') CaptureArgs(0) { my ($self, $c) = @_; $c->response->content_type('application/json'); @@ -163,16 +165,6 @@ sub nrrunning : Chained('api') PathPart('nrrunning') Args(0) { $c->forward('Hydra::View::Plain'); } -sub ts { - my ($nr, $period) = @_; - my @arr ; - - - - - return @arr; -} - sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) { my ($self, $c) = @_; my $nr = $c->request->params->{nr} ; diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 9ad0fef1..ca51b6b5 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -10,6 +10,7 @@ use File::stat; use Data::Dump qw(dump); use Nix; + sub build : Chained('/') PathPart CaptureArgs(1) { my ($self, $c, $id) = @_; @@ -29,6 +30,7 @@ sub build : Chained('/') PathPart CaptureArgs(1) { $c->stash->{project} = $c->stash->{build}->project; } + sub view_build : Chained('build') PathPart('') Args(0) { my ($self, $c) = @_; @@ -215,6 +217,7 @@ sub download_by_type : Chained('build') PathPart('download-by-type') { $c->res->redirect(defaultUriForProduct($self, $c, $product, @path)); } + sub contents : Chained('build') PathPart Args(1) { my ($self, $c, $productnr) = @_; @@ -308,6 +311,7 @@ sub buildtimedeps : Chained('build') PathPart('buildtime-deps') { $c->res->content_type('image/png'); # !!! } + sub deps : Chained('build') PathPart('deps') { my ($self, $c) = @_; @@ -539,4 +543,15 @@ sub clone_submit : Chained('build') PathPart('clone/submit') Args(0) { } +sub get_info : Chained('build') PathPart('api/get-info') Args(0) { + my ($self, $c) = @_; + my $build = $c->stash->{build}; + # !!! strip the json prefix + $c->stash->{jsonBuildId} = $build->id; + $c->stash->{jsonDrvPath} = $build->drvpath; + $c->stash->{jsonOutPath} = $build->outpath; + $c->forward('View::JSON'); +} + + 1; diff --git a/src/lib/Hydra/View/JSON.pm b/src/lib/Hydra/View/JSON.pm new file mode 100644 index 00000000..f2ab1fc8 --- /dev/null +++ b/src/lib/Hydra/View/JSON.pm @@ -0,0 +1,3 @@ +package Hydra::View::JSON; +use base qw(Catalyst::View::JSON); +1;