reminder-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reminder-client.rb +3 -0
- data/lib/reminder-client/configcenter.rb +146 -85
- data/lib/reminder-client/http_model.rb +30 -0
- data/lib/reminder-client/server_info.rb +45 -0
- data/lib/reminder-client/thrift_model.rb +34 -0
- data/test/application2.rb +7 -2
- data/test/servertest.rb +2 -2
- data/test/test.rb +83 -3
- data/test/test1.rb +21 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee3395d42bb9f436bf81ceb00546fbbe40542256
|
4
|
+
data.tar.gz: d3e0ea6cb47b8aa257f35c5d5cb4bccba4ce980a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84810a7b27105dc01e95af166921c12e4e34c1e066c35f035b2620e9fde6adf42a8cba540b6631d6caf34bae5f0fd97d1111c5bbd5ff2ef55616fe3d25fc0593
|
7
|
+
data.tar.gz: e86d6ccc9f7a4e2c0424924d40450ffb91e969ffd2313847ed52b3241f390d43843d238921ac0dc12eb69ed642c67f2cab287675ed81cb14b84d8fb4740bab68
|
data/lib/reminder-client.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/math/bin/ruby
|
2
2
|
|
3
3
|
require 'zookeeper'
|
4
|
-
require 'eventmachine'
|
5
4
|
require 'zk'
|
5
|
+
require 'yajl'
|
6
6
|
|
7
7
|
# Public: Create a Zk instence and connect, the following
|
8
8
|
# relaying on it, it will block until connected successfully.
|
@@ -17,132 +17,102 @@ require 'zk'
|
|
17
17
|
#
|
18
18
|
# Returns a Zoo instance.
|
19
19
|
class Zoo
|
20
|
+
|
21
|
+
SERVER_FOUND_BASE_PATH = "services"
|
22
|
+
SERVER_TYPE_HTTP = "http"
|
23
|
+
SERVER_TYPE_THRIFT = "thrift"
|
24
|
+
|
25
|
+
|
20
26
|
def initialize(options)
|
21
27
|
p "start connect to #{options[:zk_address]}"
|
22
28
|
@zk = ZK.new(options[:zk_address])
|
23
29
|
# @config_center_backend = options[:config_center_backend]
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# @server_found_base_path = "/xserver"
|
28
|
-
# @server_config_base_path = "/xconfig"
|
29
|
-
# @server_config_sub_path= "/ctest"
|
30
|
-
# paramters to set
|
31
|
-
# @server_found_base_path = options[:zk_server_found_base_path]
|
32
|
-
# @server_config_base_path = options[:zk_server_config_base_path]
|
33
|
-
# @server_config_sub_path= options[:zk_server_config_sub_path]
|
34
|
-
puts "init succ #{@zk}"
|
30
|
+
@parser = Yajl::Parser
|
31
|
+
@encoder = Yajl::Encoder
|
32
|
+
puts "zk successfully connected to #{options[:zk_address]}"
|
35
33
|
end
|
36
|
-
|
37
|
-
|
34
|
+
|
35
|
+
|
38
36
|
# Public: zk server found server part, and it will create a ephemeral path
|
39
37
|
# with current server's service ip, address, or so on.
|
40
38
|
#
|
41
39
|
# option - The hash :ip_port -> service address .eg "192.168.3.1:2222".
|
42
40
|
# child(option) - The sub-path name.
|
43
41
|
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
puts
|
42
|
+
def server_found_server(option, member_path = 'default')
|
43
|
+
# todo reise problem if some key params is nil
|
44
|
+
#raise "error" if
|
45
|
+
server_info = ServerInfo.new(option)
|
46
|
+
|
47
|
+
p "input params is #{option}"
|
48
|
+
p server_info
|
49
|
+
server_json = @encoder.encode(server_info.getHash)
|
50
|
+
create_path = get_combined_path([SERVER_FOUND_BASE_PATH, server_info.serviceType, server_info.groupPath, server_info.memberName])
|
51
|
+
# create parent path if not exists
|
52
|
+
create_parentPath([SERVER_FOUND_BASE_PATH, server_info.serviceType, server_info.groupPath])
|
53
|
+
puts server_json
|
54
|
+
re = @zk.create(create_path, server_json.to_s, :ephemeral => true, :sequence => true)
|
55
|
+
# re = @zk.create(option[:server_found_base_path] + "/" + child, option[:ip_port], :ephemeral => true, :sequence => true)
|
56
|
+
puts "create ephemeral path #{re} with data #{server_json} succ !!!"
|
56
57
|
#end
|
57
58
|
end
|
58
|
-
|
59
|
+
|
59
60
|
|
60
61
|
# Public: server found client part.
|
61
62
|
#
|
62
|
-
#
|
63
|
+
# service_type -
|
64
|
+
# group_path - The String (zk's path) to be watched.
|
63
65
|
# block - The callback to be call when the server_path to be watched changed.
|
64
66
|
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# puts load_balance
|
70
|
-
# }
|
71
|
-
# # => nil
|
72
|
-
#
|
73
|
-
def server_found_client(server_path, &block)
|
74
|
-
puts "zk server_found start watching on #{server_path}"
|
75
|
-
relist = @zk.children(server_path, :watch => true)
|
67
|
+
def server_found_client(service_type, group_path, &block)
|
68
|
+
watch_path = get_combined_path([SERVER_FOUND_BASE_PATH, service_type, group_path])
|
69
|
+
puts "zk server_found start watching on #{watch_path}"
|
70
|
+
relist = @zk.children(watch_path, :watch => true)
|
76
71
|
# relist = @zk.children(server_path)
|
77
|
-
load_balance = @zk.get(
|
78
|
-
|
72
|
+
load_balance = @zk.get(watch_path, :watch => true)[0]
|
73
|
+
|
79
74
|
puts "get children #{relist} and get load_balance #{load_balance} for the first time"
|
80
|
-
|
75
|
+
|
81
76
|
#context[:serverlist => relist]
|
82
|
-
block.call(get_ip_from_server(server_path, relist),load_balance)
|
77
|
+
#block.call(get_ip_from_server(server_path, relist), load_balance)
|
78
|
+
run_block(service_type, group_path, relist, load_balance, &block)
|
83
79
|
|
84
|
-
node_subscription = @zk.register(
|
80
|
+
node_subscription = @zk.register(watch_path) do |event|
|
85
81
|
puts "server found event is #{event}"
|
86
|
-
# get children and re-set watch
|
87
|
-
relist = @zk.children(server_path, :watch => true)
|
88
|
-
# relist = @zk.children(server_path)
|
89
|
-
load_balance = @zk.get(server_path, :watch => true)[0]
|
90
82
|
if event.node_child? || event.node_changed?
|
83
|
+
# get children and re-set watch
|
84
|
+
relist = @zk.children(watch_path, :watch => true)
|
85
|
+
# relist = @zk.children(server_path)
|
86
|
+
load_balance = @zk.get(watch_path, :watch => true)[0]
|
91
87
|
#puts relist
|
92
|
-
|
88
|
+
# check if server_type == thrift or http
|
89
|
+
# block.call()
|
90
|
+
# block.call(get_ip_from_server(server_path, relist), load_balance)
|
91
|
+
run_block(service_type, group_path, relist, load_balance, &block)
|
93
92
|
end
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
|
-
# Private: Internal function, get each sub path's data.
|
98
|
-
#
|
99
|
-
# server_path - The String to be duplicated.
|
100
|
-
# relist - The Integer number of times to duplicate the text.
|
101
|
-
#
|
102
|
-
# Examples
|
103
|
-
#
|
104
|
-
# get_ip_from_server('/server-stat', ['default0000001', 'default0000002'
|
105
|
-
# , 'default0000003'])
|
106
|
-
# # => ['192.168.2.220:2222', '192.168.2.220:3333', '192.168.2.222:4444']
|
107
|
-
#
|
108
|
-
# Returns the ip list.
|
109
|
-
def get_ip_from_server(server_path, relist)
|
110
|
-
list = []
|
111
|
-
relist.each { |child|
|
112
|
-
#puts "get child #{child}"
|
113
|
-
str = @zk.get(server_path + "/" + child)[0]
|
114
|
-
p str
|
115
|
-
list << str if str and !str.empty?
|
116
|
-
#p "lalalala -> #{@zk.get(server_path + "/" + child)}"
|
117
|
-
}
|
118
|
-
list.uniq
|
119
|
-
end
|
120
95
|
|
96
|
+
|
121
97
|
# Public: The serverConfig client part
|
122
98
|
#
|
123
99
|
# config_path - The config_path of zk tobe watched.
|
124
100
|
# group - The group of the service
|
125
101
|
# block - The callback to be call when the config_path to be watched changed.
|
126
102
|
#
|
127
|
-
#
|
128
|
-
# Examples
|
129
|
-
#
|
130
|
-
# server_config_client('/config/server-stat', 'stat-service', 1){ |configdata|
|
131
|
-
# puts configdata
|
132
|
-
# }
|
133
|
-
# # => nil
|
103
|
+
# under development
|
134
104
|
#
|
135
105
|
# Returns nil.
|
136
106
|
def server_config_client(config_path, group, &block)
|
137
107
|
puts "zk server_config start watching on #{config_path}"
|
138
|
-
|
108
|
+
|
139
109
|
# get server config for the first time
|
140
110
|
version = @zk.get(config_path, :watch => true)[0]
|
141
111
|
version = -1 if version.empty?
|
142
112
|
version = version.to_i
|
143
113
|
|
144
114
|
# call hessian to get the config data
|
145
|
-
configdata = REMINDER_BACKEND_SERVICE.getMapdata(version,
|
115
|
+
configdata = REMINDER_BACKEND_SERVICE.getMapdata(version, config_path, group)
|
146
116
|
puts "get version for the first time configdata is #{configdata}"
|
147
117
|
block.call(configdata)
|
148
118
|
|
@@ -155,11 +125,102 @@ class Zoo
|
|
155
125
|
version = -1 if version.empty?
|
156
126
|
version = version.to_i
|
157
127
|
puts "server config version is #{version}"
|
158
|
-
|
128
|
+
|
159
129
|
# get the config data by version and service through hessian
|
160
|
-
configdata = REMINDER_BACKEND_SERVICE.getMapdata(version,
|
130
|
+
configdata = REMINDER_BACKEND_SERVICE.getMapdata(version, config_path, group)
|
161
131
|
block.call(configdata)
|
162
132
|
end
|
163
133
|
end
|
164
134
|
end
|
165
|
-
|
135
|
+
|
136
|
+
private
|
137
|
+
def run_block(server_type, group_path, children, load_balance, &block)
|
138
|
+
parent_path = get_combined_path([SERVER_FOUND_BASE_PATH, server_type, group_path])
|
139
|
+
list = []
|
140
|
+
children.each { |child|
|
141
|
+
#puts "get child #{child}"
|
142
|
+
json_data = @zk.get(get_combined_path([parent_path, child]))[0]
|
143
|
+
puts json_data
|
144
|
+
list << json_data if json_data and !json_data.empty?
|
145
|
+
#p "lalalala -> #{@zk.get(server_path + "/" + child)}"
|
146
|
+
}
|
147
|
+
if server_type == SERVER_TYPE_HTTP
|
148
|
+
block.call(http_models_generator(list.uniq), load_balance)
|
149
|
+
elsif server_type == SERVER_TYPE_THRIFT
|
150
|
+
block.call(thrift_models_generator(list.uniq), load_balance)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def http_models_generator(jsons)
|
155
|
+
relist = []
|
156
|
+
jsons.each do |json|
|
157
|
+
hash = @parser.parse(json)
|
158
|
+
relist << server_info_hash_to_http_model(hash)
|
159
|
+
end
|
160
|
+
relist
|
161
|
+
end
|
162
|
+
|
163
|
+
def thrift_models_generator(jsons)
|
164
|
+
relist = []
|
165
|
+
jsons.each do |json|
|
166
|
+
hash = @parser.parse(json)
|
167
|
+
relist << server_info_hash_to_thrift_model(hash)
|
168
|
+
end
|
169
|
+
relist
|
170
|
+
end
|
171
|
+
|
172
|
+
def server_info_hash_to_http_model(hash)
|
173
|
+
HttpModel.new({ ip: hash["ip"], port: hash["port"],
|
174
|
+
serviceType: hash["serviceType"], serviceName: hash["serviceName"]})
|
175
|
+
end
|
176
|
+
|
177
|
+
def server_info_hash_to_thrift_model(hash)
|
178
|
+
ThriftModel.new({ ip: hash["ip"], port: hash["port"],
|
179
|
+
serviceType: hash["serviceType"], serviceName: hash["serviceName"],
|
180
|
+
workerSize: hash["workerSize"], selectorSize: hash["selectorSize"] })
|
181
|
+
end
|
182
|
+
|
183
|
+
def create_parentPath(paths)
|
184
|
+
create_path = ""
|
185
|
+
paths.each do |path|
|
186
|
+
create_path << "/"
|
187
|
+
create_path << path
|
188
|
+
# create path if not exists
|
189
|
+
re = @zk.create(create_path, '', :ephemeral => false, :sequence => false) if !@zk.exists?(create_path)
|
190
|
+
puts "create parent path #{re}" if !re.nil?
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def get_combined_path(paths)
|
195
|
+
repath = ""
|
196
|
+
paths.each do |path|
|
197
|
+
repath << "/" if !path.start_with?("/")
|
198
|
+
repath << path
|
199
|
+
end
|
200
|
+
repath
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# Private: Internal function, get each sub path's data.
|
205
|
+
#
|
206
|
+
# server_path - The String to be duplicated.
|
207
|
+
# relist - The Integer number of times to duplicate the text.
|
208
|
+
#
|
209
|
+
# Examples
|
210
|
+
#
|
211
|
+
# get_ip_from_server('/server-stat', ['default0000001', 'default0000002'
|
212
|
+
# , 'default0000003'])
|
213
|
+
# # => ['192.168.2.220:2222', '192.168.2.220:3333', '192.168.2.222:4444']
|
214
|
+
#
|
215
|
+
# Returns the ip list.
|
216
|
+
# def get_ip_from_server(server_path, relist)
|
217
|
+
# list = []
|
218
|
+
# relist.each { |child|
|
219
|
+
# #puts "get child #{child}"
|
220
|
+
# str = @zk.get(server_path + "/" + child)[0]
|
221
|
+
# p str
|
222
|
+
# list << str if str and !str.empty?
|
223
|
+
# #p "lalalala -> #{@zk.get(server_path + "/" + child)}"
|
224
|
+
# }
|
225
|
+
# list.uniq
|
226
|
+
# end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class HttpModel
|
2
|
+
attr_accessor :ip, :port, :serviceType, :serviceName
|
3
|
+
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:groupPath => nil,
|
6
|
+
:memberName => "default",
|
7
|
+
:ip => nil,
|
8
|
+
:port => nil,
|
9
|
+
:serviceType => nil,
|
10
|
+
:serviceName => nil,
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
raise "initialize HttpModel error, options can not be nil." if options == nil
|
15
|
+
#@options = DEFAULT_OPTIONS.merge(options)
|
16
|
+
@ip = options[:ip]
|
17
|
+
@port = options[:port]
|
18
|
+
@serviceType = options[:serviceType]
|
19
|
+
@serviceName = options[:serviceName]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
{
|
24
|
+
:ip => @ip,
|
25
|
+
:port => @port,
|
26
|
+
:serviceType => @serviceType,
|
27
|
+
:serviceName => @serviceName,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class ServerInfo
|
2
|
+
attr_accessor :groupPath, :memberName, :ip, :port, :serviceType, :serviceName, :workerSize, :selectorSize
|
3
|
+
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:groupPath => nil,
|
6
|
+
:memberName => "default",
|
7
|
+
:ip => nil,
|
8
|
+
:port => nil,
|
9
|
+
:serviceType => nil,
|
10
|
+
:serviceName => nil,
|
11
|
+
:workerSize => nil,
|
12
|
+
:selectorSize => nil
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
raise "initialize ServerInfo error, options can not be nil." if options == nil
|
17
|
+
#@options = DEFAULT_OPTIONS.merge(options)
|
18
|
+
@groupPath = options[:groupPath]
|
19
|
+
if options[:memberName].nil?
|
20
|
+
@memberName = "default"
|
21
|
+
else
|
22
|
+
@memberName = options[:memberName]
|
23
|
+
end
|
24
|
+
@ip = options[:ip]
|
25
|
+
@port = options[:port]
|
26
|
+
@serviceType = options[:serviceType]
|
27
|
+
@serviceName = options[:serviceName]
|
28
|
+
@workerSize = options[:workerSize]
|
29
|
+
@selectorSize = options[:selectorSize]
|
30
|
+
end
|
31
|
+
|
32
|
+
def getHash
|
33
|
+
{
|
34
|
+
:groupPath => @groupPath,
|
35
|
+
:memberName => @memberName,
|
36
|
+
:ip => @ip,
|
37
|
+
:port => @port,
|
38
|
+
:serviceType => @serviceType,
|
39
|
+
:serviceName => @serviceName,
|
40
|
+
:workerSize => @workerSize,
|
41
|
+
:selectorSize => @selectorSize
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ThriftModel
|
2
|
+
attr_accessor :ip, :port, :serviceType, :serviceName, :workerSize, :selectorSize
|
3
|
+
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:ip => nil,
|
6
|
+
:port => nil,
|
7
|
+
:serviceType => nil,
|
8
|
+
:serviceName => nil,
|
9
|
+
:workerSize => nil,
|
10
|
+
:selectorSize => nil
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
raise "initialize ThriftModel error, options can not be nil." if options == nil
|
15
|
+
#@options = DEFAULT_OPTIONS.merge(options)
|
16
|
+
@ip = options[:ip]
|
17
|
+
@port = options[:port]
|
18
|
+
@serviceType = options[:serviceType]
|
19
|
+
@serviceName = options[:serviceName]
|
20
|
+
@workerSize = options[:workerSize]
|
21
|
+
@selectorSize = options[:selectorSize]
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_hash
|
25
|
+
{
|
26
|
+
:ip => @ip,
|
27
|
+
:port => @port,
|
28
|
+
:serviceType => @serviceType,
|
29
|
+
:serviceName => @serviceName,
|
30
|
+
:workerSize => @workerSize,
|
31
|
+
:selectorSize => @selectorSize
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
data/test/application2.rb
CHANGED
@@ -14,8 +14,13 @@ class HelloApp < Sinatra::Base
|
|
14
14
|
#end
|
15
15
|
|
16
16
|
get '/' do
|
17
|
-
"
|
18
|
-
<br>
|
17
|
+
"mobile_list -> #{$global_server_list[:mobile].join('<br>')}
|
18
|
+
<br><br>
|
19
|
+
|
20
|
+
xserver_list -> #{$global_server_list[:xserver].join('<br>')}
|
21
|
+
<br><br>
|
22
|
+
server-stat_list -> #{$global_server_list["server-stat"].join('<br>')}
|
23
|
+
<br><br>
|
19
24
|
<br>
|
20
25
|
config -> #{$global_idservice_thrift_config}
|
21
26
|
"
|
data/test/servertest.rb
CHANGED
@@ -25,7 +25,7 @@ class Zoo
|
|
25
25
|
1000.times do
|
26
26
|
re = @zk.create(@server_found_base_path + "/" + child, "192.168.2.2:#{rand(9999)}", :ephemeral => true, :sequence => true)
|
27
27
|
puts "create ephemeral path #{re} "
|
28
|
-
sleep(rand(
|
28
|
+
sleep(rand(10))
|
29
29
|
end
|
30
30
|
}
|
31
31
|
Thread.new{
|
@@ -33,7 +33,7 @@ class Zoo
|
|
33
33
|
relist = @zk.children(@server_found_base_path)
|
34
34
|
re = @zk.delete(@server_found_base_path+"/"+relist.pop) if !relist.empty?
|
35
35
|
puts "delete ephemeral path #{re}"
|
36
|
-
sleep(rand(
|
36
|
+
sleep(rand(9))
|
37
37
|
end
|
38
38
|
}
|
39
39
|
end
|
data/test/test.rb
CHANGED
@@ -1,10 +1,86 @@
|
|
1
1
|
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require
|
4
|
+
|
5
|
+
require 'zk'
|
6
|
+
require 'yajl'
|
7
|
+
|
8
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
9
|
+
require "reminder-client"
|
10
|
+
require "reminder-client/server_info"
|
11
|
+
require "reminder-client/http_model"
|
12
|
+
|
13
|
+
#zk = ZK.new('localhost:2181')
|
14
|
+
#p zk.stat('/path').exists?
|
15
|
+
#p zk.stat('/services').exists?
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
serverinfo = ServerInfo.new({ groupPath:"mobile", ip:"192.23.33.123", port:"2121", serviceType:"http", serviceName:"mobile" })
|
20
|
+
|
21
|
+
#p serverinfo
|
22
|
+
|
23
|
+
server_json = Yajl::Encoder.encode(serverinfo.getHash)
|
24
|
+
p server_json
|
25
|
+
hhash = Yajl::Parser.parse(server_json)
|
26
|
+
p hhash
|
27
|
+
# p HttpModel.new(hhash)
|
28
|
+
|
2
29
|
list = ["22","22",nil,""]
|
3
30
|
list1 = []
|
4
31
|
list.each{|x|
|
5
32
|
list1 << x if x and !x.empty?
|
6
33
|
#p x if x
|
7
34
|
}
|
35
|
+
|
36
|
+
a = nil
|
37
|
+
a = "ddd"
|
38
|
+
member = "default" if a.nil?
|
39
|
+
p " ----- > #{member}"
|
40
|
+
|
41
|
+
zoo = Zoo.new(:zk_address => "127.0.0.1:2181")
|
42
|
+
|
43
|
+
zoo.server_found_server( { groupPath:"mobile", ip:"192.23.33.123", port:"2121", serviceType:"http", serviceName:"mobile" })
|
44
|
+
|
45
|
+
|
46
|
+
# puts Zoo::SERVER_TYPE_HTTP
|
47
|
+
zoo.server_found_client(Zoo::SERVER_TYPE_HTTP, "mobile"){ |context, _load_balance|
|
48
|
+
puts "http list is -#{context}-, load_balance is -#{_load_balance}-"
|
49
|
+
}
|
50
|
+
|
51
|
+
zoo.server_found_server({ groupPath:"mobile", ip:"192.23.33.123", port:"2121", serviceType:"http", serviceName:"mobile" })
|
52
|
+
|
53
|
+
sleep(10)
|
54
|
+
|
55
|
+
|
56
|
+
def server_info_hash_to_http_model(hash)
|
57
|
+
HttpModel.new({ ip: hash["ip"], port: hash["port"],
|
58
|
+
serviceType: hash["serviceType"], serviceName: hash["serviceName"]})
|
59
|
+
end
|
60
|
+
|
61
|
+
def server_info_hash_to_thrift_model(hash)
|
62
|
+
ThriftModel.new({ ip: hash["ip"], port: hash["port"],
|
63
|
+
serviceType: hash["serviceType"], serviceName: hash["serviceName"],
|
64
|
+
workerSize: hash["workerSize"], selectorSize: hash["selectorSize"] })
|
65
|
+
end
|
66
|
+
|
67
|
+
p "-------- ----- ---- ----------"
|
68
|
+
p server_info_hash_to_http_model(hhash)
|
69
|
+
|
70
|
+
def create_parentPath(paths)
|
71
|
+
create_path = ""
|
72
|
+
paths.each do|path|
|
73
|
+
create_path << "/"
|
74
|
+
create_path << path
|
75
|
+
# do somethings
|
76
|
+
p create_path
|
77
|
+
end
|
78
|
+
create_path
|
79
|
+
end
|
80
|
+
|
81
|
+
#p get_combined_path(["/","aaa","bbb","ccc"])
|
82
|
+
#p create_parentPath(["aaa",'bbb','cc'])
|
83
|
+
|
8
84
|
#p list1.uniq
|
9
85
|
#p list1
|
10
86
|
|
@@ -89,7 +165,11 @@ p '---------------'
|
|
89
165
|
# html = open("www.baidu.com").read
|
90
166
|
# p html
|
91
167
|
|
92
|
-
require 'hessian2'
|
93
|
-
Z_SERVICE = Hessian2::Client.new("http://192.168.5.100:8080/reminder-backend/hessian/requestconfigdataservice")
|
168
|
+
#require 'hessian2'
|
169
|
+
#Z_SERVICE = Hessian2::Client.new("http://192.168.5.100:8080/reminder-backend/hessian/requestconfigdataservice")
|
170
|
+
#Z_SERVICE = Hessian2::Client.new("http://localhost:8080/reminder-backend/hessian/requestconfigdataservice")
|
171
|
+
|
172
|
+
#p Z_SERVICE.getMapdata(1, "xservice", "0")
|
173
|
+
|
174
|
+
#semaphore = Mutex.new
|
94
175
|
|
95
|
-
p Z_SERVICE.getMapdata(1, "xservice", "0")
|
data/test/test1.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#require 'bundler'
|
2
|
+
#Bundler.require
|
3
|
+
|
4
|
+
require File.expand_path("../application",__FILE__)
|
5
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
6
|
+
$:.unshift File.expand_path("../../test", __FILE__)
|
7
|
+
|
8
|
+
#require '../../lib/server_info'
|
9
|
+
|
10
|
+
require "reminder-client"
|
11
|
+
|
12
|
+
p ServerInfo.new({ groupPath: "groupxx", ip: "192.214.22.22" })
|
13
|
+
|
14
|
+
Thread.new{
|
15
|
+
while true
|
16
|
+
p 1
|
17
|
+
sleep(1)
|
18
|
+
end
|
19
|
+
}
|
20
|
+
|
21
|
+
sleep(100)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reminder-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caorong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zk
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.9.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yajl-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.0
|
27
41
|
description: reminder client
|
28
42
|
email: caorong@ximalaya.com
|
29
43
|
executables: []
|
@@ -32,11 +46,15 @@ extra_rdoc_files: []
|
|
32
46
|
files:
|
33
47
|
- lib/reminder-client.rb
|
34
48
|
- lib/reminder-client/configcenter.rb
|
49
|
+
- lib/reminder-client/http_model.rb
|
50
|
+
- lib/reminder-client/server_info.rb
|
51
|
+
- lib/reminder-client/thrift_model.rb
|
35
52
|
- test/application.rb
|
36
53
|
- test/application1.rb
|
37
54
|
- test/application2.rb
|
38
55
|
- test/servertest.rb
|
39
56
|
- test/test.rb
|
57
|
+
- test/test1.rb
|
40
58
|
homepage: http://www.ximalaya.com
|
41
59
|
licenses:
|
42
60
|
- MIT2.0
|
@@ -62,6 +80,7 @@ signing_key:
|
|
62
80
|
specification_version: 4
|
63
81
|
summary: A zookeeper client wrapper provide serverfound and serverconfig.
|
64
82
|
test_files:
|
83
|
+
- test/test1.rb
|
65
84
|
- test/application1.rb
|
66
85
|
- test/test.rb
|
67
86
|
- test/servertest.rb
|