class PGPool::CommandLauncher

class: CommandLauncher, a simple wrapper for PCP PGPool management CLI

Constants

DEFAULT_PREFIX
PCP_NODE_COUNT_EXE
PCP_NODE_INFO_EXE

Attributes

number_of_nodes[R]

Public Class Methods

new(hostname, port, user, password, timeout, options = {}) click to toggle source
# File lib/pgpool/command_launcher.rb, line 30
def initialize(hostname, port, user, password, timeout, options = {})
  options = { prefix: DEFAULT_PREFIX }.merge(options)

  @hostname = hostname
  @port     = port
  @user     = user
  @password = password
  @timeout  = timeout

  @pcp_command_options    = "#{@timeout} #{@hostname} #{@port} #{@user} #{@password}"
  @pcp_node_count_command = "#{File.join(options[:prefix], PCP_NODE_COUNT_EXE)} #{@pcp_command_options}"
  @pcp_node_info_command  = "#{File.join(options[:prefix], PCP_NODE_INFO_EXE)} #{@pcp_command_options}"

  self
end

Public Instance Methods

node_information(node_id) click to toggle source
# File lib/pgpool/command_launcher.rb, line 54
def node_information(node_id)
  fail("Invalid node id(#{node_id}) must be between 0 and #{number_of_nodes - 1}") unless valid_node_id?(node_id)
  Response.new(node_id, launch("#{@pcp_node_info_command} #{node_id}"))
end
nodes_information() click to toggle source
# File lib/pgpool/command_launcher.rb, line 59
def nodes_information
  number_of_nodes.times.map { |node_id| node_information(node_id) }
end
valid_node_id?(node_id) click to toggle source
# File lib/pgpool/command_launcher.rb, line 50
def valid_node_id?(node_id)
  node_id >= 0 && node_id < number_of_nodes
end

Private Instance Methods

extract_number_of_nodes() click to toggle source
# File lib/pgpool/command_launcher.rb, line 22
def extract_number_of_nodes
  launch(@pcp_node_count_command).stdout.to_i
end
launch(command_str) click to toggle source
# File lib/pgpool/command_launcher.rb, line 14
def launch(command_str)
  command = ::Mixlib::ShellOut.new(command_str)

  command.run_command
  command.error!
  command
end