NAME

Gridport::Job - Perl extension for running globus jobs on the Grid.


DESCRIPTION

The Gridport::Job module lets you submit jobs to remote resources using globus. Jobs can be either simple jobs such as ``/bin/ls'', ``/bin/cat /home/myfile'', or they can be batchjobs.

Jobs must first be instantiated through the subroutine ``new''. This can also be used to instantiate a job object for a previously submitted job by calling new with the jobid passed in as a parameter. From there you can check the status of jobs, delete jobs, and get the out/err of jobs.


SYNOPSIS

        use Gridport::Job;
        my $job = Gridport::Job->new()
        $job->[subroutine]


EXAMPLES

  use Gridport::Job;
  # Job Run
  my $job = Gridport::Job->new();
  my @output = $job->run(executable=>'/bin/echo', 
   host=>'perigee.sdsc.edu', arguments=>'hello steve',
   directory=>'/etc'
  );
  foreach(@output) {
     print "<br>$_<br>";
  }
 
  #Batch Job
  my $bjob = Gridport::Job->new();
  my @boutput = $job->batch_submit(
     executable=>'/bin/echo', host=>'tfglobus.sdsc.edu/jobmanager-loadleveler',
     arguments=>'hello foo', directory=>'/etc',
     np=>'8', queue=>'express',
     maxtime=>'10'
  );
  my $jobid = $bjob->get_jobid();
  my $jobstatus = $job->get_status();
  while($jobstatus =~ /PENDING/) {
     sleep(3);
     $jobstatus = $job->get_status();
     print "<br>JOB STATUS : $jobstatus<br>JOBID : $jobid";
  }
  my @bstout  = $bjob->get_stdout();
  my @bstderr = $bjob->get_stderr();
  my $clear   = $bjob->cancel(clean=>'true');


SEE ALSO

Cog::lib::Cog::Globus::Job, Cog::lib::Cog::Globus::RSL, Cog::lib::Cog::Globus::Run, Cog::lib::Cog::Globus::URLCopy, Cog::lib::Cog::MDS::Search, Cog::lib::Cog::Security::Cacl, Cog::lib::Cog::Security::Myproxy, Cog::lib::Cog::Security::Proxy, Cog::src::Config, CogUtil::lib::CogUtil::Log, CogUtil::lib::CogUtil::UnixRun, Gridport::lib::Gridport::Authentication, Gridport::lib::Gridport::FileTransfer, Gridport::lib::Gridport::Job, Gridport::lib::Gridport::ProxyForward, Gridport::lib::Gridport::SRB, NWS::lib::NWS, SRB::lib::SRB


AUTHOR

Maytal Dahan, maytal@tacc.utexas.edu Catherine Mills, cmills@sdsc.edu Stephen Mock, mock@sdsc.edu


SUBROUTINES

new()

Description:

 This subroutine is used to instantiate a job. 
 All jobs must be instantiated before run or batch_submitted.
 You can also use this to create a job with a jobID by calling
 you might want to do this to check on a job that you submitted
 before and strored and want to check on the status
 You must be properly logged into gridport using the Gridport::Authentication
 module for this to work at all.

Parameters: None

Optional Parameters: jobid - the jobid of the a previous job

Usage: my $job = Gridport::Job->new(); OR my $job = Gridport::Job->new(jobid=>$jobid);

Returns: a job object


=cut

sub new { my $class = shift; my $self = bless({},$class);

   my %arg = @_;
   $self->{'error'} = undef;
   $self->{'gridport_auth'} = new Gridport::Authentication;
   my $gp = $self->{'gridport_auth'};
   $self->{'logstate'} = $gp->get_login_state(gsi=>'true');
   if(!defined($self->{'logstate'}) || $self->{'logstate'} ne "1") {
      warn "You must be properly logged in to instantiate job.";
      return undef;
   }
   if(defined($arg{'jobid'})) {
      $self->{'jobid'} = $arg{'jobid'};
      $self->get_status();
    }
   return $self;
}

run()

Description: This subroutine used to run a command on a remote resource through globus

Parameters: executable - string describing the executable to be run host - the globus host contact string

Optional Parameters: arguments - arguments to the executable timeout - how long (seconds) to wait before killing the process, default 120 directory - remote directory to execute the command in batch - set to 'true' will submit the job and then detach, thus returning just a jobid rsl - instead of defining executable, args, directory if the user knows how to make their own RSL strings, they can just pass that in with the host and optoinally the timeout

Usage: @output = Gridport::Job->run( executable=>'/bin/echo', host=>'perigee.sdsc.edu', arguments=>'hello steve', directory=>'/etc' );

Returns: an array with the output, and if a jobid is returned, then it stores that in the job object

batch_submit()

Description batch_submit submits a batch job to the batch queuing gram gatekeeper on a globus resource, and returns an array containing the output from the submission while storing any jobid in the job object that it happens upon. If a job id is returned, it captures that and stuffs it into the job object.

Parameters: host - the globus host contact string for the scheduler np - the number of processors to submit the job to queue - batch queue to run the job in executable - the executable of the job to be submitted maxtime - the maximum time that the job will run in minutes

Optional Parameters: project - project id to charge the job to directory - directory to execute the job in stdin - remote file to get stdin from stdout - remote file to pipe stdout to stderr - remote file to pipe stderr to rsl - rsl string describing the job this supercedes any other job parameter that overlaps arguments - any arguments to the executable

Usage: my @boutput = $job->batch_submit( executable=>'/bin/echo', host=>'tfglobus.sdsc.edu/jobmanager-loadleveler', arguments=>'hello foo', directory=>'/etc', np=>'8', queue=>'express', maxtime=>'10' );

Returns : an array containing the output of submitting the job

get_jobid()

Description: Returns the job id from the job object

Parameters: None

Usage: my $jobid = $job->get_jobid();

Returns: a globus job id like https://perigee.sdsc.edu:50439/11576/1012521617/ undef if no job id exists

get_status()

Description: Gets the status of a job submitted in batch mode.

Parameters: None

Usage: $status = $job->get_status()

Returns: the status of a job submitted in batch mode or undefined The status can be one of ``DONE|ACTIVE|FAILED|PENDING'' =cut

sub get_status { my $self = shift;

   if(!defined($self->{'gridport_auth'})) {
      warn "You must call Gridport::Job::new to create a job object before submission.";
      return undef;
   }
   if(!defined($self->{'jobid'})) {
      return undef;
   }
   my $gp = $self->{'gridport_auth'};
   $gp->set_gsi_env();
   my $status = Cog::Globus::Run::status(jobid=>$self->{'jobid'});
   $self->{'status'} = $status;
   return $self->{'status'};
}
=head1

get_stdout()

Description: Gets standard out from a job submitted in batch mode

Parameters: None

Usage: @stdout = $job->get_stdout()

Returns: an array with the stdout from that jobid undefined if their is an error

get_stderr

Description: Gets standard error from a job submitted in batch mode

Parameters: None

Usage: @stderr = $job->get_stderr()

Returns: an array with the stderr from that jobid undefined if their is an error

cancel()

Description: for cancelling a job which was sumitted in batch mode if clean is passed in then it deletes the output/errfiles

Optional Parameter: clean - boolean, if true then it cleans the output and error files, default is false.

Usage: $job->cancel(); OR $job->cancel(clean=>'true');

Returns: results from cancel or undefined if couldn't cancel job.