How to set cluster for an app from an initializer?

We have multiple sites/clusters each with it’s own dedicated OnDemand server and I’d like to share apps between the clusters with the apps being agnositc to which site they are running at so they can be copied from site to site without needing to modify them. To get to that I’ve been moving site specific stuff into into /etc/ood/config/apps/dashboard/initializers/ and loading into the apps from there. I’m trying to do that with cluster: , in an initializer I have:

class SiteOptions

  @@cluster = "mysite"

  def self.cluster
    @@cluster
  end
end

Then in form.yml.erb I use:

cluster: "<% SiteOptions.cluster %>"

This works fine to get the app added to the menu at a site, but when I try to have the app submit a job, I get the error:

save
The cluster was never set. Either set it in form.yml.erb with `cluster` or `form.cluster` or
set `cluster` in submit.yml.erb.

If I set cluster without using a template, e.g.

cluster: "mysite"

Then the app works fine. What am I doing wrong here? Alternatively, is there a better way to abstract the cluster name out of the app and into /etc/ood that I’ve missed?

griznog

It looks like you aren’t returning a string here in that ERB. To do so, you would need to use <%= %> instead of <% %>.

That might clear the issue. Also, in Ruby you don’t want to use global variables like that with @@.

Try something more like this:

class SiteOptions
  @cluster = "mysite"

  class << self
    attr_accessor :cluster
  end
end
1 Like

Brilliant, thank you @travert! That works great.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.