Skip to content

Commit

Permalink
Create a hawkular client for partial endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooli Tayer committed Feb 13, 2017
1 parent 2d44267 commit aeb4035
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions app/models/manageiq/providers/hawkular/datawarehouse_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,38 @@ def self.verify_ssl_mode
end

# Hawkular Client
def self.raw_connect(hostname, port, token, alerts = false)
client = alerts ? ::Hawkular::Alerts::AlertsClient : ::Hawkular::Metrics::Client
client.new(
def self.raw_connect(hostname, port, token, type = :alerts)
klass = case type
when :metrics
::Hawkular::Metrics::Client
when :alerts
::Hawkular::Alerts::AlertsClient
else
raise ArgumentError, "Client not found for #{type}"
end
klass.new(
URI::HTTPS.build(:host => hostname, :port => port.to_i).to_s,
{ :token => token },
{ :tenant => '_system', :verify_ssl => verify_ssl_mode }
)
end

def connect(options = {})
@client ||= self.class.raw_connect(hostname,
port,
authentication_token('default'),
options[:alerts])
@clients ||= {}
@clients[options[:type]] ||= self.class.raw_connect(
hostname,
port,
authentication_token('default'),
options[:type]
)
end

def alerts_client
connect(:type => :alerts)
end

def metrics_client
connect(:type => :metrics)
end

def supports_port?
Expand Down

0 comments on commit aeb4035

Please sign in to comment.