Class: EasyE::Plugin::MongoPlugin

Inherits:
EasyE::Plugin show all
Defined in:
lib/plugins/mongo_plugin.rb

Constant Summary collapse

WIRED_TIGER_KEY =
'wiredTiger'

Instance Attribute Summary collapse

Attributes inherited from EasyE::Plugin

#logger, #options

Instance Method Summary collapse

Methods inherited from EasyE::Plugin

#carefully, #collect_options, inherited, registered_plugins

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/plugins/mongo_plugin.rb', line 4

def client
  @client
end

Instance Method Details

#afterObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/plugins/mongo_plugin.rb', line 63

def after
  return logger.error "Refusing to operate" if carefully('check whether this node is a primary') { primary? }.nil?
  return logger.error "This appears to be a primary member, refusing to operate" if primary?
  
  if wired_tiger?
    carefully('start mongo') { start_mongo } if options.shutdown
  else
    carefully('unlock mongo') { unlock_mongo }
  end

  if carefully('check that mongo is still accessible') { client.command(serverStatus: 1).first }
    logger.info "Received status from mongo, everything appears to be ok"
  end
end

#beforeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/plugins/mongo_plugin.rb', line 48

def before
  require 'mongo'
  Mongo::Logger.logger = logger
  return logger.error "Refusing to operate" if carefully('check whether this node is a primary') { primary? }.nil?
  return logger.error "This appears to be a primary member, refusing to operate" if primary?

  if wired_tiger?
    logger.info "Wired Tiger storage engine detected"
    carefully('shutdown mongo') { shutdown_mongo } if options.shutdown
  else
    logger.info "MMAPv1 storage engine detected"
    carefully('lock mongo') { lock_mongo }
  end
end

#client_optionsObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/plugins/mongo_plugin.rb', line 37

def client_options
  {
    user: options.user,
    password: options.password,
    server_selection_timeout: options.server_selection_timeout.to_i,
    wait_queue_timeout: options.wait_queue_timeout.to_i,
    connection_timeout: options.connection_timeout.to_i,
    socket_timeout: options.socket_timeout.to_i
  }
end

#default_optionsObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/plugins/mongo_plugin.rb', line 20

def default_options
  {
    service: 'mongodb',
    port: '27017',
    shutdown: false,
    host: 'localhost',
    server_selection_timeout: 30,
    wait_queue_timeout: 1,
    connection_timeout: 5,
    socket_timeout: 5
  }
end

#defined_optionsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/plugins/mongo_plugin.rb', line 5

def defined_options
  {
    service: 'Service to start after shutting down server',
    shutdown: 'Shutdown mongodb server (this is required if your data and journal are on different volumes',
    user: 'Mongo user',
    password: 'Mongo password',
    port: 'Mongo port',
    host: 'Mongo host',
    server_selection_timeout: 'Timeout in seconds while choosing a server to connect to (default 30)',
    wait_queue_timeout: 'Timeout in seconds while waiting for a connection in the pool (default 1)',
    connection_timeout: 'Timeout in seconds to wait for a socket to connect (default 5)',
    socket_timeout: 'Timeout in seconds to wait for an operation to execute on a socket (default 5)'
  }
end

#nameObject



78
79
80
# File 'lib/plugins/mongo_plugin.rb', line 78

def name
  "Mongo"
end