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