X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/90d84d8578b760b493ac76b22c42bc284868bc0c..e16ee88755436818cbed44dabb784d1d3254d469:/services/api/app/models/keep_service.rb diff --git a/services/api/app/models/keep_service.rb b/services/api/app/models/keep_service.rb index f9dd01837c..f76f5e47a5 100644 --- a/services/api/app/models/keep_service.rb +++ b/services/api/app/models/keep_service.rb @@ -7,6 +7,7 @@ class KeepService < ArvadosModel include KindAndEtag include CommonApiTemplate extend DbCurrentTime + extend CurrentApiClient SERVER_START_TIME = db_current_time @@ -20,6 +21,21 @@ class KeepService < ArvadosModel api_accessible :superuser, :extend => :user do |t| end + # return the set of keep services from the database (if this is an + # older installation or test system where entries have been added + # manually) or, preferably, the cluster config file. + def self.all *args + if super.count == 0 + from_config + else + super + end + end + + def self.where *args + all.where *args + end + protected def permission_to_create @@ -36,26 +52,27 @@ class KeepService < ArvadosModel values = [] id = 1 Rails.configuration.Services.Keepstore.InternalURLs.each do |url, info| - values << "(#{id}, " + quoted_column_values_from_url(url: url.to_s, info: info).join(", ") + ", 'disk', 'f'::bool, #{config_time}, #{config_time}, #{owner}, #{owner}, null)" + values << "(#{id}, " + quoted_column_values_from_url(url: url.to_s, rendezvous: info.Rendezvous).join(", ") + ", 'disk', 'f'::bool, #{config_time}, #{config_time}, #{owner}, #{owner}, null)" id += 1 end - Rails.configuration.Services.Keepproxy.InternalURLs.each do |url, info| - values << "(#{id}, " + quoted_column_values_from_url(url: url.to_s, info: info).join(", ") + ", 'proxy', 'f'::bool, #{config_time}, #{config_time}, #{owner}, #{owner}, null)" + url = Rails.configuration.Services.Keepproxy.ExternalURL.to_s + if !url.blank? + values << "(#{id}, " + quoted_column_values_from_url(url: url, rendezvous: "").join(", ") + ", 'proxy', 'f'::bool, #{config_time}, #{config_time}, #{owner}, #{owner}, null)" id += 1 end if values.length == 0 # return empty set as AR relation - return where('1=0') + return unscoped.where('1=0') else sql = "(values #{values.join(", ")}) as keep_services (id, uuid, service_host, service_port, service_ssl_flag, service_type, read_only, created_at, modified_at, owner_uuid, modified_by_user_uuid, modified_by_client_uuid)" - return KeepService.from(sql) + return unscoped.from(sql) end end private - def self.quoted_column_values_from_url(url:, info:) - rvz = info.Rendezvous + def self.quoted_column_values_from_url(url:, rendezvous:) + rvz = rendezvous rvz = url if rvz.blank? if /^[a-zA-Z0-9]{15}$/ !~ rvz # If rvz is an URL (either the real service URL, or an alternate