mms-api 0.1.3 → 0.1.4

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: ed084e5a96495658bf4b5775abe035e50e6c7091
4
- data.tar.gz: 55a19c53ad7c459788093069dafd2f8a49e3e2a3
3
+ metadata.gz: fa0051f575f3a3ae3a361221591a57fca40256b9
4
+ data.tar.gz: acda37863edf79ad4929c758dcf2cb60b5f7efef
5
5
  SHA512:
6
- metadata.gz: 55c9e5339e3d37247a7c85331f16240b5ba20c1a5bcaa13cb853c27687035fe4cc7c29a36bdc7f94211e008d8e728e85ebd2295058175de498af9cf0080c0a65
7
- data.tar.gz: c178e0e010081f87eee5372db173fddd4df21523dac70baa3bdd0c5d00e0da559846739eb671f04b65280b4b1c50a6dba1d6368775cc8bd70c2736db21ea80f4
6
+ metadata.gz: f48f1b2cf25beef5d7b13e1361764548f4d77889cf2c7c9b7dea3462520386b72a5f8d2fa75a0115d89b6c2729e4bf089232a843ebdac924b246517642324949
7
+ data.tar.gz: 931ed08d4581148c0d4e191188524f9051af12b5b0b1df8ba33507a2124eb140c86e0992729cc48e61c77591db3d9ae31f4cb0cd375c65ba15b0f9a51b13ca99
data/README.md CHANGED
@@ -12,14 +12,16 @@ API coverage
12
12
  ------------
13
13
  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.
14
14
 
15
- |Resource |Get All |Get One |Create |Update |Delete |
16
- |:------------|:------:|:------:|:-----:|:-----:|:-----:|
17
- |Groups | + | + | | | |
18
- |Hosts | + | + | | | |
19
- |Clusters | + | + | | | |
20
- |Snapshots | + | + | | | |
21
- |Alerts | + | + | | | |
22
- |Restore Jobs | + | + | + | | |
15
+ |Resource |Get All |Get One |Create |Update |Delete |
16
+ |:--------------|:------:|:------:|:-----:|:-----:|:-----:|
17
+ |Groups | + | + | | | |
18
+ |Hosts | + | + | | | |
19
+ |Clusters | + | + | | | |
20
+ |Snapshots | + | + | | | |
21
+ |Alerts | + | + | | | |
22
+ |Restore Jobs | + | + | + | | |
23
+ |Backup Configs | + | + | | | |
24
+ |Metrics | + | + | | | |
23
25
 
24
26
  Library usage
25
27
  -------------
@@ -73,6 +75,28 @@ group = MMS::Resource::Group.find(client, 'group_id')
73
75
  hosts = group.hosts
