Navigation Menu

Skip to content

Commit

Permalink
Validate options
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 27, 2014
1 parent 542cac6 commit ee3849f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
22 changes: 21 additions & 1 deletion bin/droonga-engine-join
Expand Up @@ -71,10 +71,24 @@ parser.parse!(ARGV)
base_dir = Pathname(options.base_dir).expand_path
ENV[Droonga::Path::BASE_DIR_ENV_NAME] = base_dir.to_s

catalog_path = Droonga::Path.base + "catalog.json"
catalog_path = Droonga::Path.catalog
unless catalog_path.exist?
raise "Cannot load 'catalog.json'. You must specify correct path " +
"to the base directory via --base-dir option."
end
source_catalog = JSON.parse(catalog_path.read)


unless options.replica_source_host
raise "You must specify the host name or the IP address of a node " +
"of an existing cluster via --replica-source-host option."
end
unless options.my_host
raise "You must specify the host name or the IP address of this node " +
"via --my-host option."
end


generator = Droonga::CatalogGenerator.new
dataset_params = generator.catalog_to_params(source_catalog)
dataset_params.each do |name, dataset|
Expand All @@ -86,6 +100,12 @@ dataset_params.each do |name, dataset|
options.other_hosts = dataset[:hosts]
end

unless options.dataset
raise "Specified source host #{options.replica_source_host} is not a " +
"member of the cluster. You must specify correct host via " +
"--replica-source-host option."
end

puts "Initializing new replica..."

absorb_destination_params = Marshal.load(Marshal.dump(dataset_params))
Expand Down
18 changes: 17 additions & 1 deletion bin/droonga-engine-unjoin
Expand Up @@ -51,10 +51,20 @@ parser.parse!(ARGV)
base_dir = Pathname(options.base_dir).expand_path
ENV[Droonga::Path::BASE_DIR_ENV_NAME] = base_dir.to_s

catalog_path = Droonga::Path.base + "catalog.json"
catalog_path = Droonga::Path.catalog
unless catalog_path.exist?
raise "Cannot load 'catalog.json'. You must specify correct path " +
"to the base directory via --base-dir option."
end
source_catalog = JSON.parse(catalog_path.read)


unless options.replica_remove_host
raise "You must specify the host name or the IP address of a node to " +
"be removed from the cluster via --replica-remove-host option."
end


generator = Droonga::CatalogGenerator.new
dataset_params = generator.catalog_to_params(source_catalog)
dataset_params.each do |name, dataset|
Expand All @@ -66,6 +76,12 @@ dataset_params.each do |name, dataset|
options.other_hosts = dataset[:hosts]
end

unless options.dataset
raise "Specified host #{options.replica_remove_host} is not a member of "+
"the cluster. You must specify correct host via --replica-remove-host " +
"option."
end

sleep(1) # wait for restart

puts "Unjoining from the cluster..."
Expand Down

0 comments on commit ee3849f

Please sign in to comment.