Grid-Request

 view release on metacpan or  search on metacpan

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


B<Description:> This method is used to establish the environment that a
request to the grid should run under. Users may pass this method a list of
strings that are in "key=value" format. The keys will be converted into
environment variables set to "value" before execution of the command is begun.
Normally, a request will not copy the user's environment in this way.  The only
time the environment is established on the grid will be if the user invokes the
getenv method or sets it with this method. This  method allows the user to
override the environment with his or her own notion of what the environment
should be at runtime on the grid.

B<Parameters:> A list of strings in "key=value" format. If any string does
not contain the equals (=) sign, it is skipped and a warning is generated. 

B<Returns:> None.

=cut

sub set_env_list {
    my ($self, @args) = @_;
    my @valid; 
    foreach my $arg (@args) {
        if ($arg !~ /\S+=\S+/) {
            $logger->logcroak("$arg is not a valid environment parameter. Skipping it.");
            next;
        }
        push(@valid, $arg);
    }

    $self->{_env} = \@valid;

    # If the user has set their own environment with set_envlist, then we
    # assume that they want getenv to be true. We do it for them here to save
    # them an extra step.
    $self->getenv(1);
}


=item $obj->show_invocations();

B<Description:> Show what will be executed on the DRM. An attempt is made
to excape shell sensitive characters so that the commands can be copied
and pasted for test execution.

B<Parameters:> None.

B<Returns:> None. The method print to STDOUT.

=cut

sub show_invocations {
    my $self = shift;

    # Remember, we may have multiple command objects...
    my @command_objs = $self->_com_obj_list();

    # Iterate over them...
    my $command_count = 1;

    eval { require Grid::Request::JobFormulator };
    my $formulator = Grid::Request::JobFormulator->new();

    foreach my $com_obj (@command_objs) {
        print "Command #" . $command_count . "\n"; 
        my $exe = $com_obj->command();
        my $block_size = $com_obj->block_size();
        my @params = $com_obj->params();
        my @param_strings = ();

        foreach my $param_obj (@params) {
            my $param_str = $param_obj->to_string();
            push (@param_strings, $param_str);
        }

        my @invocations = $formulator->formulate($block_size, $exe, @param_strings);
        foreach my $invocations (@invocations) {
            my @cli = @$invocations;
            my @esc_cli = _esc_chars(@cli);
            print join(" ", @esc_cli) . "\n";
        }
        
        $command_count++;
    }
}

sub _esc_chars {
    # will change, for example, a!!a to a\!\!a
    my @cli = @_;
    my $e;
    @cli = map { $e =$_; $e =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g; $e } @cli;
    @cli = map { if ($_ =~ m/\s/) { '"' . $_ . '"' } else { $_ } } @cli;
    return @cli;
}


=item $obj->simulate([value]);

B<Description:> This method is used to toggle the simulate flag for the
request. If this method is passed a true value, the request will not be
submitted to the grid, but will appear to have been submitted. This is most
useful in development and testing environments to conserve resources. When a
request marked simulate is submitted, the request ID returned will be -1. Note
that this attribute cannot be modified once a request is submitted.

B<Parameters:> A true value (such as 1) to mark the request as a simulation.
A false value, or express (such as 0) to mark the request for execution.

B<Returns:> When called with no arguments, this method returns the current
values of the simulate toggle. 1 for simulation, 0 for execution. 

=cut

sub simulate {
    $logger->debug("In simulate.");
    my ($self, $simulate, @args) = @_;
    if (defined $simulate) {
        $self->{_simulate} = ($simulate) ? 1 : 0;
    } else {
        return $self->{_simulate};
    }
}


=item $obj->start_time();

B<Description:> Retrieve the start time when the request began processing.
Any attempt to set the time will result in an error.

B<Parameters:> None.

B<Returns:> $time, the start time (scalar) that the grid began processing
the request.


=item $obj->state();



( run in 0.529 second using v1.01-cache-2.11-cpan-39bf76dae61 )