about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-06 07:46:38 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-06 07:46:38 +0000
commitbbe2702bb95a8fd11c1b8fb87f758a946876f58e (patch)
tree9ccd9e6c82761c5f0bd236328924104ed3731127
parent347c41d307f85b1264fbf1c06fff9e5c8cb2e091 (diff)
downloadmogilefs-client-bbe2702bb95a8fd11c1b8fb87f758a946876f58e.tar.gz
We'll need to evaluate dropping support for older MogileFS.
They probably didn't have replpolicy back in the day.
-rw-r--r--lib/mogilefs/admin.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb
index 3201aab..7533745 100644
--- a/lib/mogilefs/admin.rb
+++ b/lib/mogilefs/admin.rb
@@ -129,22 +129,47 @@ class MogileFS::Admin < MogileFS::Client
   end
 
   ##
-  # Returns the domains present in the mogilefs.
+  # Returns the domains and classes, and their policies present in the mogilefs.
   #
   #   admin.get_domains
   #
-  # Returns:
+  # Returns (on newer MogileFS servers):
+  #   {
+  #     "test" => {
+  #       "default" => {
+  #         "mindevcount" => 2,
+  #         "replpolicy" => "MultipleHosts()"
+  #       }
+  #     }
+  #   }
+  #
+  # Returns (on older MogileFS servers without replication policies):
   #
   #   {"test"=>{"normal"=>3, "default"=>2}}
 
   def get_domains
     res = @backend.get_domains
+    have_replpolicy = false
 
     domains = {}
     (1..res['domains'].to_i).each do |i|
       domain = clean "domain#{i}classes", "domain#{i}class", res, false
-      domain = domain.map { |d| [d.values.first, d.values.last.to_i] }
-      domains[res["domain#{i}"]] = Hash[*domain.flatten]
+
+      tmp = domains[res["domain#{i}"]] = {}
+      domain.each do |d|
+        tmp[d.delete("name")] = d
+        d["mindevcount"] = d["mindevcount"].to_i
+        have_replpolicy ||= d.include?("replpolicy")
+      end
+    end
+
+    # only for MogileFS 1.x?, maybe we can drop support for this...
+    unless have_replpolicy
+      domains.each do |namespace, class_data|
+        class_data.each do |class_name, data|
+          class_data[class_name] = data["mindevcount"]
+        end
+      end
     end
 
     domains