Skip to content

Commit

Permalink
SystemConfig is setup via the ServiceConfig subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Mar 10, 2013
1 parent d07fde9 commit f8b390f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/bosh-cloudfoundry/config/postgresql_service_config.rb
Expand Up @@ -7,6 +7,7 @@ class PostgresqlServiceConfig < ServiceConfig

# name that maps into the cf-release's jobs folder
# for postgresql_gateway and postgresql_node jobs
# also used as the key into SystemConfig manifest
def service_name
"postgresql"
end
Expand Down
1 change: 1 addition & 0 deletions lib/bosh-cloudfoundry/config/redis_service_config.rb
Expand Up @@ -7,6 +7,7 @@ class RedisServiceConfig < ServiceConfig

# name that maps into the cf-release's jobs folder
# for redis_gateway and redis_node jobs
# also used as the key into SystemConfig manifest
def service_name
"redis"
end
Expand Down
36 changes: 21 additions & 15 deletions lib/bosh-cloudfoundry/config/system_config.rb
Expand Up @@ -17,7 +17,7 @@ def initialize(system_dir)
super(config_file, system_dir)
self.system_dir = system_dir
self.system_name = File.basename(system_dir)
setup_default_service_config
setup_services
end

[
Expand Down Expand Up @@ -65,24 +65,30 @@ def microbosh
@microbosh ||= Bosh::CloudFoundry::Config::MicroboshConfig.new(bosh_target)
end

def setup_services
@services = {}
service_classes.each do |service_class|
service = service_class.build_from_system_config(self)
service_name = service.service_name
self.send("#{service_name}=", [])
@services[service_name] = service
end
end

def service_classes
[
Bosh::CloudFoundry::Config::PostgresqlServiceConfig,
Bosh::CloudFoundry::Config::RedisServiceConfig,
]
end

def supported_services
%w[postgresql redis]
@services.keys
end

def service(service_name)
case service_name.to_sym
when :postgresql
Bosh::CloudFoundry::Config::PostgresqlServiceConfig.build_from_system_config(self)
when :redis
Bosh::CloudFoundry::Config::RedisServiceConfig.build_from_system_config(self)
else
raise "please add #{service_name} support to SystemConfig#service method"
end
@services[service_name] ||
raise("please add #{service_name} support to SystemConfig#service method")
end

def setup_default_service_config
supported_services.each do |service_name|
self.send("#{service_name}=", [])
end
end
end

0 comments on commit f8b390f

Please sign in to comment.