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, cache_key, find, #from_hash, #invalidate_cache, #to_hash

Constructor Details

#initializeCluster

Returns a new instance of Cluster.



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

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

Instance Attribute Details

#last_heartbeatObject

Returns the value of attribute last_heartbeat.



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

def last_heartbeat
  @last_heartbeat
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mms/resource/cluster.rb', line 3

def name
  @name
end

#replicaset_nameObject

Returns the value of attribute replicaset_name.



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

def replicaset_name
  @replicaset_name
end

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

Returns the value of attribute restorejobs.



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

def restorejobs
  @restorejobs
end

#shard_nameObject

Returns the value of attribute shard_name.



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

def shard_name
  @shard_name
end

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

Returns the value of attribute snapshots.



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

def snapshots
  @snapshots
end

#type_nameObject

Returns the value of attribute type_name.



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

def type_name
  @type_name
end

Class Method Details

._find(client, group_id, id) ⇒ Object



93
94
95
# File 'lib/mms/resource/cluster.rb', line 93

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

.table_headerObject



89
90
91
# File 'lib/mms/resource/cluster.rb', line 89

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

Instance Method Details

#_from_hash(data) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/mms/resource/cluster.rb', line 97

def _from_hash(data)
  @name = data['clusterName']
  @shard_name = data['shardName']
  @replicaset_name = data['replicaSetName']
  @type_name = data['typeName']
  @last_heartbeat = data['lastHeartbeat']
end

#_to_hashObject



105
106
107
# File 'lib/mms/resource/cluster.rb', line 105

def _to_hash
  @data
end

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

Parameters:

  • point_in_time (String) (defaults to: nil)

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mms/resource/cluster.rb', line 60

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

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

  job_data_list.map do |job_data|
    j = MMS::Resource::RestoreJob.new
    j.client(@client)
    j.data(job_data)
    j
  end
end

#groupObject



17
18
19
# File 'lib/mms/resource/cluster.rb', line 17

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

#snapshot(id) ⇒ Object



21
22
23
# File 'lib/mms/resource/cluster.rb', line 21

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

#snapshot_scheduleObject



38
39
40
# File 'lib/mms/resource/cluster.rb', line 38

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

#table_rowObject



81
82
83
# File 'lib/mms/resource/cluster.rb', line 81

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

#table_sectionObject



85
86
87
# File 'lib/mms/resource/cluster.rb', line 85

def table_section
  [table_row]
end