mms-api 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9f237818d6e0c66e6511c157bbd76e0339c0a76
4
- data.tar.gz: 8dd890ae570320a80c0bd084ca81a2c5c5af5900
3
+ metadata.gz: dcfd755e463ac666d8e74d34a431c3717b077740
4
+ data.tar.gz: 729f27cc6f767df07686fbaae459636e489c2561
5
5
  SHA512:
6
- metadata.gz: d4de5e93a356694501f7a7a6948e16243f967f84d50485cb58a425302425526b320d640baa604312c486e9d01e6e89644153d7855d74570c71b8fc6c3cbc1847
7
- data.tar.gz: 2ff3507c8107f1811e440479d53259bda028a9150b3a135aa8d65c960cf861b6c97e1d0f21f1b6c8314978929d29497afcb4c279b007626cd78a20b837d88135
6
+ metadata.gz: cfe42349fbce3d933b355a92c173bbdde3cc6852fdcdac9141658eba1b05419f22e150dd9538b2ef4150ac06ecf55658f7f691ef512db1046cbca2d5752aae9e
7
+ data.tar.gz: 010ec281cb1a8251c3950b92d724208e0bcb1ad208a34ce6635102b8e17917a49c382460d1e618fc661d7a3787316d7e372e082790fbde7c05fcc2c3a0d397fd
data/README.md CHANGED
@@ -32,8 +32,21 @@ Options:
32
32
  -h, --help Show this help
33
33
  ```
34
34
 
35
- Development
36
- -----------
35
+ API coverage
36
+ ------------
37
+ The MMS Public API follows the principles of the REST architectural style to expose a number of internal resources which enable programmatic access to [MMS’s features](http://mms.mongodb.com/help/reference/api/). Current implementation support only a few of API features.
38
+
39
+ |Resource|Get All|Get One|Create|Update|Delete|
40
+ |:---|:---:|:---:|:---:|:---:|:---:|
41
+ |Groups| + | + | | | | |
42
+ |Hosts| + | + | | | | |
43
+ |Clusters| + | + | | | | |
44
+ |Snapshots| + | + | | | | |
45
+ |Restore Jobs| + | + | + | | | |
46
+
47
+
48
+ Example
49
+ -------
37
50
  ```ruby
38
51
  require 'mms'
39
52
 
data/bin/mms-api CHANGED
@@ -89,14 +89,14 @@ begin
89
89
  rows << [group.name, group.active_agent_count, group.replicaset_count, group.shard_count, group.last_active_agent, group.id]
90
90
  end
91
91
  when 'hosts'
92
- heading = ['Group', 'Type', 'Hostname', 'IP', 'Port', 'Last ping', 'Alerts enabled', 'HostId']
92
+ heading = ['Group', 'Type', 'Hostname', 'IP', 'Port', 'Last ping', 'Alerts enabled', 'HostId', 'Shard', 'Replica']
93
93
  results.each do |host|
94
- rows << [host.group.name, host.type_name, host.name, host.ip_address, host.port, host.last_ping, host.alerts_enabled, host.id]
94
+ rows << [host.group.name, host.type_name, host.name, host.ip_address, host.port, host.last_ping, host.alerts_enabled, host.id, host.shard_name, host.replicaset_name]
95
95
  end
96
96
  when 'clusters'
97
- heading = ['Group', 'Cluster', 'Shard name', 'Replica name', 'Type', 'Last heartbeat']
97
+ heading = ['Group', 'Cluster', 'Shard name', 'Replica name', 'Type', 'Last heartbeat', 'Cluster Id']
98
98
  results.each do |cluster|
99
- rows << [cluster.group.name, cluster.name, cluster.shard_name, cluster.replicaset_name, cluster.type_name, cluster.last_heartbeat]
99
+ rows << [cluster.group.name, cluster.name, cluster.shard_name, cluster.replicaset_name, cluster.type_name, cluster.last_heartbeat, cluster.id]
100
100
  end
101
101
  when 'snapshots'
102
102
  heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Name (created date)', 'Expires']
data/lib/mms/resource.rb CHANGED
@@ -19,6 +19,11 @@ module MMS
19
19
  end
20
20
  end
21
21
 
22
+ def reload
23
+ @data = _load(@id)
24
+ save @data unless @data.nil? or @data.empty?
25
+ end
26
+
22
27
  def load
23
28
  _data = MMS::Cache.instance.get "Class::#{self.class.name}:#{@id}"
24
29
 
@@ -9,30 +9,38 @@ module MMS
9
9
  attr_accessor :type_name
10
10
  attr_accessor :last_heartbeat
11
11
 
12
+ attr_accessor :snapshots
13
+ attr_accessor :restorejobs
14
+
12
15
  def initialize(id, group_id, data = nil)
16
+ @snapshots = []
17
+ @restorejobs = []
18
+
13
19
  @group = MMS::Resource::Group.new(group_id)
