line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::Model; |
2
|
|
|
|
|
|
|
# git description: v5.0.1-1-g08fbd72 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
5
|
|
|
|
|
|
|
$Tapper::Model::VERSION = '5.0.2'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Tapper - Context sensitive connected DBIC schema |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
94446
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
76
|
|
9
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
66
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
61
|
use 5.010; |
|
3
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# avoid these warnings |
14
|
|
|
|
|
|
|
# Subroutine initialize redefined at /2home/ss5/perl510/lib/site_perl/5.10.0/Class/C3.pm line 70. |
15
|
|
|
|
|
|
|
# Subroutine uninitialize redefined at /2home/ss5/perl510/lib/site_perl/5.10.0/Class/C3.pm line 88. |
16
|
|
|
|
|
|
|
# Subroutine reinitialize redefined at /2home/ss5/perl510/lib/site_perl/5.10.0/Class/C3.pm line 101. |
17
|
|
|
|
|
|
|
# by forcing correct load order. |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
1227
|
use English; |
|
3
|
|
|
|
|
8347
|
|
|
3
|
|
|
|
|
12
|
|
20
|
3
|
|
|
3
|
|
2183
|
use Class::C3; |
|
3
|
|
|
|
|
4838
|
|
|
3
|
|
|
|
|
11
|
|
21
|
3
|
|
|
3
|
|
1189
|
use MRO::Compat; |
|
3
|
|
|
|
|
3304
|
|
|
3
|
|
|
|
|
70
|
|
22
|
3
|
|
|
3
|
|
1126
|
use Tapper::Config; |
|
3
|
|
|
|
|
71516
|
|
|
3
|
|
|
|
|
99
|
|
23
|
3
|
|
|
3
|
|
1085
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
589
|
|
|
3
|
|
|
|
|
12
|
|
24
|
3
|
|
|
3
|
|
1313
|
use Tapper::Schema::TestrunDB; |
|
3
|
|
|
|
|
2137860
|
|
|
3
|
|
|
|
|
2499
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $or_testrundb_schema; |
27
|
|
|
|
|
|
|
our @EXPORT_OK = qw(model get_hardware_overview); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub model { |
31
|
|
|
|
|
|
|
return $or_testrundb_schema //= Tapper::Schema::TestrunDB->connect( |
32
|
5
|
|
66
|
5
|
1
|
2130441
|
@{Tapper::Config->subconfig->{database}{TestrunDB}}{qw/ dsn username password /},{}, |
|
2
|
|
|
|
|
17
|
|
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get_or_create_owner { |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
1
|
761
|
my ($login) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
4
|
return model('TestrunDB') |
42
|
|
|
|
|
|
|
->resultset('Owner') |
43
|
|
|
|
|
|
|
->find_or_create({ login => $login },{ login => $login }) |
44
|
|
|
|
|
|
|
->id() |
45
|
|
|
|
|
|
|
; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_hardware_overview { |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
1
|
1
|
22037
|
my ($host_id) = @_; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
4
|
my $host = model('TestrunDB') |
55
|
|
|
|
|
|
|
->resultset('Host') |
56
|
|
|
|
|
|
|
->search({ 'me.id' => $host_id }, { prefetch => 'features' }) |
57
|
|
|
|
|
|
|
->first() |
58
|
|
|
|
|
|
|
; |
59
|
|
|
|
|
|
|
|
60
|
1
|
50
|
|
|
|
10729
|
if (! $host ) { |
61
|
0
|
|
|
|
|
0
|
return qq(Host with id '$host_id' not found); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
112
|
return { map { $_->entry => $_->value } $host->features }; |
|
4
|
|
|
|
|
902
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my @a_supported_storage_engines = qw/ mysql SQLite Pg /; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $fn_execute_raw_sql = sub { |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my ( $or_schema, $hr_params ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if (! $hr_params->{query_name} ) { |
76
|
|
|
|
|
|
|
die 'missing query name'; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
require Module::Load; |
80
|
|
|
|
|
|
|
return $or_schema->storage->dbh_do( |
81
|
|
|
|
|
|
|
sub { |
82
|
|
|
|
|
|
|
my ( $or_storage, $or_dbh, $hr_params ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my ( $s_query_ns, $s_query_sub ) = ( $hr_params->{query_name} =~ /(.*)::(.*)/ ); |
85
|
|
|
|
|
|
|
my $s_storage_engine = ( split /::/, ref $or_storage )[-1]; |
86
|
|
|
|
|
|
|
my $s_schema = ( split /::/, ref $or_storage->schema )[-1]; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
if ( scalar(grep {$_ eq $s_storage_engine} @a_supported_storage_engines) < 1 ) { |
89
|
|
|
|
|
|
|
die 'storage engine not supported'; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $s_module = 'Tapper::RawSQL::' . $s_schema . '::' . $s_query_ns; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Module::Load::load( $s_module ); |
95
|
|
|
|
|
|
|
if ( my $fh_query_sub = $s_module->can($s_query_sub) ) { |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $hr_query_vals = $hr_params->{query_vals}; |
98
|
|
|
|
|
|
|
my $hr_query = $fh_query_sub->( $hr_query_vals ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
if ( my $s_sql = $hr_query->{$s_storage_engine} || $hr_query->{default} ) { |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# replace own placeholer with sql placeholder ("?") |
103
|
|
|
|
|
|
|
my @a_vals; |
104
|
|
|
|
|
|
|
$s_sql =~ s/ |
105
|
|
|
|
|
|
|
\$(.+?)\$ |
106
|
|
|
|
|
|
|
/ |
107
|
|
|
|
|
|
|
ref $hr_query_vals->{$1} eq 'ARRAY' |
108
|
|
|
|
|
|
|
? ( push( @a_vals, @{$hr_query_vals->{$1}} ) && join ',', map { q#?# } @{$hr_query_vals->{$1}} ) |
109
|
|
|
|
|
|
|
: ( push( @a_vals, $hr_query_vals->{$1} ) && q#?# ) |
110
|
|
|
|
|
|
|
/egx; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if ( $hr_params->{debug} ) { |
113
|
|
|
|
|
|
|
require Carp; |
114
|
|
|
|
|
|
|
Carp::cluck( $s_sql . '(' . join( q#,#, @a_vals ) . ')' ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
if ( $hr_params->{fetch_type} ) { |
118
|
|
|
|
|
|
|
if ( $hr_params->{fetch_type} eq q|$$| ) { |
119
|
|
|
|
|
|
|
return $or_dbh->selectrow_arrayref( $s_sql, { Columns => [ 0 ] }, @a_vals )->[0] |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
elsif ( $hr_params->{fetch_type} eq q|$@| ) { |
122
|
|
|
|
|
|
|
return $or_dbh->selectrow_arrayref( $s_sql, {}, @a_vals ) |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
elsif ( $hr_params->{fetch_type} eq q|$%| ) { |
125
|
|
|
|
|
|
|
return $or_dbh->selectrow_hashref ( $s_sql, {}, @a_vals ) |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif ( $hr_params->{fetch_type} eq q|@$| ) { |
128
|
|
|
|
|
|
|
return $or_dbh->selectcol_arrayref( $s_sql, {}, @a_vals ) |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
elsif ( $hr_params->{fetch_type} eq q|@@| ) { |
131
|
|
|
|
|
|
|
return $or_dbh->selectall_arrayref( $s_sql, {}, @a_vals ) |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
elsif ( $hr_params->{fetch_type} eq q|@%| ) { |
134
|
|
|
|
|
|
|
return $or_dbh->selectall_arrayref( $s_sql, { Slice => {} }, @a_vals ) |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
|
|
|
|
|
|
die 'unknown fetch type' |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else { |
143
|
|
|
|
|
|
|
die "raw sql statement isn't supported for storage engine '$s_storage_engine'"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
|
|
|
|
|
|
die 'named query does not exist'; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
}, |
151
|
|
|
|
|
|
|
$hr_params, |
152
|
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
return; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
}; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub fetch_raw_sql { |
159
|
0
|
|
|
0
|
0
|
|
my ( $or_schema, $s_name, $s_fetch_type, $ar_vals ) = @_; |
160
|
0
|
|
|
|
|
|
return $fn_execute_raw_sql->( $or_schema, $s_name, $s_fetch_type, $ar_vals ) |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub execute_raw_sql { |
164
|
0
|
|
|
0
|
0
|
|
my ( $or_schema, $s_name, $ar_vals ) = @_; |
165
|
0
|
|
|
|
|
|
return $fn_execute_raw_sql->( $or_schema, $s_name, undef, $ar_vals ) |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; # End of Tapper::Model |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=pod |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=encoding UTF-8 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 NAME |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Tapper::Model - Tapper - Context sensitive connected DBIC schema |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SYNOPSIS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
use Tapper::Model 'model'; |
183
|
|
|
|
|
|
|
my $testrun = model('TestrunDB')->schema('Testrun')->find(12); |
184
|
|
|
|
|
|
|
my $testrun = model('TestrunDB')->schema('Report')->find(7343); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 model |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Returns a connected schema, depending on the environment (live, |
189
|
|
|
|
|
|
|
development, test). |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
@param 1. $schema_basename - optional, default is "Tests", meaning the |
192
|
|
|
|
|
|
|
Schema "Tapper::Schema::Tests" |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
@return $schema |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 get_or_create_owner |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Search a owner based on login name. Create a owner with this login name if |
199
|
|
|
|
|
|
|
not found. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
@param string - login name |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
@return success - id (primary key of owner table) |
204
|
|
|
|
|
|
|
@return error - undef |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 get_hardware_overview |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Returns an overview of a given machine revision. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
@param int - machine lid |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
@return success - hash ref |
213
|
|
|
|
|
|
|
@return error - undef |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 AUTHORS |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=over 4 |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=back |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Advanced Micro Devices, Inc.. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This is free software, licensed under: |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |