gflocator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/LICENSE +26 -0
- data/README.md +14 -0
- data/Rakefile +4 -0
- data/bin/gflocator +5 -0
- data/gflocator.gemspec +20 -0
- data/lib/gflocator.rb +5 -0
- data/lib/gflocator/handler.rb +41 -0
- data/lib/gflocator/main.rb +42 -0
- data/lib/gflocator/util_daemon.rb +18 -0
- data/lib/gflocator/version.rb +3 -0
- data/test/test_handler.rb +47 -0
- data/test/unittest_helper.rb +56 -0
- metadata +83 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2012, Internet Initiative Japan Inc.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above
|
12
|
+
copyright notice, this list of conditions and the following
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
14
|
+
with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# gflocator
|
2
|
+
|
3
|
+
gflocator is a daemon for providing responses to queries against file locations of GlusterFS
|
4
|
+
|
5
|
+
## Installation and Usage
|
6
|
+
|
7
|
+
gem install gflocator
|
8
|
+
sudo gflocator
|
9
|
+
|
10
|
+
(gflocator must run as root)
|
11
|
+
|
12
|
+
## Copyright
|
13
|
+
|
14
|
+
Copyright:: Copyright (c) 2012, Internet Initiative Japan Inc. All rights reserved.
|
data/Rakefile
ADDED
data/bin/gflocator
ADDED
data/gflocator.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "gflocator/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "gflocator"
|
7
|
+
s.version = Gflocator::VERSION
|
8
|
+
s.authors = ["maebashi"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{file location server for GlusterFS}
|
11
|
+
s.description = %q{a daemon for providing responses to queries against file locations of GlusterFS}
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n").select {|e| /^tmp/!~e}
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency "msgpack-rpc"
|
19
|
+
s.add_runtime_dependency "ffi-xattr"
|
20
|
+
end
|
data/lib/gflocator.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'xattr'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
unless defined? XAttr
|
7
|
+
require 'ffi-xattr'
|
8
|
+
end
|
9
|
+
|
10
|
+
module Gflocator
|
11
|
+
class Handler
|
12
|
+
if defined? XAttr
|
13
|
+
def xattr_get path, name
|
14
|
+
XAttr.get path, name
|
15
|
+
end
|
16
|
+
else
|
17
|
+
def xattr_get path, name
|
18
|
+
Xattr::Lib.get path, false, name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_locations args, glob_flag
|
23
|
+
if glob_flag
|
24
|
+
paths = Dir.glob args.join("\0")
|
25
|
+
else
|
26
|
+
paths = args
|
27
|
+
end
|
28
|
+
name = 'trusted.glusterfs.pathinfo'
|
29
|
+
locations = {}
|
30
|
+
for path in paths
|
31
|
+
if (loc_str = xattr_get(path, name))
|
32
|
+
res = loc_str.scan(/<POSIX(?:\([^\)]+\))?:([-\w\.]+):([^>]+)>/)
|
33
|
+
locations[path] = res
|
34
|
+
else
|
35
|
+
raise RuntimeError, 'getxattr failed'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
locations
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'msgpack-rpc'
|
5
|
+
|
6
|
+
module Gflocator
|
7
|
+
class Main
|
8
|
+
OPTS = {:daemonize=>true}
|
9
|
+
|
10
|
+
def self.run
|
11
|
+
new.run OPTS
|
12
|
+
end
|
13
|
+
|
14
|
+
def run options={}
|
15
|
+
optparser = optparse options
|
16
|
+
optparser.parse!
|
17
|
+
host = options[:bind_host] || '0.0.0.0'
|
18
|
+
port = options[:bind_port] || 7076
|
19
|
+
|
20
|
+
raise RuntimeError, 'must run as root' unless Process.euid.zero?
|
21
|
+
handler = Handler.new
|
22
|
+
server = MessagePack::RPC::Server.new
|
23
|
+
server.listen host, port, handler
|
24
|
+
Process.daemon true if options[:daemonize] and !$debug
|
25
|
+
server.run
|
26
|
+
end
|
27
|
+
|
28
|
+
def optparse options={}
|
29
|
+
optparser = OptionParser.new
|
30
|
+
optparser.on('--debug') {$debug = true; STDOUT.sync = true}
|
31
|
+
optparser.on('-h', '--bind-host=HOST', 'bind to HOST address') {|a|
|
32
|
+
options[:bind_host] = a}
|
33
|
+
optparser.on('-p', '--bind-port=PORT', Integer, 'bind to port PORT') {|a|
|
34
|
+
options[:bind_port] = a}
|
35
|
+
class <<optparser
|
36
|
+
attr_accessor :options
|
37
|
+
end
|
38
|
+
optparser.options = options
|
39
|
+
optparser
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Process
|
2
|
+
class << self
|
3
|
+
unless method_defined?(:daemon)
|
4
|
+
def daemon(nochdir = nil, noclose = nil)
|
5
|
+
exit!(0) if Process.fork
|
6
|
+
Process.setsid
|
7
|
+
exit!(0) if Process.fork
|
8
|
+
Dir.chdir("/") unless nochdir
|
9
|
+
unless noclose
|
10
|
+
STDIN.reopen("/dev/null", "r")
|
11
|
+
STDOUT.reopen("/dev/null", "w")
|
12
|
+
STDERR.reopen("/dev/null", "w")
|
13
|
+
end
|
14
|
+
0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gflocator/handler'
|
4
|
+
|
5
|
+
class Gflocator::Handler
|
6
|
+
attr_accessor :t
|
7
|
+
|
8
|
+
def xattr_get path, name
|
9
|
+
path.sub!(%r{^/}, '')
|
10
|
+
case @t
|
11
|
+
when :g33b2
|
12
|
+
"(<DISTRIBUTE:test-dht> <POSIX:g33b2.example.com:/glusterfs/t/#{path}>)"
|
13
|
+
when :g33b2r
|
14
|
+
"(<DISTRIBUTE:test-dht> (<REPLICATE:test-replicate-6> <POSIX:a006.example.com:/glusterfs/t/test/#{path}> <POSIX:b006.example.com:/glusterfs/t/test/#{path}>))"
|
15
|
+
else
|
16
|
+
"(<DISTRIBUTE:test-dht> <POSIX(/glusterfs/t):g330.example.com:/glusterfs/t/#{path}>)"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestHandler < Test::Unit::TestCase
|
22
|
+
def setup
|
23
|
+
@handler = Gflocator::Handler.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_handler
|
27
|
+
files = ['file1', 'file2']
|
28
|
+
res = @handler.get_locations files, false
|
29
|
+
ae 2, res.size
|
30
|
+
files.each {|f|
|
31
|
+
ae 1, res[f].size
|
32
|
+
ae 2, res[f].first.size
|
33
|
+
}
|
34
|
+
@handler.t = :g33b2
|
35
|
+
res = @handler.get_locations files, false
|
36
|
+
files.each {|f|
|
37
|
+
ae 1, res[f].size
|
38
|
+
ae 2, res[f].first.size
|
39
|
+
}
|
40
|
+
@handler.t = :g33b2r
|
41
|
+
res = @handler.get_locations files, false
|
42
|
+
files.each {|f|
|
43
|
+
ae 2, res[f].size
|
44
|
+
ae 2, res[f].first.size
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
$test_dir = File.expand_path File.dirname(__FILE__)
|
6
|
+
$:.unshift $test_dir
|
7
|
+
$:.unshift($test_dir + '/../lib')
|
8
|
+
$test = true
|
9
|
+
$debug = true
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'rubygems'
|
13
|
+
require 'test/unit/ui/console/testrunner'
|
14
|
+
require 'term/ansicolor'
|
15
|
+
Term::ANSIColor::coloring = STDERR.tty?
|
16
|
+
module Test
|
17
|
+
module Unit
|
18
|
+
module UI
|
19
|
+
module Console
|
20
|
+
class TestRunner
|
21
|
+
include Term::ANSIColor
|
22
|
+
def output_single(something, level=NORMAL)
|
23
|
+
if output?(level)
|
24
|
+
@io.write(send(something == '.' ? 'on_green' : 'on_red', something))
|
25
|
+
end
|
26
|
+
@io.flush
|
27
|
+
end
|
28
|
+
def output(something, level=NORMAL)
|
29
|
+
if output?(level)
|
30
|
+
if something.respond_to?('passed?')
|
31
|
+
@io.puts(send(something.passed? ? 'on_green' : 'on_red', something.to_s))
|
32
|
+
else
|
33
|
+
@io.puts(something)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@io.flush
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
rescue LoadError
|
44
|
+
end
|
45
|
+
|
46
|
+
module Test
|
47
|
+
module Unit
|
48
|
+
module Assertions
|
49
|
+
alias ae assert_equal
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
unless ARGV.grep(/--show-log/).empty?
|
55
|
+
$show_log = true
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gflocator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- maebashi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: msgpack-rpc
|
16
|
+
requirement: &22849380 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *22849380
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ffi-xattr
|
27
|
+
requirement: &22848940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *22848940
|
36
|
+
description: a daemon for providing responses to queries against file locations of
|
37
|
+
GlusterFS
|
38
|
+
email:
|
39
|
+
executables:
|
40
|
+
- gflocator
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- bin/gflocator
|
49
|
+
- gflocator.gemspec
|
50
|
+
- lib/gflocator.rb
|
51
|
+
- lib/gflocator/handler.rb
|
52
|
+
- lib/gflocator/main.rb
|
53
|
+
- lib/gflocator/util_daemon.rb
|
54
|
+
- lib/gflocator/version.rb
|
55
|
+
- test/test_handler.rb
|
56
|
+
- test/unittest_helper.rb
|
57
|
+
homepage: ''
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.11
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: file location server for GlusterFS
|
81
|
+
test_files:
|
82
|
+
- test/test_handler.rb
|
83
|
+
- test/unittest_helper.rb
|