14
20
 
15
21
  super id, data
16
22
  end
17
23
 
18
24
  def snapshot(id)
19
- MMS::Resource::Snapshot.new id, self.id, self.group.id
25
+ MMS::Resource::Snapshot.new id, @id, @group.id
20
26
  end
21
27
 
22
28
  def snapshots(page = 1, limit = 1000)
23
- snapshot_list = []
24
- MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
25
- snapshot_list.push MMS::Resource::Snapshot.new(snapshot['id'], snapshot['clusterId'], snapshot['groupId'], snapshot)
29
+ if @snapshots.empty?
30
+ MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
31
+ @snapshots.push MMS::Resource::Snapshot.new(snapshot['id'], snapshot['clusterId'], snapshot['groupId'], snapshot)
32
+ end
26
33
  end
27
- snapshot_list
34
+ @snapshots
28
35
  end
29
36
 
30
37
  def restorejobs(page = 1, limit = 1000)
31
- job_list = []
32
- MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + @id + '/restoreJobs?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |job|
33
- job_list.push MMS::Resource::RestoreJob.new(job['id'], job['clusterId'], job['groupId'], job)
38
+ if @restorejobs.empty?
39
+ MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + @id + '/restoreJobs?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |job|
40
+ @restorejobs.push MMS::Resource::RestoreJob.new(job['id'], job['clusterId'], job['groupId'], job)
41
+ end
34
42
  end
35
- job_list
43
+ @restorejobs
36
44
  end
37
45
 
38
46
  def _load(id)
@@ -8,7 +8,11 @@ module MMS
8
8
  attr_reader :shard_count
9
9
  attr_reader :last_active_agent
10
10
 
11
+ attr_accessor :clusters
12
+
11
13
  def initialize(id, data = nil)
14
+ @clusters = []
15
+
12
16
  super id, data
13
17
  end
14
18
 
@@ -21,15 +25,29 @@ module MMS
21
25
  end
22
26
 
23
27
  def clusters(page = 1, limit = 1000)
