Class: MMS::Resource::Snapshot

Inherits:
MMS::Resource show all
Defined in:
lib/mms/resource/snapshot.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

Instance Attribute Details

#completeObject

Returns the value of attribute complete.



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

def complete
  @complete
end

#created_dateObject

Returns the value of attribute created_date.



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

def created_date
  @created_date
end

#created_incrementObject

Returns the value of attribute created_increment.



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

def created_increment
  @created_increment
end

#expiresObject

Returns the value of attribute expires.



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

def expires
  @expires
end

#is_possibly_inconsistentObject

Returns the value of attribute is_possibly_inconsistent.



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

def is_possibly_inconsistent
  @is_possibly_inconsistent
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#partsObject

Returns the value of attribute parts.



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

def parts
  @parts
end

Class Method Details

._find(client, group_id, cluster_id, host_id, id) ⇒ MMS::Resource::Snapshot

Parameters:

  • client (MMS::Client)
  • group_id (String)
  • cluster_id (String)
  • id (String)

Returns:



102
103
104
# File 'lib/mms/resource/snapshot.rb', line 102

def self._find(client, group_id, cluster_id, host_id, id)
  host_id.nil? ? _find_by_cluster(client, group_id, cluster_id, id) : _find_by_host(client, group_id, host_id, id)
end

._find_by_cluster(client, group_id, cluster_id, id) ⇒ Object



106
107
108
# File 'lib/mms/resource/snapshot.rb', line 106

def self._find_by_cluster(client, group_id, cluster_id, id)
  client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/snapshots/' + id.to_s)
end

._find_by_host(client, group_id, host_id, id) ⇒ Object



110
111
112
# File 'lib/mms/resource/snapshot.rb', line 110

def self._find_by_host(client, group_id, host_id, id)
  client.get('/groups/' + group_id + '/hosts/' + host_id + '/snapshots/' + id.to_s)
end

.table_headerObject



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

def self.table_header
  ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Name (created date)', 'Expires', 'Inconsistent']
end

Instance Method Details

#clusterMMS::Resource::Cluster



54
55
56
# File 'lib/mms/resource/snapshot.rb', line 54

def cluster
  MMS::Resource::Cluster.find(@client, @data['groupId'], @data['clusterId'])
end

#cluster_nameString, NilClass

Returns:

  • (String, NilClass)


30
31
32
# File 'lib/mms/resource/snapshot.rb', line 30

def cluster_name
  cluster.name if is_cluster
end

#config_nameString, NilClass

Returns:

  • (String, NilClass)


35
36
37
# File 'lib/mms/resource/snapshot.rb', line 35

def config_name
  'config' if is_config
end

#create_restorejobArray<MMS::Resource::RestoreJob>

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mms/resource/snapshot.rb', line 59

def create_restorejob
  data = { snapshotId: @id }
  job_data_list = @client.post '/groups/' + cluster.group.id + '/clusters/' + cluster.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

#is_clusterTrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


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

def is_cluster
  @parts.length > 1
end

#is_configTrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


20
21
22
# File 'lib/mms/resource/snapshot.rb', line 20

def is_config
  @parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['hostId'].nil?
end

#is_replicaTrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


25
26
27
# File 'lib/mms/resource/snapshot.rb', line 25

def is_replica
  @parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['clusterId'].nil?
end

#replica_nameString, NilClass

Returns:

  • (String, NilClass)


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

def replica_name
  @parts.first['replicaSetName'] if is_replica
end

#source_nameString, NilClass

Returns:

  • (String, NilClass)


45
46
47
48
49
50
51
# File 'lib/mms/resource/snapshot.rb', line 45

def source_name
  name = nil
  name = replica_name if is_replica
  name = config_name if is_config
  name = cluster_name if is_cluster
  name
end

#table_rowObject



75
76
77
# File 'lib/mms/resource/snapshot.rb', line 75

def table_row
  [cluster.group.name, cluster.name, @id, @complete, @created_increment, @name, @expires, @is_possibly_inconsistent]
end

#table_sectionObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/mms/resource/snapshot.rb', line 79

def table_section
  rows = []
  rows << table_row
  rows << :separator
  part_count = 0
  @parts.each do |part|
    file_size_mb = part['fileSizeBytes'].to_i / (1024 * 1024)
    rows << [{ value: "part #{part_count}", colspan: 4, alignment: :right }, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"]
    part_count += 1
  end
  rows << :separator
  rows
end