Class: MysqlSlaver::StatusFetcher

Inherits:
Object
  • Object
show all
Includes:
Logger, MysqlCommand
Defined in:
lib/mysql_slaver/status_fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MysqlCommand

#mysql_command, #mysql_credentials

Methods included from Logger

#log

Constructor Details

#initialize(params) ⇒ StatusFetcher

Returns a new instance of StatusFetcher.



8
9
10
11
12
13
# File 'lib/mysql_slaver/status_fetcher.rb', line 8

def initialize(params)
  @master_host         = params.fetch(:master_host)
  @socket_file         = params.fetch(:socket_file, nil)
  @mysql_root_password = params.fetch(:mysql_root_password, '')
  @executor            = params.fetch(:executor) { Executor.new(ssh_port: params[:ssh_port]) }
end

Instance Attribute Details

#executorObject

Returns the value of attribute executor.



6
7
8
# File 'lib/mysql_slaver/status_fetcher.rb', line 6

def executor
  @executor
end

#master_hostObject

Returns the value of attribute master_host.



6
7
8
# File 'lib/mysql_slaver/status_fetcher.rb', line 6

def master_host
  @master_host
end

#mysql_root_passwordObject

Returns the value of attribute mysql_root_password.



6
7
8
# File 'lib/mysql_slaver/status_fetcher.rb', line 6

def mysql_root_password
  @mysql_root_password
end

#socket_fileObject

Returns the value of attribute socket_file.



6
7
8
# File 'lib/mysql_slaver/status_fetcher.rb', line 6

def socket_file
  @socket_file
end

Instance Method Details

#statusObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mysql_slaver/status_fetcher.rb', line 15

def status
  params = {root_password: mysql_root_password, socket_file: socket_file}
  cmd = mysql_command("show master status\\G", params)
  if data = executor.execute(executor.ssh_command(cmd, master_host))
    rtn = parse data
    log "MASTER STATUS - file: #{rtn[:file]}, position: #{rtn[:position]}"
    rtn
  else
    raise Exception.new("Failed to get master status")
  end
end