24
- cluster_list = []
25
- MMS::Client.instance.get('/groups/' + @id + '/clusters?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |cluster|
26
- cluster_list.push MMS::Resource::Cluster.new(cluster['id'], cluster['groupId'], cluster)
28
+ if @clusters.empty?
29
+ MMS::Client.instance.get('/groups/' + @id + '/clusters?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |cluster|
30
+ @clusters.push MMS::Resource::Cluster.new(cluster['id'], cluster['groupId'], cluster)
31
+ end
27
32
  end
28
- cluster_list
33
+ @clusters
29
34
  end
30
35
 
31
36
  def cluster(id)
32
- MMS::Resource::Cluster.new id, self.id
37
+ MMS::Resource::Cluster.new id, @id
38
+ end
39
+
40
+ def findSnapshot(id)
41
+ snapshot = nil
42
+ clusters.each do |cluster|
43
+ begin
44
+ snapshot = cluster.snapshot(id)
45
+ rescue => e
46
+ # cannot load snapshotId for cluster if config-server is the source?
47
+ # not supported in current MMS API version
48
+ end
49
+ end
50
+ snapshot
33
51
  end
34
52
 
35
53
  def _load(id)
@@ -14,6 +14,9 @@ module MMS
14
14
  attr_accessor :replicaset_name
15
15
  attr_accessor :replica_state_name
16
16
  attr_accessor :alerts_enabled
17
+ attr_accessor :host_enabled
18
+ attr_accessor :profiler_enabled
19
+ attr_accessor :logs_enabled
17
20
 
18
21
  def initialize(id, group_id, data = nil)
19
22
  @group = MMS::Resource::Group.new(group_id)
@@ -36,6 +39,9 @@ module MMS
36
39
  @replicaset_name = data['replicaSetName']
37
40
  @replica_state_name = data['replicaStateName']
38
41
  @alerts_enabled = data['alertsEnabled']
42
+ @host_enabled = data['hostEnabled']
43
+ @profiler_enabled = data['profilerEnabled']
44
+ @logs_enabled = data['logsEnabled']
39
45
  @name = @hostname
40
46
  end
41
47
  end
@@ -5,8 +5,15 @@ module MMS
5
5
  class Resource::RestoreJob < Resource
6
6
 
7
7
  attr_accessor :name
8
+
9
+ # this is restore point cluster e.g full cluster (configs, replicas)
8
10
  attr_accessor :cluster
9
11
 
12
+ # this is source point from where RestoreJob was created
13
+ # RestoreJob.snapshot.cluster is e.g replica, config server
14
+ # RestoreJob.cluster is full cluster group (configs, replicas)
15
+ attr_accessor :snapshot
16
+
10
17
  attr_accessor :snapshot_id
11
18
  attr_accessor :created
12
19
  attr_accessor :status_name
@@ -21,8 +28,33 @@ module MMS
21
28
  super id, data
22
29
  end
23
30
 
31
+ def has_cluster
32
+ # cluster definition for config-server cannot be loaded
33
+ # as there is no clusterId for this type of group.
34
+ # there is snapshotId for RestoreJob but seems to be stored
35
+ # internally in MMS API. Not accessible by public API.
36
+ snapshot != nil
37
+ end
38
+
39
+ def snapshot
40
+ # snapshot details for config-server cannot be loaded
41
+ # as there is no clusterId. See also has_cluster()
42
+ if @snapshot.nil?
43
+ @snapshot = @cluster.group.findSnapshot(@snapshot_id)
44
+ end
45
+ @snapshot
46
+ end
47
+
24
48
  def _load(id)
25
- MMS::Client.instance.get '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/restoreJobs/' + id.to_s
49
+ if has_cluster
50
+ data = MMS::Client.instance.get '/groups/' + snapshot.cluster.group.id + '/clusters/' + snapshot.cluster.id + '/restoreJobs/' + id.to_s
51
+ else
52
+ # config server has no cluster but owns RestoreJob and Snapshot
53
+ restore_jobs = @cluster.restorejobs
54
+ job = restore_jobs.select {|restorejob| restorejob.id == id }
55
+ data = job.first.data unless job.nil? and job.empty?
56
+ end
57
+ data
26
58
  end
27
59
 
28
60
  def _from_hash(data)
@@ -30,9 +62,9 @@ module MMS
30
62
  @created = data['created']
31
63
  @status_name = data['statusName']
32
64
  @point_in_time = data['pointInTime']
33
- @delivery_method_name = data['delivery']['methodName']
34
- @delivery_status_name = data['delivery']['statusName']
35
- @delivery_url = data['delivery']['url']
65
+ @delivery_method_name = data['delivery']['methodName'] unless data['delivery'].nil?
66
+ @delivery_status_name = data['delivery']['statusName'] unless data['delivery'].nil?
67
+ @delivery_url = data['delivery']['url'] unless data['delivery'].nil?
36
68
  @name = DateTime.parse(@created).strftime("%Y-%m-%d %H:%M:%S")
37
69
  end
38
70
  end
@@ -19,8 +19,36 @@ module MMS
19
19
  super id, data
20
20
  end
21
21
 
22
- def _load(id)
23
- MMS::Client.instance.get '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/snapshots/' + id.to_s
22
+ def is_cluster
23
+ @parts.length > 1
24
+ end
25
+
26
+ def is_config
27
+ @parts.length == 1 and @parts.first['typeName'] == 'CONFIG_SERVER'
28
+ end
29
+
30
+ def is_replica
31
+ @parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET'
32
+ end
33
+
34
+ def cluster_name
35
+ @cluster.name if is_cluster
36
+ end
37
+
38
+ def config_name
39
+ 'config' if is_config
40
+ end
41
+
42
+ def replica_name
43
+ @parts.first['replicaSetName'] if is_replica
44
+ end
45
+
46
+ def source_name
47
+ name = nil
48
+ name = replica_name if is_replica
49
+ name = config_name if is_config
50
+ name = cluster_name if is_cluster
51
+ name
24
52
  end
25
53
 
26
54
  def create_restorejob
@@ -33,21 +61,21 @@ module MMS
33
61
 
34
62
  job_list = []
35
63
  # work around due to bug in MMS API; cannot read restoreJob using provided info.
64
+ # The config-server RestoreJob and Snapshot has no own ClusterId to be accessed.
36
65
  restore_jobs = @cluster.restorejobs
37
-
38
66
  jobs.each do |job|
39
67
  _list = restore_jobs.select {|restorejob| restorejob.id == job['id'] }
40
68
  _list.each do |restorejob|
41
- begin
42
- job_list.push MMS::Resource::RestoreJob.new(restorejob.id, restorejob.cluster.id, restorejob.cluster.group.id)
43
- rescue => e
44
- puts "load error #{e.message}"
45
- end
69
+ job_list.push restorejob
46
70
  end
47
71
  end
48
72
  job_list
49
73
  end
50
74
 
75
+ def _load(id)
76
+ MMS::Client.instance.get '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/snapshots/' + id.to_s
77
+ end
78
+
51
79
  def _from_hash(data)
52
80
  @complete = data['complete']
53
81
  @created_date = data['created']['date']
@@ -55,6 +83,8 @@ module MMS
55
83
  @expires = data['expires']
56
84
  @parts = data['parts']
57
85
  @name = DateTime.parse(@created_date).strftime("%Y-%m-%d %H:%M:%S")
86
+
87
+ @cluster = MMS::Resource::Cluster.new data['clusterId'], data['groupId']
58
88
  end
59
89
  end
60
90
  end
data/lib/mms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MMS
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
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.6
4
+ version: 0.0.7
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: 2014-08-27 00:00:00.000000000 Z
13
+ date: 2014-09-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-http-digest_auth