orientdb4r 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/changelog.txt CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.2 2012-11-02
2
+ - Enhancement #13 : configurable User-Agent request header
3
+ - Enhancement #16 : configurable Recovery Time in Load Balancing
4
+
1
5
  0.3.1 2012-08-27
2
6
  - Timeout for reuse of dirty (already failed) nodes in load balancing
3
7
  - Bug Fix #14, #15
@@ -0,0 +1,97 @@
1
+ require 'socket'
2
+ require 'bindata'
3
+
4
+ module Orientdb4r
5
+
6
+ ###
7
+ # This client implements the binary protocol.
8
+ class BinClient < Client
9
+
10
+
11
+ def initialize(options) #:nodoc:
12
+ super()
13
+ options_pattern = {
14
+ :host => 'localhost', :port => 2424
15
+ }
16
+ verify_and_sanitize_options(options, options_pattern)
17
+
18
+ @host = options[:host]
19
+ @port = options[:port]
20
+ end
21
+
22
+
23
+ # --------------------------------------------------------------- CONNECTION
24
+
25
+ def connect options #:nodoc:
26
+ options_pattern = { :database => :mandatory, :user => :mandatory, :password => :mandatory }
27
+ verify_and_sanitize_options(options, options_pattern)
28
+ @database = options[:database]
29
+ @user = options[:user]
30
+ @password = options[:password]
31
+
32
+ socket = TCPSocket.open(@host, @port)
33
+ protocol = BinData::Int16be.read(socket)
34
+
35
+ Orientdb4r::logger.info "Binary protocol number: #{protocol}"
36
+
37
+ command = DbOpen.new
38
+ command.version = protocol
39
+ command.database = 'temp'
40
+ command.user = 'admin'
41
+ command.password = 'admin'
42
+ command.write(socket)
43
+
44
+ resp = BinData::Int8.read(socket).to_i
45
+ puts "EE #{resp}"
46
+
47
+ socket.close
48
+ end
49
+
50
+
51
+ def disconnect #:nodoc:
52
+ end
53
+
54
+
55
+ def server(options={})
56
+ raise NotImplementedError, 'this should be overridden by concrete client'
57
+ end
58
+
59
+ class ProtocolString < BinData::Primitive
60
+ endian :big
61
+
62
+ int32 :len, :value => lambda { data.length }
63
+ string :data, :read_length => :len
64
+
65
+ def get; self.data; end
66
+ def set(v) self.data = v; end
67
+ end
68
+ class DbOpen < BinData::Record
69
+ endian :big
70
+
71
+ int8 :operation, :value => 3 #DB_OPEN
72
+ int32 :session, :value => -1 #NEW_SESSION
73
+
74
+ protocol_string :driver, :value => 'Orientdb4r Ruby Client'
75
+ protocol_string :driver_version, :value => Orientdb4r::VERSION
76
+ int16 :version
77
+ protocol_string :client_id
78
+ protocol_string :database
79
+ protocol_string :user
80
+ protocol_string :password
81
+ end
82
+ class Connect < BinData::Record
83
+ endian :big
84
+
85
+ int8 :operation, :value => 2
86
+ int32 :session, :value => -1 #NEW_SESSION
87
+ protocol_string :driver, :value => 'Orientdb4r Ruby Client'
88
+ protocol_string :driver_version, :value => Orientdb4r::VERSION
89
+ int16 :version
90
+ protocol_string :client_id
91
+ protocol_string :user
92
+ protocol_string :password
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -4,16 +4,18 @@ module Orientdb4r
4
4
  # Base class for implementation of load balancing strategy.
5
5
  class LBStrategy
6
6
 
7
- # If occures a new try to communicate from node can be tested [s].
8
- RECOVERY_TIMEOUT = 30
7
+ # After what time [s] can be a failed node reused in load balancing.
8
+ DEFAULT_RECOVER_TIME = 30
9
9
 
10
- attr_reader :nodes_count, :bad_nodes
10
+ attr_reader :nodes_count, :bad_nodes
11
+ attr_accessor :recover_time
11
12
 
12
13
  ###
13
14
  # Constructor.
14
15
  def initialize nodes_count
15
16
  @nodes_count = nodes_count
16
17
  @bad_nodes = {}
18
+ @recover_time = DEFAULT_RECOVER_TIME
17
19
  end
18
20
 
19
21
  ###
@@ -56,7 +58,7 @@ module Orientdb4r
56
58
  failure_time = @bad_nodes[candidate]
57
59
  now = Time.now
58
60
  # timeout candidate
59
- if (now - failure_time) > RECOVERY_TIMEOUT
61
+ if (now - failure_time) > recover_time
60
62
  timeout_candidate = candidate
61
63
  Orientdb4r::logger.debug "node timeout recovery, idx=#{candidate}"
62
64
  good_one(candidate)
@@ -17,7 +17,9 @@ module Orientdb4r
17
17
  :nodes => :optional,
18
18
  :connection_library => :restclient,
19
19
  :load_balancing => :sequence,
20
- :proxy => :optional
20
+ :proxy => :optional,
21
+ :user_agent => :optional,
22
+ :lb_recover_time => :optional
21
23
  }
22
24
  verify_and_sanitize_options(options, options_pattern)
23
25
 
