priam 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,5 +1,38 @@
1
1
  module Priam::Command
2
2
  module Get
3
+
4
+ def self.get(client, column_family, super_column, key, options={})
5
+ raise_exception_flag = options[:raise_exception_flag]
6
+ retry_max_count = options[:retry_max_count] || 0
7
+ weight_second = options[:weight_second] || 1
8
+
9
+ retry_count = 0
10
+ begin
11
+ if super_column
12
+ record = client.get(column_family, super_column, key)
13
+ else
14
+ record = client.get(column_family, key)
15
+ end
16
+ rescue Exception => e
17
+ if retry_max_count <= retry_count then
18
+ if raise_exception_flag then
19
+ raise e
20
+ else
21
+ backtrace = e.backtrace.map{|s| " #{s}"}.join("\n")
22
+ Priam.logger.warn(" #{e.message}(#{e.class.name}): #{backtrace}")
23
+ return {}
24
+ end
25
+ else
26
+ retry_count += 1
27
+ Priam.logger.warn(" #{e.message}(#{e.class.name})")
28
+ Priam.logger.info(" retry(#{retry_count})")
29
+ sleep(weight_second) if weight_second
30
+ retry
31
+ end
32
+ end
33
+ return record
34
+ end
35
+
3
36
  def self.run(argv, input_stream=$stdin, output_stream=$stdout)
4
37
  params = Priam::Core::Common.parse_opts(argv)
5
38
  host = params[:host]
@@ -8,7 +41,7 @@ module Priam::Command
8
41
  column_family = params[:column_family]
9
42
  super_column = params[:super_column]
10
43
  name = params[:name]
11
-
44
+
12
45
  client = Cassandra.new(keyspace, "#{host}:#{port}")
13
46
 
14
47
  Priam.logger.debug "Cluster Name: #{client.cluster_name}"
@@ -25,25 +58,17 @@ module Priam::Command
25
58
  next
26
59
  end
27
60
 
28
- begin
29
- if super_column then
30
- record = client.get(column_family, super_column, key)
31
- else
32
- record = client.get(column_family, key)
33
- end
34
-
35
- if name then
36
- output_stream.puts "#{record[name]}"
37
- else
38
- output_stream.puts record.to_json
39
- end
40
- count += 1
41
- if count % 10 == 0 then
42
- Priam.logger.info " GET [#{key_list.join(',')}]"
43
- key_list.clear
44
- end
45
- rescue Exception => e
46
- raise e.class, "#{e.message}, key list = #{key_list.inspect}"
61
+ record = self.get(client, column_family, super_column, key, params)
62
+
63
+ if name then
64
+ output_stream.puts "#{record[name]}"
65
+ else
66
+ output_stream.puts record.to_json
67
+ end
68
+ count += 1
69
+ if count % 10 == 0 then
70
+ Priam.logger.info " GET [#{key_list.join(',')}]"
71
+ key_list.clear
47
72
  end
48
73
  end
49
74
 
@@ -86,7 +86,8 @@ module Priam::Command
86
86
  if raise_exception_flag then
87
87
  raise e
88
88
  else
89
- Priam.logger.warn(" #{e.message}(#{e.class.name}): #{e.backtrace.map{|s| " #{s}"}.join("\n")}")
89
+ backtrace = e.backtrace.map{|s| " #{s}"}.join("\n")
90
+ Priam.logger.warn(" #{e.message}(#{e.class.name}): #{backtrace}")
90
91
  end
91
92
  else
92
93
  retry_count += 1
data/priam.gemspec ADDED
@@ -0,0 +1,92 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "priam"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kenji Hara"]
12
+ s.date = "2012-12-12"
13
+ s.description = "Command-base client for Cassandra."
14
+ s.email = "haracane@gmail.com"
15
+ s.executables = ["priam"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/priam",
30
+ "lib/priam.rb",
31
+ "lib/priam/command.rb",
32
+ "lib/priam/command/cql.rb",
33
+ "lib/priam/command/cql/create.rb",
34
+ "lib/priam/command/delete.rb",
35
+ "lib/priam/command/get.rb",
36
+ "lib/priam/command/insert.rb",
37
+ "lib/priam/command/put.rb",
38
+ "lib/priam/core.rb",
39
+ "lib/priam/core/common.rb",
40
+ "priam.gemspec",
41
+ "spec/bin/priam_spec.rb",
42
+ "spec/lib/priam/command/delete_spec.rb",
43
+ "spec/lib/priam/command/get_spec.rb",
44
+ "spec/lib/priam/command/insert_spec.rb",
45
+ "spec/lib/priam/command/put_spec.rb",
46
+ "spec/lib/priam/core/common_spec.rb",
47
+ "spec/lib/priam_spec.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+ s.homepage = "http://github.com/haracane/priam"
51
+ s.licenses = ["MIT"]
52
+ s.require_paths = ["lib"]
53
+ s.rubygems_version = "1.8.21"
54
+ s.summary = "Command-base client for Cassandra."
55
+
56
+ if s.respond_to? :specification_version then
57
+ s.specification_version = 3
58
+
59
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
60
+ s.add_runtime_dependency(%q<thrift>, ["~> 0.7.0"])
61
+ s.add_runtime_dependency(%q<thrift_client>, ["~> 0.7.1"])
62
+ s.add_runtime_dependency(%q<simple_uuid>, ["~> 0.2.0"])
63
+ s.add_runtime_dependency(%q<cassandra>, ["~> 0.12.1"])
64
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
65
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
67
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
68
+ s.add_development_dependency(%q<rcov>, [">= 0"])
69
+ else
70
+ s.add_dependency(%q<thrift>, ["~> 0.7.0"])
71
+ s.add_dependency(%q<thrift_client>, ["~> 0.7.1"])
72
+ s.add_dependency(%q<simple_uuid>, ["~> 0.2.0"])
73
+ s.add_dependency(%q<cassandra>, ["~> 0.12.1"])
74
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
75
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
76
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
77
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
78
+ s.add_dependency(%q<rcov>, [">= 0"])
79
+ end
80
+ else
81
+ s.add_dependency(%q<thrift>, ["~> 0.7.0"])
82
+ s.add_dependency(%q<thrift_client>, ["~> 0.7.1"])
83
+ s.add_dependency(%q<simple_uuid>, ["~> 0.2.0"])
84
+ s.add_dependency(%q<cassandra>, ["~> 0.12.1"])
85
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
86
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
87
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
88
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
89
+ s.add_dependency(%q<rcov>, [">= 0"])
90
+ end
91
+ end
92
+
@@ -61,7 +61,6 @@ describe "bin/priam" do
61
61
  context "when command = get" do
62
62
  context "when key&value exists" do
63
63
  it "should output value" do
64
-
65
64
  result = `echo key1 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --name d --verbose #{@stderr_dst}`
66
65
  result.chomp!
67
66
  result.should == "val1"
@@ -74,6 +73,13 @@ describe "bin/priam" do
74
73
  result.should == ""
75
74
  end
76
75
  end
76
+ context "when retry option is enabled" do
77
+ it "should output value" do
78
+ result = `echo key1 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --name d --retry 5 --weight 1000 --verbose #{@stderr_dst}`
79
+ result.chomp!
80
+ result.should == "val1"
81
+ end
82
+ end
77
83
  end
78
84
 
79
85
  context "when command = delete" do
@@ -1,6 +1,49 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Priam::Core::Common do
4
- it "should success" do
4
+ describe ".parse_opts(argv)" do
5
+ context "when argv = []" do
6
+ it "should return defalut hash" do
7
+ result = Priam::Core::Common.parse_opts([])
8
+ result[:host].should == "localhost"
9
+ result[:port].should == 9160
10
+ result[:raise_exception_flag].should == false
11
+ result[:value_column].should == "d"
12
+ result[:retry_max_count].should == 0
13
+ result[:check_exist_flag].should == false
14
+ result[:output_keys_flag].should == false
15
+ result[:replication_factor].should == 1
16
+ result[:verbose_flag].should == false
17
+ end
18
+ end
19
+
20
+ argv = ("-h cassandra-server -p 19160" \
21
+ + " --keyspace KeySpace --column-family ColumnFamily" \
22
+ + " --super-column SuperColumn --name name" \
23
+ + " --raise-exception --unit-size 10 --value-column value_column" \
24
+ + " --weight 11000 --retry 12 --count-log count.log" \
25
+ + " --check-exist --output-keys --replication-factor 13 --verbose").split(/ /)
26
+
27
+ context "when argv = #{argv.inspect}" do
28
+ it "should return valid hash" do
29
+ result = Priam::Core::Common.parse_opts(argv)
30
+ result[:host].should == "cassandra-server"
31
+ result[:port].should == 19160
32
+ result[:keyspace].should == "KeySpace"
33
+ result[:column_family].should == "ColumnFamily"
34
+ result[:super_column].should == "SuperColumn"
35
+ result[:name].should == "name"
36
+ result[:raise_exception_flag].should == true
37
+ result[:unit_size].should == 10
38
+ result[:value_column].should == "value_column"
39
+ result[:weight_second].should == 11
40
+ result[:retry_max_count].should == 12
41
+ result[:count_log_path].should == "count.log"
42
+ result[:check_exist_flag].should == true
43
+ result[:output_keys_flag].should == true
44
+ result[:replication_factor].should == 13
45
+ result[:verbose_flag].should == true
46
+ end
47
+ end
5
48
  end
6
49
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: priam
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kenji Hara
@@ -187,6 +187,7 @@ files:
187
187
  - lib/priam/command/put.rb
188
188
  - lib/priam/core.rb
189
189
  - lib/priam/core/common.rb
190
+ - priam.gemspec
190
191
  - spec/bin/priam_spec.rb
191
192
  - spec/lib/priam/command/delete_spec.rb
192
193
  - spec/lib/priam/command/get_spec.rb