Grid-Request

 view release on metacpan or  search on metacpan

lib/Grid/Request/Command.pm  view on Meta::CPAN

                      VALUE => 1,
                      TYPE  => 1,
                    ); 

# The default operating system to run the command on. This must be
# a key in %VALID_OS.
my $default_opsys = "Linux";

my $default_cmd_type = "htc";

# The default state of a command. This is the state that all commands
# start with.
my $default_state = "INIT";

=item Grid::Request::Command->new(%args);

B<Description:> This is the object constructor. Parameters are passed to
the constructor in the form of a hash. Example:

  my $req = Grid::Request::Command->new( opsys => "Linux",
                                         project => "SomeProject",
                                       );

B<Parameters:> Only the project parameter is required when calling the
constructor. Remaining parameters can be added with individual method calls.

B<Returns:> $obj, a command object.

=cut

sub new {
    $logger->debug("In constructor, new.");
    my ($class, %args) = @_;
    my $self = bless {}, $class || ref($class);
    $self->_init(\%args);
    return $self;
}


sub _init {
    $logger->debug("In _init");
    my ($self, $arg_ref) = @_;
    my %args = %$arg_ref;

    # Set the opsys attribute.
    my $opsys = $args{opsys} || $default_opsys;
    $logger->debug("Setting the opsys to $opsys.");
    $self->opsys($opsys);

    $self->cmd_type($default_cmd_type);

    $self->{params} = [];
    $self->{ids} = [];

    # Set the state attribute to the default.
    $self->{state} = $default_state;

    # This is important for systems such as psearch, which change
    # uid's in order to submit jobs on behalf of users.
    # We should use the real user id.
    $self->{username} = getpwuid($<);
    $logger->debug("Set the username to the effective UID: " . $self->{username});

    # Set the default block size.
    $logger->debug("Setting the default block size.");
    $self->{block_size} = $DEFAULT_BLOCK_SIZE;
    
    foreach my $method (qw(block_size command class error getenv initialdir
                           input output name project priority times evictable
                           length runtime hosts)) {
        if (exists($args{$method}) && defined($args{$method})) {
            $logger->info("Initializing $method.");
            $self->$method( $args{$method} );
        }
    }
}

=item $obj->account([account]);

B<Description:> The account attribute is used to affiliate a grid job with
a particular account. Grid engines differ in their treatment of the account
attribute.

B<Parameters:> To use as a setter, the first parameter will be used to
set (or reset) the account attribute for the command.

B<Returns:> The currently set account (if called with no parameters).

=cut

sub account {
    $logger->debug("In account");
    my ($self, $account, @args) = @_;

    if (defined $account) {
        $logger->warn("The account method takes only one argument ",
                      "when making an assignment.") if @args;
        $self->{account} = $account;
    } elsif (exists($self->{account}) && defined($self->{account})) {
        return $self->{account};
    } else {
        return undef;
    }
}


=item $obj->block_size( [ $scalar | $code_ref ] );

B<Description:> By default, Master/Worker jobs have a default block size of
100.  That is to say, that each worker on the grid will process 100 elements of
the overall pool of job invocations. However, this isn't always appropriate.
The user may override the default block size by calling this method and setting
the block size to an alternate value (a positive integer). The user may also
provide an anonoymous subroutine (code reference) so that the block size can be
computed dynamically. If choosing to pass a subroutine , the code will be passed
two arguments: the command that will be invoked, and the number of elements that
will be iterated over. The subroutine can then use these pieces of information
to compute the block size. The subroutine MUST return a positive integer scalar
or an exception will be thrown.

B<Parameters:> A positive integer scalar, or an anonymous subroutine/code



( run in 3.410 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )