mms-api 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -8
- data/lib/mms.rb +5 -5
- data/lib/mms/agent.rb +87 -11
- data/lib/mms/cache.rb +2 -7
- data/lib/mms/cli.rb +36 -74
- data/lib/mms/client.rb +22 -13
- data/lib/mms/config.rb +15 -44
- data/lib/mms/errors.rb +2 -10
- data/lib/mms/resource.rb +20 -23
- data/lib/mms/resource/alert.rb +3 -7
- data/lib/mms/resource/backup_config.rb +0 -3
- data/lib/mms/resource/cluster.rb +9 -15
- data/lib/mms/resource/group.rb +13 -15
- data/lib/mms/resource/host.rb +7 -12
- data/lib/mms/resource/metric.rb +5 -7
- data/lib/mms/resource/restore_job.rb +7 -9
- data/lib/mms/resource/snapshot.rb +10 -13
- data/lib/mms/resource/snapshot_schedule.rb +9 -12
- data/lib/mms/version.rb +1 -1
- metadata +30 -2
data/lib/mms/resource/host.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module MMS
|
2
|
-
|
3
2
|
class Resource::Host < Resource
|
4
|
-
|
5
3
|
attr_accessor :name
|
6
4
|
attr_accessor :hostname
|
7
5
|
attr_accessor :port
|
@@ -30,12 +28,12 @@ module MMS
|
|
30
28
|
MMS::Resource::Snapshot.find(@client, group.id, nil, @id, id)
|
31
29
|
end
|
32
30
|
|
33
|
-
def snapshots(page = 1, limit =
|
31
|
+
def snapshots(page = 1, limit = 100)
|
34
32
|
if @snapshots.empty?
|
35
33
|
@client.get('/groups/' + group.id + '/hosts/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
|
36
34
|
s = MMS::Resource::Snapshot.new
|
37
|
-
s.
|
38
|
-
s.
|
35
|
+
s.client(@client)
|
36
|
+
s.data(snapshot)
|
39
37
|
|
40
38
|
@snapshots.push s
|
41
39
|
end
|
@@ -58,18 +56,18 @@ module MMS
|
|
58
56
|
# @param [MMS::Client] client
|
59
57
|
# @param [String] group_id
|
60
58
|
# @param [String] id
|
61
|
-
# @
|
59
|
+
# @return [Hash]
|
62
60
|
def self._find(client, group_id, id)
|
63
61
|
client.get('/groups/' + group_id + '/hosts/' + id)
|
64
62
|
end
|
65
63
|
|
66
|
-
# @
|
64
|
+
# @return [Array<MMS::Resource::Metric>]
|
67
65
|
def metrics
|
68
66
|
if @metric_list.empty?
|
69
67
|
@client.get('/groups/' + group.id + '/hosts/' + @id + '/metrics').each do |metric|
|
70
68
|
m = MMS::Resource::Metric.new
|
71
|
-
m.
|
72
|
-
m.
|
69
|
+
m.client(@client)
|
70
|
+
m.data(metric)
|
73
71
|
|
74
72
|
@metric_list.push m
|
75
73
|
end
|
@@ -77,8 +75,6 @@ module MMS
|
|
77
75
|
@metric_list
|
78
76
|
end
|
79
77
|
|
80
|
-
private
|
81
|
-
|
82
78
|
def _from_hash(data)
|
83
79
|
@hostname = data['hostname']
|
84
80
|
@port = data['port']
|
@@ -99,6 +95,5 @@ module MMS
|
|
99
95
|
def _to_hash
|
100
96
|
@data
|
101
97
|
end
|
102
|
-
|
103
98
|
end
|
104
99
|
end
|
data/lib/mms/resource/metric.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module MMS
|
2
|
-
|
3
2
|
class Resource::Metric < Resource
|
4
|
-
|
5
3
|
attr_accessor :name
|
6
4
|
attr_accessor :units
|
7
5
|
attr_accessor :granularity
|
@@ -12,7 +10,7 @@ module MMS
|
|
12
10
|
end
|
13
11
|
|
14
12
|
# @param [Hash] options
|
15
|
-
# @
|
13
|
+
# @return [Array<Hash>]
|
16
14
|
def data_points(options = {})
|
17
15
|
series = []
|
18
16
|
metric_data = get_metric_data(options)
|
@@ -31,7 +29,7 @@ module MMS
|
|
31
29
|
# @param [String] group_id
|
32
30
|
# @param [String] host_id
|
33
31
|
# @param [String] metric_name
|
34
|
-
# @
|
32
|
+
# @return [Hash]
|
35
33
|
def self._find(client, group_id, host_id, metric_name)
|
36
34
|
client.get('/groups/' + group_id + '/hosts/' + host_id + '/metrics/' + metric_name)
|
37
35
|
end
|
@@ -39,12 +37,12 @@ module MMS
|
|
39
37
|
private
|
40
38
|
|
41
39
|
# @param [Hash] options
|
42
|
-
# @param [String]
|
43
|
-
# @
|
40
|
+
# @param [String] d_name
|
41
|
+
# @return [Hash]
|
44
42
|
def get_metric_data(options = {}, d_name = '')
|
45
43
|
params = options.map { |k, v| "#{k}=#{v}" }.join('&')
|
46
44
|
ret = client.get("/groups/#{@data['groupId']}/hosts/#{@data['hostId']}/metrics/#{@data['metricName']}/#{d_name}?#{params}")
|
47
|
-
ret.delete(
|
45
|
+
ret.delete('links')
|
48
46
|
ret
|
49
47
|
end
|
50
48
|
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
module MMS
|
4
|
-
|
5
4
|
class Resource::RestoreJob < Resource
|
6
|
-
|
7
5
|
attr_accessor :name
|
8
6
|
|
9
7
|
# this is source point from where RestoreJob was created
|
@@ -44,17 +42,17 @@ module MMS
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def table_row
|
47
|
-
time_str = DateTime.parse(@timestamp).strftime(
|
45
|
+
time_str = DateTime.parse(@timestamp).strftime('%m/%d/%Y %H:%M')
|
48
46
|
[time_str, @snapshot_id, @name, @status_name, @point_in_time, @delivery_method_name, @delivery_status_name]
|
49
47
|
end
|
50
48
|
|
51
49
|
def table_section
|
52
50
|
[
|
53
51
|
table_row,
|
54
|
-
[@id, "#{cluster.name} (#{cluster.id})", {:
|
55
|
-
['', cluster.group.name, {:
|
56
|
-
[{:
|
57
|
-
[{:
|
52
|
+
[@id, "#{cluster.name} (#{cluster.id})", { value: '', colspan: 5 }],
|
53
|
+
['', cluster.group.name, { value: '', colspan: 5 }],
|
54
|
+
[{ value: 'download url:', colspan: 7 }],
|
55
|
+
[{ value: @delivery_url || '(waiting for link)', colspan: 7 }],
|
58
56
|
:separator
|
59
57
|
]
|
60
58
|
end
|
@@ -64,7 +62,7 @@ module MMS
|
|
64
62
|
end
|
65
63
|
|
66
64
|
def self._find(client, group_id, cluster_id, host_id, id)
|
67
|
-
host_id.nil? ?
|
65
|
+
host_id.nil? ? _find_by_cluster(client, group_id, cluster_id, id) : _find_by_host(client, group_id, host_id, id)
|
68
66
|
end
|
69
67
|
|
70
68
|
def self._find_by_host(client, group_id, host_id, id)
|
@@ -86,7 +84,7 @@ module MMS
|
|
86
84
|
@delivery_method_name = data['delivery']['methodName'] unless data['delivery'].nil?
|
87
85
|
@delivery_status_name = data['delivery']['statusName'] unless data['delivery'].nil?
|
88
86
|
@delivery_url = data['delivery']['url'] unless data['delivery'].nil?
|
89
|
-
@name = DateTime.parse(@created).strftime(
|
87
|
+
@name = DateTime.parse(@created).strftime('%Y-%m-%d %H:%M:%S')
|
90
88
|
@cluster_id = data['clusterId']
|
91
89
|
@group_id = data['groupId']
|
92
90
|
@host_id = data['hostId']
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
module MMS
|
4
|
-
|
5
4
|
class Resource::Snapshot < Resource
|
6
|
-
|
7
5
|
attr_accessor :name
|
8
6
|
|
9
7
|
attr_accessor :complete
|
@@ -20,12 +18,12 @@ module MMS
|
|
20
18
|
|
21
19
|
# @return [TrueClass, FalseClass]
|
22
20
|
def is_config
|
23
|
-
@parts.length == 1
|
21
|
+
@parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['hostId'].nil?
|
24
22
|
end
|
25
23
|
|
26
24
|
# @return [TrueClass, FalseClass]
|
27
25
|
def is_replica
|
28
|
-
@parts.length == 1
|
26
|
+
@parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['clusterId'].nil?
|
29
27
|
end
|
30
28
|
|
31
29
|
# @return [String, NilClass]
|
@@ -59,17 +57,17 @@ module MMS
|
|
59
57
|
|
60
58
|
# @return [Array<MMS::Resource::RestoreJob>]
|
61
59
|
def create_restorejob
|
62
|
-
data = {:
|
60
|
+
data = { snapshotId: @id }
|
63
61
|
job_data_list = @client.post '/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/restoreJobs', data
|
64
62
|
|
65
63
|
if job_data_list.nil?
|
66
|
-
|
64
|
+
fail MMS::ResourceError.new("Cannot create job from snapshot `#{id}`", self)
|
67
65
|
end
|
68
66
|
|
69
67
|
job_data_list.map do |job_data|
|
70
68
|
j = MMS::Resource::RestoreJob.new
|
71
|
-
j.
|
72
|
-
j.
|
69
|
+
j.client(@client)
|
70
|
+
j.data(job_data)
|
73
71
|
j
|
74
72
|
end
|
75
73
|
end
|
@@ -84,8 +82,8 @@ module MMS
|
|
84
82
|
rows << :separator
|
85
83
|
part_count = 0
|
86
84
|
@parts.each do |part|
|
87
|
-
file_size_mb = part['fileSizeBytes'].to_i / (1024*1024)
|
88
|
-
rows << [{:
|
85
|
+
file_size_mb = part['fileSizeBytes'].to_i / (1024 * 1024)
|
86
|
+
rows << [{ value: "part #{part_count}", colspan: 4, alignment: :right }, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"]
|
89
87
|
part_count += 1
|
90
88
|
end
|
91
89
|
rows << :separator
|
@@ -102,7 +100,7 @@ module MMS
|
|
102
100
|
# @param [String] id
|
103
101
|
# @return [MMS::Resource::Snapshot]
|
104
102
|
def self._find(client, group_id, cluster_id, host_id, id)
|
105
|
-
host_id.nil? ?
|
103
|
+
host_id.nil? ? _find_by_cluster(client, group_id, cluster_id, id) : _find_by_host(client, group_id, host_id, id)
|
106
104
|
end
|
107
105
|
|
108
106
|
def self._find_by_cluster(client, group_id, cluster_id, id)
|
@@ -122,12 +120,11 @@ module MMS
|
|
122
120
|
@expires = data['expires']
|
123
121
|
@parts = data['parts']
|
124
122
|
@is_possibly_inconsistent = data['isPossiblyInconsistent']
|
125
|
-
@name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime(
|
123
|
+
@name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime('%Y-%m-%d %H:%M:%S')
|
126
124
|
end
|
127
125
|
|
128
126
|
def _to_hash
|
129
127
|
@data
|
130
128
|
end
|
131
|
-
|
132
129
|
end
|
133
130
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module MMS
|
2
|
-
|
3
2
|
class Resource::SnapshotSchedule < Resource
|
4
|
-
|
5
3
|
attr_accessor :name
|
6
4
|
|
7
5
|
attr_accessor :snapshot_interval_hours
|
@@ -18,14 +16,14 @@ module MMS
|
|
18
16
|
|
19
17
|
def table_row
|
20
18
|
[
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
cluster.group.name,
|
20
|
+
cluster.name,
|
21
|
+
@snapshot_interval_hours,
|
22
|
+
@snapshot_retention_days,
|
23
|
+
@cluster_checkpoint_interval_min,
|
24
|
+
@daily_snapshot_retention_days,
|
25
|
+
@weekly_snapshot_retention_weeks,
|
26
|
+
@monthly_snapshot_retention_months
|
29
27
|
]
|
30
28
|
end
|
31
29
|
|
@@ -34,7 +32,7 @@ module MMS
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def self.table_header
|
37
|
-
|
35
|
+
%w(Group Cluster IntervalHours RetentionDays CheckpointIntervalMin RetentionDays RetentionWeeks RetentionMonths)
|
38
36
|
end
|
39
37
|
|
40
38
|
def self._find(client, group_id, cluster_id)
|
@@ -55,6 +53,5 @@ module MMS
|
|
55
53
|
def _to_hash
|
56
54
|
@data
|
57
55
|
end
|
58
|
-
|
59
56
|
end
|
60
57
|
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.
|
4
|
+
version: 0.2.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-
|
13
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-http-digest_auth
|
@@ -82,6 +82,34 @@ dependencies:
|
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: pry
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rubocop
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
85
113
|
- !ruby/object:Gem::Dependency
|
86
114
|
name: rspec
|
87
115
|
requirement: !ruby/object:Gem::Requirement
|