Top Level Namespace

Includes:
LS4, LS4RPC

Defined Under Namespace

Modules: LS4, LS4RPC, Test01, Test02, Test03, Test04 Classes: CCLog, EventBus, Node, TargetNode, Top, VariableByteCode

Constant Summary collapse

Host =
host
Port =
port
TITLES =
%w[nid name address location replset #Read #Write Read/s Write/s QPS items time]
FORMAT_LARGE =
%[%1$3s %2$12s %3$23s %4$23s %5$8s %6$8s %7$8s %8$7s %9$7s %10$7s %11$10s %12$20s]
FORMAT_LARGE_SIMPLE =
%[%1$3s %2$12s%4$22s %5$8s %8$7s %9$7s %10$7s %11$10s]
FORMAT_SMALL =
%[%1$3s%2$13s  %5$7s%6$9s%7$9s%11$9s%4$21s] +
%[\n  %3$23s%8$9s%9$9s%10$9s%12$21s]
FORMAT_SMALL_SIMPLE =

3 8 9 10 12

%[%1$3s%2$13s  %5$7s%6$9s%7$9s%11$9s%4$21s] +
%[\n                         %8$9s%9$9s%10$9s]
TIME_FORMAT =

8 9 10

"%Y-%m-%d %H:%M:%S"
CS_PARAMS =
%w[
  nid address name rsid rsids location
]
DS_PARAMS =
%w[
  read write delete items
  time uptime pid version
]
EXT_PARAMS =
%w[
  state
]
ALL_PARAMS =
CS_PARAMS + EXT_PARAMS + DS_PARAMS
DEFAULT_PARAMS =
%w[
  nid address name read write delete time
]

Constants included from LS4RPC

LS4RPC::CS_METHODS, LS4RPC::DS_METHODS, LS4RPC::GW_METHODS

Constants included from LS4

LS4::Address, LS4::CS_DEFAULT_PORT, LS4::DS_DEFAULT_PORT, LS4::GW_DEFAULT_PORT, LS4::SYNC_FAULT_LIST, LS4::SYNC_MDS_CACHE_URI, LS4::SYNC_MDS_URI, LS4::SYNC_MEMBERSHIP, LS4::SYNC_REPLSET_WEIGHT, LS4::VERSION

Instance Method Summary collapse

Methods included from LS4RPC

cs_rpc, ds_rpc, gw_rpc, rpc, #show

Methods included from LS4

HTTPGatewayService_get_binding

Instance Method Details

#assert(boolean) ⇒ Object



336
337
338
339
340
# File 'lib/ls4/lib/ebus.rb', line 336

def assert(boolean)
  unless boolean
    raise "test failed"
  end
end

#call(method, *args) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ls4/command/cmd.rb', line 75

def call(klass, *args)
  start = Time.now

  s = $net.get_session(*$addr)
  s.timeout = 20
  result = s.call(*args)
  if klass && result
    result = klass.new.from_msgpack(result)
  end

  finish = Time.now
  $stderr.puts "#{finish - start} sec."

  result
end

#check(a, b) ⇒ Object



203
204
205
206
207
208
209
210
211
# File 'lib/ls4/lib/vbcode.rb', line 203

def check(value)
  raw = VariableByteCode.encode(value)
  if VariableByteCode.decode(raw) != value
    puts "VariableByteCode.decode test failed #{value}"
  end
  if VariableByteCode.decode_index(raw,0)[0] != value
    puts "VariableByteCode.decode_index test failed #{value}"
  end
end

#check_n(values) ⇒ Object



217
218
219
220
221
222
# File 'lib/ls4/lib/vbcode.rb', line 217

def check_n(values)
  raw = VariableByteCode.encode_n(values)
  if VariableByteCode.decode_n(raw) != values
    puts "VariableByteCode.decode_n test failed #{values}"
  end
end

#cmd_args(n) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ls4/command/cmd.rb', line 62

def cmd_args(n)
  if n < 0
    return ARGV
  end
  usage if ARGV.length != n
  ARGV.map! {|ar| ar == '-' ? $stdin.read : ar }
  if n == 1
    ARGV[0]
  else
    ARGV
  end
end

#dump_slots(bus) ⇒ Object



342
343
344
345
346
347
348
349
350
351
# File 'lib/ls4/lib/ebus.rb', line 342

def dump_slots(bus)
  if bus.is_a?(Class)
    puts bus.name
  else
    puts bus.class.name
  end
  bus.ebus_all_slots.each {|s|
    puts "  #{s}"
  }
end

#each_node(&block) ⇒ Object



101
102
103
104
105
106
# File 'lib/ls4/command/ctl.rb', line 101

def each_node(&block)
  get_nodes.map {|node|
    result = yield($net.get_session(node.address), node)
    [node, result]
  }
end

#get_node_mapObject



92
93
94
95
96
97
98
99
# File 'lib/ls4/command/ctl.rb', line 92

def get_node_map
  map = {}
  call(nil, :stat, 'nodes').each {|nid,address,name,rsids|
    address = MessagePack::RPC::Address.load(address)
    map[nid] = [address, name, rsids]
  }
  map
end

#get_nodesObject



83
84
85
86
87
88
89
90
# File 'lib/ls4/command/ctl.rb', line 83

def get_nodes
  call(nil, :stat, 'nodes').map {|nid,address,name,rsids,location|
    address = MessagePack::RPC::Address.load(address)
    Node.new(nid, address, name, rsids, location)
  }.sort_by {|node|
    node.nid
  }
end

#usageObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ls4/command/cmd.rb', line 22

def usage
  puts "Usage: #{File.basename($0)} <cs address[:port]> <command> [options]"
  puts "command:"
  puts "   get <key>                           get data and attributes"
  puts "   gett <time> <key>                   get data and attributes using the time"
  puts "   getv <vname> <key>                  get data and attributes using the version name"
  puts "   get_data <key>                      get data"
  puts "   gett_data <time> <key>              get data using the time"
  puts "   getv_data <vname> <key>             get data using the version name"
  puts "   get_attrs <key>                     get attributes"
  puts "   gett_attrs <time> <key>             get attributes using the time"
  puts "   getv_attrs <vname> <key>            get attributes using the version name"
  puts "   read <key> <offset> <size>          get data with the offset and the size"
  puts "   readt <time> <key> <offset> <size>  get data with the offset and the size using version time"
  puts "   readv <vname> <key> <offset> <size> get data with the offset and the size using version name"
  puts "   add <key> <data> <json>             set data and attributes"
  puts "   addv <vname> <key> <data> <json>    set data and attributes with version name"
  puts "   add_data <key> <data>               set data"
  puts "   addv_data <vname> <key> <data>      set data with version name"
  puts "   update_attrs <key> <json>           update attributes"
  puts "   delete <key>                        delete the data and attributes"
  puts "   deletet <time> <key>                delete the data and attributes using the time"
  puts "   deletev <vname> <key>               delete the data and attributes using the version name"
  puts "   remove <key>                        remove the data and attributes"
  exit 1
end

#usage_exitObject



137
138
139
140
# File 'lib/ls4/command/rpc.rb', line 137

def usage_exit
  puts "Usage: #{File.basename($0)} <host>:<port> [method [args ...]]"
  exit 1
end