Remove support for views
They're replaced by aggregates, which are declarative, faster, and have a better interface.
This commit is contained in:
@ -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});
|
||||
|
@ -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;
|
@ -256,36 +256,6 @@ __PACKAGE__->has_many(
|
||||
undef,
|
||||
);
|
||||
|
||||
=head2 viewjobs
|
||||
|
||||
Type: has_many
|
||||
|
||||
Related object: L<Hydra::Schema::ViewJobs>
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"viewjobs",
|
||||
"Hydra::Schema::ViewJobs",
|
||||
{ "foreign.project" => "self.name" },
|
||||
undef,
|
||||
);
|
||||
|
||||
=head2 views
|
||||
|
||||
Type: has_many
|
||||
|
||||
Related object: L<Hydra::Schema::Views>
|
||||
|
||||
=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</projectmembers> -> 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 => [
|
||||
|
@ -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<Hydra::Component::ToJSON>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->load_components("+Hydra::Component::ToJSON");
|
||||
|
||||
=head1 TABLE: C<ViewJobs>
|
||||
|
||||
=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</project>
|
||||
|
||||
=item * L</view_>
|
||||
|
||||
=item * L</job>
|
||||
|
||||
=item * L</attrs>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->set_primary_key("project", "view_", "job", "attrs");
|
||||
|
||||
=head1 RELATIONS
|
||||
|
||||
=head2 project
|
||||
|
||||
Type: belongs_to
|
||||
|
||||
Related object: L<Hydra::Schema::Projects>
|
||||
|
||||
=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<Hydra::Schema::Views>
|
||||
|
||||
=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;
|
@ -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<Hydra::Component::ToJSON>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->load_components("+Hydra::Component::ToJSON");
|
||||
|
||||
=head1 TABLE: C<Views>
|
||||
|
||||
=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</project>
|
||||
|
||||
=item * L</name>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->set_primary_key("project", "name");
|
||||
|
||||
=head1 RELATIONS
|
||||
|
||||
=head2 project
|
||||
|
||||
Type: belongs_to
|
||||
|
||||
Related object: L<Hydra::Schema::Projects>
|
||||
|
||||
=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<Hydra::Schema::ViewJobs>
|
||||
|
||||
=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;
|
Reference in New Issue
Block a user