Class: MysqlSlaver::Slaver

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/mysql_slaver/slaver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(params) ⇒ Slaver

Returns a new instance of Slaver.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mysql_slaver/slaver.rb', line 13

def initialize(params)
  mysql_root_password = params.fetch(:mysql_root_password, '')
  port                = params.fetch(:port, 3306)
  ssh_port            = params.fetch(:ssh_port, 22)
  socket_file         = params.fetch(:socket_file, nil)
  tables              = params.fetch(:tables, nil)
  @no_copy            = params.fetch(:no_copy, false)

  dry_run             = params.fetch(:dry_run, false)
  executor            = Executor.new(ssh_port: params[:ssh_port], dry_run: dry_run)

  @status_fetcher = params.fetch(:status_fetcher) {
    StatusFetcher.new(
      master_host:          params.fetch(:master_host),
      mysql_root_password:  mysql_root_password,
      socket_file:          socket_file,
      ssh_port:             ssh_port,
      executor:             executor
    )
  }

  @data_copier = params.fetch(:data_copier) {
    DbCopier.new(
      master_host:          params.fetch(:master_host),
      mysql_root_password:  mysql_root_password,
      database:             params.fetch(:database),
      port:                 port,
      socket_file:          socket_file,
      tables:               tables,
      ssh_port:             ssh_port,
      executor:             executor
    )
  }

  @master_changer = params.fetch(:master_changer) {
    MasterChanger.new(
      master_host:           params.fetch(:master_host),
      mysql_root_password:   mysql_root_password,
      replication_user:      params.fetch(:replication_user),
      replication_password:  params.fetch(:replication_password),
      port:                  port,
      socket_file:           socket_file,
      executor:              executor
    )
  }
end

Instance Attribute Details

#data_copierObject (readonly)

Returns the value of attribute data_copier.



11
12
13
# File 'lib/mysql_slaver/slaver.rb', line 11

def data_copier
  @data_copier
end

#master_changerObject (readonly)

Returns the value of attribute master_changer.



11
12
13
# File 'lib/mysql_slaver/slaver.rb', line 11

def master_changer
  @master_changer
end

#no_copyObject (readonly)

Returns the value of attribute no_copy.



11
12
13
# File 'lib/mysql_slaver/slaver.rb', line 11

def no_copy
  @no_copy
end

#status_fetcherObject (readonly)

Returns the value of attribute status_fetcher.



11
12
13
# File 'lib/mysql_slaver/slaver.rb', line 11

def status_fetcher
  @status_fetcher
end

#tablesObject (readonly)

Returns the value of attribute tables.



11
12
13
# File 'lib/mysql_slaver/slaver.rb', line 11

def tables
  @tables
end

Instance Method Details

#enslave!Object



60
61
62
63
64
65
66
# File 'lib/mysql_slaver/slaver.rb', line 60

def enslave!
  master_status = status_fetcher.status
  data_copier.copy! unless no_copy
  master_changer.change!(master_status)
rescue Exception => e
  log e.message
end