mms-api 0.0.10 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mms.rb +1 -0
- data/lib/mms/agent.rb +34 -7
- data/lib/mms/cache.rb +5 -0
- data/lib/mms/cli.rb +45 -17
- data/lib/mms/client.rb +15 -0
- data/lib/mms/errors.rb +5 -0
- data/lib/mms/resource.rb +34 -28
- data/lib/mms/resource/alert.rb +20 -23
- data/lib/mms/resource/cluster.rb +32 -29
- data/lib/mms/resource/group.rb +44 -35
- data/lib/mms/resource/host.rb +11 -20
- data/lib/mms/resource/restore_job.rb +30 -34
- data/lib/mms/resource/snapshot.rb +26 -29
- data/lib/mms/resource/snapshot_schedule.rb +60 -0
- data/lib/mms/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91354b2007ab1bf12006b201e465bbc64c7c4e73
|
4
|
+
data.tar.gz: 0c1fdc6932a86acdc3f3f41061f2dcb8782bd612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78d3bde92f63163a64454077f6edee97d82619458c3329f9ba5fa6f84eb2414a04452b46be57f3d0d8fabb9a9862fe2cc67ff48919c90433641b9bd621660479
|
7
|
+
data.tar.gz: e0210ba968b2d67ba035700b952b67445c896ab9b849ba1e1d9899369f18286b57c8d11aa45301de47d02a8cd6eb95815bb17b7e35819092c2f4712be82ff640
|
data/lib/mms.rb
CHANGED
data/lib/mms/agent.rb
CHANGED
@@ -4,18 +4,30 @@ module MMS
|
|
4
4
|
|
5
5
|
attr_accessor :client
|
6
6
|
|
7
|
+
# @param [MMS::Client] client
|
7
8
|
def initialize(client)
|
8
9
|
@client = client
|
9
10
|
end
|
10
11
|
|
12
|
+
# @param [String] apiurl
|
11
13
|
def set_apiurl(apiurl)
|
12
14
|
@client.url = apiurl
|
13
15
|
end
|
14
16
|
|
17
|
+
# @return [Array<MMS::Resource::Group>]
|
15
18
|
def groups
|
16
|
-
|
19
|
+
group_list = []
|
20
|
+
client.get('/groups').each do |group|
|
21
|
+
g = MMS::Resource::Group.new
|
22
|
+
g.set_client(client)
|
23
|
+
g.set_data(group)
|
24
|
+
|
25
|
+
group_list.push g
|
26
|
+
end
|
27
|
+
group_list
|
17
28
|
end
|
18
29
|
|
30
|
+
# @return [Array<MMS::Resource::Host>]
|
19
31
|
def hosts
|
20
32
|
host_list = []
|
21
33
|
groups.each do |group|
|
@@ -24,6 +36,7 @@ module MMS
|
|
24
36
|
host_list
|
25
37
|
end
|
26
38
|
|
39
|
+
# @return [Array<MMS::Resource::Cluster>]
|
27
40
|
def clusters
|
28
41
|
cluster_list = []
|
29
42
|
groups.each do |group|
|
@@ -32,6 +45,7 @@ module MMS
|
|
32
45
|
cluster_list
|
33
46
|
end
|
34
47
|
|
48
|
+
# @return [Array<MMS::Resource::Snapshot>]
|
35
49
|
def snapshots
|
36
50
|
snapshot_list = []
|
37
51
|
clusters.each do |cluster|
|
@@ -40,6 +54,7 @@ module MMS
|
|
40
54
|
snapshot_list.sort_by { |snapshot| snapshot.created_date }.reverse
|
41
55
|
end
|
42
56
|
|
57
|
+
# @return [Array<MMS::Resource::Alert>]
|
43
58
|
def alerts
|
44
59
|
alert_list = []
|
45
60
|
groups.each do |group|
|
@@ -48,6 +63,7 @@ module MMS
|
|
48
63
|
alert_list.sort_by { |alert| alert.created }.reverse
|
49
64
|
end
|
50
65
|
|
66
|
+
# @return [Array<MMS::Resource::RestoreJob>]
|
51
67
|
def restorejobs
|
52
68
|
restorejob_list = []
|
53
69
|
clusters.each do |cluster|
|
@@ -56,32 +72,43 @@ module MMS
|
|
56
72
|
restorejob_list.sort_by { |job| job.created }.reverse
|
57
73
|
end
|
58
74
|
|
75
|
+
# @param [String] type_value
|
76
|
+
# @param [String] group_id
|
77
|
+
# @param [String] cluster_id
|
78
|
+
# @return [Array<MMS::Resource::RestoreJob>]
|
59
79
|
def restorejob_create(type_value, group_id, cluster_id)
|
60
80
|
if type_value.length == 24
|
61
|
-
|
81
|
+
find_group(group_id).cluster(cluster_id).snapshot(type_value).create_restorejob
|
62
82
|
elsif datetime = (type_value == 'now' ? DateTime.now : DateTime.parse(type_value))
|
63
83
|
raise('Invalid datetime. Correct `YYYY-MM-RRTH:m:s`') if datetime.nil?
|
64
84
|
datetime_string = [[datetime.year, datetime.day, datetime.month].join('-'), 'T', [datetime.hour, datetime.minute, datetime.second].join(':'), 'Z'].join
|
65
|
-
|
85
|
+
find_group(group_id).cluster(cluster_id).create_restorejob(datetime_string)
|
66
86
|
end
|
67
87
|
end
|
68
88
|
|
89
|
+
# @param [String] alert_id
|
90
|
+
# @param [String, Integer] timestamp
|
91
|
+
# @param [String] group_id
|
92
|
+
# @return [TrueClass, FalseClass]
|
69
93
|
def alert_ack(alert_id, timestamp, group_id)
|
70
94
|
timestamp = DateTime.now if timestamp == 'now'
|
71
95
|
timestamp = DateTime.new(4000, 1, 1, 1, 1, 1, 1, 1) if timestamp == 'forever'
|
72
96
|
|
73
|
-
group =
|
97
|
+
group = find_group(group_id)
|
74
98
|
|
75
99
|
if alert_id == 'all'
|
76
100
|
group.alerts.each do |alert|
|
77
101
|
alert.ack(timestamp, 'Triggered by CLI for all alerts.')
|
78
102
|
end
|
79
|
-
|
103
|
+
else
|
104
|
+
group.alert(alert_id).ack(timestamp, 'Triggered by CLI.')
|
80
105
|
end
|
81
106
|
end
|
82
107
|
|
83
|
-
|
84
|
-
|
108
|
+
# @param [String] id
|
109
|
+
# @return [MMS::Resource::Group]
|
110
|
+
def find_group(id)
|
111
|
+
MMS::Resource::Group.find(@client, id)
|
85
112
|
end
|
86
113
|
|
87
114
|
end
|
data/lib/mms/cache.rb
CHANGED
@@ -12,14 +12,19 @@ module MMS
|
|
12
12
|
@storage = Hash.new {|hash, key| hash[key] = nil }
|
13
13
|
end
|
14
14
|
|
15
|
+
# @param [String] key
|
16
|
+
# @param [Object] value
|
15
17
|
def set(key, value)
|
16
18
|
@storage[key] = value
|
17
19
|
end
|
18
20
|
|
21
|
+
# @param [String] key
|
22
|
+
# @return [Object]
|
19
23
|
def get(key)
|
20
24
|
@storage[key].nil? ? nil : @storage[key]
|
21
25
|
end
|
22
26
|
|
27
|
+
# @param [String] key
|
23
28
|
def delete(key)
|
24
29
|
@storage.delete key unless @storage[key].nil?
|
25
30
|
end
|
data/lib/mms/cli.rb
CHANGED
@@ -71,15 +71,35 @@ module MMS
|
|
71
71
|
|
72
72
|
end
|
73
73
|
|
74
|
+
# @return [MMS::Agent]
|
74
75
|
def agent
|
75
76
|
@client = MMS::Client.new(@config.username, @config.apikey)
|
76
77
|
@agent = MMS::Agent.new(client)
|
77
78
|
end
|
78
79
|
|
80
|
+
# @return [Array<MMS::Resource::Group>]
|
81
|
+
def groups
|
82
|
+
id = ignore? ? nil : @config.default_group_id
|
83
|
+
id.nil? ? agent.groups : [agent.find_group(id)]
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Array<MMS::Resource::Cluster>]
|
87
|
+
def clusters
|
88
|
+
id = ignore? ? nil : @config.default_cluster_id
|
89
|
+
|
90
|
+
groups.collect! do |group|
|
91
|
+
id.nil? ? group.clusters : group.cluster(id)
|
92
|
+
end.flatten
|
93
|
+
end
|
94
|
+
|
95
|
+
# @param [String] heading
|
96
|
+
# @param [Array<MMS::Resource>]
|
79
97
|
def print(heading, resource_list)
|
80
98
|
json? ? print_json(resource_list) : print_human(heading, resource_list)
|
81
99
|
end
|
82
100
|
|
101
|
+
# @param [String] heading
|
102
|
+
# @param [Array<MMS::Resource>]
|
83
103
|
def print_human(heading, resource_list)
|
84
104
|
rows = []
|
85
105
|
|
@@ -87,11 +107,12 @@ module MMS
|
|
87
107
|
rows += resource.table_section
|
88
108
|
end
|
89
109
|
|
90
|
-
puts Terminal::Table.new :
|
110
|
+
puts Terminal::Table.new :headings => (heading.nil? ? [] : heading), :rows => rows
|
91
111
|
|
92
112
|
print_tips unless ignore?
|
93
113
|
end
|
94
114
|
|
115
|
+
# @param [Array<MMS::Resource>]
|
95
116
|
def print_json(resource_list)
|
96
117
|
rows = []
|
97
118
|
|
@@ -111,6 +132,8 @@ module MMS
|
|
111
132
|
end
|
112
133
|
end
|
113
134
|
|
135
|
+
|
136
|
+
# @param [Array] arguments
|
114
137
|
def run(arguments)
|
115
138
|
begin
|
116
139
|
parse_user_home_config
|
@@ -127,27 +150,24 @@ module MMS
|
|
127
150
|
end
|
128
151
|
end
|
129
152
|
|
130
|
-
class MMS::CLI::Command::
|
153
|
+
class MMS::CLI::Command::Groups < MMS::CLI::Command
|
131
154
|
|
132
|
-
subcommand 'list', '
|
155
|
+
subcommand 'list', 'Group list' do
|
133
156
|
|
134
157
|
def execute
|
135
|
-
print(MMS::Resource::
|
158
|
+
print(MMS::Resource::Group.table_header, groups)
|
136
159
|
end
|
137
160
|
end
|
138
161
|
|
139
162
|
end
|
140
163
|
|
141
|
-
class MMS::CLI::Command::
|
164
|
+
class MMS::CLI::Command::Hosts < MMS::CLI::Command
|
142
165
|
|
143
|
-
subcommand 'list', '
|
166
|
+
subcommand 'list', 'Host list' do
|
144
167
|
|
145
168
|
def execute
|
146
|
-
|
147
|
-
|
148
|
-
group_list.reject! { |group| group.id != @config.default_group_id } unless @config.default_group_id.nil? or ignore?
|
149
|
-
|
150
|
-
print(MMS::Resource::Group.table_header, group_list)
|
169
|
+
host_list = groups.collect! { |group| group.hosts }.flatten
|
170
|
+
print(MMS::Resource::Host.table_header, host_list)
|
151
171
|
end
|
152
172
|
end
|
153
173
|
|
@@ -158,10 +178,15 @@ module MMS
|
|
158
178
|
subcommand 'list', 'Cluster list' do
|
159
179
|
|
160
180
|
def execute
|
161
|
-
|
162
|
-
|
181
|
+
print(MMS::Resource::Cluster.table_header, clusters)
|
182
|
+
end
|
183
|
+
end
|
163
184
|
|
164
|
-
|
185
|
+
subcommand 'snapshot-schedule', 'Cluster snapshot schedule config' do
|
186
|
+
|
187
|
+
def execute
|
188
|
+
snapshot_schedule_list = clusters.collect! { |cluster| cluster.snapshot_schedule }.flatten
|
189
|
+
print(MMS::Resource::SnapshotSchedule.table_header, snapshot_schedule_list)
|
165
190
|
end
|
166
191
|
end
|
167
192
|
|
@@ -173,7 +198,8 @@ module MMS
|
|
173
198
|
subcommand 'list', 'Alerts list' do
|
174
199
|
|
175
200
|
def execute
|
176
|
-
|
201
|
+
alert_list = groups.collect! { |group| group.alerts }.flatten
|
202
|
+
print(MMS::Resource::Alert.table_header, alert_list)
|
177
203
|
end
|
178
204
|
|
179
205
|
end
|
@@ -199,7 +225,8 @@ module MMS
|
|
199
225
|
subcommand 'list', 'Snapshot list' do
|
200
226
|
|
201
227
|
def execute
|
202
|
-
|
228
|
+
snapshot_list = clusters.collect! { |cluster| cluster.snapshots }.flatten.sort_by { |snapshot| snapshot.created_date }.reverse
|
229
|
+
print(MMS::Resource::Snapshot.table_header, snapshot_list)
|
203
230
|
end
|
204
231
|
end
|
205
232
|
|
@@ -210,7 +237,8 @@ module MMS
|
|
210
237
|
subcommand 'list', 'Restorejob list' do
|
211
238
|
|
212
239
|
def execute
|
213
|
-
|
240
|
+
restorejob_list = clusters.collect! { |cluster| cluster.restorejobs }.flatten.sort_by { |job| job.created }.reverse
|
241
|
+
print(MMS::Resource::RestoreJob.table_header, restorejob_list)
|
214
242
|
end
|
215
243
|
|
216
244
|
end
|
data/lib/mms/client.rb
CHANGED
@@ -6,22 +6,33 @@ module MMS
|
|
6
6
|
attr_accessor :apikey
|
7
7
|
attr_accessor :url
|
8
8
|
|
9
|
+
# @param [String] username
|
10
|
+
# @param [String] apikey
|
11
|
+
# @param [String] url
|
9
12
|
def initialize(username = nil, apikey = nil, url = nil)
|
10
13
|
@username = username
|
11
14
|
@apikey = apikey
|
12
15
|
@url = url.nil? ? 'https://mms.mongodb.com:443/api/public/v1.0' : url
|
13
16
|
end
|
14
17
|
|
18
|
+
# @param [String] path
|
19
|
+
# @return [Hash]
|
15
20
|
def get(path)
|
16
21
|
_get(@url + path, @username, @apikey)
|
17
22
|
end
|
18
23
|
|
24
|
+
# @param [String] path
|
25
|
+
# @param [Hash] data
|
26
|
+
# @return [Hash]
|
19
27
|
def post(path, data)
|
20
28
|
_post(@url + path, data, @username, @apikey)
|
21
29
|
end
|
22
30
|
|
23
31
|
private
|
24
32
|
|
33
|
+
# @param [String] path
|
34
|
+
# @param [String] username
|
35
|
+
# @param [String] password
|
25
36
|
def _get(path, username, password)
|
26
37
|
|
27
38
|
digest_auth = Net::HTTP::DigestAuth.new
|
@@ -55,6 +66,10 @@ module MMS
|
|
55
66
|
(response_json.nil? or response_json['results'].nil?) ? response_json : response_json['results']
|
56
67
|
end
|
57
68
|
|
69
|
+
# @param [String] path
|
70
|
+
# @param [Hash] data
|
71
|
+
# @param [String] username
|
72
|
+
# @param [String] password
|
58
73
|
def _post(path, data, username, password)
|
59
74
|
digest_auth = Net::HTTP::DigestAuth.new
|
60
75
|
digest_auth.next_nonce
|
data/lib/mms/errors.rb
CHANGED
@@ -2,6 +2,9 @@ module MMS
|
|
2
2
|
|
3
3
|
class RuntimeError < StandardError;
|
4
4
|
|
5
|
+
# @param [String] message
|
6
|
+
# @param [Net::HTTPRequest] request
|
7
|
+
# @param [Net::HTTPResponse] response
|
5
8
|
def initialize(message, request, response)
|
6
9
|
super(message)
|
7
10
|
|
@@ -16,6 +19,8 @@ module MMS
|
|
16
19
|
|
17
20
|
class ResourceError < StandardError
|
18
21
|
|
22
|
+
# @param [String] message
|
23
|
+
# @param [MMS::Resource] resource
|
19
24
|
def initialize(message, resource)
|
20
25
|
super(message)
|
21
26
|
|
data/lib/mms/resource.rb
CHANGED
@@ -5,13 +5,22 @@ module MMS
|
|
5
5
|
attr_accessor :id
|
6
6
|
attr_accessor :data
|
7
7
|
|
8
|
-
|
9
|
-
@id = id
|
10
|
-
@data = data
|
8
|
+
attr_accessor :client
|
11
9
|
|
12
|
-
|
10
|
+
# @param [MMS::Client] client
|
11
|
+
def set_client(client)
|
12
|
+
@client = client
|
13
13
|
end
|
14
14
|
|
15
|
+
# @param [Hash] data
|
16
|
+
def set_data(data)
|
17
|
+
@data = data
|
18
|
+
from_hash(data)
|
19
|
+
cache_key = "Class::#{self.class.name}:#{@id}"
|
20
|
+
MMS::Cache.instance.set(cache_key, data)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [Hash] data
|
15
24
|
def from_hash(data)
|
16
25
|
unless data.nil?
|
17
26
|
@id = data['id']
|
@@ -23,38 +32,17 @@ module MMS
|
|
23
32
|
_to_hash
|
24
33
|
end
|
25
34
|
|
26
|
-
|
27
|
-
@data = _load(@id)
|
28
|
-
save @data unless @data.nil? or @data.empty?
|
29
|
-
end
|
30
|
-
|
31
|
-
def load
|
32
|
-
_data = MMS::Cache.instance.get "Class::#{self.class.name}:#{@id}"
|
33
|
-
|
34
|
-
if _data.nil? and @data.nil?
|
35
|
-
_data = _load(@id) unless @id.nil?
|
36
|
-
|
37
|
-
if _data.nil?
|
38
|
-
raise "Cannot load data for #{self.class.name}, id `#{@id}`"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
save _data || @data
|
43
|
-
end
|
44
|
-
|
45
|
-
def save(data)
|
46
|
-
from_hash data
|
47
|
-
MMS::Cache.instance.set "Class::#{self.class.name}:#{@id}", data
|
48
|
-
end
|
49
|
-
|
35
|
+
# @return [Array<String>]
|
50
36
|
def table_row
|
51
37
|
raise("`#{__method__}` is not implemented for `#{self.class.name}`")
|
52
38
|
end
|
53
39
|
|
40
|
+
# @return [Array]
|
54
41
|
def table_section
|
55
42
|
raise("`#{__method__}` is not implemented for `#{self.class.name}`")
|
56
43
|
end
|
57
44
|
|
45
|
+
# @return [Array<String>]
|
58
46
|
def self.table_header
|
59
47
|
raise("`#{__method__}` is not implemented for `#{self.class.name}`")
|
60
48
|
end
|
@@ -63,12 +51,30 @@ module MMS
|
|
63
51
|
raise("`#{__method__}` is not implemented for `#{self.class.name}`")
|
64
52
|
end
|
65
53
|
|
54
|
+
# @param [Hash] data
|
66
55
|
def _from_hash(data)
|
67
56
|
raise("`#{__method__}` is not implemented for `#{self.class.name}`")
|
68
57
|
end
|
69
58
|
|
59
|
+
# @return [Hash]
|
70
60
|
def _to_hash
|
71
61
|
raise("`#{__method__}` is not implemented for `#{self.class.name}`")
|
72
62
|
end
|
63
|
+
|
64
|
+
# @param [MMS::Client] client
|
65
|
+
# @param arguments...
|
66
|
+
# @return self
|
67
|
+
def self.find(client, *arguments)
|
68
|
+
cache_key = "Class::#{self.name}:#{arguments.last()}"
|
69
|
+
data = MMS::Cache.instance.get(cache_key)
|
70
|
+
unless data
|
71
|
+
data = self._find(client, *arguments)
|
72
|
+
end
|
73
|
+
|
74
|
+
resource = self.new
|
75
|
+
resource.set_client(client)
|
76
|
+
resource.set_data(data)
|
77
|
+
resource
|
78
|
+
end
|
73
79
|
end
|
74
80
|
end
|
data/lib/mms/resource/alert.rb
CHANGED
@@ -2,10 +2,7 @@ module MMS
|
|
2
2
|
|
3
3
|
class Resource::Alert < Resource
|
4
4
|
|
5
|
-
@client = nil
|
6
|
-
|
7
5
|
attr_accessor :name
|
8
|
-
attr_accessor :group
|
9
6
|
|
10
7
|
attr_accessor :type_name
|
11
8
|
attr_accessor :event_type_name
|
@@ -17,37 +14,32 @@ module MMS
|
|
17
14
|
attr_accessor :last_notified
|
18
15
|
attr_accessor :current_value
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
raise MMS::ResourceError.new('`Id` for alert resource must be defined', self) if id.nil?
|
25
|
-
raise MMS::ResourceError.new('`groupId` for alert resource must be defined', self) if group_id.nil?
|
26
|
-
|
27
|
-
@client = client
|
28
|
-
|
29
|
-
@group = MMS::Resource::Group.new(client, {'id' => group_id})
|
30
|
-
|
31
|
-
super id, data
|
17
|
+
# @return [MMS::Resource::Group]
|
18
|
+
def group
|
19
|
+
MMS::Resource::Group.find(@client, @data['groupId'])
|
32
20
|
end
|
33
21
|
|
22
|
+
|
23
|
+
# @param [Time, Integer] time
|
24
|
+
# @param [String] description
|
25
|
+
# @return [TrueClass, FalseClass]
|
34
26
|
def ack(time, description)
|
35
27
|
data = {
|
36
|
-
:acknowledgedUntil => time,
|
28
|
+
:acknowledgedUntil => time.to_i,
|
37
29
|
:acknowledgementComment => description
|
38
30
|
}
|
39
|
-
alert = @client.post '/groups/' +
|
31
|
+
alert = @client.post '/groups/' + group.id + '/alerts/' + @id, data
|
40
32
|
!alert.nil?
|
41
33
|
end
|
42
34
|
|
43
35
|
def table_row
|
44
|
-
[@status,
|
36
|
+
[@status, group.name, @type_name, @event_type_name, @created, @updated, @resolved, @last_notified, JSON.dump(@current_value)]
|
45
37
|
end
|
46
38
|
|
47
39
|
def table_section
|
48
40
|
rows = []
|
49
41
|
rows << table_row
|
50
|
-
rows << [{:value => "AlertId: #{@id} GroupId: #{
|
42
|
+
rows << [{:value => "AlertId: #{@id} GroupId: #{group.id}", :colspan => 9, :alignment => :left}]
|
51
43
|
rows << :separator
|
52
44
|
rows
|
53
45
|
end
|
@@ -56,12 +48,17 @@ module MMS
|
|
56
48
|
['Status', 'Group', 'Type', 'Event name', 'Created', 'Updated', 'Resolved', 'Last notified', 'Value']
|
57
49
|
end
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
# @param [MMS::Client] client
|
52
|
+
# @param [String] group_id
|
53
|
+
# @param [String] id
|
54
|
+
# @return [Hash]
|
55
|
+
def self._find(client, group_id, id)
|
56
|
+
client.get('/groups/' + group_id + '/alerts/' + id)
|
63
57
|
end
|
64
58
|
|
59
|
+
private
|
60
|
+
|
61
|
+
# @param [Hash] data
|
65
62
|
def _from_hash(data)
|
66
63
|
@type_name = data['typeName']
|
67
64
|
@event_type_name = data['eventTypeName']
|
data/lib/mms/resource/cluster.rb
CHANGED
@@ -2,10 +2,7 @@ module MMS
|
|
2
2
|
|
3
3
|
class Resource::Cluster < Resource
|
4
4
|
|
5
|
-
@client = nil
|
6
|
-
|
7
5
|
attr_accessor :name
|
8
|
-
attr_accessor :group
|
9
6
|
attr_accessor :shard_name
|
10
7
|
attr_accessor :replicaset_name
|
11
8
|
attr_accessor :type_name
|
@@ -14,53 +11,59 @@ module MMS
|
|
14
11
|
attr_accessor :snapshots
|
15
12
|
attr_accessor :restorejobs
|
16
13
|
|
17
|
-
def initialize
|
18
|
-
id = data['id']
|
19
|
-
group_id = data['groupId']
|
20
|
-
|
21
|
-
raise MMS::ResourceError.new('`Id` for cluster resource must be defined', self) if id.nil?
|
22
|
-
raise MMS::ResourceError.new('`groupId` for cluster resource must be defined', self) if group_id.nil?
|
23
|
-
|
14
|
+
def initialize
|
24
15
|
@snapshots = []
|
25
16
|
@restorejobs = []
|
17
|
+
end
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
@group = MMS::Resource::Group.new(client, {'id' => group_id})
|
30
|
-
|
31
|
-
super id, data
|
19
|
+
def group
|
20
|
+
MMS::Resource::Group.find(@client, @data['groupId'])
|
32
21
|
end
|
33
22
|
|
34
23
|
def snapshot(id)
|
35
|
-
MMS::Resource::Snapshot.
|
24
|
+
MMS::Resource::Snapshot.find(@client, group.id, @id, id)
|
36
25
|
end
|
37
26
|
|
38
|
-
def snapshots(page = 1, limit =
|
27
|
+
def snapshots(page = 1, limit = 1000)
|
39
28
|
if @snapshots.empty?
|
40
|
-
@client.get('/groups/' +
|
41
|
-
|
29
|
+
@client.get('/groups/' + group.id + '/clusters/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
|
30
|
+
s = MMS::Resource::Snapshot.new
|
31
|
+
s.set_client(@client)
|
32
|
+
s.set_data(snapshot)
|
33
|
+
|
34
|
+
@snapshots.push s
|
42
35
|
end
|
43
36
|
end
|
44
37
|
@snapshots
|
45
38
|
end
|
46
39
|
|
47
|
-
def
|
40
|
+
def snapshot_schedule
|
41
|
+
MMS::Resource::SnapshotSchedule.find(@client, group.id, @id)
|
42
|
+
end
|
43
|
+
|
44
|
+
def restorejobs(page = 1, limit = 1000)
|
48
45
|
if @restorejobs.empty?
|
49
|
-
@client.get('/groups/' +
|
46
|
+
@client.get('/groups/' + group.id + '/clusters/' + @id + '/restoreJobs?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |job|
|
50
47
|
|
51
48
|
if job['snapshotId'].nil? and job['clusterId'].nil?
|
52
49
|
raise MMS::ResourceError.new("RestoreJob `#{job['id']}` with status `#{job['statusName']}` has no `clusterId` and no `snapshotId`.", self)
|
53
50
|
elsif job['clusterId'].nil?
|
54
|
-
snapshot =
|
51
|
+
snapshot = group.find_snapshot(job['snapshotId'])
|
55
52
|
job['clusterId'] = snapshot.cluster.id unless snapshot.nil?
|
56
53
|
end
|
57
54
|
|
58
|
-
|
55
|
+
j = MMS::Resource::RestoreJob.new
|
56
|
+
j.set_client(@client)
|
57
|
+
j.set_data(job)
|
58
|
+
|
59
|
+
@restorejobs.push j
|
59
60
|
end
|
60
61
|
end
|
61
62
|
@restorejobs
|
62
63
|
end
|
63
64
|
|
65
|
+
# @param [String] point_in_time
|
66
|
+
# @return [Array<MMS::Resource::RestoreJob>]
|
64
67
|
def create_restorejob(point_in_time = nil)
|
65
68
|
data = {
|
66
69
|
'timestamp' => {
|
@@ -68,7 +71,7 @@ module MMS
|
|
68
71
|
'increment' => 0
|
69
72
|
}
|
70
73
|
}
|
71
|
-
jobs = @client.post('/groups/' +
|
74
|
+
jobs = @client.post('/groups/' + group.id + '/clusters/' + @id + '/restoreJobs', data)
|
72
75
|
|
73
76
|
if jobs.nil?
|
74
77
|
raise MMS::ResourceError.new("Cannot create job from snapshot `#{self.id}`", self)
|
@@ -102,7 +105,7 @@ module MMS
|
|
102
105
|
end
|
103
106
|
|
104
107
|
def table_row
|
105
|
-
[
|
108
|
+
[group.name, @name, @shard_name, @replicaset_name, @type_name, @last_heartbeat, @id]
|
106
109
|
end
|
107
110
|
|
108
111
|
def table_section
|
@@ -113,12 +116,12 @@ module MMS
|
|
113
116
|
['Group', 'Cluster', 'Shard name', 'Replica name', 'Type', 'Last heartbeat', 'Cluster Id']
|
114
117
|
end
|
115
118
|
|
116
|
-
|
117
|
-
|
118
|
-
def _load(id)
|
119
|
-
@client.get('/groups/' + @group.id + '/clusters/' + id.to_s)
|
119
|
+
def self._find(client, group_id, id)
|
120
|
+
client.get('/groups/' + group_id + '/clusters/' + id)
|
120
121
|
end
|
121
122
|
|
123
|
+
private
|
124
|
+
|
122
125
|
def _from_hash(data)
|
123
126
|
@name = data['clusterName']
|
124
127
|
@shard_name = data['shardName']
|
data/lib/mms/resource/group.rb
CHANGED
@@ -10,69 +10,79 @@ module MMS
|
|
10
10
|
|
11
11
|
attr_accessor :clusters
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(client, data)
|
16
|
-
id = data['id']
|
17
|
-
|
18
|
-
raise MMS::ResourceError.new('`Id` for group resource must be defined', self) if id.nil?
|
19
|
-
|
20
|
-
@client = client
|
21
|
-
|
13
|
+
def initialize
|
22
14
|
@clusters = []
|
23
|
-
|
24
|
-
super id, data
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.findGroups(client)
|
28
|
-
group_list = []
|
29
|
-
client.get('/groups').each do |group|
|
30
|
-
group_list.push MMS::Resource::Group.new(client, group)
|
31
|
-
end
|
32
|
-
group_list
|
33
15
|
end
|
34
16
|
|
35
|
-
|
17
|
+
# @param [Integer] page
|
18
|
+
# @param [Integer] limit
|
19
|
+
# @return [Array<MMS::Resource::Host>]
|
20
|
+
def hosts(page = 1, limit = 1000)
|
36
21
|
host_list = []
|
37
22
|
@client.get('/groups/' + @id + '/hosts?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |host|
|
38
|
-
|
23
|
+
h = MMS::Resource::Host.new
|
24
|
+
h.set_client(@client)
|
25
|
+
h.set_data(host)
|
26
|
+
|
27
|
+
host_list.push h
|
39
28
|
end
|
40
29
|
host_list
|
41
30
|
end
|
42
31
|
|
43
|
-
|
32
|
+
# @param [Integer] page
|
33
|
+
# @param [Integer] limit
|
34
|
+
# @param [String] status
|
35
|
+
# @return [Array<MMS::Resource::Alert>]
|
36
|
+
def alerts(page = 1, limit = 1000, status = 'OPEN')
|
44
37
|
alert_list = []
|
45
38
|
@client.get('/groups/' + @id + '/alerts?status=' + status + '&pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |alert|
|
46
|
-
|
39
|
+
a = MMS::Resource::Alert.new
|
40
|
+
a.set_client(@client)
|
41
|
+
a.set_group(self)
|
42
|
+
a.set_data(data)
|
43
|
+
|
44
|
+
alert_list.push a
|
47
45
|
end
|
48
46
|
alert_list
|
49
47
|
end
|
50
48
|
|
49
|
+
# @param [String] id
|
50
|
+
# @return [MMS::Resource::Alert]
|
51
51
|
def alert(id)
|
52
|
-
MMS::Resource::Alert.
|
52
|
+
MMS::Resource::Alert.find(@client, @id, id)
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
# @param [Integer] page
|
56
|
+
# @param [Integer] limit
|
57
|
+
# @return [Array<MMS::Resource::Cluster>]
|
58
|
+
def clusters(page = 1, limit = 1000)
|
56
59
|
if @clusters.empty?
|
57
60
|
@client.get('/groups/' + @id + '/clusters?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |cluster|
|
58
|
-
|
61
|
+
c = MMS::Resource::Cluster.new
|
62
|
+
c.set_client(@client)
|
63
|
+
c.set_data(cluster)
|
64
|
+
@clusters.push c
|
59
65
|
end
|
60
66
|
end
|
61
67
|
@clusters
|
62
68
|
end
|
63
69
|
|
70
|
+
# @param [String] id
|
71
|
+
# @return [MMS::Resource::Cluster]
|
64
72
|
def cluster(id)
|
65
|
-
MMS::Resource::Cluster.
|
73
|
+
MMS::Resource::Cluster.find(@client, @id, id)
|
66
74
|
end
|
67
75
|
|
68
|
-
|
76
|
+
# @param [String] id
|
77
|
+
# @return [MMS::Resource::Snapshot]
|
78
|
+
def find_snapshot(id)
|
69
79
|
snapshot = nil
|
70
80
|
clusters.each do |cluster|
|
71
81
|
begin
|
72
82
|
snapshot = cluster.snapshot(id)
|
73
83
|
rescue => e
|
74
|
-
# cannot load snapshotId for cluster if config-server is the source
|
75
|
-
# not supported in current MMS API version
|
84
|
+
# STDERR.puts 'cannot load snapshotId for cluster if config-server is the source!'
|
85
|
+
# STDERR.puts 'not supported in current MMS API version'
|
76
86
|
end
|
77
87
|
end
|
78
88
|
snapshot
|
@@ -90,12 +100,12 @@ module MMS
|
|
90
100
|
['Name', 'Active Agents', 'Replicas count', 'Shards count', 'Last Active Agent', 'GroupId']
|
91
101
|
end
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
def _load(id)
|
96
|
-
@client.get('/groups/' + id.to_s)
|
103
|
+
def self._find(client, id)
|
104
|
+
client.get('/groups/' + id)
|
97
105
|
end
|
98
106
|
|
107
|
+
private
|
108
|
+
|
99
109
|
def _from_hash(data)
|
100
110
|
@name = data['name']
|
101
111
|
@active_agent_count = data['activeAgentCount']
|
@@ -107,6 +117,5 @@ module MMS
|
|
107
117
|
def _to_hash
|
108
118
|
@data
|
109
119
|
end
|
110
|
-
|
111
120
|
end
|
112
121
|
end
|
data/lib/mms/resource/host.rb
CHANGED
@@ -2,10 +2,7 @@ module MMS
|
|
2
2
|
|
3
3
|
class Resource::Host < Resource
|
4
4
|
|
5
|
-
@client = nil
|
6
|
-
|
7
5
|
attr_accessor :name
|
8
|
-
attr_accessor :group
|
9
6
|
attr_accessor :hostname
|
10
7
|
attr_accessor :port
|
11
8
|
attr_accessor :type_name
|
@@ -20,22 +17,13 @@ module MMS
|
|
20
17
|
attr_accessor :profiler_enabled
|
21
18
|
attr_accessor :logs_enabled
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
raise MMS::ResourceError.new('`Id` for host resource must be defined', self) if id.nil?
|
28
|
-
raise MMS::ResourceError.new('`groupId` for host resource must be defined', self) if group_id.nil?
|
29
|
-
|
30
|
-
@client = client
|
31
|
-
|
32
|
-
@group = MMS::Resource::Group.new(client, {'id' => group_id})
|
33
|
-
|
34
|
-
super id, data
|
20
|
+
# @return [MMS::Resource::Group]
|
21
|
+
def group
|
22
|
+
MMS::Resource::Group.find(@client, @data['groupId'])
|
35
23
|
end
|
36
24
|
|
37
25
|
def table_row
|
38
|
-
[
|
26
|
+
[group.name, @type_name, @name, @ip_address, @port, @last_ping, @alerts_enabled, @id, @shard_name, @replicaset_name]
|
39
27
|
end
|
40
28
|
|
41
29
|
def table_section
|
@@ -46,12 +34,15 @@ module MMS
|
|
46
34
|
['Group', 'Type', 'Hostname', 'IP', 'Port', 'Last ping', 'Alerts enabled', 'HostId', 'Shard', 'Replica']
|
47
35
|
end
|
48
36
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
37
|
+
# @param [MMS::Client] client
|
38
|
+
# @param [String] group_id
|
39
|
+
# @param [String] id
|
40
|
+
def self._find(client, group_id, id)
|
41
|
+
client.get('/groups/' + group_id + '/hosts/' + id)
|
53
42
|
end
|
54
43
|
|
44
|
+
private
|
45
|
+
|
55
46
|
def _from_hash(data)
|
56
47
|
@hostname = data['hostname']
|
57
48
|
@port = data['port']
|
@@ -4,13 +4,8 @@ module MMS
|
|
4
4
|
|
5
5
|
class Resource::RestoreJob < Resource
|
6
6
|
|
7
|
-
@client = nil
|
8
|
-
|
9
7
|
attr_accessor :name
|
10
8
|
|
11
|
-
# this is restore point cluster e.g full cluster (configs, replicas)
|
12
|
-
attr_accessor :cluster
|
13
|
-
|
14
9
|
# this is source point from where RestoreJob was created
|
15
10
|
# RestoreJob.snapshot.cluster is e.g replica, config server
|
16
11
|
# RestoreJob.cluster is full cluster group (configs, replicas)
|
@@ -25,22 +20,22 @@ module MMS
|
|
25
20
|
attr_accessor :delivery_status_name
|
26
21
|
attr_accessor :delivery_url
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
super id, data
|
23
|
+
# @return [MMS::Resource::Cluster]
|
24
|
+
def cluster
|
25
|
+
begin
|
26
|
+
cluster = MMS::Resource::Cluster.find(@client, @data['groupId'], @data['clusterId'])
|
27
|
+
rescue
|
28
|
+
# Workaround
|
29
|
+
# time to time the mms-api return data without "clusterId" defined
|
30
|
+
# creation of empty clluster instance is a good solution here.
|
31
|
+
cluster = MMS::Resource::Cluster.new
|
32
|
+
cluster.set_client(@client)
|
33
|
+
cluster.set_data({'groupId' => @data['groupId']})
|
34
|
+
end
|
35
|
+
cluster
|
42
36
|
end
|
43
37
|
|
38
|
+
# @return [TrueClass, FalseClass]
|
44
39
|
def has_cluster
|
45
40
|
# cluster definition for config-server cannot be loaded
|
46
41
|
# as there is no clusterId for this type of group.
|
@@ -49,11 +44,12 @@ module MMS
|
|
49
44
|
snapshot != nil
|
50
45
|
end
|
51
46
|
|
47
|
+
# @return [MMS::Resource::Snapshot]
|
52
48
|
def snapshot
|
53
49
|
# snapshot details for config-server cannot be loaded
|
54
50
|
# as there is no clusterId. See also has_cluster()
|
55
51
|
if @snapshot.nil?
|
56
|
-
@snapshot =
|
52
|
+
@snapshot = cluster.group.find_snapshot(@snapshot_id)
|
57
53
|
end
|
58
54
|
@snapshot
|
59
55
|
end
|
@@ -66,8 +62,8 @@ module MMS
|
|
66
62
|
def table_section
|
67
63
|
[
|
68
64
|
table_row,
|
69
|
-
[@id, "#{
|
70
|
-
['',
|
65
|
+
[@id, "#{cluster.name} (#{cluster.id})", {:value => '', :colspan => 5}],
|
66
|
+
['', cluster.group.name, {:value => '', :colspan => 5}],
|
71
67
|
[{:value => 'download url:', :colspan => 7}],
|
72
68
|
[{:value => @delivery_url || '(waiting for link)', :colspan => 7}],
|
73
69
|
:separator
|
@@ -78,20 +74,21 @@ module MMS
|
|
78
74
|
['Timestamp / RestoreId', 'SnapshotId / Cluster / Group', 'Name (created)', 'Status', 'Point in time', 'Delivery', 'Restore status']
|
79
75
|
end
|
80
76
|
|
81
|
-
|
77
|
+
# @return [Hash, NilClass]
|
78
|
+
def self.find_recursively(client, group_id, cluster_id, id)
|
79
|
+
cluster = MMS::Resource::Cluster.find(client, group_id, cluster_id)
|
80
|
+
# config server has no cluster but owns RestoreJob and Snapshot
|
81
|
+
restore_jobs = cluster.restorejobs
|
82
|
+
job = restore_jobs.select { |restorejob| restorejob.id == id }
|
83
|
+
job.first.data unless job.nil? and job.empty?
|
84
|
+
end
|
82
85
|
|
83
|
-
def
|
84
|
-
|
85
|
-
data = @client.get '/groups/' + snapshot.cluster.group.id + '/clusters/' + snapshot.cluster.id + '/restoreJobs/' + id.to_s
|
86
|
-
else
|
87
|
-
# config server has no cluster but owns RestoreJob and Snapshot
|
88
|
-
restore_jobs = @cluster.restorejobs
|
89
|
-
job = restore_jobs.select { |restorejob| restorejob.id == id }
|
90
|
-
data = job.first.data unless job.nil? and job.empty?
|
91
|
-
end
|
92
|
-
data
|
86
|
+
def self._find(client, group_id, cluster_id, id)
|
87
|
+
client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/restoreJobs/' + id)
|
93
88
|
end
|
94
89
|
|
90
|
+
private
|
91
|
+
|
95
92
|
def _from_hash(data)
|
96
93
|
@snapshot_id = data['snapshotId']
|
97
94
|
@created = data['created']
|
@@ -107,6 +104,5 @@ module MMS
|
|
107
104
|
def _to_hash
|
108
105
|
@data
|
109
106
|
end
|
110
|
-
|
111
107
|
end
|
112
108
|
end
|
@@ -4,10 +4,7 @@ module MMS
|
|
4
4
|
|
5
5
|
class Resource::Snapshot < Resource
|
6
6
|
|
7
|
-
@client = nil
|
8
|
-
|
9
7
|
attr_accessor :name
|
10
|
-
attr_accessor :cluster
|
11
8
|
|
12
9
|
attr_accessor :complete
|
13
10
|
attr_accessor :created_date
|
@@ -15,46 +12,37 @@ module MMS
|
|
15
12
|
attr_accessor :expires
|
16
13
|
attr_accessor :parts
|
17
14
|
|
18
|
-
|
19
|
-
id = data['id']
|
20
|
-
cluster_id = data['clusterId']
|
21
|
-
group_id = data['groupId']
|
22
|
-
|
23
|
-
raise MMS::ResourceError.new('`Id` for restorejob resource must be defined', self) if id.nil?
|
24
|
-
raise MMS::ResourceError.new('`clusterId` for restorejob resource must be defined', self) if cluster_id.nil?
|
25
|
-
raise MMS::ResourceError.new('`groupId` for restorejob resource must be defined', self) if group_id.nil?
|
26
|
-
|
27
|
-
@client = client
|
28
|
-
|
29
|
-
@cluster = MMS::Resource::Cluster.new(client, {'id' => cluster_id, 'groupId' => group_id})
|
30
|
-
|
31
|
-
super id, data
|
32
|
-
end
|
33
|
-
|
15
|
+
# @return [TrueClass, FalseClass]
|
34
16
|
def is_cluster
|
35
17
|
@parts.length > 1
|
36
18
|
end
|
37
19
|
|
20
|
+
# @return [TrueClass, FalseClass]
|
38
21
|
def is_config
|
39
22
|
@parts.length == 1 and @parts.first['typeName'] == 'CONFIG_SERVER'
|
40
23
|
end
|
41
24
|
|
25
|
+
# @return [TrueClass, FalseClass]
|
42
26
|
def is_replica
|
43
27
|
@parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET'
|
44
28
|
end
|
45
29
|
|
30
|
+
# @return [String, NilClass]
|
46
31
|
def cluster_name
|
47
|
-
|
32
|
+
cluster.name if is_cluster
|
48
33
|
end
|
49
34
|
|
35
|
+
# @return [String, NilClass]
|
50
36
|
def config_name
|
51
37
|
'config' if is_config
|
52
38
|
end
|
53
39
|
|
40
|
+
# @return [String, NilClass]
|
54
41
|
def replica_name
|
55
42
|
@parts.first['replicaSetName'] if is_replica
|
56
43
|
end
|
57
44
|
|
45
|
+
# @return [String, NilClass]
|
58
46
|
def source_name
|
59
47
|
name = nil
|
60
48
|
name = replica_name if is_replica
|
@@ -63,9 +51,15 @@ module MMS
|
|
63
51
|
name
|
64
52
|
end
|
65
53
|
|
54
|
+
# @return [MMS::Resource::Cluster]
|
55
|
+
def cluster
|
56
|
+
MMS::Resource::Cluster.find(@client, @data['groupId'], @data['clusterId'])
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Array<MMS::Resource::RestoreJob>]
|
66
60
|
def create_restorejob
|
67
61
|
data = {:snapshotId => @id}
|
68
|
-
jobs = @client.post '/groups/' +
|
62
|
+
jobs = @client.post '/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/restoreJobs', data
|
69
63
|
|
70
64
|
if jobs.nil?
|
71
65
|
raise MMS::ResourceError.new("Cannot create job from snapshot `#{self.id}`", self)
|
@@ -74,7 +68,7 @@ module MMS
|
|
74
68
|
job_list = []
|
75
69
|
# work around due to bug in MMS API; cannot read restoreJob using provided info.
|
76
70
|
# The config-server RestoreJob and Snapshot has no own ClusterId to be accessed.
|
77
|
-
restore_jobs =
|
71
|
+
restore_jobs = cluster.restorejobs
|
78
72
|
jobs.each do |job|
|
79
73
|
_list = restore_jobs.select { |restorejob| restorejob.id == job['id'] }
|
80
74
|
_list.each do |restorejob|
|
@@ -85,7 +79,7 @@ module MMS
|
|
85
79
|
end
|
86
80
|
|
87
81
|
def table_row
|
88
|
-
[
|
82
|
+
[cluster.group.name, cluster.name, @id, @complete, @created_increment, @name, @expires]
|
89
83
|
end
|
90
84
|
|
91
85
|
def table_section
|
@@ -106,12 +100,17 @@ module MMS
|
|
106
100
|
['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Name (created date)', 'Expires']
|
107
101
|
end
|
108
102
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
103
|
+
# @param [MMS::Client] client
|
104
|
+
# @param [String] group_id
|
105
|
+
# @param [String] cluster_id
|
106
|
+
# @param [String] id
|
107
|
+
# @return [MMS::Resource::Snapshot]
|
108
|
+
def self._find(client, group_id, cluster_id, id)
|
109
|
+
client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/snapshots/' + id.to_s)
|
113
110
|
end
|
114
111
|
|
112
|
+
private
|
113
|
+
|
115
114
|
def _from_hash(data)
|
116
115
|
@complete = data['complete']
|
117
116
|
@created_date = data['created'].nil? ? nil : data['created']['date']
|
@@ -119,8 +118,6 @@ module MMS
|
|
119
118
|
@expires = data['expires']
|
120
119
|
@parts = data['parts']
|
121
120
|
@name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime("%Y-%m-%d %H:%M:%S")
|
122
|
-
|
123
|
-
@cluster = MMS::Resource::Cluster.new(@client, {'id' => data['clusterId'], 'groupId' => data['groupId']})
|
124
121
|
end
|
125
122
|
|
126
123
|
def _to_hash
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module MMS
|
2
|
+
|
3
|
+
class Resource::SnapshotSchedule < Resource
|
4
|
+
|
5
|
+
attr_accessor :name
|
6
|
+
|
7
|
+
attr_accessor :snapshot_interval_hours
|
8
|
+
attr_accessor :snapshot_retention_days
|
9
|
+
attr_accessor :cluster_checkpoint_interval_min
|
10
|
+
attr_accessor :daily_snapshot_retention_days
|
11
|
+
attr_accessor :weekly_snapshot_retention_weeks
|
12
|
+
attr_accessor :monthly_snapshot_retention_months
|
13
|
+
|
14
|
+
# @return [MMS::Resource::Cluster]
|
15
|
+
def cluster
|
16
|
+
MMS::Resource::Cluster.find(@client, @data['groupId'], @data['clusterId'])
|
17
|
+
end
|
18
|
+
|
19
|
+
def table_row
|
20
|
+
[
|
21
|
+
cluster.group.name,
|
22
|
+
cluster.name,
|
23
|
+
@snapshot_interval_hours,
|
24
|
+
@snapshot_retention_days,
|
25
|
+
@cluster_checkpoint_interval_min,
|
26
|
+
@daily_snapshot_retention_days,
|
27
|
+
@weekly_snapshot_retention_weeks,
|
28
|
+
@monthly_snapshot_retention_months,
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def table_section
|
33
|
+
[table_row]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.table_header
|
37
|
+
['Group', 'Cluster', 'IntervalHours', 'RetentionDays', 'CheckpointIntervalMin', 'RetentionDays', 'RetentionWeeks', 'RetentionMonths']
|
38
|
+
end
|
39
|
+
|
40
|
+
def self._find(client, group_id, cluster_id)
|
41
|
+
client.get('/groups/' + group_id + '/backupConfigs/' + cluster_id + '/snapshotSchedule')
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def _from_hash(data)
|
47
|
+
@snapshot_interval_hours = data['snapshotIntervalHours']
|
48
|
+
@snapshot_retention_days = data['snapshotRetentionDays']
|
49
|
+
@cluster_checkpoint_interval_min = data['clusterCheckpointIntervalMin']
|
50
|
+
@daily_snapshot_retention_days = data['dailySnapshotRetentionDays']
|
51
|
+
@weekly_snapshot_retention_weeks = data['weeklySnapshotRetentionWeeks']
|
52
|
+
@monthly_snapshot_retention_months = data['monthlySnapshotRetentionMonths']
|
53
|
+
end
|
54
|
+
|
55
|
+
def _to_hash
|
56
|
+
@data
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/mms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mms-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cargo Media
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-02-
|
13
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-http-digest_auth
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/mms/resource/host.rb
|
121
121
|
- lib/mms/resource/restore_job.rb
|
122
122
|
- lib/mms/resource/snapshot.rb
|
123
|
+
- lib/mms/resource/snapshot_schedule.rb
|
123
124
|
- lib/mms/version.rb
|
124
125
|
homepage: https://github.com/cargomedia/mms-api
|
125
126
|
licenses:
|
@@ -146,3 +147,4 @@ signing_key:
|
|
146
147
|
specification_version: 4
|
147
148
|
summary: MongoDB MMS API client
|
148
149
|
test_files: []
|
150
|
+
has_rdoc:
|