Class: Bosh::CloudFoundry::Config::PostgresqlServiceConfig
- Inherits:
-
Object
- Object
- Bosh::CloudFoundry::Config::PostgresqlServiceConfig
- Defined in:
- lib/bosh-cloudfoundry/config/postgresql_service_config.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#add_core_jobs_to_manifest(manifest) ⇒ Object
Adds “postgresql_gateway” to colocated “core” job.
-
#add_jobs_to_manifest(manifest) ⇒ Object
Jobs to add to the target manifest.
-
#add_resource_pools_to_manifest(manifest) ⇒ Object
Adds resource pools to the target manifest, if server_count > 0.
-
#any_service_nodes? ⇒ Boolean
True if there are any postgresql nodes to be provisioned.
- #bosh_provider_name ⇒ Object
-
#cluster_name(cluster) ⇒ Object
resource_pool name for a cluster cluster_name like ‘postgresql_m1_xlarge_free’.
- #config ⇒ Object
-
#find_cluster_for_flavor(server_flavor) ⇒ Hash
nil if its not currently a requested flavor.
-
#initialize(system_config) ⇒ PostgresqlServiceConfig
constructor
A new instance of PostgresqlServiceConfig.
-
#merge_manifest_properties(manifest) ⇒ Object
Add extra configuration properties into the manifest for the gateway, node, and service plans.
-
#preallocated_ram ⇒ Integer
The ballpark ram for postgresql, BOSH agent, etc.
-
#provider ⇒ Object
a helper object for the target BOSH provider.
- #ram_for_server_flavor ⇒ Object
- #save ⇒ Object
- #total_service_nodes_count ⇒ Object
- #update_cluster_count_for_flavor(server_count, server_flavor, server_plan = "free") ⇒ Object
Constructor Details
#initialize(system_config) ⇒ PostgresqlServiceConfig
Returns a new instance of PostgresqlServiceConfig.
7 8 9 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 7 def initialize(system_config) @system_config = system_config end |
Class Method Details
.build_from_system_config(system_config) ⇒ Object
11 12 13 14 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 11 def self.build_from_system_config(system_config) system_config.postgresql ||= [] new(system_config) end |
Instance Method Details
#add_core_jobs_to_manifest(manifest) ⇒ Object
Adds “postgresql_gateway” to colocated “core” job
63 64 65 66 67 68 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 63 def add_core_jobs_to_manifest(manifest) if any_service_nodes? @core_job ||= manifest["jobs"].find { |job| job["name"] == "core" } @core_job["template"] << "postgresql_gateway" end end |
#add_jobs_to_manifest(manifest) ⇒ Object
Jobs to add to the target manifest
-
name: postgresql template:
-
postgresql
instances: 2 resource_pool: postgresql networks:
-
name: default default:
-
dns
-
gateway
-
-
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 116 def add_jobs_to_manifest(manifest) if any_service_nodes? config.each do |cluster| server_count = cluster["count"] server_flavor = cluster["flavor"] job = { "name" => cluster_name(cluster), "template" => ["postgresql_node"], "instances" => server_count, "resource_pool" => cluster_name(cluster), # TODO are these AWS-specific networks? "networks" => [{ "name" => "default", "default" => ["dns", "gateway"] }], "persistent_disk" => 16192 } manifest["jobs"] << job end end end |
#add_resource_pools_to_manifest(manifest) ⇒ Object
Adds resource pools to the target manifest, if server_count > 0
-
name: postgresql network: default size: 2 stemcell:
name: bosh-stemcell version: 0.6.4
cloud_properties:
instance_type: m1.xlarge
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 80 def add_resource_pools_to_manifest(manifest) if any_service_nodes? config.each do |cluster| server_count = cluster["count"] server_flavor = cluster["flavor"] resource_pool = { "name" => cluster_name(cluster), "network" => "default", "size" => server_count, "stemcell" => { "name" => @system_config.stemcell_name, "version" => @system_config.stemcell_version }, # TODO how to create "cloud_properties" per-provider? "cloud_properties" => { "instance_type" => server_flavor }, "persistent_disk" => 16192 } manifest["resource_pools"] << resource_pool end end end |
#any_service_nodes? ⇒ Boolean
Returns true if there are any postgresql nodes to be provisioned.
21 22 23 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 21 def any_service_nodes? total_service_nodes_count > 0 end |
#bosh_provider_name ⇒ Object
29 30 31 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 29 def bosh_provider_name @system_config.bosh_provider end |
#cluster_name(cluster) ⇒ Object
resource_pool name for a cluster cluster_name like ‘postgresql_m1_xlarge_free’
54 55 56 57 58 59 60 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 54 def cluster_name(cluster) server_flavor = cluster["flavor"] server_plan = cluster["plan"] || "free" cluster_name = "postgresql_#{server_flavor}_#{server_plan}" cluster_name.gsub!(/\W+/, '_') cluster_name end |
#config ⇒ Object
16 17 18 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 16 def config @system_config.postgresql end |
#find_cluster_for_flavor(server_flavor) ⇒ Hash
nil if its not currently a requested flavor
44 45 46 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 44 def find_cluster_for_flavor(server_flavor) @system_config.postgresql.find { |cl| cl["flavor"] == server_flavor } end |
#merge_manifest_properties(manifest) ⇒ Object
Add extra configuration properties into the manifest for the gateway, node, and service plans
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 140 def merge_manifest_properties(manifest) if any_service_nodes? manifest["properties"]["postgresql_gateway"] = { "admin_user"=>"psql_admin", "admin_passwd_hash"=>nil, "token"=>"TOKEN", "supported_versions"=>["9.0"], "version_aliases"=>{"current"=>"9.0"} } manifest["properties"]["postgresql_node"] = { "admin_user"=>"psql_admin", "admin_passwd_hash"=>nil, "available_storage"=>2048, "max_db_size"=>256, "max_long_tx"=>30, "supported_versions"=>["9.0"], "default_version"=>"9.0" } manifest["properties"]["service_plans"]["postgresql"] = { "free"=> {"job_management"=>{"high_water"=>1400, "low_water"=>100}, "configuration"=> {"capacity"=>200, "max_db_size"=>128, "max_long_query"=>3, "max_long_tx"=>30, "max_clients"=>20, "backup"=>{"enable"=>true}}} } end end |
#preallocated_ram ⇒ Integer
Returns the ballpark ram for postgresql, BOSH agent, etc.
173 174 175 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 173 def preallocated_ram 300 end |
#provider ⇒ Object
a helper object for the target BOSH provider
182 183 184 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 182 def provider @provider ||= Bosh::CloudFoundry::Providers.for_bosh_provider_name(system_config) end |
#ram_for_server_flavor ⇒ Object
177 178 179 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 177 def ram_for_server_flavor provider.ram_for_server_flavor(server_flavor) end |
#save ⇒ Object
48 49 50 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 48 def save @system_config.save end |
#total_service_nodes_count ⇒ Object
25 26 27 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 25 def total_service_nodes_count config.inject(0) { |total, cluster| total + (cluster["count"].to_i) } end |
#update_cluster_count_for_flavor(server_count, server_flavor, server_plan = "free") ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/bosh-cloudfoundry/config/postgresql_service_config.rb', line 33 def update_cluster_count_for_flavor(server_count, server_flavor, server_plan="free") if cluster = find_cluster_for_flavor(server_flavor.to_s) cluster["count"] = server_count else config << {"count" => server_count, "flavor" => server_flavor.to_s, "plan" => server_plan} end self.save end |