summaryrefslogtreecommitdiff
path: root/lib/oxidized/api/domain.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2013-04-19 12:36:45 +0300
committerSaku Ytti <saku@ytti.fi>2013-04-19 12:41:29 +0300
commit96668cc2dc0367e3d1a3ec94265ce889b62d8ada (patch)
tree340f92a6dd4b68e41a946729c8fae34db7aff40b /lib/oxidized/api/domain.rb
parent9d217025fac3e335c308f02e7377e14ccfdc0e66 (diff)
Add restful API
Diffstat (limited to 'lib/oxidized/api/domain.rb')
-rw-r--r--lib/oxidized/api/domain.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/oxidized/api/domain.rb b/lib/oxidized/api/domain.rb
new file mode 100644
index 0000000..fa6a1c7
--- /dev/null
+++ b/lib/oxidized/api/domain.rb
@@ -0,0 +1,48 @@
+# this is not used, just added here if I want to revive it
+
+module Oxidized
+ require 'socket'
+ require 'json'
+ module API
+ class Domain
+ def initialize nodes, socket=CFG.api
+ puts 'here'
+ @nodes = nodes
+ File.unlink socket rescue Errno::ENOENT
+ @server = UNIXServer.new socket
+ end
+ def work
+ io = select [@server], nil, nil, Config::Sleep
+ process io.first.first.accept if io
+ end
+ def read
+ @socket.recv 1024
+ end
+ def write data=''
+ begin
+ @socket.send JSON.dump(data), 0
+ rescue Errno::EPIPE
+ end
+ end
+ def process socket
+ @socket = socket
+ cmd = read
+ cmd, data = cmd.split /\s+/, 2
+ data = data.to_s.chomp
+ case cmd
+ when /next/i
+ @nodes.next data
+ write 'OK'
+ when /reload/i
+ @nodes.load if data.match /nodes/i
+ write 'OK'
+ when /list/i
+ write @nodes.map{|e|e.name}
+ when /node/i
+ write @nodes.show(data)
+ end
+ @socket.close
+ end
+ end
+ end
+end