| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tapper::Schema::TestrunDB::Result::Queue; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
|
3
|
|
|
|
|
|
|
$Tapper::Schema::TestrunDB::Result::Queue::VERSION = '5.0.9'; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Tapper - Containing queues of testruns |
|
5
|
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
2863
|
use strict; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
325
|
|
|
7
|
7
|
|
|
7
|
|
24
|
use warnings; |
|
|
7
|
|
|
|
|
7
|
|
|
|
7
|
|
|
|
|
152
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
22
|
use parent 'DBIx::Class'; |
|
|
7
|
|
|
|
|
9
|
|
|
|
7
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); |
|
12
|
|
|
|
|
|
|
__PACKAGE__->table("queue"); |
|
13
|
|
|
|
|
|
|
__PACKAGE__->add_columns |
|
14
|
|
|
|
|
|
|
( |
|
15
|
|
|
|
|
|
|
"id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 11, is_auto_increment => 1, }, |
|
16
|
|
|
|
|
|
|
"name", { data_type => "VARCHAR", default_value => "", is_nullable => 1, size => 255, }, |
|
17
|
|
|
|
|
|
|
"priority", { data_type => "INT", default_value => 0, is_nullable => 0, size => 10, }, |
|
18
|
|
|
|
|
|
|
"runcount", { data_type => "INT", default_value => 0, is_nullable => 0, size => 10, }, # aux for algorithm |
|
19
|
|
|
|
|
|
|
"active", { data_type => "INT", default_value => 0, is_nullable => 1, size => 1, }, |
|
20
|
|
|
|
|
|
|
"is_deleted", { data_type => "TINYINT", default_value => "0", is_nullable => 1, }, # deleted queues need to be kept in db to show old testruns correctly |
|
21
|
|
|
|
|
|
|
"created_at", { data_type => "TIMESTAMP", default_value => \'CURRENT_TIMESTAMP', is_nullable => 1, }, #' emacs highlight bug |
|
22
|
|
|
|
|
|
|
"updated_at", { data_type => "DATETIME", default_value => undef, is_nullable => 1, }, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
(my $basepkg = __PACKAGE__) =~ s/::\w+$//; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__->set_primary_key("id"); |
|
28
|
|
|
|
|
|
|
__PACKAGE__->add_unique_constraint( unique_queue_name => [ qw/name/ ], ); |
|
29
|
|
|
|
|
|
|
__PACKAGE__->has_many ( testrunschedulings => 'Tapper::Schema::TestrunDB::Result::TestrunScheduling', { 'foreign.queue_id' => 'self.id' }); |
|
30
|
|
|
|
|
|
|
__PACKAGE__->has_many ( queuehosts => "${basepkg}::QueueHost", { 'foreign.queue_id' => 'self.id' }); |
|
31
|
|
|
|
|
|
|
__PACKAGE__->has_many ( deniedhosts => "${basepkg}::DeniedHost", { 'foreign.queue_id' => 'self.id' }); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# -------------------- methods on results -------------------- |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub queued_testruns |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->testrunschedulings->search({ |
|
41
|
|
|
|
|
|
|
status => 'schedule' |
|
42
|
|
|
|
|
|
|
}, |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
|
|
|
|
|
|
order_by => 'testrun_id' |
|
45
|
|
|
|
|
|
|
}); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_first_fitting |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
0
|
|
|
0
|
1
|
|
my ($self, $free_hosts) = @_; |
|
52
|
0
|
|
|
|
|
|
my $jobs = $self->queued_testruns; |
|
53
|
0
|
|
|
|
|
|
foreach my $job ($jobs->all()) { |
|
54
|
0
|
0
|
|
|
|
|
if (my $host = $job->fits($free_hosts)) { |
|
55
|
0
|
|
|
|
|
|
$job->host_id ($host->id); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ($job->testrun->scenario_element) { |
|
58
|
0
|
|
|
|
|
|
$job->testrun->scenario_element->is_fitted(1); |
|
59
|
0
|
|
|
|
|
|
$job->testrun->scenario_element->update(); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
0
|
|
|
|
|
|
return $job; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
0
|
|
|
|
|
|
return; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub to_string |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $format = join( $Tapper::Schema::TestrunDB::DELIM, qw/%s %s %s %s %s %s %s %s %s %s %s %s %s %s /, ''); |
|
73
|
|
|
|
|
|
|
sprintf ( |
|
74
|
|
|
|
|
|
|
$format, |
|
75
|
|
|
|
|
|
|
map { |
|
76
|
0
|
0
|
|
|
|
|
defined $self->$_ |
|
77
|
|
|
|
|
|
|
? $self->$_ |
|
78
|
|
|
|
|
|
|
: $Tapper::Schema::TestrunDB::NULL |
|
79
|
0
|
|
|
|
|
|
} @{$self->result_source->{_ordered_columns} } |
|
|
0
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub is_member |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
1
|
|
my ($head, @tail) = @_; |
|
87
|
0
|
|
|
|
|
|
grep { $head->id eq $_->id } @tail; |
|
|
0
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub ordered_preconditions |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my @done = (); |
|
96
|
0
|
|
|
|
|
|
my %seen = (); |
|
97
|
0
|
|
|
|
|
|
my @todo = (); |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
@todo = $self->preconditions->search({}, {order_by => 'succession'})->all; |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
while (my $head = shift @todo) |
|
102
|
|
|
|
|
|
|
{ |
|
103
|
0
|
0
|
|
|
|
|
if ($seen{$head->id}) |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
0
|
0
|
|
|
|
|
push @done, $head unless is_member($head, @done); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
else |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
0
|
|
|
|
|
|
$seen{$head->id} = 1; |
|
110
|
0
|
|
|
|
|
|
my @pre_todo = $head->child_preconditions->search({}, { order_by => 'succession' } )->all; |
|
111
|
0
|
|
|
|
|
|
unshift @todo, @pre_todo, $head; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
0
|
|
|
|
|
|
return @done; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub producer |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $producer_class = "Tapper::MCP::Scheduler::PreconditionProducer::".$self->producer; |
|
123
|
0
|
|
|
|
|
|
eval "use $producer_class"; ## no critic (ProhibitStringyEval) |
|
124
|
0
|
0
|
|
|
|
|
return $producer_class->new unless $@; |
|
125
|
0
|
|
|
|
|
|
return; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub produce |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
0
|
|
|
0
|
1
|
|
my ($self, $request) = @_; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $producer = $self->producer; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if (not $producer) { |
|
136
|
0
|
|
|
|
|
|
warn "Queue ".$self->name." does not have an associated producer"; |
|
137
|
|
|
|
|
|
|
} else { |
|
138
|
0
|
|
|
|
|
|
print STDERR "Queue.producer: ", Dumper($producer); |
|
139
|
0
|
|
|
|
|
|
return $producer->produce($request); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub update_content { |
|
145
|
0
|
|
|
0
|
1
|
|
my ($self, $args) =@_; |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
require DateTime; |
|
148
|
0
|
0
|
|
|
|
|
$self->priority( $args->{priority} ) if exists($args->{priority}); |
|
149
|
0
|
0
|
|
|
|
|
$self->active( $args->{active} ) if exists($args->{active}); |
|
150
|
0
|
|
|
|
|
|
$self->updated_at( DateTime->now->strftime('%F %T') ); |
|
151
|
0
|
|
|
|
|
|
$self->update; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return $self->id; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
__END__ |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=pod |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=encoding UTF-8 |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 NAME |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Tapper::Schema::TestrunDB::Result::Queue - Tapper - Containing queues of testruns |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 queued_testruns |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Return all scheduled testruns in current queue. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 get_first_fitting |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Return first fitting testrun according to the scheduling rules. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 to_string |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Return a readable repesentation of Queue. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 is_member($head, @tail) |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Checks if the first element is already in the list of the remaining |
|
183
|
|
|
|
|
|
|
elements. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 ordered_preconditions |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns all preconditions in the order they need to be installed. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 producer |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Return instance of PreconditionProducer according to associated |
|
192
|
|
|
|
|
|
|
producer. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 produce |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Return associated producer. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 update_content |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Update I<priority> and I<active> flags. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 AUTHORS |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=over 4 |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=back |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Advanced Micro Devices, Inc.. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This is free software, licensed under: |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |