@@ -102,7 +102,7 @@ def self.shard_collection_details(obj, shard_name)
102102
103103 def self . shard_properties ( shard )
104104 properties = { }
105- output = mongo_command ( 'sh.status()' )
105+ output = mongo_command ( 'sh.status()' ) [ 'value' ]
106106 output [ 'shards' ] . each do |s |
107107 next unless s [ '_id' ] == shard
108108
@@ -118,7 +118,7 @@ def self.shard_properties(shard)
118118 end
119119
120120 def self . shards_properties
121- output = mongo_command ( 'sh.status()' )
121+ output = mongo_command ( 'sh.status()' ) [ 'value' ]
122122 properties = if output [ 'shards' ] . empty?
123123 [ ]
124124 else
@@ -163,64 +163,6 @@ def self.mongo_command(command, host = nil, _retries = 4)
163163 retry
164164 end
165165
166- # NOTE: (spredzy) : sh.status()
167- # does not return a json stream
168- # we jsonify it so it is easier
169- # to parse and deal with it
170- if command == 'sh.status()'
171- myarr = output . split ( "\n " )
172- myarr . shift
173- myarr . pop
174- myarr . pop
175- final_stream = [ ]
176- prev_line = nil
177- in_shard_list = 0
178- in_chunk = 0
179- myarr . each do |line |
180- line . gsub! ( %r{sharding version:} , '{ "sharding version":' )
181- line . gsub! ( %r{shards:} , ',"shards":[' )
182- line . gsub! ( %r{databases:} , '], "databases":[' )
183- line . gsub! ( %r{"clusterId" : ObjectId\( "(.*)"\) } , '"clusterId" : "ObjectId(\'\1\')"' )
184- line . gsub! ( %r{\{ "_id" :} , ',{ "_id" :' ) if %r{_id} =~ prev_line
185- # Modification for shard
186- line = '' if line =~ %r{on :.*Timestamp}
187- if line =~ %r{_id} && in_shard_list == 1
188- in_shard_list = 0
189- last_line = final_stream . pop . strip
190- proper_line = "#{ last_line } ]},"
191- final_stream << proper_line
192- end
193- if line =~ %r{shard key} && in_shard_list == 1
194- shard_name = final_stream . pop . strip
195- proper_line = ",{\" #{ shard_name } \" :"
196- final_stream << proper_line
197- end
198- if line =~ %r{shard key} && in_shard_list . zero?
199- in_shard_list = 1
200- shard_name = final_stream . pop . strip
201- id_line = "#{ final_stream . pop [ 0 ..-2 ] } , \" shards\" : "
202- proper_line = "[{\" #{ shard_name } \" :"
203- final_stream << id_line
204- final_stream << proper_line
205- end
206- if in_chunk == 1
207- in_chunk = 0
208- line = "\" #{ line . strip } \" }}"
209- end
210- in_chunk = 1 if line =~ %r{chunks} && in_chunk . zero?
211- line . gsub! ( %r{shard key} , '{"shard key"' )
212- line . gsub! ( %r{chunks} , ',"chunks"' )
213- final_stream << line unless line . empty?
214- prev_line = line
215- end
216- final_stream << ' ] }' if in_shard_list == 1
217- final_stream << ' ] }'
218- output = final_stream . join ( "\n " )
219- end
220-
221- # Hack to avoid non-json empty sets
222- output = '{}' if output == "null\n "
223- output . gsub! ( %r{\s *} , '' )
224166 JSON . parse ( output )
225167 end
226168end
0 commit comments