Module: Roma::Command::RoutingCommandReceiver

Included in:
Receiver
Defined in:
lib/roma/command/rt_command_receiver.rb

Instance Method Summary collapse

Instance Method Details

#ev_add_rttable_sub_nid(s) ⇒ Object

add_rttable_sub_nid <netmask> <regexp> <replace>



251
252
253
254
255
256
257
258
259
# File 'lib/roma/command/rt_command_receiver.rb', line 251

def ev_add_rttable_sub_nid(s)
  if s.length != 4
    return send_data("usage:add_rttable_sub_nid <netmask> <regexp> <replace>\r\n")
  end
  res = broadcast_cmd("radd_rttable_sub_nid #{s[1]} #{s[2]} #{s[3]}\r\n")
  @rttable.sub_nid[s[1]] = {:regexp => "#{s[2]}", :replace => "#{s[3]}"}
  res[@stats.ap_str] = "ADDED"
  send_data("#{res}\r\n")
end

#ev_clear_rttable_sub_nid(s) ⇒ Object

cleat RTTABLE_SUB_NID map



238
239
240
241
242
243
# File 'lib/roma/command/rt_command_receiver.rb', line 238

def ev_clear_rttable_sub_nid(s)
  res = broadcast_cmd("rclear_rttable_sub_nid\r\n")
  @rttable.sub_nid.clear()
  res[@stats.ap_str] = "CLEARED"
  send_data("#{res}\r\n")
end

#ev_create_nodes_from_v_idx(s) ⇒ Object



32
33
34
35
# File 'lib/roma/command/rt_command_receiver.rb', line 32

def ev_create_nodes_from_v_idx(s)
  @rttable.create_nodes_from_v_idx
  send_data("CREATED\r\n")
end

#ev_delete_rttable_sub_nid(s) ⇒ Object

delete_rttable_sub_nid <netmask>



271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/roma/command/rt_command_receiver.rb', line 271

def ev_delete_rttable_sub_nid(s)
  if s.length != 2
    return send_data("usage:delete_rttable_sub_nid <netmask>\r\n")
  end

  res = broadcast_cmd("rdelete_rttable_sub_nid #{s[1]}\r\n")
  unless @rttable.sub_nid.delete s[1]
    res[@stats.ap_str] = "NOT_FOUND"
  else
    res[@stats.ap_str] = "DELETED"
  end
  send_data("#{res}\r\n")
end

#ev_enabled_repetition_in_routing?(s) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/roma/command/rt_command_receiver.rb', line 63

def ev_enabled_repetition_in_routing?(s)
  rt = @rttable
  rd = @rttable.sub_nid_rd(@addr)
  rt = Roma::Routing::RoutingTable.new(rd) if rd

  if s.length == 1
    repetition = rt.check_repetition_in_routing
    send_data("#{repetition}\r\n")
  else
    send_data("CLIENT_ERROR\r\n")
  end
end

#ev_get_key_info(s) ⇒ Object

get_key_info <key>



299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/roma/command/rt_command_receiver.rb', line 299

def ev_get_key_info(s)
  if s.length != 2
    return send_data("CLIENT_ERROR number of arguments(0 for 1)\r\n")
  end

  d = Digest::SHA1.hexdigest(s[1]).hex % @rttable.hbits
  vn = @rttable.get_vnode_id(d)
  nodes = @rttable.search_nodes_for_write(vn)
  send_data(sprintf("d = %s 0x%x\r\n",d,d))
  send_data(sprintf("vn = %s 0x%x\r\n",vn,vn))
  send_data("nodes = #{nodes.inspect}\r\n")
  send_data("END\r\n")
end

#ev_getroute(s) ⇒ Object

getroute <vnode-id>



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/roma/command/rt_command_receiver.rb', line 100

def ev_getroute(s)
  if s.length < 2
    send_data("CLIENT_ERROR\r\n")
    return
  end
  clk,nids = @rttable.search_nodes_with_clk(s[1].to_i)
  if clk == nil
    send_data("END\r\n")
    return
  end
  res = "#{clk-1}"
  nids.each{ |nid| res << " #{nid}" }
  send_data("#{res}\r\n")
end

#ev_history_of_lost(s) ⇒ Object

history_of_lost [yyyymmddhhmmss]



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/roma/command/rt_command_receiver.rb', line 121

def ev_history_of_lost(s)
  if s.length != 2
    t = Time.mktime(2000, 1, 1, 0, 0, 0)
  else
    t = Time.mktime(s[1][0..3], s[1][4..5], s[1][6..7], s[1][8..9], s[1][10..11], s[1][12..13])
  end
  nodes = @rttable.search_lost_vnodes(t)
  nodes.each{|vn| send_data("#{vn}\r\n") }
  send_data("END\r\n")
rescue =>e
  send_data("CLIENT_ERROR\r\n")
end

#ev_join(s) ⇒ Object

join <node id>



8
9
10
11
# File 'lib/roma/command/rt_command_receiver.rb', line 8

