#!/usr/bin/perl -W use strict; # # This script implements last-mile communication with the storage RM. # It is called when Moab is initiating a data staging operation. The # commands currently specified are: # # command: stage # remove # returns: [,] # exit: 0=success,1=syntax error,2=unrecognized command,3=system error # notes: The stage time should be reported in seconds until completion. # The destination file size is reported in bytes. Returning zero # for the stage time means the staging operation is complete, and # a negative one indicates an indefinite stage time. If an error # occurs, nothing is returned and the exit value is set. The # actual data stage operation should be executed in the background # if the operation is expected to take more than one second. # my $transferrate = 0.0; # set transfer rate to value > 0 to allow stage time estimates my $filesize = 0.0; my $stagetime = 0.0; my $stagecmd = "/bin/cp"; my $removecmd = "/bin/rm"; exit 1 if scalar(@ARGV) < 1; # verify existence of command parameter my $command = $ARGV[0]; # get command from arguments if ('stage' eq $command) { exit 1 if scalar(@ARGV) < 3; # verify existence of src and dst parameters # NOTE: These will have to be parsed later (NYI) my $SrcFile = $ARGV[1]; # extract SrcFile name from URL my $DstFile = $ARGV[2]; # extract DstFile name from URL if (($filesize > 0.0) && ($transferrate > 0.0)) { $stagetime = $filesize / $transferrate; } else { $stagetime = -1.0; } if (($stagetime < 0.0) || ($stagetime > 1.0)) { system("$stagecmd $SrcFile $DstFile &"); # unknown or long stage time, so stage file in the background } else { system("$stagecmd $SrcFile $DstFile"); # short stage time, so block until staging is complete $stagetime = 0; } print "$stagetime"; # output remaining stage time exit 0; # assume success and exit with error code set to success } elsif ('remove' eq $command) { exit 1 if scalar(@ARGV) < 2; # verify existence of file parameters # NOTE: This will have to be parsed later (NYI) my $File = $ARGV[1]; # extract File name from URL system("$removecmd $File"); # always block until file remove is complete exit 0; # assume success and exit with error code set to success } else { exit 2; # exit with error code set to unrecognized command }