« Tapper/Schema/TestrunDB/ResultSet/Testrun.pm
↑ Summary
Tapper/Schema/TestrunDB/Result/ReportgroupArbitrary.pm »
| 1 | package Tapper::Schema::TestrunDB::Result::Host; | ||||||||||||||||||||
| 2 | 10 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||
| 3 | 10 | $Tapper::Schema::TestrunDB::Result::Host::VERSION = '5.0.12'; | |||||||||||||||||||
| 4 | # ABSTRACT: Tapper - Containing hosts used by Tapper | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 10 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 10 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 10 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 10 | ▶ | use parent 'DBIx::Class'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 10 | __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); | |||||||||||||||||||
| 13 | 10 | __PACKAGE__->table("host"); | |||||||||||||||||||
| 14 | 10 | __PACKAGE__->add_columns | |||||||||||||||||||
| 15 | ( | ||||||||||||||||||||
| 16 | "id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 11, is_auto_increment => 1, }, | ||||||||||||||||||||
| 17 | "name", { data_type => "VARCHAR", default_value => "", is_nullable => 1, size => 255, }, | ||||||||||||||||||||
| 18 | "comment", { data_type => "VARCHAR", default_value => "", is_nullable => 1, size => 255, }, | ||||||||||||||||||||
| 19 | "free", { data_type => "TINYINT", default_value => "0", is_nullable => 1, }, | ||||||||||||||||||||
| 20 | "active", { data_type => "TINYINT", default_value => "0", is_nullable => 1, }, | ||||||||||||||||||||
| 21 | "is_deleted", { data_type => "TINYINT", default_value => "0", is_nullable => 1, }, # deleted hosts need to be kept in db to show old testruns correctly | ||||||||||||||||||||
| 22 | "pool_free", { data_type => "INT", default_value => undef, is_nullable => 1, }, # number of free hosts in pool | ||||||||||||||||||||
| 23 | "pool_id", { data_type => "INT", default_value => undef, is_nullable => 1, is_foreign_key => 1, }, # pool host that this host is element of | ||||||||||||||||||||
| 24 | "created_at", { data_type => "TIMESTAMP", default_value => \'CURRENT_TIMESTAMP', is_nullable => 1, }, # ' | ||||||||||||||||||||
| 25 | "updated_at", { data_type => "DATETIME", default_value => undef, is_nullable => 1, }, | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 10 | __PACKAGE__->set_primary_key("id"); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 10 | (my $basepkg = __PACKAGE__) =~ s/::\w+$//; | |||||||||||||||||||
| 32 | 10 | __PACKAGE__->add_unique_constraint( constraint_name => [ qw/name/ ] ); | |||||||||||||||||||
| 33 | 10 | __PACKAGE__->has_many ( testrunschedulings => "${basepkg}::TestrunScheduling", { 'foreign.host_id' => 'self.id' }); | |||||||||||||||||||
| 34 | 10 | __PACKAGE__->has_many ( testrunrequestedhost => "${basepkg}::TestrunRequestedHost", { 'foreign.host_id' => 'self.id' }); | |||||||||||||||||||
| 35 | 10 | __PACKAGE__->has_many ( queuehosts => "${basepkg}::QueueHost", { 'foreign.host_id' => 'self.id' }); | |||||||||||||||||||
| 36 | 10 | __PACKAGE__->has_many ( denied_from_queue => "${basepkg}::DeniedHost", { 'foreign.host_id' => 'self.id' }); | |||||||||||||||||||
| 37 | 10 | __PACKAGE__->has_many ( features => "${basepkg}::HostFeature", { 'foreign.host_id' => 'self.id' }); | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 10 | __PACKAGE__->belongs_to( pool_master => "${basepkg}::Host", { 'foreign.id' => 'self.pool_id'},{ join_type => 'left' }); | |||||||||||||||||||
| 41 | 10 | __PACKAGE__->has_many ( pool_elements => "${basepkg}::Host", { 'foreign.pool_id' => 'self.id' }); | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub is_pool | ||||||||||||||||||||
| 46 | 14 | ▶ | { | ||||||||||||||||||
|
Subroutine
is_pool: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 47 | 14 | my($self) = @_; | |||||||||||||||||||
| 48 | 14 | ▶ | return defined($self->pool_free) || $self->pool_elements->count != 0; | ||||||||||||||||||
|
Condition66%2/3
defined $self->pool_free || $self->pool_elements->count != 0
MC/DC50%1/2
defined $self->pool_free || $self->pool_elements->count != 0
defined $self->pool_free
$self->pool_elements->count != 0
Truth table66%2/3
A || B
A= defined $self->pool_freeB= $self->pool_elements->count != 0
| |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub pool_count | ||||||||||||||||||||
| 53 | 9 | ▶ | { | ||||||||||||||||||
|
Subroutine
pool_count: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 54 | 9 | my ($self, $new_count) = @_; | |||||||||||||||||||
| 55 | 9 | ▶ | if (defined $new_count) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | # if host is not a pool yet, we make it a pool but don't need to care for existing elements | ||||||||||||||||||||
| 57 | 3 | ▶ | if (not $self->is_pool) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 1 | $self->pool_free($new_count); | |||||||||||||||||||
| 59 | 1 | $self->free(1); | |||||||||||||||||||
| 60 | 1 | $self->update; | |||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||
| 62 | # need a transaction because its possible that the number | ||||||||||||||||||||
| 63 | # of running tests changes between query and setting | ||||||||||||||||||||
| 64 | 2 | my $guard = $self->result_source->schema->txn_scope_guard; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 2 | my $new_free = $new_count - $self->testrunschedulings->search({status => 'running'})->count; | |||||||||||||||||||
| 67 | 2 | $self->pool_free($new_free); | |||||||||||||||||||
| 68 | 2 | ▶ | if ($self->pool_free > 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 1 | $self->free(1); | |||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||
| 71 | 1 | $self->free(0); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 2 | $self->update; | |||||||||||||||||||
| 74 | 2 | $guard->commit; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||
| 77 | 6 | ▶ | return undef unless $self->is_pool; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 5 | return($self->pool_free + $self->testrunschedulings->search({status => 'running'})->count); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 10 | 1; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||