Admission rules are managed with the oaradmissionrule command. See the usage or man page of the command.

The code of the admission rules is executed within oarsub at submission time. Many internal variables are available, making the mechanism very powerful… and dangerous. Hence the administrator must be very careful when playing with admission rules.

Example 1: avoid the ugly SQL error warning which appear in case of a typo in the oarsub -l syntax

The following admission rule can be added, which check the syntax for valid resource propoerties

# Check the validity of the resource request (-l option of oarsub) to avoid SQL ugly message
# The following variable lists the valid resource properties that the user can use
# See the output of the `oarproperty -l' command for the list of available properties.
# Only properties which defines the implicit resource hierarchy need to be listed.
my @properties=("host","cpu","core","thread");
 
foreach my $group (@$ref_resource_list) {
  foreach my $subgroup (@$group) {
    foreach my $moldable (@$subgroup) {
      foreach my $resource (@{$moldable->{resources}}) {
        while (my ($k,$v) = each(%$resource)) {
          if ($k eq "resource" and not grep (/^$v$/, ("nodes", "resource_id", @properties))) {
            warn "Admission Rule ERROR : Unknown resource property \"$v\"\n";
            exit 1;
          }
        }
      }
    }
  }
}

Example 2: enforce a minimum number of hosts in job

Question

I'm looking for an admission rule that would reject job requests if the user ask for less than N hosts. E.g:

$ oarsub -l host=2 -I

would fail if I configure N=3.

I have a very limited set of properties configured:

$ oarproperty -l
last_available_upto
host
Answer

You could inspect what resources are requested by looking at the the oarsub command line in an admission rule, using the $initial_request_string variable.

However, this could be very tricky to handle any request case.

You could also use the $ref_resource_list variable, which is a reference to the structure containing the result of the parsing of the resource request. That structure is complex, since it must store information such as the resources hierarchy, moldable jobs, properties, etc. See the code for the admission rule below:

my $min_resources = 5; # N=5
my $error = 0;
foreach my $group (@$ref_resource_list) {
  foreach my $subgroup (@$group) {
    foreach my $moldable (@$subgroup) {
      foreach my $resource (@{$moldable->{resources}}) {
        while (my ($k,$v) = each(%$resource)) {
          if ($k eq "resource" and ($v ne "network_address" or $v ne "host")) {
            warn "requesting resource of type $v is not allowed, use nodes or host\n";
            $error = 1;
          } elsif ($k eq "value" and $v < $min_resources) {
            warn "requesting less than $min_resources nodes is not allowed, you requested $v\n";
            $error = 1;
          }
        }
        exit 1 if $error;
      }
    }
  }
}

Example 3: managing 2 compute nodes generations in the same cluster

After upgrading the cluster with new nodes, we need a rule to:

  1. send the interactive sessions on the old nodes as a default
  2. send the passive sessions on the new nodes as a default
  3. avoid mixing old and new nodes for parallel jobs as a default
  4. users are allowed to override this behavior via setting a property in their request.
Answer

First we need to add a property. We called it “cluster” and it is an integer (the year of the node installation): 2011 or 2016

$ oarproperty -a cluster

Nodes kareline-0-x (old one) are inserted in the OAR database with:

oarnodesetting -a -h ’kareline-0-0-p host=’kareline-0-0’  .... -p "cluster=2011"

Nodes kareline-1-x (new one) are inserted in the OAR database with:

oarnodesetting -a -h ’kareline-1-0-p host=’kareline-1-0’  .... -p "cluster=2016"

Then we add a rule to match our requirements, based on this property:

my $cluster;
if ($jobType eq "INTERACTIVE") {
     print "[DEBUG] Interactive job";
     $cluster =2011;
} else {
     print "[DEBUG] Passive job";
     $cluster =2016;
}
if (index($jobproperties, ’cluster’) == -1) {
     print " without cluster (".$jobproperties.")";
     if ($jobproperties ne ""){
          $jobproperties = "($jobproperties) AND cluster = ’".$cluster."’";
     } else {
          $jobproperties = "cluster = ’".$cluster."’";
     }
     print "\n $jobproperties \n";
}

(You can remove the “print” lines used to check what the rule is doing)

This rule is written in a text file: regle.oar and added ro oar with:

oaradmissionrules -n -r ./regle.oar 

Example 4:

Limit access to a queue, based on usernames set in a file

Answer
# Title : limit access to the challenge queue to authorized usersqueue
if ($queue_name eq "challenge"){
  open(FILE, "< $ENV{HOME}/challenge.users") || die("[ADMISSION RULE] Challenge user list is empty");
  my $authorized = 0;
  while (<FILE>){
    if (m/^\s*$user\s*$/m){
      $authorized = 1;
    }
  }
  close(FILE);
  if($authorized ne 1){
    die("[ADMISSION RULE] $user is not authorized to submit in challenge queue\n");
  }
}
wiki/some_examples_of_admission_rules.txt · Last modified: 2017/03/29 10:14 by neyron
Recent changes RSS feed GNU Free Documentation License 1.3 Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki