summaryrefslogtreecommitdiff
path: root/lib/oxidized/api
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-04-16 10:04:12 +0300
committerSaku Ytti <saku@ytti.fi>2014-04-16 10:04:12 +0300
commitd74a152bba73095a0c7090dc078a7023eeb9ad18 (patch)
tree43f0a47fc93bcdd22f5799d41989582fc57c1cc9 /lib/oxidized/api
parent2af41e1769225ac42027f2f686763389296bab79 (diff)
remove web API
It is now separately in oxidized-web package
Diffstat (limited to 'lib/oxidized/api')
-rw-r--r--lib/oxidized/api/domain.rb48
-rw-r--r--lib/oxidized/api/rest.rb93
-rw-r--r--lib/oxidized/api/web.rb19
-rw-r--r--lib/oxidized/api/web/views/default.haml4
-rw-r--r--lib/oxidized/api/web/views/head.haml5
-rw-r--r--lib/oxidized/api/web/views/node.haml6
-rw-r--r--lib/oxidized/api/web/views/nodes.haml34
-rw-r--r--lib/oxidized/api/web/views/oxidized.sass51
-rw-r--r--lib/oxidized/api/web/webapp.rb104
9 files changed, 0 insertions, 364 deletions
diff --git a/lib/oxidized/api/domain.rb b/lib/oxidized/api/domain.rb
deleted file mode 100644
index fa6a1c7..0000000
--- a/lib/oxidized/api/domain.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# 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
diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb
deleted file mode 100644
index cdf5c80..0000000
--- a/lib/oxidized/api/rest.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-module Oxidized
- require 'webrick'
- require 'json'
- module API
- class Rest
- module Helpers
- def send res, msg='OK', ascii=false, status=200
- res.body = msg
- if not ascii
- msg = {:result => msg}
- res['Content-Type'] = 'application/json'
- res.status = status
- res.body = JSON.dump msg
- end
- end
- end
- include Oxidized::API::Rest::Helpers
- def initialize nodes, listen
- @nodes = nodes
- addr, port = listen.to_s.split ':'
- port, addr = addr, nil if not port
- @web = WEBrick::HTTPServer.new :BindAddress=>addr, :Port=>port, :Logger=>Log, :AccessLog=>[]
- maps
- end
- def work
- req = select @web.listeners, nil, nil, Config::Sleep
- while req
- @web.run req.first.first.accept
- req = select @web.listeners, nil, nil, 0
- end
- end
- def maps
- @web.mount '/nodes/next', Next, @nodes
- @web.mount_proc '/nodes' do |req, res|
- #script_name, #path_info
- case req.path_info[1..-1]
- # /nodes/reload - reloads list of nodes
- when 'reload'
- @nodes.load
- send res
- # /nodes/list - returns list of nodes
- when 'list'
- send res, @nodes.list
- # /nodes/show/node - returns data about node
- when /show\/(.*)/
- send res, @nodes.show($1)
- # /nodes/fetch/<node> or /nodes/fetch/group/<group>/<node> - returns json formatted configuration file for <node>
- when /fetch\/(.*)/
- begin
- if $1.include? '/'
- group, node = $1.split("/")[1..2]
- else
- group, node = nil, $1
- end
- ascii = if node[-4..-1] == '.txt'
- node = node[0..-5]
- end
- send res, @nodes.fetch(node, group), ascii
- rescue Oxidized::NotSupported => e
- send res, e
- end
- end
- end
- end
-
- # /nodes/next/node - moves node to head of queue
- class Next < WEBrick::HTTPServlet::AbstractServlet
- include Oxidized::API::Rest::Helpers
- def initialize server, nodes
- super server
- @nodes = nodes
- end
- def do_GET req, res
- @nodes.next req.path_info[1..-1]
- send res
- end
- def do_PUT req, res
- node = req.path_info[1..-1]
- begin
- opt = JSON.load req.body
- Log.debug "before: #{@nodes.list}"
- @nodes.next node, opt
- Log.debug "after: #{@nodes.list}"
- send res
- rescue JSON::ParserError
- send res, 'broken JSON', 400
- end
- end
- end
-
- end
- end
-end
diff --git a/lib/oxidized/api/web.rb b/lib/oxidized/api/web.rb
deleted file mode 100644
index 9a5a507..0000000
--- a/lib/oxidized/api/web.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-module Oxidized
- module API
- class Web
- attr_reader :thread
- def initialize nodes, listen
- require 'oxidized/api/web/webapp'
- addr, port = listen.to_s.split ':'
- port, addr = addr, nil if not port
- WebApp.set :server, %w(puma)
- WebApp.set :bind, addr if addr
- WebApp.set :port, port
- WebApp.set :nodes, nodes
- end
- def run
- @thread = Thread.new { WebApp.run! }
- end
- end
- end
-end
diff --git a/lib/oxidized/api/web/views/default.haml b/lib/oxidized/api/web/views/default.haml
deleted file mode 100644
index 1ff1f4b..0000000
--- a/lib/oxidized/api/web/views/default.haml
+++ /dev/null
@@ -1,4 +0,0 @@
-%html
- !=haml :head
- %body
- =@data
diff --git a/lib/oxidized/api/web/views/head.haml b/lib/oxidized/api/web/views/head.haml
deleted file mode 100644
index f8c41f8..0000000
--- a/lib/oxidized/api/web/views/head.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-%head
- %title oxidized
- %script{:src=>'//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'}
- %script{:src=>'//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.13.3/jquery.tablesorter.min.js'}
- %link{:rel=>'stylesheet', :href=>'/stylesheets/oxidized.css'}
diff --git a/lib/oxidized/api/web/views/node.haml b/lib/oxidized/api/web/views/node.haml
deleted file mode 100644
index 6c68e07..0000000
--- a/lib/oxidized/api/web/views/node.haml
+++ /dev/null
@@ -1,6 +0,0 @@
-%html
- !=haml :head
- %body
- -out='';PP.pp(@data,out)
- %pre
- =out
diff --git a/lib/oxidized/api/web/views/nodes.haml b/lib/oxidized/api/web/views/nodes.haml
deleted file mode 100644
index 336a4c2..0000000
--- a/lib/oxidized/api/web/views/nodes.haml
+++ /dev/null
@@ -1,34 +0,0 @@
-%html
- !=haml :head
- %body
- %table{:id=>'nodesTable', :class=>'center tablesorter'}
- %thead
- %tr
- %th Name
- %th IP
- %th Group
- %th Last Status
- %th Last Time
- %th Config
- %th Update
- %tbody
- -trclass = %w(even odd)
- -@data.sort_by{|e|e[:name]}.each do |node|
- -klass = trclass.rotate!.first
- %tr{:class=>klass}
- %td
- %a(href="/node/show/#{node[:name]}") #{node[:name]}
- %td= node[:ip]
- %td= node[:group]
- %td= node[:status]
- %td= node[:time]
- %td
- %a(href="/node/fetch/#{node[:full_name]}") config
- %td
- %a(href="/node/next/#{node[:full_name]}") update
- %p{:class=>'center'}
- %a(href="/reload") reload list of nodes
- :javascript
- $(function(){
- $("#nodesTable").tablesorter();
- });
diff --git a/lib/oxidized/api/web/views/oxidized.sass b/lib/oxidized/api/web/views/oxidized.sass
deleted file mode 100644
index 39d090f..0000000
--- a/lib/oxidized/api/web/views/oxidized.sass
+++ /dev/null
@@ -1,51 +0,0 @@
-$font-stack: Helvetica, sans-serif
-$base03: #002b36
-$base02: #073642
-$base01: #586e75
-$base00: #657b83
-$base0: #839496
-$base1: #93a1a1
-$base2: #eee8d5
-$base3: #fdf6e3
-$yellow: #b58900
-$orange: #cb4b16
-$red: #dc322f
-$magenta: #d33682
-$violet: #6c71c4
-$blue: #268bd2
-$cyan: #2aa198
-$green: #859900
-
-body
- font: 100% $font-stack
- color: $base03
- background: $base3
-
-a:link
- color: $red
- text-decoration: none
-
-// a:visited
-// a:active
-
-a:hover
- color: $magenta
- text-decoration: underline
-
-.center
- margin-left: auto
- margin-right: auto
- text-align: center
-
-th
- color: $cyan
-
-tr.odd
- background: $base2
-
-tr.even
- background: $base3
-
-tr:hover
- background: $base01
- color: $base3
diff --git a/lib/oxidized/api/web/webapp.rb b/lib/oxidized/api/web/webapp.rb
deleted file mode 100644
index 751a4c7..0000000
--- a/lib/oxidized/api/web/webapp.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-require 'sinatra/base'
-require 'sinatra/json'
-require 'haml'
-require 'sass'
-require 'pp'
-module Oxidized
- module API
- class WebApp < Sinatra::Base
-
- get '/' do
- redirect '/nodes'
- end
-
- get '/nodes.?:format?' do
- @data = nodes.list.map do |node|
- node[:status] = 'never'
- node[:time] = 'never'
- node[:group] = 'default' unless node[:group]
- if node[:last]
- node[:status] = node[:last][:status]
- node[:time] = node[:last][:end]
- end
- node
- end
- out :nodes
- end
-
- get '/reload.?:format?' do
- nodes.load
- @data = 'reloaded list of nodes'
- out
- end
-
-
- get '/node/fetch/:node' do
- node, @json = route_parse :node
- @data = nodes.fetch node, nil
- out :text
- end
-
- get '/node/fetch/:group/:node' do
- node, @json = route_parse :node
- @data = nodes.fetch node, params[:group]
- out :text
- end
-
-
- get '/node/next/:node' do
- node, @json = route_parse :node
- nodes.next node
- redirect '/nodes' unless @json
- @data = 'ok'
- out
- end
-
- # use this to attach author/email/message to commit
- put '/node/next/:node' do
- node, @json = route_parse :node
- opt = JSON.load request.body.read
- nodes.next node, opt
- redirect '/nodes' unless @json
- @data = 'ok'
- out
- end
-
- get '/node/show/:node' do
- node, @json = route_parse :node
- @data = nodes.show node
- out :node
- end
-
- get '/stylesheets/*.css' do
- sass params[:splat].first.to_sym
- end
-
- private
-
- def out template=:default
- if @json or params[:format] == 'json'
- json @data
- elsif template == :text
- content_type :text
- @data
- else
- haml template
- end
- end
-
- def nodes
- settings.nodes
- end
-
- def route_parse param
- json = false
- e = params[param].split '.'
- if e.last == 'json'
- e.pop
- json = true
- end
- [e.join('.'), json]
- end
- end
- end
-end