Class: MMS::Resource::Cluster

Inherits:
MMS::Resource show all
Defined in:
lib/mms/resource/cluster.rb

Instance Attribute Summary collapse

Attributes inherited from MMS::Resource

#client, #data, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MMS::Resource

#_load, find, #from_hash, #set_client, #set_data, #to_hash

Constructor Details

#initialize ⇒ Cluster

Returns a new instance of Cluster.



14
15
16
17
# File 'lib/mms/resource/cluster.rb', line 14

def initialize
  @snapshots = []
  @restorejobs = []
end

Instance Attribute Details

#last_heartbeat ⇒ Object

Returns the value of attribute last_heartbeat.



9
10
11
# File 'lib/mms/resource/cluster.rb', line 9

def last_heartbeat
  @last_heartbeat
end

#name ⇒ Object

Returns the value of attribute name.



5
6
7
# File 'lib/mms/resource/cluster.rb', line 5

def name
  @name
end

#replicaset_name ⇒ Object

Returns the value of attribute replicaset_name.



7
8
9
# File 'lib/mms/resource/cluster.rb', line 7

def replicaset_name
  @replicaset_name
end

#restorejobs(page = 1, limit = 1000) ⇒ Object

Returns the value of attribute restorejobs.



12
13
14
# File 'lib/mms/resource/cluster.rb', line 12

def restorejobs
  @restorejobs
end

#shard_name ⇒ Object

Returns the value of attribute shard_name.



6
7
8
# File 'lib/mms/resource/cluster.rb', line 6

def shard_name
  @shard_name
end

#snapshots(page = 1, limit = 1000) ⇒ Object

Returns the value of attribute snapshots.



11
12
13
# File 'lib/mms/resource/cluster.rb', line 11

def snapshots
  @snapshots
end

#type_name ⇒ Object

Returns the value of attribute type_name.



8
9
10
# File 'lib/mms/resource/cluster.rb', line 8

def type_name
  @type_name
end

Class Method Details

._find(client, group_id, id) ⇒ Object



119
120
121
# File 'lib/mms/resource/cluster.rb', line 119

def self._find(client, group_id, id)
  client.get('/groups/' + group_id + '/clusters/' + id)
end

.table_header ⇒ Object



115
116
117
# File 'lib/mms/resource/cluster.rb', line 115

def self.table_header
  ['Group', 'Cluster', 'Shard name', 'Replica name', 'Type', 'Last heartbeat', 'Cluster Id']
end

Instance Method Details

#create_restorejob(point_in_time = nil) ⇒ Array<MMS::Resource::RestoreJob>

Parameters:

  • point_in_time (String) (defaults to: nil)

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/mms/resource/cluster.rb', line 67

def create_restorejob(point_in_time = nil)
  data = {
      'timestamp' => {
          'date' => point_in_time,
          'increment' => 0
      }
  }
  jobs = @client.post('/groups/' + group.id + '/clusters/' + @id + '/restoreJobs', data)

  if jobs.nil?
    raise MMS::ResourceError.new("Cannot create job from snapshot `#{self.id}`", self)
  end

  job_list = []
  # work around due to bug in MMS API; cannot read restoreJob using provided info.
  # The config-server RestoreJob and Snapshot has no own ClusterId to be accessed.
  tries = 5
  while tries > 0
    begin
      restore_jobs = restorejobs
      tries = 0
    rescue Exception => e
      tries-=1;
      raise MMS::ResourceError.new(e.message, self) if tries < 1

      STDERR.puts e.message
      STDERR.puts 'Sleeping for 5 seconds. Trying again...'
      sleep(5)
    end
  end

  jobs.each do |job|
    _list = restore_jobs.select { |restorejob| restorejob.id == job['id'] }
    _list.each do |restorejob|
      job_list.push restorejob
    end
  end
  job_list
end

#group ⇒ Object



19
20
21
# File 'lib/mms/resource/cluster.rb', line 19

def group
  MMS::Resource::Group.find(@client, @data['groupId'])
end

#snapshot(id) ⇒ Object



23
24
25
# File 'lib/mms/resource/cluster.rb', line 23

def snapshot(id)
  MMS::Resource::Snapshot.find(@client, group.id, @id, id)
end

#snapshot_schedule ⇒ Object



40
41
42
# File 'lib/mms/resource/cluster.rb', line 40

def snapshot_schedule
  MMS::Resource::SnapshotSchedule.find(@client, group.id, @id)
end

#table_row ⇒ Object



107
108
109
# File 'lib/mms/resource/cluster.rb', line 107

def table_row
  [group.name, @name, @shard_name, @replicaset_name, @type_name, @last_heartbeat, @id]
end

#table_section ⇒ Object



111
112
113
# File 'lib/mms/resource/cluster.rb', line 111

def table_section
  [table_row]
end