From: Aleš Křenek Date: Wed, 6 Jun 2007 15:31:33 +0000 (+0000) Subject: merged from 3.1 branch X-Git-Tag: glite-yaim-lb_R_3_1_1-1~47 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=53b4807dc39e83f32f71485085ee19b32242aea4;p=jra1mw.git merged from 3.1 branch --- diff --git a/org.glite.jp.index/examples/pch06/pch.pm b/org.glite.jp.index/examples/pch06/pch.pm new file mode 100644 index 0000000..e8bf688 --- /dev/null +++ b/org.glite.jp.index/examples/pch06/pch.pm @@ -0,0 +1,219 @@ +# +# Job Provenance queries wrapper (Primary and Index queries) +# +# $debug - trace calls +# $err - error status from last query +# + +package pch; + +use strict; +use warnings; +use XML::Twig; +use Data::Dumper; + +our $lbattr='http://egee.cesnet.cz/en/Schema/LB/Attributes'; +our $jpsys='http://egee.cesnet.cz/en/Schema/JP/System'; +our $jpwf='http://egee.cesnet.cz/en/Schema/JP/Workflow'; +our $jplbtag='http://egee.cesnet.cz/en/WSDL/jp-lbtag'; + +our @view_attributes=("$pch::jplbtag:IPAW_STAGE", "$pch::jplbtag:IPAW_PROGRAM", "$pch::jplbtag:IPAW_PARAM", "$pch::jplbtag:IPAW_INPUT", "$pch::jplbtag:IPAW_OUTPUT", "$pch::lbattr:CE", "$pch::lbattr:parent", "$pch::lbattr:host", "$pch::jpsys:regtime"); + + +our $debug = 0; +our $err = 0; + +my $jpis_client_program = "./glite-jpis-client"; +my $jpps_client_program = "./glite-jp-primary-test"; +my @default_is_attributes = ( + "http://egee.cesnet.cz/en/Schema/JP/System:owner", + "http://egee.cesnet.cz/en/Schema/JP/System:jobId", + "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus", + "http://egee.cesnet.cz/en/Schema/LB/Attributes:user", + "http://egee.cesnet.cz/en/WSDL/jp-lbtag:IPAW_PROGRAM", + "http://egee.cesnet.cz/en/Schema/JP/Workflow:ancestor" +); +my @isquery = ( +' + +', +' +' +); + + +my @jobs; + + +# +# query to Job Provenance Index Server +# +sub isquery { + my ($server, $queries, $attributes) = @_; + my ($s, @jobs); + my $args = ''; + my @attributes; + my $fh; + + $err = 0; + if ($attributes) { @attributes = @$attributes; } + else { @attributes = @default_is_attributes; } + + $s = $isquery[0]; + foreach my $query (@$queries) { + my @query = @$query; + my $i = 1; + $s .= "\n"; + $s .= "\t$query[0]\n"; + while ($i <= $#query) { + my @record = @{$query[$i]}; + $s .= "\t\n"; + $s .= "\t\t$record[0]\n"; + $s .= "\t\t$record[1]\n"; + $s .= "\t\t$record[2]\n" if ($record[2]); + $s .= "\t\n"; + $i++; + } + $s .= "\n"; + } + + foreach my $attribute (@attributes) { + $s .= "$attribute\n"; + } + $s .= $isquery[1]; + + $args .= "-i $server " if ($server); + $args .= '-q -'; + + if ($debug) { + print STDERR "calling 'echo '$s' | $jpis_client_program $args |'\n"; + } + if (!open($fh, "echo '$s' | $jpis_client_program $args |")) { + print STDERR "Can't execute '$jpis_client_program $args'\n"; + $err = 1; + return (); + } + @jobs = parse_is($fh); +# print STDERR <$fh>; print STDERR "\n"; + close $fh; + if ($?) { + print STDERR "Error returned from $jpis_client_program $args\n"; + $err = 1; + return (); + } + + return @jobs; +} + + +sub parse_is { + my ($fh) = @_; + my $twig; + + @jobs = (); + + $twig = new XML::Twig(TwigHandlers => { jobs => \&jobs_handler }); + if (!$twig->safe_parse($fh)) { $err = 1; return (); } + else { return @jobs; } +} + + +sub jobs_handler { + my($twig, $xmljobs)= @_; + my (%attributes, $xmljobid, $xmlattribute, %job); + %attributes = (); + + $xmljobid = $xmljobs->first_child('jobid'); + die "No jobid on '".$xmljobs->text."'" if (!$xmljobid); + $job{jobid} = $xmljobid->text; + + $xmlattribute = $xmljobs->first_child('attributes'); + while ($xmlattribute) { + my ($xmlname, $xmlvalue); + my @values = (); + my %attribute = (); + + $xmlname = $xmlattribute->first_child('name'); + die "No name on '".$xmlattribute->text."'" if (!$xmlname); +#print $xmljobid->text.": ".$xmlname->text.":\n"; + if (exists $attributes{$xmlname->text}) { + %attribute = %{$attributes{$xmlname->text}}; + } +#print " prev attr: ".Dumper(%attribute)."\n"; + if (exists $attribute{value}) { + @values = @{$attribute{value}}; + } +#print " prev values: ".Dumper(@values)."\n"; + $xmlvalue = $xmlattribute->first_child('value'); + while ($xmlvalue) { +#print " to add: ".$xmlvalue->text."\n"; + push @values, $xmlvalue->text; + $xmlvalue = $xmlvalue->next_sibling('value'); + } + @{$attribute{value}} = @values; +#print " new values: ".Dumper($attribute{value})."\n"; + $attribute{timestamp} = $xmlattribute->first_child('timestamp')->text; + $xmlattribute = $xmlattribute->next_sibling('attributes'); + + $attributes{$xmlname->text} = \%attribute; + } + $job{attributes} = \%attributes; + + push @jobs, \%job; +} + +# +# query to Job Provenance Primary Storage +# ==> array of string +# +sub psquery { + my ($server, $jobid, $attribute) = @_; + my $args = ''; + my @attrs = (); + my $fh; + + $err = 0; + $args .= "-s $server " if ($server); + $args .= "GetJobAttr $jobid $attribute"; + if ($debug) { + print STDERR "calling '$jpps_client_program $args |'\n"; + } + if (!open($fh, "$jpps_client_program $args |")) { + print STDERR "Can't execute '$jpps_client_program $args'\n"; + $err = 1; + return (); + } + @attrs = parse_ps($fh); + close $fh; + if ($?) { + print STDERR "Error returned from $jpps_client_program $args\n"; + $err = 1; + return (); + } + + return @attrs; +} + + +sub parse_ps { + my ($fh) = @_; + my @attrs = (); + my $attr; + + while (<$fh>) { + chomp; + next if (!$_); + next if (/^OK$/); + next if (/^Attribute values:$/); +# print STDERR "$_\n"; + $attr = $_; + $attr =~ s/\t*//; + $attr =~ s/\t.*//; + push @attrs, $attr; + } + + return @attrs; +} + + +1; diff --git a/org.glite.jp.index/examples/pch06/query1.pl b/org.glite.jp.index/examples/pch06/query1.pl new file mode 100644 index 0000000..9b155b1 --- /dev/null +++ b/org.glite.jp.index/examples/pch06/query1.pl @@ -0,0 +1,116 @@ +#! /usr/bin/perl + +# +# 1. query: +# +# Find the process that led to Atlas X Graphic / everything that caused Atlas X +# Graphic to be as it is. This should tell us the new brain images from which +# the averaged atlas was generated, the warping performed etc. +# +# call: +# ./query1.pl OUTPUT_FILE_NAME 2>/dev/null +# + +use strict; +use pch; +use Data::Dumper; + +my $ps='https://skurut1.cesnet.cz:8901'; +my $is='https://skurut1.cesnet.cz:8902'; + +my @according_jobs = (); # sequencially jobid list +my %according_jobs = (); # hash jobid list +my $according_count = 0; +my $output; + + +if ($#ARGV + 1 != 1) { + print STDERR "Usage: $0 OUTPUT_FILE\n"; + exit 1 +} +$output = $ARGV[0]; + +# debug calls +$pch::debug = 0; +my $debug = 0; + +# +# find out processes with given output +# +my @jobs = pch::isquery($is, [ + ["$pch::jplbtag:IPAW_OUTPUT", ['EQUAL', "$output"]], +], ["$pch::jpsys:jobId", "$pch::jpwf:ancestor"]); +print Dumper(@jobs) if ($debug); +die "...so exit on error" if ($pch::err); + +# +# initial set from index server +# +foreach my $job (@jobs) { + my %job = %$job; + my %attributes = %{$job{attributes}}; + + if (!exists $according_jobs{$job{jobid}}) { + push @according_jobs, $job{jobid}; + $according_jobs{$job{jobid}} = 1; + } +} +undef @jobs; + + +# +# collect all jobids (tree browsing) +# +# better implementation will be: using children attribute on LB:parent +# +$according_count = 0; +foreach my $jobid (@according_jobs) { + my @attrs; + + print "Handling $jobid (position $according_count)\n" if ($debug); + @attrs = pch::psquery($ps, $jobid, "$pch::jpwf:ancestor"); + + for my $anc_jobid (@attrs) { + print "Considered: $anc_jobid\n" if ($debug); + if (!exists $according_jobs{$anc_jobid}) { + $according_jobs{$anc_jobid} = 1; + push @according_jobs, $anc_jobid; + print "Added $anc_jobid to $#according_jobs\n" if ($debug); + } + else { + print "Already existing $anc_jobid\n" if ($debug); + } + } + $according_count++; +} + +foreach my $jobid (@according_jobs) { + my @attrs2 = pch::psquery($ps, $jobid, "$pch::jplbtag:IPAW_STAGE"); + $according_jobs{$jobid} = $attrs2[0]; +} + +# +# queries on result set +# +print "Results\n"; +print "=======\n"; +print "\n"; +foreach my $jobid (sort { $according_jobs{$b} <=> $according_jobs{$a} } keys %according_jobs) { + print "jobid $jobid:\n"; + + # query & output all desired atributes + foreach my $attr (@pch::view_attributes) { + my @attrs; + my $attr_name = $attr; $attr_name =~ s/.*://; + + @attrs = pch::psquery($ps, $jobid, $attr); + print " attr $attr_name: "; + if ($attr eq "$pch::jpsys:regtime") { + print gmtime(@attrs[0])." (".join(", ", @attrs).")\n"; + } else { + print join(", ", @attrs)."\n"; + } + } + + print "\n"; +} diff --git a/org.glite.jp.index/examples/pch06/query2.pl b/org.glite.jp.index/examples/pch06/query2.pl new file mode 100644 index 0000000..e189b59 --- /dev/null +++ b/org.glite.jp.index/examples/pch06/query2.pl @@ -0,0 +1,125 @@ +#! /usr/bin/perl + +# +# 2. query: +# +# Find the process that led to Atlas X Graphic, excluding everything prior to +# the averaging of images with softmean. +# +# call: +# ./query2.pl OUTPUT_FILE_NAME 2>/dev/null +# + +use strict; +use pch; +use Data::Dumper; + +my $ps='https://skurut1.cesnet.cz:8901'; +my $is='https://skurut1.cesnet.cz:8902'; +my $program_name = "softmean"; + +my @according_jobs = (); # sequencially jobid list +my %according_jobs = (); # hash jobid list +my $according_count = 0; +my $output; + + +if ($#ARGV + 1 != 1) { + print STDERR "Usage: $0 OUTPUT_FILE\n"; + exit 1 +} +$output = $ARGV[0]; + +# debug calls +$pch::debug = 0; +my $debug = 0; + +# +# find out processes with given output +# +my @jobs = pch::isquery($is, [ + ["$pch::jplbtag:IPAW_OUTPUT", ['EQUAL', "$output"]], +], ["$pch::jpsys:jobId", "$pch::jpwf:ancestor"]); +print Dumper(@jobs) if ($debug); +die "...so exit on error" if ($pch::err); + +# +# initial set from index server +# +foreach my $job (@jobs) { + my %job = %$job; + my %attributes = %{$job{attributes}}; + + if (!exists $according_jobs{$job{jobid}}) { + push @according_jobs, $job{jobid}; + $according_jobs{$job{jobid}} = 1; + } +} +undef @jobs; + + +# +# collect all jobids (tree browsing), stop on softmean program +# +# note, the browsing tree is really needed here since we explore the workflow +# +$according_count = 0; +foreach my $jobid (@according_jobs) { + my (@attrs, @program); + + print "Handling $jobid (position $according_count)\n" if ($debug); + + # stop on given program name + @program = pch::psquery($ps, $jobid, "$pch::jplbtag:IPAW_PROGRAM"); + die "More program names of $jobid?" if ($#program > 0); + if ($program[0] eq $program_name) { + print "$jobid is $program_name, stop here\n" if $debug; + next; + } + + # else browse up + @attrs = pch::psquery($ps, $jobid, "$pch::jpwf:ancestor"); + for my $anc_jobid (@attrs) { + print "Considered: $anc_jobid\n" if ($debug); + if (!exists $according_jobs{$anc_jobid}) { + $according_jobs{$anc_jobid} = 1; + push @according_jobs, $anc_jobid; + print "Added $anc_jobid to $#according_jobs\n" if ($debug); + } + else { + print "Already existing $anc_jobid\n" if ($debug); + } + } + $according_count++; +} + +foreach my $jobid (@according_jobs) { + my @attrs2 = pch::psquery($ps, $jobid, "$pch::jplbtag:IPAW_STAGE"); + $according_jobs{$jobid} = $attrs2[0]; +} + +# +# queries on result set +# +print "Results\n"; +print "=======\n"; +print "\n"; +foreach my $jobid (sort { $according_jobs{$b} <=> $according_jobs{$a} } keys %according_jobs) { + print "jobid $jobid:\n"; + + # query & output all desired atributes + foreach my $attr (@pch::view_attributes) { + my @attrs; + my $attr_name = $attr; $attr_name =~ s/.*://; + + @attrs = pch::psquery($ps, $jobid, $attr); + print " attr $attr_name: "; + if ($attr eq "$pch::jpsys:regtime") { + print gmtime(@attrs[0])." (".join(", ", @attrs).")\n"; + } else { + print join(", ", @attrs)."\n"; + } + } + + print "\n"; +} diff --git a/org.glite.jp.index/examples/pch06/query3.pl b/org.glite.jp.index/examples/pch06/query3.pl new file mode 100644 index 0000000..7182679 --- /dev/null +++ b/org.glite.jp.index/examples/pch06/query3.pl @@ -0,0 +1,123 @@ +#! /usr/bin/perl + +# +# 3. query: +# +# Find the Stage 3, 4 and 5 details of the process that led to Atlas X Graphic. +# +# call: +# ./query3.pl OUTPUT_FILE_NAME 2>/dev/null +# + +use strict; +use pch; +use Data::Dumper; + +my $ps='https://skurut1.cesnet.cz:8901'; +my $is='https://skurut1.cesnet.cz:8902'; +my @attributes = ("$pch::jpsys:jobId", "$pch::jpwf:ancestor", @pch::view_attributes); + +my @according_jobs = (); # sequencially jobid list +my %according_jobs = (); # hash jobid list +my $according_count = 0; +my $output; + + +if ($#ARGV + 1 != 1) { + print STDERR "Usage: $0 OUTPUT_FILE\n"; + exit 1 +} +$output = $ARGV[0]; + +# debug calls +$pch::debug = 0; +my $debug = 0; + +# +# find out processes with given output +# +my @jobs = pch::isquery($is, [ + ["$pch::jplbtag:IPAW_OUTPUT", ['EQUAL', "$output"]], +], \@attributes); +die "...so exit on error" if ($pch::err); +print Dumper(@jobs) if ($debug); + +# +# initial set from index server +# +foreach my $job (@jobs) { + my %job = %$job; + my %attributes = %{$job{attributes}}; + + if (!exists $according_jobs{$job{jobid}}) { + push @according_jobs, $job{jobid}; + $according_jobs{$job{jobid}} = \%job; + } +} +undef @jobs; + + +# +# collect all jobs (tree browsing) +# +$according_count = 0; +foreach my $jobid (@according_jobs) { + my @ancs; + + print "Handling $jobid (position $according_count)\n" if ($debug); + @ancs = pch::isquery($is, [["$pch::jpwf:successor", ['EQUAL', "$jobid"]]], \@attributes); + die "...so exit on error" if ($pch::err); + + for my $anc (@ancs) { + my %anc = %$anc; + print "Considered: $anc{jobid}\n" if ($debug); + if (!exists $according_jobs{$anc{jobid}}) { + $according_jobs{$anc{jobid}} = \%anc; + push @according_jobs, $anc{jobid}; + print "Added $anc{jobid} to $#according_jobs\n" if ($debug); + } + else { + print "Already existing $anc{jobid}\n" if ($debug); + } + } + $according_count++; +} + + +# +# queries on result set +# +print "Results\n"; +print "=======\n"; +print "\n"; +foreach my $jobid (sort { $according_jobs{$b}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] <=> $according_jobs{$a}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] } keys %according_jobs) { + my %job = %{$according_jobs{$jobid}}; + my %attributes = %{$job{attributes}}; + my $stage = $attributes{"$pch::jplbtag:IPAW_STAGE"}{value}[0]; + + if ( $stage == 3 || $stage == 4 || $stage == 5) { + print "jobid $jobid:\n"; + + # query & output all desired atributes + foreach my $attr (@pch::view_attributes) { + my $attr_name = $attr; $attr_name =~ s/.*://; + + print " attr $attr_name: "; + if (exists $attributes{$attr}) { + my %attr = %{$attributes{$attr}}; + + if ($attr eq "$pch::jpsys:regtime") { + print gmtime($attr{value}[0])." (".join(", ", @{$attr{value}}).")\n"; + } else { + print join(", ", @{$attr{value}})."\n"; + } + } else { + print "N/A\n"; + } + } + + print "\n"; + } else { + print "(ignored $jobid with stage $stage)\n" if $debug; + } +} diff --git a/org.glite.jp.index/examples/pch06/query4.pl b/org.glite.jp.index/examples/pch06/query4.pl new file mode 100644 index 0000000..467c2fd --- /dev/null +++ b/org.glite.jp.index/examples/pch06/query4.pl @@ -0,0 +1,104 @@ +#! /usr/bin/perl + +# +# 4. query: +# +# Find all invocations of procedure align_warp using a twelfth order nonlinear +# 1365 parameter model (see model menu describing possible values of parameter +# "-m 12" of align_warp) that ran on a Monday. +# +# call: +# ./query4.pl 2>/dev/null +# + +use strict; +use pch; +use Data::Dumper; + +my $ps='https://skurut1.cesnet.cz:8901'; +my $is='https://skurut1.cesnet.cz:8902'; +my $program_name='align_warp'; +my $program_params='-m 12'; +my $runday=1; +#my $runday=4; +my @attributes = ("$pch::jpsys:jobId", @pch::view_attributes); + +my %according_jobs = (); # hash jobid list +my $according_count = 0; + + +# debug calls +$pch::debug = 0; +my $debug = 0; + +# +# find out processes with given name ant parameters +# +my @jobs = pch::isquery($is, [ + ["$pch::jplbtag:IPAW_PROGRAM", ['EQUAL', "$program_name"]], + ["$pch::jplbtag:IPAW_PARAM", ['EQUAL', "$program_params"]], +], \@attributes); +print Dumper(@jobs) if ($debug); +die "...so exit on error" if ($pch::err); + + +# +# check found all jobs +# +$according_count = 0; +foreach my $job (@jobs) { + my %job = %$job; + my @time; + + print "Handling $job{jobid} ($according_count.)\n" if ($debug); + + @time =@{ $job{attributes}{"$pch::jpsys:regtime"}{value}}; + my @timesep = gmtime($time[0]); + if ($timesep[6] == $runday) { + if (!exists $according_jobs{$job{jobid}}) { + $according_jobs{$job{jobid}} = \%job; + print "Added $job{jobid}\n" if $debug; + } else { + print "Already existing $job{jobid}\n" if $debug; + } + } else { + print "Job $job{jobid} ran at day $timesep[6] (0=Sun, ...): ".gmtime($time[0])."\n" if $debug; + } + + $according_count++; +} +undef @jobs; + + +# +# print the result set +# +print "Results\n"; +print "=======\n"; +print "\n"; +foreach my $jobid (sort { $according_jobs{$b}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] <=> $according_jobs{$a}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] } keys %according_jobs) { + my %job = %{$according_jobs{$jobid}}; + my %attributes = %{$job{attributes}}; + + print "jobid $jobid:\n"; + + # output all desired atributes + foreach my $attr (@pch::view_attributes) { + my $attr_name = $attr; $attr_name =~ s/.*://; + + print " attr $attr_name: "; + if (exists $attributes{$attr}) { + my %attr = %{$attributes{$attr}}; + + if ($attr eq "$pch::jpsys:regtime") { + print gmtime($attr{value}[0])." (".join(", ", @{$attr{value}}).")\n"; + } else { + print join(", ", @{$attr{value}})."\n"; + } + } else { + print "N/A\n"; + } + } + + print "\n"; +} diff --git a/org.glite.jp.index/examples/pch06/query5.pl b/org.glite.jp.index/examples/pch06/query5.pl new file mode 100644 index 0000000..c9f05b7 --- /dev/null +++ b/org.glite.jp.index/examples/pch06/query5.pl @@ -0,0 +1,134 @@ +#! /usr/bin/perl + +# +# 5. query: +# +# Find all Atlas Graphic images outputted from workflows where at least one of +# the input Anatomy Headers had an entry global maximum=4095. The contents of +# a header file can be extracted as text using the scanheader AIR utility. +# +# call: +# ./query5.pl 2>/dev/null +# + +use strict; +use pch; +use Data::Dumper; + +my $ps='https://skurut1.cesnet.cz:8901'; +my $is='https://skurut1.cesnet.cz:8902'; +my $program_name='align_warp'; +my $end_program_name='convert'; +my $header="GLOBAL_MAXIMUM=4095"; # test for exact equal (scripts already prepared it) + +my @according_jobs = (); # sequencially jobid list +my %according_jobs = (); # hash jobid list +my $according_count = 0; + + +# debug calls +$pch::debug = 0; +my $debug = 0; + +# +# find out processes with given name and parameters +# +my @jobs = pch::isquery($is, [ + ["$pch::jplbtag:IPAW_PROGRAM", ['EQUAL', "$program_name"]], + ["$pch::jplbtag:IPAW_HEADER", ['EQUAL', "$header"]], +], \@pch::view_attributes); +print Dumper(@jobs) if ($debug); +die "...so exit on error" if ($pch::err); + +# +# initial set of DAGs from index server +# +foreach my $job (@jobs) { + my %job = %$job; + my %attributes = %{$job{attributes}}; + my $dagjobid = $attributes{"$pch::lbattr:parent"}{value}[0]; + + print "Consider DAG $dagjobid\n" if $debug; + if (!exists $according_jobs{$dagjobid}) { + %job = (); + push @according_jobs, $dagjobid; + # query to primary storage when searching by jobid + $job{jobid} = $dagjobid; + foreach my $attr (@pch::view_attributes) { + my @value; + + @value = pch::psquery($ps, $dagjobid, $attr); + if (defined @value) { @{$job{attributes}{$attr}{value}} = @value; } + } + $according_jobs{$dagjobid} = \%job; + print "Added DAG $dagjobid\n" if $debug; + } +} +undef @jobs; + + +# +# collect all jobs (tree browsing down) +# +$according_count = 0; +foreach my $jobid (@according_jobs) { + my @succs; + + print "Handling $jobid (position $according_count)\n" if ($debug); + + if ($according_jobs{$jobid}{attributes}{"$pch::IPAW_PROGRAM"}{value}[0] eq $end_program_name) { + print "It's $end_program_name\n" if $debug; + next; + } + + @succs = pch::isquery($is, [["$pch::jpwf:ancestor", ['EQUAL', "$jobid"]]], \@pch::view_attributes); + die "...so exit on error" if ($pch::err); + + for my $succ (@succs) { + my %succ = %$succ; + print "Considered: $succ{jobid}\n" if ($debug); + if (!exists $according_jobs{$succ{jobid}}) { + $according_jobs{$succ{jobid}} = \%succ; + push @according_jobs, $succ{jobid}; + print "Added $succ{jobid} to $#according_jobs\n" if ($debug); + } + else { + print "Already existing $succ{jobid}\n" if ($debug); + } + } + $according_count++; +} + + +# +# print the result set +# +print "Results\n"; +print "=======\n"; +print "\n"; +foreach my $jobid (sort { $according_jobs{$b}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] <=> $according_jobs{$a}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] } keys %according_jobs) { + my %job = %{$according_jobs{$jobid}}; + my %attributes = %{$job{attributes}}; + + print "jobid $jobid:\n"; + + # output all desired atributes + foreach my $attr (@pch::view_attributes) { + my $attr_name = $attr; $attr_name =~ s/.*://; + + print " attr $attr_name: "; + if (exists $attributes{$attr}) { + my %attr = %{$attributes{$attr}}; + + if ($attr eq "$pch::jpsys:regtime") { + print gmtime($attr{value}[0])." (".join(", ", @{$attr{value}}).")\n"; + } else { + print join(", ", @{$attr{value}})."\n"; + } + } else { + print "N/A\n"; + } + } + + print "\n"; +} diff --git a/org.glite.jp.index/examples/pch06/query6.pl b/org.glite.jp.index/examples/pch06/query6.pl new file mode 100644 index 0000000..21521e8 --- /dev/null +++ b/org.glite.jp.index/examples/pch06/query6.pl @@ -0,0 +1,133 @@ +#! /usr/bin/perl + +# +# 6. query: +# +# Find all output averaged images of softmean (average) procedures, where the +# warped images taken as input were align_warped using a twelfth order +# nonlinear 1365 parameter model, i.e. "where softmean was preceded in the +# workflow, directly or indirectly, by an align_warp procedure with argument +# -m 12. +# +# call: +# ./query6.pl 2>/dev/null +# + +use strict; +use pch; +use Data::Dumper; + +my $ps='https://skurut1.cesnet.cz:8901'; +my $is='https://skurut1.cesnet.cz:8902'; +my $program_name='align_warp'; +my $program_param='-m 12'; +my $end_program_name='softmean'; + +#my %jobs = (); # just information cache +my @workflow_jobs = (); # sequencially jobid list +my %workflow_jobs = (); # hash jobid list +my @according_jobs = (); # sequencially jobid list +my %according_jobs = (); # hash jobid list +my $workflow_count = 0; + + +# debug calls +$pch::debug = 0; +my $debug = 0; + +# +# find out processes with given name and parameters +# +my @jobs = pch::isquery($is, [ + ["$pch::jplbtag:IPAW_PROGRAM", ['EQUAL', "$program_name"]], + ["$pch::jplbtag:IPAW_PARAM", ['EQUAL', "$program_param"]], +], ["$pch::jpwf:successor", @pch::view_attributes]); +print Dumper(@jobs) if ($debug); +die "...so exit on error" if ($pch::err); + +# +# initial set of starting jobs from index server +# (root jobs) +# +foreach my $job (@jobs) { + my %job = %$job; + my %attributes = %{$job{attributes}}; + my $jobid = $job{jobid}; + + if (!exists $workflow_jobs{$jobid}) { + push @workflow_jobs, $jobid; + $workflow_jobs{$jobid} = \%job; + } +} +undef @jobs; + + +# +# collect all jobs (tree browsing down) +# +$workflow_count = 0; +foreach my $jobid (@workflow_jobs) { + my @succs; + + print "Handling $jobid (position $workflow_count)\n" if ($debug); + print " progname: ".$workflow_jobs{$jobid}{attributes}{"$pch::jplbtag:IPAW_PROGRAM"}{value}[0]."\n" if ($debug); + + if ($workflow_jobs{$jobid}{attributes}{"$pch::jplbtag:IPAW_PROGRAM"}{value}[0] eq $end_program_name) { + print "It's $end_program_name, adding\n" if $debug; + $according_jobs{$jobid} = \%{$workflow_jobs{$jobid}}; + next; + } + + @succs = pch::isquery($is, [["$pch::jpwf:ancestor", ['EQUAL', "$jobid"]]], \@pch::view_attributes); + die "...so exit on error" if ($pch::err); + + for my $succ (@succs) { + my %succ = %$succ; + print "Considered: $succ{jobid}\n" if ($debug); + if (!exists $workflow_jobs{$succ{jobid}}) { + $workflow_jobs{$succ{jobid}} = \%succ; + push @workflow_jobs, $succ{jobid}; + print "Added $succ{jobid} to $#workflow_jobs\n" if ($debug); + } + else { + print "Already existing $succ{jobid}\n" if ($debug); + } + } + $workflow_count++; +} +undef @workflow_jobs; +undef %workflow_jobs; + + +# +# print the result set +# +print "Results\n"; +print "=======\n"; +print "\n"; +foreach my $jobid (sort { $according_jobs{$b}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] <=> $according_jobs{$a}{attributes}{"$pch::jplbtag:IPAW_STAGE"}{value}[0] } keys %according_jobs) { + my %job = %{$according_jobs{$jobid}}; + my %attributes = %{$job{attributes}}; + + print "jobid $jobid:\n"; + + # output all desired atributes + foreach my $attr (@pch::view_attributes) { + my $attr_name = $attr; $attr_name =~ s/.*://; + + print " attr $attr_name: "; + if (exists $attributes{$attr}) { + my %attr = %{$attributes{$attr}}; + + if ($attr eq "$pch::jpsys:regtime") { + print gmtime($attr{value}[0])." (".join(", ", @{$attr{value}}).")\n"; + } else { + print join(", ", @{$attr{value}})."\n"; + } + } else { + print "N/A\n"; + } + } + + print "\n"; +}