Class: Killbill::KPM::KPMClient

Inherits:
KillBillClient::Model::Resource
  • Object
show all
Defined in:
lib/kpm/client.rb

Constant Summary collapse

KILLBILL_KPM_PREFIX =
'/plugins/killbill-kpm'
KILLBILL_OSGI_LOGGER_PREFIX =
'/plugins/killbill-osgi-logger'

Class Method Summary collapse

Class Method Details

.get_available_plugins(kb_version_maybe_snapshot, latest, options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kpm/client.rb', line 12

def get_available_plugins(kb_version_maybe_snapshot, latest, options)
  # Mostly useful for Kill Bill developers: get the latest version before the current snapshot
  # (we rarely deploy SNAPSHOT jars)
  captures = kb_version_maybe_snapshot.scan(/0.(\d+)(\.)?(\d+)?(-SNAPSHOT)?/)
  # [["20", ".", "1", "-SNAPSHOT"]]
  kb_version = if !captures.nil? && !captures.first.nil? && !captures.first[3].nil?
                 if captures.first[2].to_i.positive?
                   "0.#{captures.first[0]}.#{captures.first[2].to_i - 1}"
                 else
                   "0.#{captures.first[0].to_i - 1}.0"
                 end
               else
                 kb_version_maybe_snapshot
               end

  path = "#{KILLBILL_KPM_PREFIX}/plugins"
  response = KillBillClient::API.get path, { kbVersion: kb_version, latest: latest }, options
  JSON.parse(response.body)
end

.stream_osgi_logs(writer, host, last_event_id_ref) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/kpm/client.rb', line 32

def stream_osgi_logs(writer, host, last_event_id_ref)
  url = host
  url = "http://#{url}" unless url.starts_with?('http:')
  SSE::Client.new(url + KILLBILL_OSGI_LOGGER_PREFIX, last_event_id: last_event_id_ref.get, logger: Rails.logger) do |client|
    client.on_event do |event|
      writer.write(event.data, id: event.id)
      last_event_id_ref.set(event.id)
    end
  end
end