Class: Legion::CLI::Broker

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/broker_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/legion/cli/broker_command.rb', line 12

def self.exit_on_failure?
  true
end

Instance Method Details

#cleanupObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/legion/cli/broker_command.rb', line 82

def cleanup
  out = formatter
  orphans = find_orphans

  if orphans.empty?
    out.success('No orphaned queues found')
    return
  end

  if options[:json]
    out.json({ orphaned_queues: orphans, deleted: options[:execute] })
    delete_orphans(orphans) if options[:execute]
    return
  end

  out.header("Orphaned Queues (#{orphans.size})")
  orphans.each { |q| out.warn(q) }
  out.spacer

  if options[:execute]
    delete_orphans(orphans)
    out.success("Deleted #{orphans.size} orphaned queue(s)")
  else
    out.warn('Dry-run mode — pass --execute to delete')
  end
rescue Legion::CLI::Error => e
  formatter.error(e.message)
  exit(1)
end

#purge_topologyObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/legion/cli/broker_command.rb', line 48

def purge_topology
  require 'legion/cli/admin_command'
  out        = formatter
  exchanges  = management_api("/exchanges/#{vhost_encoded}").map { |e| { name: e[:name], type: e[:type] } }
  candidates = Legion::CLI::AdminCommand.detect_old_exchanges(exchanges)

  if candidates.empty?
    out.success('No old v2.0 topology exchanges found.')
    return
  end

  if options[:json]
    out.json({ candidates: candidates, deleted: options[:execute] })
    candidates.each { |e| management_delete("/exchanges/#{vhost_encoded}/#{ERB::Util.url_encode(e[:name])}") } if options[:execute]
    return
  end

  out.header("Old v2.0 Exchanges (#{candidates.size})")
  candidates.each { |e| out.warn("#{e[:name]} (#{e[:type]})") }
  out.spacer

  if options[:execute]
    candidates.each { |e| management_delete("/exchanges/#{vhost_encoded}/#{ERB::Util.url_encode(e[:name])}") }
    out.success("Purged #{candidates.size} exchange(s).")
  else
    out.warn('Dry-run mode — pass --execute to delete')
  end
rescue Legion::CLI::Error => e
  formatter.error(e.message)
  exit(1)
end

#statsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/legion/cli/broker_command.rb', line 25

def stats
  out = formatter
  data = fetch_stats

  if options[:json]
    out.json(data)
  else
    out.header('RabbitMQ Broker Stats')
    out.spacer
    out.detail({
                 queues:    data[:queues],
                 exchanges: data[:exchanges],
                 consumers: data[:consumers],
                 dlx:       data[:dlx]
               })
  end
rescue Legion::CLI::Error => e
  formatter.error(e.message)
  exit(1)
end