[Bio] / FortyEight / PipelineUtils.pm Repository:
ViewVC logotype

View of /FortyEight/PipelineUtils.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Wed Jan 27 17:34:30 2010 UTC (9 years, 10 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.2: +53 -0 lines
more rastq fixes

package PipelineUtils;
use strict;

use base 'Exporter';

our @EXPORT = qw(sge_submit get_sge_deadline_arg find_fs_resource get_sge_priority);

sub sge_submit
{
    my($meta, $sge_args, $cmd) = @_;

    my @sge_opts;
    if (my $res = $meta->get_metadata("lustre_resource"))
    {
	push @sge_opts, -l => $res;
    }
    #
    # Require any node we run on to have the rast_qualified attribute.
    # This makes sure the operating environment on the node
    # has everything we need.
    #
    push(@sge_opts, -l => "rast_qualified");
    push(@sge_opts, get_sge_deadline_arg($meta));
    push(@sge_opts, get_sge_user_priority($meta));
    if (my $res = $meta->get_metadata("sge_priority"))
    {
	if (ref($res) eq 'ARRAY')
	{
	    push @sge_opts, @$res;
	}
	elsif (!ref($res))
	{
	    push @sge_opts, split(/\s+/, $res);
	}
    }

    my $sge_cmd = "qsub @sge_opts $sge_args $cmd";
    
    $meta->add_log_entry($0, $sge_cmd);

    if (!open(Q, "$sge_cmd 2>&1 |"))
    {
	die "Qsub failed: $!";
    }
    my $sge_job_id;
    my $submit_output;
    while (<Q>)
    {
	$submit_output .= $_;
	print "Qsub: $_";
	if (/Your\s+job\s+(\d+)/)
	{
	    $sge_job_id = $1;
	}
	elsif (/Your\s+job-array\s+(\d+)/)
	{
	    $sge_job_id = $1;
	}
    }
    $meta->add_log_entry($0, ["qsub_output", $submit_output]);
    if (!close(Q))
    {
	die "Qsub close failed: $!";
    }

    if (!$sge_job_id)
    {
	die "did not get job id from qsub";
    }

    return $sge_job_id;
}

sub get_sge_deadline_arg
{
    my($meta) = @_;
    if ($FIG_Config::use_deadline_scheduling)
    {
	my $dl = $meta->get_metadata("sge_deadline");
	if ($dl ne '')
	{
	    if (wantarray)
	    {
		return("-dl",  $dl);
	    }
	    else
	    {
		return "-dl $dl";
	    }
	}
    }
    return;
}

sub get_sge_user_priority
{
    my($meta) = @_;
    if ($FIG_Config::use_priority_scheduling)
    {
	my $prio = $meta->get_metadata("sge_priority");
	if (defined($prio))
	{
	    return $prio;
	}
	else
	{
	    return;
	}
    }
}

sub find_fs_resource
{
    my($job) = @_;
    my $fs_resource;
    if (my $fileserver = $job->find_job_fileserver())
    {
	if ($fileserver eq 'rast.mcs.anl.gov')
	{
	    $fs_resource = "-l local_rast";
	}
	elsif ($fileserver eq 'cgat.mcs.anl.gov')
	{
	    $fs_resource = "-l local_cgat";
	}
	elsif ($fileserver eq 'lustre')
	{
	    $fs_resource = "-l lustre_lustre1";
	}
    }

    return $fs_resource;
}

sub read_qstat
{
    if (!open(Q, "qstat  -f -s prs -u rastprod |"))
    {
	warn "Could not read queue status: $!\n";
	return;
    }

    my $qstat = {};
    my $finished;
    my $queue;
    my $host;
    while (<Q>)
    {
	
	if (/FINISHED JOBS/)
	{
	    $finished++;
	    undef $queue;
	    undef $host;
	    next;
	}
	if (/^([^@]+)@(\S+)/)
	{
	    $queue = $1;
	    $host = $2;
	}
	elsif (/^----/)
	{
	    undef $queue;
	    undef $host;
	}

	if (/^(\d+)\s+(.*)/)
	{
	    my $jobid = $1;
	    my $rest = $2;
	    my($uptime, $job, $user, $status, $date, $time, $slots) = split(/\s+/, $rest);
#	    print "Got job=$jobid status=$status user=$user date=$date time=$time finished=$finished\n";
	    $status = "done" if $finished;
	    my $ent = { id => $jobid, status => $status, user => $user, date => $date, time => $time, name => $job };

	    $ent->{queue} = $queue if $queue;
	    $ent->{host} = $host if $host;

	    $qstat->{$jobid} = $ent;
	}
    }
    return $qstat;
}

1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3