| 1 | # | ||||||||||||
| 2 | # CA::WAAE - Perl Interface to CA's AutoSys job control. | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # Original CA::AutoSys code: | ||||||||||||
| 5 | # Copyright (c) 2007 Sinisa Susnjar <sini@cpan.org> | ||||||||||||
| 6 | # See LICENSE for terms of distribution. | ||||||||||||
| 7 | # | ||||||||||||
| 8 | # This library is free software; you can redistribute it and/or | ||||||||||||
| 9 | # modify it under the terms of the GNU Lesser General Public | ||||||||||||
| 10 | # License as published by the Free Software Foundation; either | ||||||||||||
| 11 | # version 2.1 of the License, or (at your option) any later version. | ||||||||||||
| 12 | # | ||||||||||||
| 13 | # This library is distributed in the hope that it will be useful, | ||||||||||||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||
| 16 | # Lesser General Public License for more details. | ||||||||||||
| 17 | # | ||||||||||||
| 18 | # You should have received a copy of the GNU Lesser General Public | ||||||||||||
| 19 | # License along with this library; if not, write to the Free Software | ||||||||||||
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||||||||||
| 21 | # | ||||||||||||
| 22 | |||||||||||||
| 23 | package CA::WAAE; | ||||||||||||
| 24 | |||||||||||||
| 25 | 1 | require CA::WAAE::Job; | |||||||||||
| 26 | |||||||||||||
| 27 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 1 | ▶ | use DBI; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | |||||||||||||
| 31 | 1 | our $VERSION = '0.03'; | |||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||
| 34 | 0 | my $self = {}; | |||||||||||
| 35 | 0 | my $class = shift(); | |||||||||||
| 36 | |||||||||||||
| 37 | 0 | my %args = @_; | |||||||||||
| 38 | 0 | for my $attr (qw(dsn user password dbh db_type table_prefix schema)) { | |||||||||||
| 39 | 0 | $self->{$attr} = $args{$attr}; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | if ( !$self->{dbh} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | ▶ | die "no dbh/dsn given in new()" if !$self->{dsn}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | $self->{dbh} | ||||||||||||
| 45 | = DBI->connect( $self->{dsn}, $self->{user}, $self->{password}, | ||||||||||||
| 46 | 0 | { PrintError => 0, RaiseError => 1 } ); | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | my $db_type = $self->{dbh}{Driver}{Name}; | |||||||||||
| 50 | 0 | ▶ | if ( $db_type eq 'Oracle' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | |||||||||||||
| 52 | # Default and untaint schema/table_prefix | ||||||||||||
| 53 | 0 | ▶ | $self->{schema} ||= 'aedbadmin'; | ||||||||||
|
Condition0%0/2
$self->{"schema"} ||= "aedbadmin"
MC/DC0%0/1
$self->{"schema"} ||= "aedbadmin"
$self->{"schema"}
Truth table0%0/2
A
A= $self->{"schema"}
| |||||||||||||
| 54 | 0 | $self->{schema} =~ /(\w+)/; | |||||||||||
| 55 | 0 | $self->{schema} = $1; | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | $self->{table_prefix} ||= 'ujo_'; | ||||||||||
|
Condition0%0/2
$self->{"table_prefix"} ||= "ujo_"
MC/DC0%0/1
$self->{"table_prefix"} ||= "ujo_"
$self->{"table_prefix"}
Truth table0%0/2
A
A= $self->{"table_prefix"}
| |||||||||||||
| 58 | 0 | $self->{table_prefix} =~ /([\w.]+)/; | |||||||||||
| 59 | 0 | $self->{table_prefix} = $1; | |||||||||||
| 60 | |||||||||||||
| 61 | 0 | $self->{dbh}->do("alter session set current_schema=$self->{schema}"); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 0 | bless $self, $class; | |||||||||||
| 65 | 0 | return $self; | |||||||||||
| 66 | } # new() | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | sub _query { | ||||||||||
|
Subroutine
_query: not called CC=2 SCAR=17.9
| |||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||
| 70 | 0 | ▶ | my $prefix = $self->{table_prefix} || ''; | ||||||||||
|
Condition0%0/2
$self->{'table_prefix'} || ''
MC/DC0%0/1
$self->{'table_prefix'} || ''
$self->{'table_prefix'}
Truth table0%0/2
A
A= $self->{'table_prefix'}
| |||||||||||||
| 71 | 0 | my $query = <<SQL; | |||||||||||
| 72 | select j.*, s.*, j2.job_name as box_name, m.name job_type_name | ||||||||||||
| 73 | from ${prefix}job j join ${prefix}job_status s | ||||||||||||
| 74 | on j.joid = s.joid | ||||||||||||
| 75 | left outer join ${prefix}job j2 | ||||||||||||
| 76 | on j.box_joid = j2.joid | ||||||||||||
| 77 | left outer join ${prefix}meta_types m | ||||||||||||
| 78 | on j.job_type = m.type_id and m.sub_type = 'STRINGS' | ||||||||||||
| 79 | SQL | ||||||||||||
| 80 | 0 | return $query; | |||||||||||
| 81 | } # _query() | ||||||||||||
| 82 | |||||||||||||
| 83 | 0 | ▶ | sub find_jobs { | ||||||||||
|
Subroutine
find_jobs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 84 | 0 | my $self = shift(); | |||||||||||
| 85 | 0 | my $job_name = shift(); | |||||||||||
| 86 | |||||||||||||
| 87 | 0 | $job_name =~ s/\*/%/g; | |||||||||||
| 88 | 0 | ▶ | my $op = ( $job_name =~ /[%?]/ ) ? 'like' : '='; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | |||||||||||||
| 90 | 0 | my $query = $self->_query() . <<SQL; | |||||||||||
| 91 | where j.job_name $op ? | ||||||||||||
| 92 | order by j.joid | ||||||||||||
| 93 | SQL | ||||||||||||
| 94 | 0 | my $sth = $self->{dbh}->prepare($query); | |||||||||||
| 95 | 0 | $sth->execute($job_name); | |||||||||||
| 96 | |||||||||||||
| 97 | return CA::WAAE::JobList->new( | ||||||||||||
| 98 | parent => $self->{parent}, | ||||||||||||
| 99 | database_handle => $self->{dbh}, | ||||||||||||
| 100 | statement_handle => $sth, | ||||||||||||
| 101 | table_prefix => $self->{table_prefix}, | ||||||||||||
| 102 | 0 | ); | |||||||||||
| 103 | |||||||||||||
| 104 | } # find_jobs() | ||||||||||||
| 105 | |||||||||||||
| 106 | 0 | ▶ | sub job_list { | ||||||||||
|
Subroutine
job_list: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 107 | 0 | my $self = shift; | |||||||||||
| 108 | 0 | my $h = $self->find_jobs(@_); | |||||||||||
| 109 | 0 | my @list; | |||||||||||
| 110 | 0 | ▶ | while ( my $job = $h->next_job() ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 0 | push @list, $job; | |||||||||||
| 112 | } | ||||||||||||
| 113 | 0 | ▶ | return wantarray ? @list : \@list; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | } | ||||||||||||
| 115 | |||||||||||||
| 116 | 0 | ▶ | sub send_event { | ||||||||||
|
Subroutine
send_event: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||
| 117 | 0 | my $self = shift(); | |||||||||||
| 118 | 0 | my ( $job_name, $event, $status, $event_time ); | |||||||||||
| 119 | 0 | ▶ | if (@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | 0 | my %args = @_; | |||||||||||
| 121 | 0 | ▶ | $job_name = $args{job_name} ? $args{job_name} : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | 0 | ▶ | $event = $args{event} ? $args{event} : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | 0 | ▶ | $status = $args{status} ? $args{status} : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | 0 | ▶ | $event_time = $args{event_time} ? $args{event_time} : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 0 | my $dbh = $self->{dbh}; | |||||||||||
| 128 | 0 | my $db_type = $self->{db_type}; | |||||||||||
| 129 | |||||||||||||
| 130 | 0 | $_ = $dbh->quote($_) for $job_name, $event, $status, $event_time; | |||||||||||
| 131 | 0 | ▶ | my $prefix = $self->{table_prefix} || ''; | ||||||||||
|
Condition0%0/2
$self->{'table_prefix'} || ''
MC/DC0%0/1
$self->{'table_prefix'} || ''
$self->{'table_prefix'}
Truth table0%0/2
A
A= $self->{'table_prefix'}
| |||||||||||||
| 132 | 0 | ▶ | my $sql | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 133 | = ( $db_type eq 'Oracle' ) | ||||||||||||
| 134 | ? "BEGIN :rtn := ${prefix}sendevent( $event, $job_name, $status, '', $event_time ); END;" | ||||||||||||
| 135 | : qq( exec sendevent $event, $job_name, $status, '', $event_time, '' ); | ||||||||||||
| 136 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||
| 137 | |||||||||||||
| 138 | 0 | my $rc; | |||||||||||
| 139 | 0 | ▶ | $sth->bind_param_inout( ':rtn', \$rc, 128 ) if $db_type eq 'Oracle'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 140 | 0 | $sth->execute(); | |||||||||||
| 141 | 0 | ▶ | ($rc) = $sth->fetchrow_array() if $db_type ne 'Oracle'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 142 | |||||||||||||
| 143 | 0 | return $rc; | |||||||||||
| 144 | } # send_event() | ||||||||||||
| 145 | |||||||||||||
| 146 | 1 | 1; | |||||||||||
| 147 | __END__ | ||||||||||||