-
Danny Auble authoredDanny Auble authored
Slurm.pm 45.39 KiB
package Slurm;
use 5.008;
use strict;
use warnings;
use Carp;
use Slurm::Hostlist;
use Slurm::Bitstr;
use Slurm::Stepctx;
use Slurm::Constant;
sub import {
# export constants
Slurm::Constant->import2() if grep(/^:constant$/, @_) || grep(/^:all$/, @_);
# export job/node state testing macros
my $callpkg = caller(0);
{
no strict "refs";
my ($macro, $sub);
while( ($macro, $sub) = each(%{Slurm::}) ) {
next unless $macro =~ /^IS_JOB_/ or $macro =~ /^IS_NODE_/;
*{$callpkg . "::$macro"} = $sub;
}
}
}
our $VERSION = '0.02';
# XSLoader will not work for SLURM because it does not honour dl_load_flags.
require DynaLoader;
our @ISA;
push @ISA, 'DynaLoader';
bootstrap Slurm $VERSION;
sub dl_load_flags { if($^O eq 'aix') { 0x00 } else { 0x01 }}
############################################################
# handy macros defined in slurm_protocol_defs.h
############################################################
# /* Defined job states */
sub IS_JOB_PENDING { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_PENDING) }
sub IS_JOB_RUNNING { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_RUNNING) }
sub IS_JOB_SUSPENDED { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_SUSPENDED) }
sub IS_JOB_COMPLETE { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_COMPLETE) }
sub IS_JOB_CANCELLED { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_CANCELLED) }
sub IS_JOB_FAILED { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_FAILED) }
sub IS_JOB_TIMEOUT { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_TIMEOUT) }
sub IS_JOB_NODE_FAILED { (($_[0]->{job_state} & JOB_STATE_BASE) == JOB_NODE_FAIL) }
# /* Derived job states */
sub IS_JOB_COMPLETING { ($_[0]->{job_state} & JOB_COMPLETING) }
sub IS_JOB_CONFIGURING { ($_[0]->{job_state} & JOB_CONFIGURING) }
sub IS_JOB_STARTED { (($_[0]->{job_state} & JOB_STATE_BASE) > JOB_PENDING) }
sub IS_JOB_FINISHED { (($_[0]->{job_state} & JOB_STATE_BASE) > JOB_SUSPENDED) }
sub IS_JOB_COMPLETED { (IS_JOB_FINISHED($_[0]) && (($_[0]->{job_state} & JOB_COMPLETING) == 0)) }
sub IS_JOB_RESIZING { ($_[0]->{job_state} & JOB_RESIZING) }
# /* Defined node states */
sub IS_NODE_UNKNOWN { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_UNKNOWN) }
sub IS_NODE_DOWN { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_DOWN) }
sub IS_NODE_IDLE { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_IDLE) }
sub IS_NODE_ALLOCATED { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_ALLOCATED) }
sub IS_NODE_ERROR { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_ERROR) }
sub IS_NODE_MIXED { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_MIXED) }
sub IS_NODE_FUTURE { (($_[0]->{node_state} & NODE_STATE_BASE) == NODE_STATE_FUTURE) }
# /* Derived node states */
sub IS_NODE_DRAIN { ($_[0]->{node_state} & NODE_STATE_DRAIN) }
sub IS_NODE_DRAINING { (($_[0]->{node_state} & NODE_STATE_DRAIN) &&
(IS_NODE_ALLOCATED($_[0]) || IS_NODE_ERROR($_[0]) || IS_NODE_MIXED($_[0]))) }