#! /usr/bin/env perl =head1 NAME gateway-submit-attributes - Submit gateway user attributes with jobs. =head1 SYNOPSIS gateway-submit-attributes local-jobid gateway-user-id =head1 DESCRIPTION This command should be run after each local job submission by a TeraGrid Science Gateway to associate a user identifier with the local job submission. The command will submit the user identifier to the local GRAM Audit database (using the GRAM2/GRAM5 Audit mechanism), and later the accounting system will query the GRAM Audit database to obtain the user identifier for inclusion in the AMIE NPU packet sent to the TGCDB. This allows each gateway job record in the TGCDB to identify the individual gateway user who submitted it. =head1 EXAMPLE $ qsub myjob.pbs 2066029.tg-master.ncsa.teragrid.org $ gateway-submit-attributes 2066029.tg-master.ncsa.teragrid.org jbasney@gisolve.org Gateway user attribute (jbasney@gisolve.org) submitted for job 2066029.tg-master.ncsa.teragrid.org. $ echo $? 0 =head1 EXIT STATUS Exits with status 0 on success and 1 on error. =cut use strict; use Sys::Hostname; use Time::gmtime; # must specify the location of the GRAM2/GRAM5 audit directory here my $trestles_audit_dir = "trestles-login.sdsc.edu:/var/spool/globus/gram5-audit"; my $audit_dir = "/tmp"; # Need to create audit files world-readable so globus cron job can read them umask 0022; # initial sanity checks my $usage = "gateway-submit-attributes local-jobid gateway-user-id"; if ($#ARGV != 1) { print STDERR "usage: $usage\n"; exit(1); } # prepare the audit DB fields my $gm = gmtime(); my $year = $gm->year+1900; my $mon = $gm->mon + 1; my $local_job_id = $ARGV[0]; my $qstat_f = `qstat -f $local_job_id` or die "Could not qstat the job, are you on the right host?\n $!"; my $hostname = "NONE"; if ($qstat_f =~ /submit_host\s*=\s*(\S+)/ ) { $hostname = $1; }else{ die "Could not parse the hostname out of qstat results."; } my $job_grid_id = sprintf("http://%s/local-job/%04d%02d%02d%02d%02d%02d/%s/%s", $hostname, $year, $mon, $gm->mday, $gm->hour, $gm->min, $gm->sec, $$, $local_job_id); my $subject_name = `grid-proxy-info -identity 2>/dev/null`; if ($? != 0) { $subject_name = ""; } else { chomp($subject_name); } my $username = getpwuid($<); my $idempotent_id = "NULL"; my $creation_time = gmctime(); $creation_time =~ s/$year$//; $creation_time .= "UTC $year"; my $queued_time = $creation_time; my $stage_in_grid_id = "NULL"; my $stage_out_grid_id = "NULL"; my $clean_up_grid_id = "NULL"; my $globus_toolkit_version = ""; my $resource_manager_type = "local"; my $job_description = ""; my $success_flag = "true"; my $finished_flag = "true"; my $gateway_user = $ARGV[1]; # now write our audit DB record my $uniq_id = $$; my $filename = sprintf("%s/%04d%02d%02dT%02d:%02d:%02d-%s-%s.gramaudit", $audit_dir, $year, $mon, $gm->mday, $gm->hour, $gm->min, $gm->sec, $username, $uniq_id); #DEBUG print $filename; unless (open(F, ">$filename")) { printf STDERR "Error: Failed to open $filename: $!\n"; exit(1); } unless (printf F "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", $job_grid_id, $local_job_id, $subject_name, $username, $idempotent_id, $creation_time, $queued_time, $stage_in_grid_id, $stage_out_grid_id, $clean_up_grid_id, $globus_toolkit_version, $resource_manager_type, $job_description, $success_flag, $finished_flag, $gateway_user) { printf STDERR "Error: Failed to write to $filename: $!\n"; exit(1); } close(F); my $scpretcode = system("scp $filename $trestles_audit_dir"); if($scpretcode == 0){ unlink $filename;#delete the temporary file print "Gateway user attribute (", $gateway_user, ") submitted for job ", $local_job_id, ".\n"; exit(0); }else{ die "Could not SCP dumpfile to target location\n $! \n"; }