Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
wiki:some_examples_of_admission_rules [2017/05/11 15:32] – [Example 5:] mvesinwiki:some_examples_of_admission_rules [2020/04/07 21:49] neyron
Line 248: Line 248:
 (There may be some limitations in that property filtering, which could allow malicious users to overcome the usage policy) (There may be some limitations in that property filtering, which could allow malicious users to overcome the usage policy)
  
 +==== Example 5:  ====
 +Verify that the <code>oarsub -l ''resource request''</code> gives a correct resource definition.
 +
 +OAR resource request hierarchies are implicit in the OAR database, but they can be enforced by an admission rule.
 +
 +Lets assume that valid resources hierarchies are:
 +
 +  * switch > cluster > host > cpu > gpu > core
 +  * cluster > switch > host > cpu > gpu > core
 +  * cluster > switch > host > disk
 +  * switch > cluster > host > disk
 +  * license
 +
 +Here both switch > cluster, or cluster > switch can be valid (some clusters spread their nodes on many switches, some clusters share a same switch). Disks are special resources to reserve disks on hosts, independently from cpu, gpu and cores. Licenses are yet a completly independente type of resources. 
 +
 +Any of those resources properties can define a valid hierarchy or resources, for instance:
 +  * <code>oarsub -l switch=2/core=1</code> → get 2 cores on different switches
 +  * <code>oarsub -l cluster=1/host=2/disk=1</code> → get 2 disks of 2 different hosts but on a same cluster
 +  * oarsub -l license=1</code> → get 1 license
 +
 +But incorrect hierachry should raise an error:
 +  * oarsub -l gpu=1/host=2 → cannot get 2 hosts for a same gpu
 +  * oarsub -l host=1/disk=1/core=1 → cannot mix disk and core
 +
 +==Answer==
 +
 +<code perl>
 +
 +# definition of the valid implicit hierarchies of resources.
 +my %valid_children = (
 +                # both cluster > switch and switch > cluster are relevant
 +                "cluster"  => ["switch", "cpu", "host", "core", "gpu", "disk"],
 +                "switch"   => ["cluster", "cpu", "host", "core", "gpu", "disk"],
 +                "host"     => ["cpu", "core", "gpu", "disk"],
 +                "cpu"      => ["core", "gpu"],
 +                "gpu"      => ["core"],
 +                "disk"     => [],
 +                "license"  => [],
 +                );
 +
 +# nodes is synonym of host
 +my %aliases = (
 +        "nodes" => "host",
 +);
 +
 +# valid values are in one of the possible hierarchies
 +my %valid_resources;
 +foreach my $key (keys %valid_children) {
 +        $valid_resources{$key} = undef;
 +        foreach my $child (@{%valid_children{$key}}) {
 +                $valid_resources{$child} = undef;
 +        }
 +}
 +my @valid_resources = keys %valid_resources;
 +
 +# test the user's request for possible errors
 +foreach my $mold (@{$ref_resource_list}) { # loop on all moldable resources requests (oarsub -l ... -l ...)
 +        foreach my $r (@{$mold->[0]}) { # loop on all joint resources requests (oarsub -l ...+...)
 +                my @resources_hierarchy;
 +                my $parent_resource;
 +                foreach my $h (@{$r->{resources}}) { # loop on every resource, look at the resource name only ($h->{resource}) not the value ($h->{value})
 +                        if(!grep { $_ eq $h->{resource} } @valid_resources) {
 +                                die("[ADMISSION RULE] Error: the requested resources '$h->{resource}' is not valid, please check your syntax.\n");
 +                        }
 +                        if (!grep { $_ eq $h->{resource} } @resources_hierarchy) {
 +                                push @resources_hierarchy, $h->{resource};
 +                        } else {
 +                                # catching the case `oarsub -l /cluster=a/switch=b/cluster=c` or `oarsub -l /switch=a/cluster=b/switch=c`
 +                                push @resources_hierarchy, $h->{resource};
 +                                die("[ADMISSION RULE] Error: duplicated resource '$h->{resource}' in the requested resources hiearchy '".join(" > ", @resources_hierarchy)."'.\n");
 +                        }
 +                        if (defined($parent_resource)) {
 +                                if (!grep { $_ eq $h->{resource} } @{$valid_children{$parent_resource}}) {
 +                                        die("[ADMISSION RULE] Error: the requested resources hierarchy '".join(" > ", @resources_hierarchy)."' is not relevant.\n");
 +                                }
 +                        }
 +                        if (exists $aliases{$h->{resource}}) {
 +                                $parent_resource = $aliases{$h->{resource}};
 +                        } else {
 +                                $parent_resource = $h->{resource};
 +                        }
 +                }
 +        }
 +}
 +</code>
wiki/some_examples_of_admission_rules.txt · Last modified: 2020/04/07 22:01 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