| 2 |
## $Id$ |
## $Id$ |
| 3 |
## ------------------------------------------------------------------------- |
## ------------------------------------------------------------------------- |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.5 2003/05/13 09:07:36 joko |
| 6 |
|
## updated api method signatures |
| 7 |
|
## tasks running asynchronously |
| 8 |
|
## |
| 9 |
|
## Revision 1.4 2003/04/18 16:04:03 joko |
| 10 |
|
## new api method: getTaskGroups - returns job groups (just a hash) from some configuration slot |
| 11 |
|
## |
| 12 |
|
## Revision 1.3 2003/04/04 17:29:49 joko |
| 13 |
|
## updated signatures: session-based service |
| 14 |
|
## enabled method protection |
| 15 |
|
## |
| 16 |
|
## Revision 1.2 2003/03/28 03:07:41 joko |
| 17 |
|
## minor fix: 'run_cmd' required here |
| 18 |
|
## |
| 19 |
## Revision 1.1 2003/03/27 15:39:55 joko |
## Revision 1.1 2003/03/27 15:39:55 joko |
| 20 |
## initial commit, jobs -core and -api |
## initial commit, jobs -core and -api |
| 21 |
## |
## |
| 31 |
use base qw( OEF::API::Abstract ); |
use base qw( OEF::API::Abstract ); |
| 32 |
|
|
| 33 |
|
|
| 34 |
#use Data::Dumper; |
use Data::Dumper; |
| 35 |
#use Data::Mungle::Transform::Deep qw( merge_to expand ); |
#use Data::Mungle::Transform::Deep qw( merge_to expand ); |
| 36 |
#use shortcuts qw( run_cmd ); |
use shortcuts qw( run_cmd now ); |
| 37 |
|
|
| 38 |
# get logger instance |
# get logger instance |
| 39 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 61 |
my $procs = [ |
my $procs = [ |
| 62 |
{ |
{ |
| 63 |
name => "getTaskList", |
name => "getTaskList", |
| 64 |
version => "0.02", |
version => "0.03", |
| 65 |
hidden => 0, |
hidden => 0, |
| 66 |
code => \&getTaskList, |
code => \&getTaskList, |
| 67 |
signature => [ 'struct string' ], |
signature => [ |
| 68 |
|
'struct struct', # w/o session |
| 69 |
|
'struct struct struct', # session initialized (a struct containing a key 'RPCSESSID' will get propagated!) |
| 70 |
|
], |
| 71 |
help => "", |
help => "", |
| 72 |
|
protected => 1, |
| 73 |
}, |
}, |
| 74 |
{ |
{ |
| 75 |
name => "getTaskInfo", |
name => "getTaskInfo", |
| 76 |
version => "0.02", |
version => "0.03", |
| 77 |
hidden => 0, |
hidden => 0, |
| 78 |
code => \&getTaskInfo, |
code => \&getTaskInfo, |
| 79 |
signature => [ 'struct string' ], |
signature => [ 'struct string', 'struct string struct' ], |
| 80 |
help => "", |
help => "", |
| 81 |
|
protected => 1, |
| 82 |
}, |
}, |
| 83 |
{ |
{ |
| 84 |
name => "runTask", |
name => "runTask", |
| 85 |
version => "0.02", |
version => "0.03", |
| 86 |
hidden => 0, |
hidden => 0, |
| 87 |
code => \&runTask, |
code => \&runTask, |
| 88 |
signature => [ 'string string' ], |
#signature => [ 'string string', 'string string struct' ], |
| 89 |
|
signature => [ 'struct string', 'struct string struct' ], |
| 90 |
help => "", |
help => "", |
| 91 |
|
protected => 1, |
| 92 |
|
}, |
| 93 |
|
{ |
| 94 |
|
name => "getTaskGroups", |
| 95 |
|
version => "0.03", |
| 96 |
|
hidden => 0, |
| 97 |
|
code => \&getTaskGroups, |
| 98 |
|
signature => [ 'struct', 'struct struct' ], |
| 99 |
|
help => "", |
| 100 |
|
protected => 0, |
| 101 |
}, |
}, |
| 102 |
]; |
]; |
| 103 |
$self->register($procs); |
$self->register($procs); |
| 110 |
|
|
| 111 |
sub getTaskList { |
sub getTaskList { |
| 112 |
my $srv = shift; |
my $srv = shift; |
| 113 |
my $crit_key = shift; |
my $options = shift; |
| 114 |
$crit_key ||= ''; |
|
| 115 |
|
#print Dumper($options); |
| 116 |
$logger->info( __PACKAGE__ . "->getTaskList( crit_key $crit_key )" ); |
|
| 117 |
|
# XPath query expression (to be calculated here) |
| 118 |
|
my $xpq = ''; |
| 119 |
|
|
| 120 |
#print Dumper($bizProcess); |
#print Dumper($bizProcess); |
|
|
|
| 121 |
my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs}; |
my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs}; |
| 122 |
|
|
| 123 |
# build xpath query database |
if ($options->{filter}) { |
| 124 |
my $xpq_db = { |
|
| 125 |
'all-jobs-unfiltered' => '*/*', |
my $crit_key = $options->{filter}; |
| 126 |
}; |
$crit_key ||= ''; |
| 127 |
my $crit_db = { |
|
| 128 |
'all-jobs' => '/*', |
#$logger->info( __PACKAGE__ . "->getTaskList( crit_key|filter=$crit_key )" ); |
| 129 |
'to-backend' => '@source="backend" and (@action="import" or @action="load")', |
|
| 130 |
'to-frontend' => '@target="frontend"', |
# build xpath query database |
| 131 |
}; |
my $xpq_db = { |
| 132 |
$crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})"; |
'all-jobs-unfiltered' => '*/*', |
| 133 |
|
}; |
| 134 |
# select xpath query by criteria |
my $crit_db = { |
| 135 |
my $xpq = ''; |
'all-jobs' => '/*', |
| 136 |
if ($crit_key) { |
'to-backend' => '@source="backend" and (@action="import" or @action="load")', |
| 137 |
if ($xpq_db->{$crit_key}) { |
'to-frontend' => '@target="frontend"', |
| 138 |
$xpq = $xpq_db->{$crit_key}; |
}; |
| 139 |
} else { |
$crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})"; |
| 140 |
my $crit = $crit_db->{$crit_key}; |
|
| 141 |
if ($crit) { |
# select xpath query by criteria |
| 142 |
$xpq = "*/target[*/*[$crit]]"; |
#my $xpq = ''; |
| 143 |
|
if ($crit_key) { |
| 144 |
|
if ($xpq_db->{$crit_key}) { |
| 145 |
|
$xpq = $xpq_db->{$crit_key}; |
| 146 |
|
} else { |
| 147 |
|
my $crit = $crit_db->{$crit_key}; |
| 148 |
|
if ($crit) { |
| 149 |
|
$xpq = "*/target[*/*[$crit]]"; |
| 150 |
|
} |
| 151 |
} |
} |
| 152 |
} |
} |
| 153 |
|
|
| 154 |
|
} elsif (my $query = $options->{query}) { |
| 155 |
|
#$logger->info( __PACKAGE__ . "->getTaskList( query=$query )" ); |
| 156 |
|
$xpq = $query; |
| 157 |
|
#$xpq = '*/target[@name="dummy" or @name="' . $query . '"]'; |
| 158 |
|
$xpq = '*/target[@name="dummy" or contains(@name, "' . $query . '")]'; |
| 159 |
} |
} |
| 160 |
|
|
| 161 |
|
#$xpq = '*/target[@name="transfer process dev to frontend"]'; |
| 162 |
|
#$xpq = '/*[@name="transfer process dev to frontend"]'; |
| 163 |
|
#my $crit = '/*[@name="transfer process dev to frontend"]'; |
| 164 |
|
#my $crit = '@name="transfer process dev to frontend"'; |
| 165 |
|
#$xpq = "*/target[*/*[$crit]]"; |
| 166 |
|
#$xpq = "*/target[*/*[\@source=\"expekt\"]]"; |
| 167 |
|
#$xpq = "*/target[*/*[\@target=\"dev\" or \@name=\"dummy\"]]"; |
| 168 |
|
|
| 169 |
# issue the query |
# issue the query |
| 170 |
|
$logger->info( __PACKAGE__ . "->getTaskList( xpq=$xpq )" ); |
| 171 |
my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); |
my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); |
| 172 |
$mdbe->sendQuery($xpq); |
$mdbe->sendQuery($xpq); |
| 173 |
$mdbe->circumflex('result'); |
$mdbe->circumflex('result'); |
| 203 |
my $crit = shift; |
my $crit = shift; |
| 204 |
$crit ||= ''; |
$crit ||= ''; |
| 205 |
|
|
| 206 |
$logger->info( __PACKAGE__ . "->getTaskInfo( crit $crit )" ); |
$logger->info( __PACKAGE__ . "->getTaskInfo( crit=$crit )" ); |
| 207 |
|
|
| 208 |
my $task = _getTaskByName($crit); |
my $task = _getTaskByName($crit); |
|
#print Dumper($tasks); |
|
|
return $task; |
|
| 209 |
|
|
| 210 |
my $jobname = $task->{name}; |
my $jobname = $task->{name}; |
| 211 |
|
|
| 212 |
|
=pod |
| 213 |
my $status = { |
my $status = { |
| 214 |
metadata => { |
metadata => { |
| 215 |
description => $task->{description}, |
description => $task->{description}, |
| 219 |
locked => $self->{_pcontrol}->{$jobname}->{locked}, |
locked => $self->{_pcontrol}->{$jobname}->{locked}, |
| 220 |
}, |
}, |
| 221 |
}; |
}; |
| 222 |
|
=cut |
| 223 |
|
|
| 224 |
return $status; |
# enrich pure task metadata with job status information |
| 225 |
|
$task->{status} = { |
| 226 |
|
running => $self->{_pcontrol}->{$jobname}->{running}, |
| 227 |
|
locked => $self->{_pcontrol}->{$jobname}->{locked}, |
| 228 |
|
}; |
| 229 |
|
|
| 230 |
|
return $task; |
| 231 |
} |
} |
| 232 |
|
|
| 233 |
|
|
| 243 |
#print "getTask - 1.1", "\n"; |
#print "getTask - 1.1", "\n"; |
| 244 |
|
|
| 245 |
#print Dumper($task); |
#print Dumper($task); |
| 246 |
|
#print Dumper($self); |
| 247 |
|
|
| 248 |
# build command |
# build command |
| 249 |
my $jobname = $task->{name}; |
my $rap = "rap.pl"; |
| 250 |
my $command = "rap.pl $jobname"; |
#my $rap = 'C:\home\amo\develop\netfrag.org\nfo\perl\scripts\shortcuts\rap.pl'; |
| 251 |
|
my $jobname = $task->{name}; |
| 252 |
# run |
my $command = "$rap $jobname"; |
|
# FIXME: what about asynchronous job execution? |
|
|
$self->{_pcontrol}->{$jobname}->{locked} = 1; |
|
|
$self->{_pcontrol}->{$jobname}->{running} = 1; |
|
| 253 |
|
|
| 254 |
run_cmd($command); |
# run command |
| 255 |
|
# FIXME: what about asynchronous job execution? |
| 256 |
|
$self->{_pcontrol}->{$jobname}->{locked} = 1; |
| 257 |
|
$self->{_pcontrol}->{$jobname}->{running} = 1; |
| 258 |
|
|
| 259 |
|
# new of 2003-05-11: USE_PATH and async |
| 260 |
|
#run_cmd($command, "Executed from " . __PACKAGE__ . " at " . now(), { USE_PATH => 1 }); |
| 261 |
|
run_cmd($command, "Executed from " . __PACKAGE__ . " at " . now(), { USE_PATH => 1, async => 1 }); |
| 262 |
|
|
| 263 |
=pod |
=pod |
| 264 |
#system($command); |
#system($command); |
| 273 |
print "result: $result", "\n"; |
print "result: $result", "\n"; |
| 274 |
=cut |
=cut |
| 275 |
|
|
| 276 |
$self->{_pcontrol}->{$jobname}->{locked} = 0; |
# FIXME: How to determine when execution has finished? |
| 277 |
$self->{_pcontrol}->{$jobname}->{running} = 0; |
# Implement some dot.pid-mechanism? |
| 278 |
|
# Possible solution: |
| 279 |
|
# a) Spawn a helper process monitoring the long-running one. |
| 280 |
|
# This one notifies the system when execution has finished and terminates itself afterwards. |
| 281 |
|
# b) Have a dedicated process monitoring service running which gets notified of process startup and shutdown. |
| 282 |
|
#$self->{_pcontrol}->{$jobname}->{locked} = 0; |
| 283 |
|
#$self->{_pcontrol}->{$jobname}->{running} = 0; |
| 284 |
|
|
| 285 |
return 1; |
return 1; |
| 286 |
|
#return $task; |
| 287 |
|
|
| 288 |
} |
} |
| 289 |
|
|
| 290 |
|
|
| 291 |
|
sub getTaskGroups { |
| 292 |
|
my $self = shift; |
| 293 |
|
|
| 294 |
|
$logger->info( __PACKAGE__ . "->getTaskGroups()" ); |
| 295 |
|
|
| 296 |
|
# emulate a row based result |
| 297 |
|
my $jobgroups = $bizProcess->{app}->{config}->{jobs}->{groups}; |
| 298 |
|
|
| 299 |
|
return $jobgroups; |
| 300 |
|
|
| 301 |
|
} |
| 302 |
|
|
| 303 |
|
|
| 304 |
1; |
1; |