mms-api 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -59
- data/bin/mms-api +1 -146
- data/lib/mms.rb +13 -0
- data/lib/mms/agent.rb +40 -30
- data/lib/mms/cli.rb +258 -0
- data/lib/mms/client.rb +19 -37
- data/lib/mms/config.rb +57 -0
- data/lib/mms/errors.rb +41 -0
- data/lib/mms/resource.rb +28 -0
- data/lib/mms/resource/alert.rb +83 -0
- data/lib/mms/resource/cluster.rb +87 -10
- data/lib/mms/resource/group.rb +56 -9
- data/lib/mms/resource/host.rb +32 -3
- data/lib/mms/resource/restore_job.rb +45 -4
- data/lib/mms/resource/snapshot.rb +51 -10
- data/lib/mms/version.rb +1 -1
- metadata +21 -3
data/lib/mms/resource/group.rb
CHANGED
@@ -10,31 +10,59 @@ module MMS
|
|
10
10
|
|
11
11
|
attr_accessor :clusters
|
12
12
|
|
13
|
-
|
13
|
+
@client = nil
|
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
|
+
|
14
22
|
@clusters = []
|
15
23
|
|
16
24
|
super id, data
|
17
25
|
end
|
18
26
|
|
19
|
-
def
|
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
|
+
end
|
34
|
+
|
35
|
+
def hosts(page = 1, limit = 10)
|
20
36
|
host_list = []
|
21
|
-
|
22
|
-
host_list.push MMS::Resource::Host.new(
|
37
|
+
@client.get('/groups/' + @id + '/hosts?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |host|
|
38
|
+
host_list.push MMS::Resource::Host.new(@client, host)
|
23
39
|
end
|
24
40
|
host_list
|
25
41
|
end
|
26
42
|
|
27
|
-
def
|
43
|
+
def alerts(page = 1, limit = 10, status = 'OPEN')
|
44
|
+
alert_list = []
|
45
|
+
@client.get('/groups/' + @id + '/alerts?status=' + status + '&pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |alert|
|
46
|
+
alert_list.push MMS::Resource::Alert.new(@client, alert)
|
47
|
+
end
|
48
|
+
alert_list
|
49
|
+
end
|
50
|
+
|
51
|
+
def alert(id)
|
52
|
+
MMS::Resource::Alert.new(@client, {'id' => id, 'groupId' => @id})
|
53
|
+
end
|
54
|
+
|
55
|
+
def clusters(page = 1, limit = 10)
|
28
56
|
if @clusters.empty?
|
29
|
-
|
30
|
-
@clusters.push MMS::Resource::Cluster.new(
|
57
|
+
@client.get('/groups/' + @id + '/clusters?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |cluster|
|
58
|
+
@clusters.push MMS::Resource::Cluster.new(@client, cluster)
|
31
59
|
end
|
32
60
|
end
|
33
61
|
@clusters
|
34
62
|
end
|
35
63
|
|
36
64
|
def cluster(id)
|
37
|
-
MMS::Resource::Cluster.new id, @id
|
65
|
+
MMS::Resource::Cluster.new(@client, {'id' => id, 'groupId' => @id})
|
38
66
|
end
|
39
67
|
|
40
68
|
def findSnapshot(id)
|
@@ -50,8 +78,22 @@ module MMS
|
|
50
78
|
snapshot
|
51
79
|
end
|
52
80
|
|
81
|
+
def table_row
|
82
|
+
[@name, @active_agent_count, @replicaset_count, @shard_count, @last_active_agent, @id]
|
83
|
+
end
|
84
|
+
|
85
|
+
def table_section
|
86
|
+
[table_row]
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.table_header
|
90
|
+
['Name', 'Active Agents', 'Replicas count', 'Shards count', 'Last Active Agent', 'GroupId']
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
53
95
|
def _load(id)
|
54
|
-
|
96
|
+
@client.get('/groups/' + id.to_s)
|
55
97
|
end
|
56
98
|
|
57
99
|
def _from_hash(data)
|
@@ -61,5 +103,10 @@ module MMS
|
|
61
103
|
@shard_count = data['shardCount']
|
62
104
|
@last_active_agent = data['lastActiveAgent']
|
63
105
|
end
|
106
|
+
|
107
|
+
def _to_hash
|
108
|
+
@data
|
109
|
+
end
|
110
|
+
|
64
111
|
end
|
65
112
|
end
|
data/lib/mms/resource/host.rb
CHANGED
@@ -2,6 +2,8 @@ module MMS
|
|
2
2
|
|
3
3
|
class Resource::Host < Resource
|
4
4
|
|
5
|
+
@client = nil
|
6
|
+
|
5
7
|
attr_accessor :name
|
6
8
|
attr_accessor :group
|
7
9
|
attr_accessor :hostname
|
@@ -18,14 +20,36 @@ module MMS
|
|
18
20
|
attr_accessor :profiler_enabled
|
19
21
|
attr_accessor :logs_enabled
|
20
22
|
|
21
|
-
def initialize(
|
22
|
-
|
23
|
+
def initialize(client, data)
|
24
|
+
id = data['id']
|
25
|
+
group_id = data['groupId']
|
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})
|
23
33
|
|
24
34
|
super id, data
|
25
35
|
end
|
26
36
|
|
37
|
+
def table_row
|
38
|
+
[@group.name, @type_name, @name, @ip_address, @port, @last_ping, @alerts_enabled, @id, @shard_name, @replicaset_name]
|
39
|
+
end
|
40
|
+
|
41
|
+
def table_section
|
42
|
+
[table_row]
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.table_header
|
46
|
+
['Group', 'Type', 'Hostname', 'IP', 'Port', 'Last ping', 'Alerts enabled', 'HostId', 'Shard', 'Replica']
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
27
51
|
def _load(id)
|
28
|
-
|
52
|
+
@client.get '/groups/' + @group.id + '/hosts/' + id.to_s
|
29
53
|
end
|
30
54
|
|
31
55
|
def _from_hash(data)
|
@@ -44,5 +68,10 @@ module MMS
|
|
44
68
|
@logs_enabled = data['logsEnabled']
|
45
69
|
@name = @hostname
|
46
70
|
end
|
71
|
+
|
72
|
+
def _to_hash
|
73
|
+
@data
|
74
|
+
end
|
75
|
+
|
47
76
|
end
|
48
77
|
end
|
@@ -4,6 +4,8 @@ module MMS
|
|
4
4
|
|
5
5
|
class Resource::RestoreJob < Resource
|
6
6
|
|
7
|
+
@client = nil
|
8
|
+
|
7
9
|
attr_accessor :name
|
8
10
|
|
9
11
|
# this is restore point cluster e.g full cluster (configs, replicas)
|
@@ -15,6 +17,7 @@ module MMS
|
|
15
17
|
attr_accessor :snapshot
|
16
18
|
|
17
19
|
attr_accessor :snapshot_id
|
20
|
+
attr_accessor :timestamp
|
18
21
|
attr_accessor :created
|
19
22
|
attr_accessor :status_name
|
20
23
|
attr_accessor :point_in_time
|
@@ -22,8 +25,18 @@ module MMS
|
|
22
25
|
attr_accessor :delivery_status_name
|
23
26
|
attr_accessor :delivery_url
|
24
27
|
|
25
|
-
def initialize(
|
26
|
-
|
28
|
+
def initialize(client, data)
|
29
|
+
id = data['id']
|
30
|
+
cluster_id = data['clusterId']
|
31
|
+
group_id = data['groupId']
|
32
|
+
|
33
|
+
raise MMS::ResourceError.new('`Id` for restorejob resource must be defined', self) if id.nil?
|
34
|
+
raise MMS::ResourceError.new('`clusterId` for restorejob resource must be defined', self) if cluster_id.nil?
|
35
|
+
raise MMS::ResourceError.new('`groupId` for restorejob resource must be defined', self) if group_id.nil?
|
36
|
+
|
37
|
+
@client = client
|
38
|
+
|
39
|
+
@cluster = MMS::Resource::Cluster.new(client, {'id' => cluster_id, 'groupId' => group_id})
|
27
40
|
|
28
41
|
super id, data
|
29
42
|
end
|
@@ -45,13 +58,35 @@ module MMS
|
|
45
58
|
@snapshot
|
46
59
|
end
|
47
60
|
|
61
|
+
def table_row
|
62
|
+
time_str = DateTime.parse(@timestamp).strftime("%m/%d/%Y %H:%M")
|
63
|
+
[time_str, @snapshot_id, @name, @status_name, @point_in_time, @delivery_method_name, @delivery_status_name]
|
64
|
+
end
|
65
|
+
|
66
|
+
def table_section
|
67
|
+
[
|
68
|
+
table_row,
|
69
|
+
[@id, "#{@cluster.name} (#{@cluster.id})", {:value => '', :colspan => 5}],
|
70
|
+
['', @cluster.group.name, {:value => '', :colspan => 5}],
|
71
|
+
[{:value => 'download url:', :colspan => 7}],
|
72
|
+
[{:value => @delivery_url || '(waiting for link)', :colspan => 7}],
|
73
|
+
:separator
|
74
|
+
]
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.table_header
|
78
|
+
['Timestamp / RestoreId', 'SnapshotId / Cluster / Group', 'Name (created)', 'Status', 'Point in time', 'Delivery', 'Restore status']
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
48
83
|
def _load(id)
|
49
84
|
if has_cluster
|
50
|
-
data =
|
85
|
+
data = @client.get '/groups/' + snapshot.cluster.group.id + '/clusters/' + snapshot.cluster.id + '/restoreJobs/' + id.to_s
|
51
86
|
else
|
52
87
|
# config server has no cluster but owns RestoreJob and Snapshot
|
53
88
|
restore_jobs = @cluster.restorejobs
|
54
|
-
job = restore_jobs.select {|restorejob| restorejob.id == id }
|
89
|
+
job = restore_jobs.select { |restorejob| restorejob.id == id }
|
55
90
|
data = job.first.data unless job.nil? and job.empty?
|
56
91
|
end
|
57
92
|
data
|
@@ -61,11 +96,17 @@ module MMS
|
|
61
96
|
@snapshot_id = data['snapshotId']
|
62
97
|
@created = data['created']
|
63
98
|
@status_name = data['statusName']
|
99
|
+
@timestamp = data['timestamp']['date']
|
64
100
|
@point_in_time = data['pointInTime']
|
65
101
|
@delivery_method_name = data['delivery']['methodName'] unless data['delivery'].nil?
|
66
102
|
@delivery_status_name = data['delivery']['statusName'] unless data['delivery'].nil?
|
67
103
|
@delivery_url = data['delivery']['url'] unless data['delivery'].nil?
|
68
104
|
@name = DateTime.parse(@created).strftime("%Y-%m-%d %H:%M:%S")
|
69
105
|
end
|
106
|
+
|
107
|
+
def _to_hash
|
108
|
+
@data
|
109
|
+
end
|
110
|
+
|
70
111
|
end
|
71
112
|
end
|
@@ -4,6 +4,8 @@ module MMS
|
|
4
4
|
|
5
5
|
class Resource::Snapshot < Resource
|
6
6
|
|
7
|
+
@client = nil
|
8
|
+
|
7
9
|
attr_accessor :name
|
8
10
|
attr_accessor :cluster
|
9
11
|
|
@@ -13,8 +15,18 @@ module MMS
|
|
13
15
|
attr_accessor :expires
|
14
16
|
attr_accessor :parts
|
15
17
|
|
16
|
-
def initialize(
|
17
|
-
|
18
|
+
def initialize(client, data)
|
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})
|
18
30
|
|
19
31
|
super id, data
|
20
32
|
end
|
@@ -53,10 +65,10 @@ module MMS
|
|
53
65
|
|
54
66
|
def create_restorejob
|
55
67
|
data = {:snapshotId => @id}
|
56
|
-
jobs =
|
68
|
+
jobs = @client.post '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/restoreJobs', data
|
57
69
|
|
58
70
|
if jobs.nil?
|
59
|
-
raise "Cannot create job from snapshot `#{self.id}`"
|
71
|
+
raise MMS::ResourceError.new("Cannot create job from snapshot `#{self.id}`", self)
|
60
72
|
end
|
61
73
|
|
62
74
|
job_list = []
|
@@ -64,7 +76,7 @@ module MMS
|
|
64
76
|
# The config-server RestoreJob and Snapshot has no own ClusterId to be accessed.
|
65
77
|
restore_jobs = @cluster.restorejobs
|
66
78
|
jobs.each do |job|
|
67
|
-
_list = restore_jobs.select {|restorejob| restorejob.id == job['id'] }
|
79
|
+
_list = restore_jobs.select { |restorejob| restorejob.id == job['id'] }
|
68
80
|
_list.each do |restorejob|
|
69
81
|
job_list.push restorejob
|
70
82
|
end
|
@@ -72,19 +84,48 @@ module MMS
|
|
72
84
|
job_list
|
73
85
|
end
|
74
86
|
|
87
|
+
def table_row
|
88
|
+
[@cluster.group.name, @cluster.name, @id, @complete, @created_increment, @name, @expires]
|
89
|
+
end
|
90
|
+
|
91
|
+
def table_section
|
92
|
+
rows = []
|
93
|
+
rows << table_row
|
94
|
+
rows << :separator
|
95
|
+
part_count = 0
|
96
|
+
@parts.each do |part|
|
97
|
+
file_size_mb = part['fileSizeBytes'].to_i / (1024*1024)
|
98
|
+
rows << [{:value => "part #{part_count}", :colspan => 4, :alignment => :right}, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"]
|
99
|
+
part_count += 1
|
100
|
+
end
|
101
|
+
rows << :separator
|
102
|
+
rows
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.table_header
|
106
|
+
['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Name (created date)', 'Expires']
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
75
111
|
def _load(id)
|
76
|
-
|
112
|
+
@client.get '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/snapshots/' + id.to_s
|
77
113
|
end
|
78
114
|
|
79
115
|
def _from_hash(data)
|
80
116
|
@complete = data['complete']
|
81
|
-
@created_date = data['created']['date']
|
82
|
-
@created_increment = data['created']['increment']
|
117
|
+
@created_date = data['created'].nil? ? nil : data['created']['date']
|
118
|
+
@created_increment = data['created'].nil? ? nil : data['created']['increment']
|
83
119
|
@expires = data['expires']
|
84
120
|
@parts = data['parts']
|
85
|
-
@name = DateTime.parse(@created_date).strftime("%Y-%m-%d %H:%M:%S")
|
121
|
+
@name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime("%Y-%m-%d %H:%M:%S")
|
86
122
|
|
87
|
-
@cluster = MMS::Resource::Cluster.new data['clusterId'], data['groupId']
|
123
|
+
@cluster = MMS::Resource::Cluster.new(@client, {'id' => data['clusterId'], 'groupId' => data['groupId']})
|
88
124
|
end
|
125
|
+
|
126
|
+
def _to_hash
|
127
|
+
@data
|
128
|
+
end
|
129
|
+
|
89
130
|
end
|
90
131
|
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.0.10
|
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:
|
13
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-http-digest_auth
|
@@ -54,6 +54,20 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 1.0.6
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: clamp
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.6.0
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.6.0
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
72
|
name: rake
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,8 +109,12 @@ files:
|
|
95
109
|
- lib/mms.rb
|
96
110
|
- lib/mms/agent.rb
|
97
111
|
- lib/mms/cache.rb
|
112
|
+
- lib/mms/cli.rb
|
98
113
|
- lib/mms/client.rb
|
114
|
+
- lib/mms/config.rb
|
115
|
+
- lib/mms/errors.rb
|
99
116
|
- lib/mms/resource.rb
|
117
|
+
- lib/mms/resource/alert.rb
|
100
118
|
- lib/mms/resource/cluster.rb
|
101
119
|
- lib/mms/resource/group.rb
|
102
120
|
- lib/mms/resource/host.rb
|
@@ -123,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
141
|
version: '0'
|
124
142
|
requirements: []
|
125
143
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.
|
144
|
+
rubygems_version: 2.4.5
|
127
145
|
signing_key:
|
128
146
|
specification_version: 4
|
129
147
|
summary: MongoDB MMS API client
|