def ev_join(s)
  @rttable.add_node(s[1])
  send_data("ADDED\r\n")
end

#ev_leave(s) ⇒ Object

leave <node id>



14
15
16
17
18
# File 'lib/roma/command/rt_command_receiver.rb', line 14

def ev_leave(s)
  @log.warn("receive a leave #{s[1]} message.")
  @rttable.leave(s[1])
  send_data("DELETED\r\n")
end

#ev_mklhash(s) ⇒ Object

mklhash <id>



116
117
118
# File 'lib/roma/command/rt_command_receiver.rb', line 116

def ev_mklhash(s)
  send_data("#{@rttable.mtree.get(s[1])}\r\n")
end

#ev_nodelist(s) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roma/command/rt_command_receiver.rb', line 20

def ev_nodelist(s)
  nl = nil
  @rttable.nodes.each{ |nid|
    if nl
      nl << " #{nid}"
    else
      nl = nid.clone
    end
  }
  send_data("#{nl}\r\n")
end

#ev_radd_rttable_sub_nid(s) ⇒ Object

radd_rttable_sub_nid <netmask> <regexp> <replace>



262
263
264
265
266
267
268
# File 'lib/roma/command/rt_command_receiver.rb', line 262

def ev_radd_rttable_sub_nid(s)
  if s.length != 4
    return send_data("usage:add_rttable_sub_nid <netmask> <regexp> <replace>\r\n")
  end
  @rttable.sub_nid[s[1]] = {:regexp => "#{s[2]}", :replace => "#{s[3]}"}
  send_data("ADDED\r\n")
end

#ev_rclear_rttable_sub_nid(s) ⇒ Object



245
246
247
248
# File 'lib/roma/command/rt_command_receiver.rb', line 245

def ev_rclear_rttable_sub_nid(s)
  @rttable.sub_nid.clear()
  send_data("CLEARED\r\n")
end

#ev_rdelete_rttable_sub_nid(s) ⇒ Object

rdelete_rttable_sub_nid <netmask>



286
287
288
289
290
291
292
293
294
295
296
# File 'lib/roma/command/rt_command_receiver.rb', line 286

def ev_rdelete_rttable_sub_nid(s)
  if s.length != 2
    return send_data("usage:delete_rttable_sub_nid <netmask>\r\n")
  end

  unless @rttable.sub_nid.delete s[1]
    send_data("NOT_FOUND\r\n")
  else
    send_data("DELETED\r\n")
  end
end

#ev_routingdump(s) ⇒ Object

routingdump [yaml|json|yamlbytes|bin]rn



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/roma/command/rt_command_receiver.rb', line 38

def ev_routingdump(s)
  rt = @rttable
  rd = @rttable.sub_nid_rd(@addr)
  rt = Roma::Routing::RoutingTable.new(rd) if rd

  if s.length == 1
    dmp = rt.dump
    send_data("#{dmp.length}\r\n#{dmp}\r\nEND\r\n")
  elsif s[1] == 'yaml'
    dmp = rt.dump_yaml
    send_data("#{dmp}\r\nEND\r\n")
  elsif s[1] == 'json'
    dmp = rt.dump_json
    send_data("#{dmp}\r\nEND\r\n")
  elsif s[1] == 'yamlbytes'
    dmp = rt.dump_yaml
    send_data("#{dmp.length + 7}\r\nEND\r\n")
  elsif s[1] == 'bin'
    dmp = rt.dump_binary
    send_data("#{dmp.length}\r\n#{dmp}\r\nEND\r\n")
  else
    send_data("CLIENT_ERROR\r\n")
  end
end

#ev_rset_auto_recover(s) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/roma/command/rt_command_receiver.rb', line 156

def ev_rset_auto_recover(s)
  if /^true$|^false$/ !~ s[1]
    return send_data("CLIENT_ERROR arguments must be true or false #{s[1]} #{s[1].class} \r\n")
  elsif s.length != 2 && s.length != 3
    return send_data("CLIENT_ERROR number of arguments(0 for 1)\r\n")
  elsif s.length == 3 && s[2].to_i < 1
    return send_data("CLIENT_ERROR length must be greater than zero\r\n")
  end
  if s[1] == "true"
    @rttable.auto_recover = true
  elsif s[1] == "false"
    @rttable.auto_recover = false
  end
  @rttable.auto_recover_status = "waiting"
  @rttable.auto_recover_time = s[2].to_i if s[2]
  send_data("STORED\r\n")
end

#ev_rset_gap_for_failover(s) ⇒ Object

rset_gap_for_failover



229
230
231
232
233
234
235
# File 'lib/roma/command/rt_command_receiver.rb', line 229

def ev_rset_gap_for_failover(s)
  if s.length != 2
    return send_data("usage:rset_gap_for_failover <n>\r\n")
  end
  @rttable.fail_cnt_gap = s[1].to_f
  send_data("STORED\r\n")        
end

#ev_rset_lost_action(s) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/roma/command/rt_command_receiver.rb', line 187