@@ -48,6 +50,10 @@ module Orientdb4r
48
50
  when :round_robin then Orientdb4r::RoundRobin.new nodes.size
49
51
  else raise ArgumentError, "unknow load balancing type: #{load_balancing}"
50
52
  end
53
+ # recover time
54
+ recover_time = options[:lb_recover_time]
55
+ @lb_strategy.recover_time = recover_time.to_i unless recover_time.nil?
56
+
51
57
 
52
58
  # proxy
53
59
  @proxy = options[:proxy]
@@ -58,6 +64,12 @@ module Orientdb4r
58
64
  end
59
65
  end
60
66
 
67
+ # user-agent
68
+ agent = options[:user_agent]
69
+ unless agent.nil?
70
+ nodes.each { |node| node.user_agent = agent }
71
+ end
72
+
61
73
  Orientdb4r::logger.info "client initialized with #{@nodes.size} node(s) "
62
74
  Orientdb4r::logger.info "connection_library=#{options[:connection_library]}, load_balancing=#{load_balancing}"
63
75
  end
@@ -96,6 +96,7 @@ module Orientdb4r
96
96
  rslt = {'Authorization' => basic_auth_header(options[:user], options[:password])}
97
97
  rslt['Cookie'] = "#{SESSION_COOKIE_NAME}=#{session_id}" unless session_id.nil?
98
98
  rslt['Content-Type'] = options[:content_type] if options.include? :content_type
99
+ rslt['User-Agent'] = user_agent unless user_agent.nil?
99
100
  rslt
100
101
  end
101
102
 
@@ -9,6 +9,8 @@ module Orientdb4r
9
9
  SESSION_COOKIE_NAME = 'OSESSIONID'
10
10
 
11
11
  attr_reader :ssl
12
+ # HTTP header 'User-Agent'
13
+ attr_accessor :user_agent
12
14
 
13
15
  ###
14
16
  # Constructor.
@@ -22,8 +22,10 @@ module Orientdb4r
22
22
  data = '' if data.nil? and :post == opts[:method] # POST has to have data
23
23
  opts[:payload] = data unless data.nil?
24
24
 
25
- # headers
25
+ # cookies
26
26
  opts[:cookies] = { SESSION_COOKIE_NAME => session_id} unless session_id.nil?
27
+ # headers
28
+ opts[:headers] = { 'User-Agent' => user_agent } unless user_agent.nil?
27
29
 
28
30
  begin
29
31
  response = ::RestClient::Request.new(opts).execute
@@ -2,6 +2,7 @@ module Orientdb4r
2
2
 
3
3
  # Version history.
4
4
  VERSION_HISTORY = [
5
+ ['0.3.2', '2012-11-02', "Feature #13 (User-Agent), #16 (configurable Recover Time in Load Balancing)"],
5
6
  ['0.3.1', '2012-08-27', "Timeout for reuse of dirty nodes in load balancing; BF #14, BF #15"],
6
7
  ['0.3.0', '2012-08-01', "Added support for cluster of distributed servers + load balancing"],
7
8
  ['0.2.10', '2012-07-21', "Experimental support for Excon HTTP library with Keep-Alive connection"],
data/lib/orientdb4r.rb CHANGED
@@ -11,6 +11,7 @@ module Orientdb4r
11
11
  autoload :Utils, 'orientdb4r/utils'
12
12
  autoload :Client, 'orientdb4r/client'
13
13
  autoload :RestClient, 'orientdb4r/rest/client'
14
+ autoload :BinClient, 'orientdb4r/bin/client'
14
15
  autoload :Rid, 'orientdb4r/rid'
15
16
  autoload :HashExtension, 'orientdb4r/rest/model'
16
17
  autoload :OClass, 'orientdb4r/rest/model'
@@ -37,6 +38,7 @@ module Orientdb4r
37
38
 
38
39
  Thread.exclusive {
39
40
  Thread.current[:orientdb_client] ||= RestClient.new options
41
+ #Thread.current[:orientdb_client] ||= BinClient.new options
40
42
  }
41
43
  end
42
44
 
data/test/test_ddo.rb CHANGED
@@ -40,7 +40,7 @@ class TestDdo < Test::Unit::TestCase
40
40
  assert !clazz.properties.empty?
41
41
  assert_nothing_thrown do clazz.property(:password); end
42
42
  assert_raise ArgumentError do clazz.property(:unknown_prop); end
43
- assert_equal '', clazz.super_class
43
+ assert_equal 'OIdentity', clazz.super_class
44
44
  assert_instance_of Array, clazz.clusters
45
45
  assert !clazz.clusters.empty?
46
46
  assert_not_nil clazz.default_cluster
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orientdb4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -51,6 +51,7 @@ files:
51
51
  - fstudy/study_case.rb
52
52
  - fstudy/technical_feasibility.rb
53
53
  - lib/orientdb4r.rb
54
+ - lib/orientdb4r/bin/client.rb
54
55
  - lib/orientdb4r/chained_error.rb
55
56
  - lib/orientdb4r/client.rb
56
57
  - lib/orientdb4r/load_balancing.rb
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  version: 1.3.1
94
95
  requirements: []
95
96
  rubyforge_project:
96
- rubygems_version: 1.8.23
97
+ rubygems_version: 1.8.19
97
98
  signing_key:
98
99
  specification_version: 3
99
100
  summary: Ruby binding for Orient DB.