2009-01-07 20:36:12 +00:00
|
|
|
# --
|
|
|
|
# Copyright (C) 2008-2009 10gen Inc.
|
|
|
|
#
|
2009-02-15 13:24:14 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2009-01-07 20:36:12 +00:00
|
|
|
#
|
2009-02-15 13:24:14 +00:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2009-01-07 20:36:12 +00:00
|
|
|
#
|
2009-02-15 13:24:14 +00:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2009-01-07 20:36:12 +00:00
|
|
|
# ++
|
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
module Mongo
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2010-01-06 18:51:12 +00:00
|
|
|
# @deprecated this class is deprecated. Methods defined here will
|
|
|
|
# henceforth be available in Mongo::DB.
|
2009-08-20 14:50:48 +00:00
|
|
|
class Admin
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
def initialize(db)
|
2010-01-06 18:51:12 +00:00
|
|
|
warn "The Admin class has been DEPRECATED. All admin methods now exist in DB."
|
2009-08-20 14:50:48 +00:00
|
|
|
@db = db
|
|
|
|
end
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# Return the current database profiling level.
|
2010-01-06 18:51:12 +00:00
|
|
|
#
|
|
|
|
# @return [Symbol] :off, :slow_only, or :all
|
|
|
|
#
|
|
|
|
# @deprecated please use DB#profiling_level instead.
|
2009-08-20 14:50:48 +00:00
|
|
|
def profiling_level
|
2010-01-06 18:51:12 +00:00
|
|
|
warn "Admin#profiling_level has been DEPRECATED. Please use DB#profiling_level instead."
|
2009-08-20 14:50:48 +00:00
|
|
|
oh = OrderedHash.new
|
|
|
|
oh[:profile] = -1
|
2009-11-23 20:20:05 +00:00
|
|
|
doc = @db.command(oh)
|
2009-08-20 14:50:48 +00:00
|
|
|
raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc) && doc['was'].kind_of?(Numeric)
|
|
|
|
case doc['was'].to_i
|
|
|
|
when 0
|
|
|
|
:off
|
|
|
|
when 1
|
|
|
|
:slow_only
|
|
|
|
when 2
|
|
|
|
:all
|
|
|
|
else
|
|
|
|
raise "Error: illegal profiling level value #{doc['was']}"
|
|
|
|
end
|
|
|
|
end
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# Set database profiling level to :off, :slow_only, or :all.
|
2010-01-06 18:51:12 +00:00
|
|
|
#
|
|
|
|
# @deprecated please use DB#profiling_level= instead.
|
2009-08-20 14:50:48 +00:00
|
|
|
def profiling_level=(level)
|
2010-01-06 18:51:12 +00:00
|
|
|
warn "Admin#profiling_level= has been DEPRECATED. Please use DB#profiling_level= instead."
|
2009-08-20 14:50:48 +00:00
|
|
|
oh = OrderedHash.new
|
|
|
|
oh[:profile] = case level
|
|
|
|
when :off
|
|
|
|
0
|
|
|
|
when :slow_only
|
|
|
|
1
|
|
|
|
when :all
|
|
|
|
2
|
|
|
|
else
|
|
|
|
raise "Error: illegal profiling level value #{level}"
|
|
|
|
end
|
2009-11-23 20:20:05 +00:00
|
|
|
doc = @db.command(oh)
|
2009-08-20 14:50:48 +00:00
|
|
|
raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc)
|
|
|
|
end
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2009-12-16 19:03:15 +00:00
|
|
|
# Returns an array containing current profiling information.
|
2010-01-06 18:51:12 +00:00
|
|
|
#
|
|
|
|
# @deprecated please use DB#profiling_info instead.
|
2009-08-20 14:50:48 +00:00
|
|
|
def profiling_info
|
2010-01-06 18:51:12 +00:00
|
|
|
warn "Admin#profiling_info has been DEPRECATED. Please use DB#profiling_info instead."
|
2009-10-22 18:10:12 +00:00
|
|
|
Cursor.new(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), :selector => {}).to_a
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# Validate a named collection by raising an exception if there is a
|
|
|
|
# problem or returning an interesting hash (see especially the
|
|
|
|
# 'result' string value) if all is well.
|
2010-01-06 18:51:12 +00:00
|
|
|
#
|
|
|
|
# @deprecated please use DB#validate_collection instead.
|
2009-08-20 14:50:48 +00:00
|
|
|
def validate_collection(name)
|
2010-01-06 18:51:12 +00:00
|
|
|
warn "Admin#validate_collection has been DEPRECATED. Please use DB#validate_collection instead."
|
2009-11-23 20:20:05 +00:00
|
|
|
doc = @db.command(:validate => name)
|
2009-08-20 14:50:48 +00:00
|
|
|
raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc)
|
|
|
|
result = doc['result']
|
|
|
|
raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
|
|
|
|
raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i
|
|
|
|
doc
|
2009-01-07 20:36:12 +00:00
|
|
|
end
|
2009-08-20 14:50:48 +00:00
|
|
|
|
2009-01-07 20:36:12 +00:00
|
|
|
end
|
|
|
|
end
|