74
76
  ```
75
77
 
78
+ #### Metrics
79
+
80
+ (Not available via CLI)
81
+
82
+ You can list the available metrics on each host. The list contains the resource type MMS::Resource::Metric. This can be used to see which performance metrics the host has.
83
+
84
+ In order to get the metric's data points you'll need to call the specific function.
85
+
86
+ Note - you can send a hash containing query parameter. With no input it uses MMS default.
87
+
88
+ The return value of the data points is the hash described in MMS's API reference docs.
89
+ ```ruby
90
+ client = new MMS::Client.new('username', 'api_key')
91
+ host = MMS::Resource::Host.find(client, 'group_id', 'host_id')
92
+ metrics = host.metrics
93
+ options = {"granularity" => "HOUR", "period" => "P1DT12H" }
94
+ metrics.each do |m|
95
+ puts m.data_points(options)
96
+ end
97
+ ```
98
+ In case of hardware or database metrics, the return value will be an array that each value contains the data points for the relevant device or database.
99
+
76
100
  Cli usage
77
101
  ---------
78
102
 
data/lib/mms.rb CHANGED
@@ -24,6 +24,8 @@ module MMS
24
24
  require 'mms/resource/snapshot_schedule'
25
25
  require 'mms/resource/restore_job'
26
26
  require 'mms/resource/alert'
27
+ require 'mms/resource/backup_config'
28
+ require 'mms/resource/metric'
27
29
 
28
30
  require 'mms/cli'
29
31
  end
data/lib/mms/agent.rb CHANGED
@@ -80,8 +80,8 @@ module MMS
80
80
  if type_value.length == 24
81
81
  find_group(group_id).cluster(cluster_id).snapshot(type_value).create_restorejob
82
82
  elsif datetime = (type_value == 'now' ? DateTime.now : DateTime.parse(type_value))
83
- raise('Invalid datetime. Correct `YYYY-MM-RRTH:m:s`') if datetime.nil?
84
- datetime_string = [[datetime.year, datetime.day, datetime.month].join('-'), 'T', [datetime.hour, datetime.minute, datetime.second].join(':'), 'Z'].join
83
+ raise('Invalid datetime. Correct `YYYY-MM-RRTH:m:sZ`') if datetime.nil?
84
+ datetime_string = [[datetime.year, datetime.month, datetime.day].join('-'), 'T', [datetime.hour, datetime.minute, datetime.second].join(':'), 'Z'].join
85
85
  find_group(group_id).cluster(cluster_id).create_restorejob(datetime_string)
86
86
  end
87
87
  end
@@ -0,0 +1,65 @@
1
+ require 'date'
2
+
3
+ module MMS
4
+
5
+ class Resource::BackupConfig < Resource
6
+
7
+ attr_accessor :cluster_id
8
+ attr_accessor :excluded_namespaces
9
+ attr_accessor :group_id
10
+ attr_accessor :links
11
+ attr_accessor :status_name
12
+
13
+ # @return [TrueClass, FalseClass]
14
+ def is_active
15
+ 'STARTED'.eql? @status_name
16
+ end
17
+
18
+ # @return [String, NilClass]
19
+ def cluster_name
20
+ cluster.name if is_cluster
21
+ end
22
+
23
+ # @return [MMS::Resource::Cluster]
24
+ def cluster
25
+ MMS::Resource::Cluster.find(@client, @data['groupId'], @data['clusterId'])
26
+ end
27
+
28
+ def table_row
29
+ [cluster.group.name, cluster.name, @id, @excluded_namespaces, @group_id, @links, @status_name, @cluster_id]
30
+ end
31
+
32
+ def table_section
33
+ rows = []
34
+ rows << table_row
35
+ rows << :separator
36
+ rows
37
+ end
38
+
39
+ def self.table_header
40
+ ['Group', 'Cluster', 'BackupId', 'Excluded namespaces', 'Group Id', 'Links', 'Status name', 'Cluster id']
41
+ end
42
+
43
+ # @param [MMS::Client] client
44
+ # @param [String] group_id
45
+ # @param [String] cluster_id
46
+ def self._find(client, group_id, cluster_id)
47
+ client.get('/groups/' + group_id + '/backupConfigs/' + cluster_id)
48
+ end
49
+
50
+ private
51
+
52
+ def _from_hash(data)
53
+ @cluster_id = data['clusterId']
54
+ @excluded_namespaces = data['excludedNamespaces']
55
+ @group_id = data['groupId']
56
+ @links = data['links']
57
+ @status_name = data['statusName']
58
+ end
59
+
60
+ def _to_hash
61
+ @data
62
+ end
63
+
64
+ end
65
+ end
@@ -21,7 +21,7 @@ module MMS
21
21
  end
22
22
 
23
23
  def snapshot(id)
24
- MMS::Resource::Snapshot.find(@client, group.id, @id, id)
24
+ MMS::Resource::Snapshot.find(@client, group.id, @id, nil, id)
25
25
  end
26
26
 
27
27
  def snapshots(page = 1, limit = 1000)
@@ -12,6 +12,7 @@ module MMS
12
12
 
13
13
  def initialize
14
14
  @clusters = []
15
+ @backup_configs = []
15
16
  end
16
17
 
17
18
  # @param [Integer] page
@@ -73,6 +74,19 @@ module MMS
73
74
  MMS::Resource::Cluster.find(@client, @id, id)
74
75
  end
75
76
 
77
+ def backup_configs
78
+ if @backup_configs.empty?
79
+ @client.get('/groups/' + @id + '/backupConfigs').each do |backup_config|
80
+ bc = MMS::Resource::BackupConfig.new
81
+ bc.set_client(@client)
82
+ bc.set_data(backup_config)
83
+
84
+ @backup_configs.push bc
85
+ end
86
+ end
87
+ @backup_configs
88
+ end
89
+
76
90
  # @param [String] id
77
91
  # @return [MMS::Resource::Snapshot, NilClass]
78
92
  def find_snapshot(id)
@@ -85,6 +99,16 @@ module MMS
85
99
  # Snapshot is not available on this cluster. Skip it!
86
100
  end
87
101
  end
102
+ if snapshot.nil?
103
+ hosts.each do |host|
104
+ begin
105
+ snapshot = host.snapshot(id)
106
+ break unless snapshot.nil?
107
+ rescue MMS::ApiError => e
108
+ # Snapshot is not available on this host. Skip it!
109
+ end
110
+ end
111
+ end
88
112
  snapshot
89
113
  end
90
114
 
@@ -17,11 +17,32 @@ module MMS
17
17
  attr_accessor :profiler_enabled
18
18
  attr_accessor :logs_enabled
19
19
 
20
+ def initialize
21
+ @metric_list = []
22
+ end
23
+
20
24
  # @return [MMS::Resource::Group]
21
25
  def group
22
26
  MMS::Resource::Group.find(@client, @data['groupId'])
23
27
  end
24
28
 
29
+ def snapshot(id)
30
+ MMS::Resource::Snapshot.find(@client, group.id, nil, @id, id)
31
+ end
32
+
33
+ def snapshots(page = 1, limit = 1000)
34
+ if @snapshots.empty?
35
+ @client.get('/groups/' + group.id + '/hosts/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
36
+ s = MMS::Resource::Snapshot.new
37
+ s.set_client(@client)
38
+ s.set_data(snapshot)
39
+
40
+ @snapshots.push s
41
+ end
42
+ end
43
+ @snapshots
44
+ end
45
+
25
46
  def table_row
26
47
  [group.name, @type_name, @name, @ip_address, @port, @last_ping, @alerts_enabled, @id, @shard_name, @replicaset_name]
27
48
  end
@@ -37,10 +58,25 @@ module MMS
37
58
  # @param [MMS::Client] client
38
59
  # @param [String] group_id
39
60
  # @param [String] id
61
+ # @returns [Hash]
40
62
  def self._find(client, group_id, id)
41
63
  client.get('/groups/' + group_id + '/hosts/' + id)
42
64
  end
43
65
 
66
+ # @returns [Array<MMS::Resource::Metric>]
67
+ def metrics
68
+ if @metric_list.empty?
69
+ @client.get('/groups/' + group.id + '/hosts/' + @id + '/metrics').each do |metric|
70
+ m = MMS::Resource::Metric.new
71
+ m.set_client(@client)
72
+ m.set_data(metric)
73
+
74
+ @metric_list.push m
75
+ end
76
+ end
77
+ @metric_list
78
+ end
79
+
44
80
  private
45
81
 
46
82
  def _from_hash(data)
@@ -0,0 +1,63 @@
1
+ module MMS
2
+
3
+ class Resource::Metric < Resource
4
+
5
+ attr_accessor :name
6
+ attr_accessor :units
7
+ attr_accessor :granularity
8
+ attr_accessor :data_points
9
+
10
+ def host
11
+ MMS::Resource::Host.find(@client, @data['groupId'], @data['hostId'])
12
+ end
13
+
14
+ # @param [Hash] options
15
+ # @returns [Array<Hash>]
16
+ def data_points(options = {})
17
+ series = []
18
+ metric_data = get_metric_data(options)
19
+ if !metric_data.is_a?(Array)
20
+ series << metric_data
21
+ else
22
+ metric_data.each do |m|
23
+ d_name = (m['deviceName'] || '') + (m['databaseName'] || '')
24
+ series << get_metric_data(options, d_name)
25
+ end
26
+ end
27
+ series
28
+ end
29
+
30
+ # @param [MMS::Client] client
31
+ # @param [String] group_id
32
+ # @param [String] host_id
33
+ # @param [String] metric_name
34
+ # @returns [Hash]
35
+ def self._find(client, group_id, host_id, metric_name)
36
+ client.get('/groups/' + group_id + '/hosts/' + host_id + '/metrics/' + metric_name)
37
+ end
38
+
39
+ private
40
+
41
+ # @param [Hash] options
42
+ # @param [String] name
43
+ # @returns [Hash]
44
+ def get_metric_data(options = {}, d_name = '')
45
+ params = options.map { |k, v| "#{k}=#{v}" }.join('&')
46
+ ret = client.get("/groups/#{@data['groupId']}/hosts/#{@data['hostId']}/metrics/#{@data['metricName']}/#{d_name}?#{params}")
47
+ ret.delete("links")
48
+ ret
49
+ end
50
+
51
+ def _from_hash(data)
52
+ @name = data['metricName']
53
+ @units = data['units']
54
+ @granularity = data['granularity']
55
+ @data_points = data['dataPoints']
56
+ data.delete('links')
57
+ end
58
+
59
+ def _to_hash
60
+ @data
61
+ end
62
+ end
63
+ end
@@ -22,15 +22,24 @@ module MMS
22
22
 
23
23
  attr_accessor :cluster_id
24
24
  attr_accessor :group_id
25
+ attr_accessor :host_id
25
26
 
26
27
  # @return [MMS::Resource::Cluster]
27
28
  def cluster
28
29
  MMS::Resource::Cluster.find(@client, @group_id, @cluster_id)
29
30
  end
30
31
 
32
+ def host
33
+ MMS::Resource::Host.find(@client, @group_id, @host_id)
34
+ end
35
+
36
+ def has_host?
37
+ !@host_id.nil?
38
+ end
39
+
31
40
  # @return [MMS::Resource::Snapshot, NilClass]
32
41
  def snapshot
33
- @snapshot ||= cluster.group.find_snapshot(@snapshot_id)
42
+ has_host? ? host.snapshot(@snapshot_id) : cluster.snapshot(@snapshot_id)
34
43
  end
35
44
 
36
45
  def table_row
@@ -53,22 +62,16 @@ module MMS
53
62
  ['Timestamp / RestoreId', 'SnapshotId / Cluster / Group', 'Name (created)', 'Status', 'Point in time', 'Delivery', 'Restore status']
54
63
  end
55
64
 
56
- def self._find(client, group_id, cluster_id, id)
57
- begin
58
- client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/restoreJobs/' + id)
59
- rescue MMS::ApiError => e
60
- # workaround for https://jira.mongodb.org/browse/DOCS-5017
61
- self._find_from_list(client, group_id, cluster_id, id)
62
- end
65
+ def self._find(client, group_id, cluster_id, host_id, id)
66
+ host_id.nil? ? self._find_by_cluster(client, group_id, cluster_id, id) : self._find_by_host(client, group_id, host_id, id)
63
67
  end
64
68
 
65
- def self._find_from_list(client, group_id, cluster_id, id)
66
- cluster = MMS::Resource::Cluster.find(client, group_id, cluster_id)
67
-
68
- job = cluster.restorejobs.find { |restorejob| restorejob.id == id }
69
- raise("Cannot find RestoreJob id `#{id}`") if job.nil?
69
+ def self._find_by_host(client, group_id, host_id, id)
70
+ client.get('/groups/' + group_id + '/hosts/' + host_id + '/restoreJobs/' + id)
71
+ end
70
72
 