def ev_rset_lost_action(s)
  if s.length != 2 || /^auto_assign$|^shutdown$/ !~ s[1]
    return send_data("CLIENT_ERROR changing lost_action must be auto_assign or shutdown\r\n")
  elsif /^auto_assign$|^shutdown$/ !~ @rttable.lost_action
    return send_data("CLIENT_ERROR can use this command only current lost action is auto_assign or shutdwn mode\r\n")
  end
  @rttable.lost_action = s[1].to_sym
  send_data("STORED\r\n")
end

#ev_rset_threshold_for_failover(s) ⇒ Object

rset_threshold_for_failover <n>



209
210
211
212
213
214
215
# File 'lib/roma/command/rt_command_receiver.rb', line 209

def ev_rset_threshold_for_failover(s)
  if s.length != 2 || s[1].to_i == 0
    return send_data("usage:set_threshold_for_failover <n>\r\n")
  end
  @rttable.fail_cnt_threshold = s[1].to_i
  send_data("STORED\r\n")
end

#ev_set_auto_recover(s) ⇒ Object

set_auto_recover [true|false] <sec>



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/roma/command/rt_command_receiver.rb', line 135

def ev_set_auto_recover(s)
  #check argument
  if /^true$|^false$/ !~ s[1]
    return send_data("CLIENT_ERROR arguments must be true or false\r\n")
  elsif s.length != 2 && s.length != 3
    return send_data("CLIENT_ERROR number of arguments(0 for 1)\r\n")
  elsif s.length == 3 && s[2].to_i < 1
    return send_data("CLIENT_ERROR length must be greater than zero\r\n")
  end
  res = broadcast_cmd("rset_auto_recover #{s[1]} #{s[2]}\r\n")
  if s[1] == "true"
    @rttable.auto_recover = true
  elsif s[1] == "false"
    @rttable.auto_recover = false
  end
  @rttable.auto_recover_status = "waiting"
  @rttable.auto_recover_time = s[2].to_i if s[2]
  res[@stats.ap_str] = "STORED"
  send_data("#{res}\r\n")
end

#ev_set_gap_for_failover(s) ⇒ Object

set_gap_for_failover



218
219
220
221
222
223
224
225
226
# File 'lib/roma/command/rt_command_receiver.rb', line 218

def ev_set_gap_for_failover(s)
  if s.length != 2
    return send_data("usage:set_gap_for_failover <n>\r\n")
  end
  res = broadcast_cmd("rset_gap_for_failover #{s[1]}\r\n")
  @rttable.fail_cnt_gap = s[1].to_f
  res[@stats.ap_str] = "STORED"
  send_data("#{res}\r\n")        
end

#ev_set_lost_action(s) ⇒ Object

set_lost_action [auto_assign|shutdown]



175
176
177
178
179
180
181
182
183
184
185
# File 'lib/roma/command/rt_command_receiver.rb', line 175

def ev_set_lost_action(s)
  if s.length != 2 || /^auto_assign$|^shutdown$/ !~ s[1]
    return send_data("CLIENT_ERROR changing lost_action must be auto_assign or shutdown\r\n")
  elsif /^auto_assign$|^shutdown$/ !~ @rttable.lost_action
    return send_data("CLIENT_ERROR can use this command only current lost action is auto_assign or shutdwn mode\r\n")
  end
  res = broadcast_cmd("rset_lost_action #{s[1]}\r\n")
  @rttable.lost_action = s[1].to_sym
  res[@stats.ap_str] = "STORED"
  send_data("#{res}\r\n")
end

#ev_set_threshold_for_failover(s) ⇒ Object

set_threshold_for_failover <n>



198
199
200
201
202
203
204
205
206
# File 'lib/roma/command/rt_command_receiver.rb', line 198

def ev_set_threshold_for_failover(s)
  if s.length != 2 || s[1].to_i == 0
    return send_data("usage:set_threshold_for_failover <n>\r\n")
  end
  res = broadcast_cmd("rset_threshold_for_failover #{s[1]}\r\n")
  @rttable.fail_cnt_threshold = s[1].to_i
  res[@stats.ap_str] = "STORED"
  send_data("#{res}\r\n")
end

#ev_setroute(s) ⇒ Object

setroute <vnode-id> <clock> <node-id> …



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/roma/command/rt_command_receiver.rb', line 77

def ev_setroute(s)
  if s.length < 4
    send_data("CLIENT_ERROR\r\n")
  else
    nids=[]
    s[3..-1].each{ |nid| nids << nid }
    # check irregular node name
    nids.each{ |nid|
      if !nid.ascii_only? || nid.empty?
        send_data("CLIENT_ERROR : irregular node name was input.[\"#{nid}\"]\r\n")
        return
      end
    }
    res=@rttable.set_route(s[1].to_i, s[2].to_i, nids)
    if res.is_a?(Integer)
      send_data("STORED\r\n")
    else
      send_data("SERVER_ERROR #{res}\r\n")
    end
  end
end