Class: MysqlSlaver::MasterChanger

Inherits:
Object
  • Object
show all
Includes:
MysqlCommand
Defined in:
lib/mysql_slaver/master_changer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MysqlCommand

#mysql_command, #mysql_credentials

Constructor Details

#initialize(params) ⇒ MasterChanger

Returns a new instance of MasterChanger.



7
8
9
10
11
12
13
14
15
# File 'lib/mysql_slaver/master_changer.rb', line 7

def initialize(params)
  @master_host          = params.fetch(:master_host)
  @port                 = params.fetch(:port)
  @socket_file          = params.fetch(:socket_file, nil)
  @mysql_root_password  = params.fetch(:mysql_root_password, '')
  @replication_user     = params.fetch(:replication_user)
  @replication_password = params.fetch(:replication_password)
  @executor             = params.fetch(:executor) { Executor.new }
end

Instance Attribute Details

#executorObject

Returns the value of attribute executor.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def executor
  @executor
end

#master_hostObject

Returns the value of attribute master_host.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def master_host
  @master_host
end

#mysql_root_passwordObject

Returns the value of attribute mysql_root_password.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def mysql_root_password
  @mysql_root_password
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def port
  @port
end

#replication_passwordObject

Returns the value of attribute replication_password.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def replication_password
  @replication_password
end

#replication_userObject

Returns the value of attribute replication_user.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def replication_user
  @replication_user
end

#socket_fileObject

Returns the value of attribute socket_file.



5
6
7
# File 'lib/mysql_slaver/master_changer.rb', line 5

def socket_file
  @socket_file
end

Instance Method Details

#change!(status) ⇒ Object



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

def change!(status)
  cmds = [
    'stop slave',
    change_master(status),
    'start slave'
  ]
  cmd = mysql_command(cmds.join('; '), mysql_params)
  executor.execute cmd
end