From affec8881dc4afa71fff11c7934bb2976449e638 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Apr 2014 23:21:06 +0200 Subject: [PATCH] Remove support for views They're replaced by aggregates, which are declarative, faster, and have a better interface. --- src/lib/Hydra/Controller/Project.pm | 31 ---- src/lib/Hydra/Controller/View.pm | 233 ---------------------------- src/lib/Hydra/Schema/Projects.pm | 34 +--- src/lib/Hydra/Schema/ViewJobs.pm | 157 ------------------- src/lib/Hydra/Schema/Views.pm | 123 --------------- src/root/edit-view.tt | 106 ------------- src/root/project.tt | 31 ---- src/root/view-result.tt | 57 ------- src/root/view.tt | 86 ---------- src/sql/hydra.sql | 51 ------ src/sql/upgrade-27.sql | 2 + 11 files changed, 4 insertions(+), 907 deletions(-) delete mode 100644 src/lib/Hydra/Controller/View.pm delete mode 100644 src/lib/Hydra/Schema/ViewJobs.pm delete mode 100644 src/lib/Hydra/Schema/Views.pm delete mode 100644 src/root/edit-view.tt delete mode 100644 src/root/view-result.tt delete mode 100644 src/root/view.tt create mode 100644 src/sql/upgrade-27.sql diff --git a/src/lib/Hydra/Controller/Project.pm b/src/lib/Hydra/Controller/Project.pm index 582c5e88..7e9ce672 100644 --- a/src/lib/Hydra/Controller/Project.pm +++ b/src/lib/Hydra/Controller/Project.pm @@ -29,7 +29,6 @@ sub project_GET { $c->stash->{template} = 'project.tt'; - $c->stash->{views} = [$c->stash->{project}->views->all]; $c->stash->{jobsets} = [jobsetOverview($c, $c->stash->{project})]; $c->stash->{releases} = [$c->stash->{project}->releases->search({}, {order_by => ["timestamp DESC"]})]; @@ -174,36 +173,6 @@ sub get_builds : Chained('projectChain') PathPart('') CaptureArgs(0) { } -sub create_view_submit : Chained('projectChain') PathPart('create-view/submit') Args(0) { - my ($self, $c) = @_; - - requireProjectOwner($c, $c->stash->{project}); - - my $viewName = $c->request->params->{name}; - - my $view; - txn_do($c->model('DB')->schema, sub { - # Note: $viewName is validated in updateView, which will abort - # the transaction if the name isn't valid. - $view = $c->stash->{project}->views->create({name => $viewName}); - Hydra::Controller::View::updateView($c, $view); - }); - - $c->res->redirect($c->uri_for($c->controller('View')->action_for('view_view'), - [$c->stash->{project}->name, $view->name])); -} - - -sub create_view : Chained('projectChain') PathPart('create-view') Args(0) { - my ($self, $c) = @_; - - requireProjectOwner($c, $c->stash->{project}); - - $c->stash->{template} = 'edit-view.tt'; - $c->stash->{create} = 1; -} - - sub create_release : Chained('projectChain') PathPart('create-release') Args(0) { my ($self, $c) = @_; requireProjectOwner($c, $c->stash->{project}); diff --git a/src/lib/Hydra/Controller/View.pm b/src/lib/Hydra/Controller/View.pm deleted file mode 100644 index 88e78cb5..00000000 --- a/src/lib/Hydra/Controller/View.pm +++ /dev/null @@ -1,233 +0,0 @@ -package Hydra::Controller::View; - -use strict; -use warnings; -use base 'Catalyst::Controller'; -use Hydra::Helper::Nix; -use Hydra::Helper::CatalystUtils; - - -sub getView { - my ($c, $projectName, $viewName) = @_; - - my $project = $c->model('DB::Projects')->find($projectName); - notFound($c, "Project $projectName doesn't exist.") if !defined $project; - $c->stash->{project} = $project; - - (my $view) = $c->model('DB::Views')->find($projectName, $viewName); - notFound($c, "View $viewName doesn't exist.") if !defined $view; - $c->stash->{view} = $view; - - (my $primaryJob) = $view->viewjobs->search({isprimary => 1}); - #die "View $viewName doesn't have a primary job." if !defined $primaryJob; - - my $jobs = [$view->viewjobs->search({}, - {order_by => ["isprimary DESC", "job", "attrs"]})]; - - $c->stash->{jobs} = $jobs; - - return ($project, $view, $primaryJob, $jobs); -} - - -sub updateView { - my ($c, $view) = @_; - - my $viewName = trim $c->request->params->{name}; - error($c, "Invalid view name: $viewName") - unless $viewName =~ /^[[:alpha:]][\w\-]*$/; - - $view->update( - { name => $viewName - , description => trim $c->request->params->{description} }); - - $view->viewjobs->delete; - - foreach my $param (keys %{$c->request->params}) { - next unless $param =~ /^job-(\d+)-name$/; - my $baseName = $1; - - my $name = trim $c->request->params->{"job-$baseName-name"}; - my $description = trim $c->request->params->{"job-$baseName-description"}; - my $attrs = trim $c->request->params->{"job-$baseName-attrs"}; - - $name =~ /^([\w\-]+):($jobNameRE)$/ or error($c, "Invalid job name: $name"); - my $jobsetName = $1; - my $jobName = $2; - - error($c, "Jobset `$jobsetName' doesn't exist.") - unless $view->project->jobsets->find({name => $jobsetName}); - - # !!! We could check whether the job exists, but that would - # require the evaluator to have seen the job, which may not be - # the case. - - $view->viewjobs->create( - { jobset => $jobsetName - , job => $jobName - , description => $description - , attrs => $attrs - , isprimary => $c->request->params->{"primary"} eq $baseName ? 1 : 0 - }); - } - - error($c, "There must be one primary job.") - if $view->viewjobs->search({isprimary => 1})->count != 1; -} - - -sub view : Chained('/') PathPart('view') CaptureArgs(2) { - my ($self, $c, $projectName, $viewName) = @_; - my ($project, $view, $primaryJob, $jobs) = getView($c, $projectName, $viewName); - $c->stash->{project} = $project; - $c->stash->{view} = $view; - $c->stash->{primaryJob} = $primaryJob; - $c->stash->{jobs} = $jobs; -} - - -sub view_view : Chained('view') PathPart('') Args(0) { - my ($self, $c) = @_; - - $c->stash->{template} = 'view.tt'; - - my $resultsPerPage = 10; - my $page = int($c->req->param('page') || "1") || 1; - - my @results = (); - push @results, getViewResult($_, $c->stash->{jobs}) foreach - getPrimaryBuildsForView($c->stash->{project}, $c->stash->{primaryJob}, $page, $resultsPerPage); - - $c->stash->{baseUri} = $c->uri_for($self->action_for("view_view"), $c->req->captures); - $c->stash->{results} = [@results]; - $c->stash->{page} = $page; - $c->stash->{totalResults} = getPrimaryBuildTotal($c->stash->{project}, $c->stash->{primaryJob}); - $c->stash->{resultsPerPage} = $resultsPerPage; -} - - -sub edit : Chained('view') PathPart('edit') Args(0) { - my ($self, $c) = @_; - requireProjectOwner($c, $c->stash->{project}); - $c->stash->{template} = 'edit-view.tt'; -} - - -sub submit : Chained('view') PathPart('submit') Args(0) { - my ($self, $c) = @_; - requireProjectOwner($c, $c->stash->{project}); - if (($c->request->params->{submit} || "") eq "delete") { - $c->stash->{view}->delete; - $c->res->redirect($c->uri_for($c->controller('Project')->action_for('project'), - [$c->stash->{project}->name])); - } - txn_do($c->model('DB')->schema, sub { - updateView($c, $c->stash->{view}); - }); - $c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures)); -} - - -sub latest : Chained('view') PathPart('latest') { - my ($self, $c, @args) = @_; - - # Redirect to the latest result in the view in which every build - # is successful. - my $latest = getLatestSuccessfulViewResult( - $c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs}, 0); - error($c, "This view set has no successful results yet.") if !defined $latest; - $c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures, $latest->id, @args, $c->req->params)); -} - - -sub latest_finished : Chained('view') PathPart('latest-finished') { - my ($self, $c, @args) = @_; - - # Redirect to the latest result in the view in which every build - # is successful *and* where the jobset evaluation has finished - # completely. - my $latest = getLatestSuccessfulViewResult( - $c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs}, 1); - error($c, "This view set has no successful results yet.") if !defined $latest; - $c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures, $latest->id, @args, $c->req->params)); -} - - -sub result : Chained('view') PathPart('') { - my ($self, $c, $id, @args) = @_; - - $c->stash->{template} = 'view-result.tt'; - - # Note: we don't actually check whether $id is a primary build, - # but who cares? - my $primaryBuild = $c->stash->{project}->builds->find($id) - or error($c, "Build $id doesn't exist."); - - my $result = getViewResult($primaryBuild, $c->stash->{jobs}); - $c->stash->{result} = $result; - - my %jobNames; - $jobNames{$_->{job}->job}++ foreach @{$result->{jobs}}; - $c->stash->{jobNames} = \%jobNames; - - if (scalar @args == 1 && $args[0] eq "release") { - requireProjectOwner($c, $c->stash->{project}); - - error($c, "The primary build of this view result did not provide a release name.") - unless $result->{releasename}; - - error($c, "A release named `" . $result->{releasename} . "' already exists.") - if $c->stash->{project}->releases->find({name => $result->{releasename}}); - - my $release; - - txn_do($c->model('DB')->schema, sub { - - $release = $c->stash->{project}->releases->create( - { name => $result->{releasename} - , timestamp => time - }); - - foreach my $job (@{$result->{jobs}}) { - $release->releasemembers->create( - { build => $job->{build}->id - , description => $job->{job}->description - }); - } - }); - - $c->res->redirect($c->uri_for($c->controller('Release')->action_for('view'), - [$c->stash->{project}->name, $release->name])); - } - - elsif (scalar @args >= 1 && $args[0] eq "eval") { - my $eval = $c->stash->{result}->{eval}; - notFound($c, "This view result has no evaluation.") unless defined $eval; - $c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for("view"), - [$eval->id], @args[1..$#args], $c->req->params)); - } - - # Provide a redirect to the specified job of this view result - # through `http://.../view/$project/$viewName/$viewResult/$jobName'. - # Optionally, you can append `-$system' to the $jobName to get a - # build for a specific platform. - elsif (scalar @args != 0) { - my $jobName = shift @args; - my $system; - if ($jobName =~ /^($jobNameRE)-($systemRE)$/) { - $jobName = $1; - $system = $2; - } - (my $build, my @others) = - grep { $_->{job}->job eq $jobName && (!defined $system || ($_->{build} && $_->{build}->system eq $system)) } - @{$result->{jobs}}; - notFound($c, "View doesn't have a job named ‘$jobName’" . ($system ? " for ‘$system’" : "") . ".") - unless defined $build; - error($c, "Job `$jobName' isn't unique.") if @others; - return $c->res->redirect($c->uri_for($c->controller('Build')->action_for('build'), - [$build->{build}->id], @args)); - } -} - - -1; diff --git a/src/lib/Hydra/Schema/Projects.pm b/src/lib/Hydra/Schema/Projects.pm index 162f9172..9bf9dde3 100644 --- a/src/lib/Hydra/Schema/Projects.pm +++ b/src/lib/Hydra/Schema/Projects.pm @@ -256,36 +256,6 @@ __PACKAGE__->has_many( undef, ); -=head2 viewjobs - -Type: has_many - -Related object: L - -=cut - -__PACKAGE__->has_many( - "viewjobs", - "Hydra::Schema::ViewJobs", - { "foreign.project" => "self.name" }, - undef, -); - -=head2 views - -Type: has_many - -Related object: L - -=cut - -__PACKAGE__->has_many( - "views", - "Hydra::Schema::Views", - { "foreign.project" => "self.name" }, - undef, -); - =head2 usernames Type: many_to_many @@ -297,8 +267,8 @@ Composing rels: L -> username __PACKAGE__->many_to_many("usernames", "projectmembers", "username"); -# Created by DBIx::Class::Schema::Loader v0.07033 @ 2014-04-23 22:48:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:l8eN9UAavdqnL7Sjv4rmFw +# Created by DBIx::Class::Schema::Loader v0.07033 @ 2014-04-23 23:13:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fkd9ruEoVSBGIktmAj4u4g my %hint = ( columns => [ diff --git a/src/lib/Hydra/Schema/ViewJobs.pm b/src/lib/Hydra/Schema/ViewJobs.pm deleted file mode 100644 index ce32dee4..00000000 --- a/src/lib/Hydra/Schema/ViewJobs.pm +++ /dev/null @@ -1,157 +0,0 @@ -use utf8; -package Hydra::Schema::ViewJobs; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Hydra::Schema::ViewJobs - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 COMPONENTS LOADED - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->load_components("+Hydra::Component::ToJSON"); - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("ViewJobs"); - -=head1 ACCESSORS - -=head2 project - - data_type: 'text' - is_foreign_key: 1 - is_nullable: 0 - -=head2 view_ - - data_type: 'text' - is_foreign_key: 1 - is_nullable: 0 - -=head2 job - - data_type: 'text' - is_nullable: 0 - -=head2 attrs - - data_type: 'text' - is_nullable: 0 - -=head2 isprimary - - data_type: 'integer' - default_value: 0 - is_nullable: 0 - -=head2 description - - data_type: 'text' - is_nullable: 1 - -=head2 jobset - - data_type: 'text' - is_nullable: 0 - -=head2 autorelease - - data_type: 'integer' - default_value: 0 - is_nullable: 0 - -=cut - -__PACKAGE__->add_columns( - "project", - { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, - "view_", - { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, - "job", - { data_type => "text", is_nullable => 0 }, - "attrs", - { data_type => "text", is_nullable => 0 }, - "isprimary", - { data_type => "integer", default_value => 0, is_nullable => 0 }, - "description", - { data_type => "text", is_nullable => 1 }, - "jobset", - { data_type => "text", is_nullable => 0 }, - "autorelease", - { data_type => "integer", default_value => 0, is_nullable => 0 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=item * L - -=item * L - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("project", "view_", "job", "attrs"); - -=head1 RELATIONS - -=head2 project - -Type: belongs_to - -Related object: L - -=cut - -__PACKAGE__->belongs_to( - "project", - "Hydra::Schema::Projects", - { name => "project" }, - { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" }, -); - -=head2 view - -Type: belongs_to - -Related object: L - -=cut - -__PACKAGE__->belongs_to( - "view", - "Hydra::Schema::Views", - { name => "view_", project => "project" }, - { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" }, -); - - -# Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-06-13 01:54:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hz912vBfYw0rHslBPqJW2w - -1; diff --git a/src/lib/Hydra/Schema/Views.pm b/src/lib/Hydra/Schema/Views.pm deleted file mode 100644 index 4109f034..00000000 --- a/src/lib/Hydra/Schema/Views.pm +++ /dev/null @@ -1,123 +0,0 @@ -use utf8; -package Hydra::Schema::Views; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Hydra::Schema::Views - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 COMPONENTS LOADED - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->load_components("+Hydra::Component::ToJSON"); - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("Views"); - -=head1 ACCESSORS - -=head2 project - - data_type: 'text' - is_foreign_key: 1 - is_nullable: 0 - -=head2 name - - data_type: 'text' - is_nullable: 0 - -=head2 description - - data_type: 'text' - is_nullable: 1 - -=head2 keep - - data_type: 'integer' - default_value: 0 - is_nullable: 0 - -=cut - -__PACKAGE__->add_columns( - "project", - { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, - "name", - { data_type => "text", is_nullable => 0 }, - "description", - { data_type => "text", is_nullable => 1 }, - "keep", - { data_type => "integer", default_value => 0, is_nullable => 0 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("project", "name"); - -=head1 RELATIONS - -=head2 project - -Type: belongs_to - -Related object: L - -=cut - -__PACKAGE__->belongs_to( - "project", - "Hydra::Schema::Projects", - { name => "project" }, - { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" }, -); - -=head2 viewjobs - -Type: has_many - -Related object: L - -=cut - -__PACKAGE__->has_many( - "viewjobs", - "Hydra::Schema::ViewJobs", - { "foreign.project" => "self.project", "foreign.view_" => "self.name" }, - undef, -); - - -# Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-06-13 01:54:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U23GZ3k5KZk2go6j2LYLHA - -1; diff --git a/src/root/edit-view.tt b/src/root/edit-view.tt deleted file mode 100644 index 301c0d45..00000000 --- a/src/root/edit-view.tt +++ /dev/null @@ -1,106 +0,0 @@ -[% WRAPPER layout.tt title=(create ? "New view" : "View $project.name:$view.name") %] -[% PROCESS common.tt %] -[% USE HTML %] - - -[% BLOCK renderJob %] - - - - - "$n") %] /> - "$baseName-name", name => "$baseName-name", value => "$job.jobset:$job.job") %] /> - "$baseName-description", name => "$baseName-description", value => job.description) %] /> - "$baseName-attrs", name => "$baseName-attrs", value => job.attrs) %] /> - -[% END %] - - -
- -
- -
- -
- view.name) %]/> -
-
- -
- -
- view.description) %]/> -
-
- - - - - - - - - - - - - [% n = 0 %] - [% FOREACH j IN jobs %] - [% INCLUDE renderJob baseName="job-$n" job=j %] - [% n = n + 1 %] - [% END %] - - - - -
Primary jobJob nameDescriptionConstraint
- -
- - [% IF !create %] - - - [% END %] -
- - - - - - [% INCLUDE renderJob job="" id="job-template" baseName="job-template" %] -
- - - - - -[% END %] diff --git a/src/root/project.tt b/src/root/project.tt index 4e2dbd8f..4251281f 100644 --- a/src/root/project.tt +++ b/src/root/project.tt @@ -20,9 +20,6 @@
  • Jobsets
  • Configuration
  • Releases
  • - [% IF views.size > 0 %] -
  • Views
  • - [% END %]
    @@ -99,34 +96,6 @@
    -
    - - [% IF views.size > 0 %] - -

    Project [% project.name %] has the following views:

    - - - - [% ELSE %] - -

    Project [% project.name %] has no views.

    - - [% END %] - - - -
    -