1 |
## ------------------------------------------------------------------------- |
2 |
## $Id: Admin.pm,v 1.10 2003/02/23 23:50:06 cvsmax Exp $ |
3 |
## ------------------------------------------------------------------------- |
4 |
## $Log: Admin.pm,v $ |
5 |
## ------------------------------------------------------------------------- |
6 |
|
7 |
|
8 |
package OEF::YAA::Jobs; |
9 |
|
10 |
use strict; |
11 |
use warnings; |
12 |
|
13 |
use base qw( DesignPattern::Object ); |
14 |
use base qw( OEF::API::Abstract ); |
15 |
|
16 |
|
17 |
#use Data::Dumper; |
18 |
#use Data::Mungle::Transform::Deep qw( merge_to expand ); |
19 |
#use shortcuts qw( run_cmd ); |
20 |
|
21 |
# get logger instance |
22 |
my $logger = Log::Dispatch::Config->instance; |
23 |
|
24 |
|
25 |
#my $bizWorks = $main::bizWorks; |
26 |
my $bizProcess = $main::bizProcess; |
27 |
#my $process = $main::bizProcess; |
28 |
|
29 |
#print Dumper($bizProcess); |
30 |
#push @{$process->{app}->{use_databases}}, 'control'; |
31 |
#my $boot = $main::boot; |
32 |
#$boot->_bootDatabases(); |
33 |
|
34 |
#our ($logger, $bizWorks, $bizProcess, $process, $boot); |
35 |
|
36 |
# ============================== |
37 |
# api-method-declarations |
38 |
# ============================== |
39 |
# remote method declaration |
40 |
|
41 |
sub _api_init { |
42 |
my $self = shift; |
43 |
#return; |
44 |
my $procs = [ |
45 |
{ |
46 |
name => "getTaskList", |
47 |
version => "0.02", |
48 |
hidden => 0, |
49 |
code => \&getTaskList, |
50 |
signature => [ 'struct string' ], |
51 |
help => "", |
52 |
}, |
53 |
{ |
54 |
name => "getTaskInfo", |
55 |
version => "0.02", |
56 |
hidden => 0, |
57 |
code => \&getTaskInfo, |
58 |
signature => [ 'struct string' ], |
59 |
help => "", |
60 |
}, |
61 |
{ |
62 |
name => "runTask", |
63 |
version => "0.02", |
64 |
hidden => 0, |
65 |
code => \&runTask, |
66 |
signature => [ 'string string' ], |
67 |
help => "", |
68 |
}, |
69 |
]; |
70 |
$self->register($procs); |
71 |
} |
72 |
|
73 |
|
74 |
# ============================== |
75 |
# methods |
76 |
|
77 |
|
78 |
sub getTaskList { |
79 |
my $srv = shift; |
80 |
my $crit_key = shift; |
81 |
$crit_key ||= ''; |
82 |
|
83 |
$logger->info( __PACKAGE__ . "->getTaskList( crit_key $crit_key )" ); |
84 |
|
85 |
#print Dumper($bizProcess); |
86 |
|
87 |
my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs}; |
88 |
|
89 |
# build xpath query database |
90 |
my $xpq_db = { |
91 |
'all-jobs-unfiltered' => '*/*', |
92 |
}; |
93 |
my $crit_db = { |
94 |
'all-jobs' => '/*', |
95 |
'to-backend' => '@source="backend" and (@action="import" or @action="load")', |
96 |
'to-frontend' => '@target="frontend"', |
97 |
}; |
98 |
$crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})"; |
99 |
|
100 |
# select xpath query by criteria |
101 |
my $xpq = ''; |
102 |
if ($crit_key) { |
103 |
if ($xpq_db->{$crit_key}) { |
104 |
$xpq = $xpq_db->{$crit_key}; |
105 |
} else { |
106 |
my $crit = $crit_db->{$crit_key}; |
107 |
if ($crit) { |
108 |
$xpq = "*/target[*/*[$crit]]"; |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
# issue the query |
114 |
my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); |
115 |
$mdbe->sendQuery($xpq); |
116 |
$mdbe->circumflex('result'); |
117 |
my $tasks = $mdbe->toSimpleTree(); |
118 |
|
119 |
#print Dumper($tasks); |
120 |
|
121 |
return $tasks; |
122 |
} |
123 |
|
124 |
|
125 |
sub _getTaskByName { |
126 |
#my $self = shift; |
127 |
my $name = shift; |
128 |
|
129 |
#print "getTaskByName!!!!!", "\n"; |
130 |
|
131 |
$logger->info( __PACKAGE__ . "->getTaskByName( name $name )" ); |
132 |
|
133 |
my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs}; |
134 |
|
135 |
# issue the query |
136 |
my $xpq = "*/target[\@name=\"$name\"]"; |
137 |
my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); |
138 |
$mdbe->sendQuery($xpq); |
139 |
my $task = $mdbe->toSimpleTree(); |
140 |
return $task; |
141 |
|
142 |
} |
143 |
|
144 |
sub getTaskInfo { |
145 |
my $self = shift; |
146 |
my $crit = shift; |
147 |
$crit ||= ''; |
148 |
|
149 |
$logger->info( __PACKAGE__ . "->getTaskInfo( crit $crit )" ); |
150 |
|
151 |
my $task = _getTaskByName($crit); |
152 |
#print Dumper($tasks); |
153 |
return $task; |
154 |
|
155 |
my $jobname = $task->{name}; |
156 |
|
157 |
my $status = { |
158 |
metadata => { |
159 |
description => $task->{description}, |
160 |
}, |
161 |
jobstatus => { |
162 |
running => $self->{_pcontrol}->{$jobname}->{running}, |
163 |
locked => $self->{_pcontrol}->{$jobname}->{locked}, |
164 |
}, |
165 |
}; |
166 |
|
167 |
return $status; |
168 |
} |
169 |
|
170 |
|
171 |
sub runTask { |
172 |
my $self = shift; |
173 |
my $crit = shift; |
174 |
$crit ||= ''; |
175 |
|
176 |
$logger->info( __PACKAGE__ . "->runTask( crit $crit )" ); |
177 |
|
178 |
#print "getTask - 1", "\n"; |
179 |
my $task = _getTaskByName($crit); |
180 |
#print "getTask - 1.1", "\n"; |
181 |
|
182 |
#print Dumper($task); |
183 |
|
184 |
# build command |
185 |
my $jobname = $task->{name}; |
186 |
my $command = "rap.pl $jobname"; |
187 |
|
188 |
# run |
189 |
# FIXME: what about asynchronous job execution? |
190 |
$self->{_pcontrol}->{$jobname}->{locked} = 1; |
191 |
$self->{_pcontrol}->{$jobname}->{running} = 1; |
192 |
|
193 |
run_cmd($command); |
194 |
|
195 |
=pod |
196 |
#system($command); |
197 |
my $base = $bizProcess->{app}->{config}->{paths}->{base}; |
198 |
$command = "$base/bin/$command"; |
199 |
print "command: $command", "\n"; |
200 |
my $in; my $out; my $err; |
201 |
#run $command, "", \$out, \$err or print "Could not execute $command.", "\n"; |
202 |
#my $result = run $command, '>&' or print "Could not execute $command.", "\n"; |
203 |
my $result = run $command, '2>&1' or print "Could not execute $command.", "\n"; |
204 |
#print Dumper($in, $out, $err); |
205 |
print "result: $result", "\n"; |
206 |
=cut |
207 |
|
208 |
$self->{_pcontrol}->{$jobname}->{locked} = 0; |
209 |
$self->{_pcontrol}->{$jobname}->{running} = 0; |
210 |
|
211 |
return 1; |
212 |
} |
213 |
|
214 |
|
215 |
|
216 |
|
217 |
1; |
218 |
__END__ |