71
- job.data
73
+ def self._find_by_cluster(client, group_id, cluster_id, id)
74
+ client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/restoreJobs/' + id)
72
75
  end
73
76
 
74
77
  private
@@ -85,6 +88,7 @@ module MMS
85
88
  @name = DateTime.parse(@created).strftime("%Y-%m-%d %H:%M:%S")
86
89
  @cluster_id = data['clusterId']
87
90
  @group_id = data['groupId']
91
+ @host_id = data['hostId']
88
92
  end
89
93
 
90
94
  def _to_hash
@@ -20,12 +20,12 @@ module MMS
20
20
 
21
21
  # @return [TrueClass, FalseClass]
22
22
  def is_config
23
- @parts.length == 1 and @parts.first['typeName'] == 'CONFIG_SERVER'
23
+ @parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET' and !@parts.first['hostId'].nil?
24
24
  end
25
25
 
26
26
  # @return [TrueClass, FalseClass]
27
27
  def is_replica
28
- @parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET'
28
+ @parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET' and !@parts.first['clusterId'].nil?
29
29
  end
30
30
 
31
31
  # @return [String, NilClass]
@@ -101,10 +101,18 @@ module MMS
101
101
  # @param [String] cluster_id
102
102
  # @param [String] id
103
103
  # @return [MMS::Resource::Snapshot]
