This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
wiki:some_examples_of_admission_rules [2017/05/11 15:32] – [Example 5:] mvesin | wiki: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 < | ||
+ | |||
+ | 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: | ||
+ | * < | ||
+ | * < | ||
+ | * oarsub -l license=1</ | ||
+ | |||
+ | But incorrect hierachry should raise an error: | ||
+ | * oarsub -l gpu=1/ | ||
+ | * oarsub -l host=1/ | ||
+ | |||
+ | ==Answer== | ||
+ | |||
+ | <code perl> | ||
+ | |||
+ | # definition of the valid implicit hierarchies of resources. | ||
+ | my %valid_children = ( | ||
+ | # both cluster > switch and switch > cluster are relevant | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ); | ||
+ | |||
+ | # nodes is synonym of host | ||
+ | my %aliases = ( | ||
+ | " | ||
+ | ); | ||
+ | |||
+ | # 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-> | ||
+ | my @resources_hierarchy; | ||
+ | my $parent_resource; | ||
+ | foreach my $h (@{$r-> | ||
+ | if(!grep { $_ eq $h-> | ||
+ | die(" | ||
+ | } | ||
+ | if (!grep { $_ eq $h-> | ||
+ | push @resources_hierarchy, | ||
+ | } else { | ||
+ | # catching the case `oarsub -l / | ||
+ | push @resources_hierarchy, | ||
+ | die(" | ||
+ | } | ||
+ | if (defined($parent_resource)) { | ||
+ | if (!grep { $_ eq $h-> | ||
+ | die(" | ||
+ | } | ||
+ | } | ||
+ | if (exists $aliases{$h-> | ||
+ | $parent_resource = $aliases{$h-> | ||
+ | } else { | ||
+ | $parent_resource = $h-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ |