CREATE ROLE globus WITH SUPERUSER LOGIN ENCRYPTED PASSWORD 'foo'; CREATE TABLE gram_audit_table ( job_grid_id character varying(256) NOT NULL, local_job_id character varying(512), subject_name character varying(256) NOT NULL, username character varying(16) NOT NULL, idempotence_id character varying(128), creation_time timestamp without time zone NOT NULL, queued_time timestamp without time zone, stage_in_grid_id character varying(256), stage_out_grid_id character varying(256), clean_up_grid_id character varying(256), globus_toolkit_version character varying(16) NOT NULL, resource_manager_type character varying(16) NOT NULL, job_description text NOT NULL, success_flag boolean NOT NULL, finished_flag boolean NOT NULL, end_time timestamp without time zone, duration real, count smallint); CREATE OR REPLACE FUNCTION update_stellaris() RETURNS trigger AS $update_stellaris$ ### Perl: start ### use strict; use URI; use Time::Local; use Net::hostent; use HTTP::Request; use LWP::UserAgent; my $STELLARIS_URL="http://stellaris.astrogrid-d.org"; if ($_TD->{new}{finished_flag} ne "t" && $_TD->{new}{success_flag} ne "t") { my $ua_stellaris = LWP::UserAgent->new(); my $res_stellaris = $ua_stellaris->get("http://Kerr:Einstein\@mintaka.aip.de:8080/volist/vomembers?print_id=1"); if ($res_stellaris->content !~ $_TD->{new}{subject_name}) {return;}} my $t = time(); my @now = localtime($t); my $now_ = sprintf("%.4d-%.2d-%.2dT%.2d:%.2d:%.2d", 1900+@now[5],1+@now[4],@now[3],@now[2],@now[1],@now[0]); my $job_grid_id = URI->new($_TD->{new}{job_grid_id}); my $id = unpack("H*", $job_grid_id->query()); my $host = gethost($job_grid_id->host())->name(); my $status = ""; my $count = ""; my $exe = ""; my $end_time = "", my $duration = ""; my $tc = $_TD->{new}{creation_time}; $tc =~ s/ /T/; my $c_t = $_TD->{new}{creation_time}; $c_t =~ s/-/ /g; $c_t =~ s/:/ /g; my @ct = split(/ /,$c_t); my $tq = $_TD->{new}{queued_time}; $tq =~ s/ /T/; if ($_TD->{new}{finished_flag} eq "t" && $_TD->{old}{finished_flag} ne "t" && $_TD->{new}{queued_time} ne "") { my $q_t = $_TD->{new}{queued_time}; $q_t =~ s/-/ /g; $q_t =~ s/:/ /g; my @qt = split(/ /,$q_t); my $queued_time = timelocal(@qt[5],@qt[4],@qt[3],@qt[2],@qt[1]-1,@qt[0]-1900); $end_time = $now_; $duration = sprintf("%.4f",($t-$queued_time)/3600.); $_TD->{new}{end_time} = sprintf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d", 1900+@now[5],1+@now[4],@now[3],@now[2],@now[1],@now[0]); $_TD->{new}{duration} = $duration;} if ( $_TD->{new}{finished_flag} eq "f") { if ( $_TD->{new}{queued_time} eq "" ) { $status = "queued"; } else { $status = "started"; }} else { if ($_TD->{new}{success_flag} eq "f") { $status = "failed"; } else {$status = "completed"; } } if (index($_TD->{new}{job_description}, "") > 0) { $count = $_TD->{new}{job_description}; $count =~ s/.*//; $count =~ s/<\/ns1:count>.*//; $_TD->{new}{count} = $count;} if (index($_TD->{new}{job_description}, "") > 0) { $exe = $_TD->{new}{job_description}; $exe =~ s/.*//; $exe =~ s/<\/ns1:executable>.*//;} my $usage_record = <<"EOF"; http://www.astrogrid-d.org/xml2rdf.xsl $_TD->{new}{job_grid_id} $now_ $_TD->{new}{local_job_id} $_TD->{new}{job_grid_id} $_TD->{new}{idempotence_id} $_TD->{new}{username} $_TD->{new}{subject_name} $exe $status $tc $tq $end_time hours $duration $host $_TD->{new}{resource_manager_type} $count computer $_TD->{new}{success_flag} $_TD->{new}{finished_flag} EOF if ($_TD->{new}{local_job_id} eq "") {$usage_record =~ s/.*<\/ns1:LocalJobId>//;} if ($_TD->{new}{idempotence_id} eq "") {$usage_record =~ s/.*<\/ns1:idempotence_id>//;} if ($_TD->{new}{queued_time} eq "") {$usage_record =~ s/.*<\/ns1:StartTime>//;} if ($exe eq "") {$usage_record =~ s/.*<\/ns1:JobName>//;} #if ($duration eq "") {$usage_record =~ s/.*<\/ns1:WallDuration>//;} if ($count eq "") {$usage_record =~ s/.*<\/ns1:Count>//;} my $req = HTTP::Request->new ("PUT", "$STELLARIS_URL/UsageRecords/".$host."/".@ct[0]."/".@ct[1]."/".$id."?modification=replace", HTTP::Headers->new(Content_Length=>length($usage_record), Content_Type => "application/rdf+xml"), $usage_record); my $ua = LWP::UserAgent->new(); my $res = $ua->request($req); if ($res->is_error) { print STDERR "PUT ERROR: ".$res->status_line.", using POST instead.\n"; my $req = HTTP::Request->new ("POST", "$STELLARIS_URL", HTTP::Headers->new(Content_Length=>length($usage_record), Content_Type => "application/rdf+xml", Slug=>"/UsageRecords/".$host."/".@ct[0]."/".@ct[1]."/".$id), $usage_record); my $ua = LWP::UserAgent->new(); my $res = $ua->request($req); if ($res->is_error) { print STDERR "POST ERROR: ".$res->status_line."\n"; } } #my $req = HTTP::Request->new("PUT", # "http://stellaris.astrogrid-d.org/UsageRecords/".$host."/".@ct[0]."/".@ct[1]."/".$id, # HTTP::Headers->new(Content_Length => length($usage_record)), $usage_record); #my $ua = LWP::UserAgent->new(); my $res = $ua->request($req); #if ($res->is_error) {print STDERR "ERROR: ".$res->status_line."\n";} return "MODIFY"; ### Perl: end ### $update_stellaris$ LANGUAGE plperlu; CREATE TRIGGER update_stellaris_trig BEFORE INSERT OR UPDATE ON gram_audit_table FOR EACH ROW EXECUTE PROCEDURE update_stellaris();