104
- def self._find(client, group_id, cluster_id, id)
104
+ def self._find(client, group_id, cluster_id, host_id, id)
105
+ host_id.nil? ? self._find_by_cluster(client, group_id, cluster_id, id) : self._find_by_host(client, group_id, host_id, id)
106
+ end
107
+
108
+ def self._find_by_cluster(client, group_id, cluster_id, id)
105
109
  client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/snapshots/' + id.to_s)
106
110
  end
107
111
 
112
+ def self._find_by_host(client, group_id, host_id, id)
113
+ client.get('/groups/' + group_id + '/hosts/' + host_id + '/snapshots/' + id.to_s)
114
+ end
115
+
108
116
  private
109
117
 
110
118
  def _from_hash(data)
data/lib/mms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MMS
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
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.1.3
4
+ version: 0.1.4
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-05-21 00:00:00.000000000 Z
13
+ date: 2015-09-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-http-digest_auth
@@ -115,9 +115,11 @@ files:
115
115
  - lib/mms/errors.rb
116
116
  - lib/mms/resource.rb
117
117
  - lib/mms/resource/alert.rb
118
+ - lib/mms/resource/backup_config.rb
118
119
  - lib/mms/resource/cluster.rb
119
120
  - lib/mms/resource/group.rb
120
121
  - lib/mms/resource/host.rb
122
+ - lib/mms/resource/metric.rb
121
123
  - lib/mms/resource/restore_job.rb
122
124
  - lib/mms/resource/snapshot.rb
123
125
  - lib/mms/resource/snapshot_schedule.rb