Navigation Menu

Skip to content

Commit

Permalink
Validate relations of datasets and farm
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Feb 12, 2014
1 parent 5b38fc9 commit 7ef4cae
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/droonga/catalog/base.rb
Expand Up @@ -61,6 +61,12 @@ def initialize(name, actual, path)
end
end

class UnknownFarm < ValidationError
def initialize(name, partition, path)
super("The partition #{partition} at \"#{name}\" seems to be bound to an unknown farm.", path)
end
end

class Base
attr_reader :path, :base_path
def initialize(data, path)
Expand Down Expand Up @@ -191,6 +197,7 @@ def validate
validate_zones
validate_farms
validate_datasets
validate_database_relations
end

def validate_parameter_type(expected, value, name)
Expand Down Expand Up @@ -315,6 +322,28 @@ def validate_partition(partition, name)
validate_parameter_type(String, value, "#{name}[#{index}]")
end
end

def validate_database_relations
farm_names = @data["farms"].keys.collect do |name|
Regexp.escape(name)
end
valid_farms_matcher = Regexp.new("^(#{farm_names.join("|")})\.")

datasets.each do |dataset_name, dataset|
ring = dataset["ring"]
ring.each do |ring_key, part|
part["partitions"].each do |range, partitions|
partitions.each_with_index do |partition, index|
unless partition =~ valid_farms_matcher
name = "datasets.#{dataset_name}.ring.#{ring_key}." +
"partitions.#{range}[#{index}]"
raise UnknownFarm.new(name, partition, @path)
end
end
end
end
end
end
end
end
end

0 comments on commit 7ef4cae

Please sign in to comment.