What would be the best way to modify form.yml.erb so it can provide different core or memory options based upon user group membership? I have a number of launchers with mostly sane defaults but a few groups need to be exceptions in regard to what they can select for cpu, cores. This can of course be solved via custom lab or per user/sandbox launchers but those have now proliferated into the hundreds so a central solution is better.
We don’t have a good solution for centralized dynamic config that can be shared across all interactive app plugins. So what I would do is have this code run on the dashboard startup and store the results. There are 2 approaches to that, both using a custom initializer in /etc/ood/config/apps/dashboard/initializers.
- You can create a custom module/class and add the method there, then call it from within the apps.
- Or you can utilize Rails https://guides.rubyonrails.org/configuring.html#custom-configuration.
With the first approach you would define something like:
class TuftsResourceConstraints
def self.constraints
return @constraints if defined?(@constraints)
groups = OodSupport::Process.groups.map(&:name)
if groups.include?('multicoreusers')
@constraints = { cores: 48, nodes: 1 }
elsif groups.include?('parallelusers')
@constraints = { cores: 48, nodes: 10 }
else
@constraints = { cores: 1, nodes: 1 }
end
end
end
Then in the form.yml.erb do
<%= TuftsResourceConstraints.constraints[:cores] %>
<%= TuftsResourceConstraints.constraints[:nodes] %>
With the second approach you could do something like this in the Rails initializer:
Rails.application.configure do
groups = OodSupport::Process.groups.map(&:name)
cores = 1
nodes = 1
if groups.include?('multicoreusers')
cores = 48
nodes = 1
elsif groups.include?('parallelusers')
cores = 48
nodes = 10
end
config.x.constraints.cores = cores
config.x.constraints.nodes = nodes
end
Then in the form.yml.erb do
<%= Rails.configuration.x.constraints.cores %>
<%= Rails.configuration.x.constraints.nodes %>
Neither of these approaches work for the case that you have an app submitting to multiple clusters and the constraints vary from cluster to cluster.