filbunke 1.8.3 → 1.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/filbunke.gemspec +6 -7
- data/lib/filbunke/callbacks.rb +6 -0
- data/lib/filbunke/client.rb +28 -16
- data/lib/filbunke/daemon.rb +4 -46
- metadata +20 -7
data/Rakefile
CHANGED
@@ -7,9 +7,9 @@ begin
|
|
7
7
|
gem.name = "filbunke"
|
8
8
|
gem.summary = %Q{Filbunke client}
|
9
9
|
gem.description = %Q{Filbunke client and library}
|
10
|
-
gem.email = "
|
10
|
+
gem.email = "info@deltaprojects.com"
|
11
11
|
gem.homepage = "http://github.com/deltaprojects/filbunke"
|
12
|
-
gem.authors = ["
|
12
|
+
gem.authors = ["Björn Sperber", "Karl Ravn"]
|
13
13
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
14
|
gem.files.exclude 'pkg'
|
15
15
|
gem.executables = ['filbunked']
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.8.
|
1
|
+
1.8.4
|
data/filbunke.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{filbunke}
|
8
|
-
s.version = "1.8.
|
8
|
+
s.version = "1.8.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["
|
12
|
-
s.date = %q{2012-
|
11
|
+
s.authors = ["Bj\303\266rn Sperber", "Karl Ravn"]
|
12
|
+
s.date = %q{2012-10-01}
|
13
13
|
s.default_executable = %q{filbunked}
|
14
14
|
s.description = %q{Filbunke client and library}
|
15
|
-
s.email = %q{
|
15
|
+
s.email = %q{info@deltaprojects.com}
|
16
16
|
s.executables = ["filbunked"]
|
17
17
|
s.files = [
|
18
18
|
"LICENSE",
|
@@ -38,14 +38,13 @@ Gem::Specification.new do |s|
|
|
38
38
|
]
|
39
39
|
s.homepage = %q{http://github.com/deltaprojects/filbunke}
|
40
40
|
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.
|
41
|
+
s.rubygems_version = %q{1.6.2}
|
42
42
|
s.summary = %q{Filbunke client}
|
43
43
|
|
44
44
|
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
45
|
s.specification_version = 3
|
47
46
|
|
48
|
-
if Gem::Version.new(Gem::
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
48
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
49
|
s.add_runtime_dependency(%q<json>, [">= 1.1.7"])
|
51
50
|
s.add_runtime_dependency(%q<typhoeus>, ["= 0.3.3"])
|
data/lib/filbunke/callbacks.rb
CHANGED
data/lib/filbunke/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Filbunke
|
2
2
|
class Client
|
3
3
|
|
4
|
-
attr_reader :repository
|
4
|
+
attr_reader :repository
|
5
5
|
|
6
6
|
UPDATES_ACTION = 'updates'
|
7
7
|
FILES_ACTION = 'files'
|
@@ -12,10 +12,9 @@ module Filbunke
|
|
12
12
|
HASH_KEY = 'hash'
|
13
13
|
|
14
14
|
|
15
|
-
def initialize(repository, logger,
|
15
|
+
def initialize(repository, logger, callbacks = [], failed_request_log_file_name = nil)
|
16
16
|
@repository = repository
|
17
17
|
@logger = logger
|
18
|
-
@run_every = run_every
|
19
18
|
@callbacks = callbacks
|
20
19
|
@failed_request_log_file_name = failed_request_log_file_name
|
21
20
|
end
|
@@ -38,7 +37,7 @@ module Filbunke
|
|
38
37
|
local_file_path = ::File.join(repository.local_path, file.path)
|
39
38
|
if file.state == "DELETED" then
|
40
39
|
delete_file!(local_file_path)
|
41
|
-
|
40
|
+
run_callbacks_delete(file, local_file_path)
|
42
41
|
else
|
43
42
|
|
44
43
|
if file_needs_update?(file, local_file_path)
|
@@ -53,6 +52,7 @@ module Filbunke
|
|
53
52
|
|
54
53
|
else
|
55
54
|
@logger.log "File exists with correct hash: #{local_file_path}"
|
55
|
+
run_callbacks_no_change(file, local_file_path)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -144,7 +144,6 @@ module Filbunke
|
|
144
144
|
elsif file.url =~ /^hdfs:\/\//
|
145
145
|
success = update_hdfs_file!(file, local_file_path)
|
146
146
|
run_callbacks(file, local_file_path) if success
|
147
|
-
|
148
147
|
else
|
149
148
|
raise "Unsupported protocol for file: #{file.inspect}"
|
150
149
|
end
|
@@ -156,6 +155,18 @@ module Filbunke
|
|
156
155
|
end
|
157
156
|
end
|
158
157
|
|
158
|
+
def run_callbacks_no_change(file, local_file_path)
|
159
|
+
@callbacks.each do |callback|
|
160
|
+
callback.on_no_change(file, local_file_path)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def run_callbacks_delete(file, local_file_path)
|
165
|
+
@callbacks.each do |callback|
|
166
|
+
callback.on_delete(file, local_file_path)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
159
170
|
def file_needs_update?(file, local_file_path)
|
160
171
|
return true if file.hash.nil? || file.hash == ""
|
161
172
|
|
@@ -203,8 +214,6 @@ module Filbunke
|
|
203
214
|
begin
|
204
215
|
if response.code.to_i == 200
|
205
216
|
write_file!(local_file_path, response.body)
|
206
|
-
elsif response.code.to_i == 404
|
207
|
-
delete_file!(local_file_path)
|
208
217
|
else
|
209
218
|
@logger.log "Failed to update file #{file.url}, error code = #{response.code}"
|
210
219
|
success = false
|
@@ -254,16 +263,19 @@ module Filbunke
|
|
254
263
|
end
|
255
264
|
|
256
265
|
def write_file!(file_path, contents)
|
257
|
-
if ::File.exists?(file_path)
|
258
|
-
@logger.log("Updating: #{file_path}")
|
259
|
-
else
|
260
|
-
@logger.log("Writing: #{file_path}")
|
261
|
-
end
|
262
266
|
::FileUtils.mkdir_p(::File.dirname(file_path))
|
263
|
-
|
264
|
-
|
265
|
-
file
|
266
|
-
|
267
|
+
@logger.log("Updating: #{file_path}")
|
268
|
+
begin
|
269
|
+
::File.open("#{file_path}.tmp", 'w') do |file|
|
270
|
+
file.write(contents);
|
271
|
+
file.close
|
272
|
+
end
|
273
|
+
::FileUtils.mv "#{file_path}.tmp", file_path
|
274
|
+
return true
|
275
|
+
rescue StandardError => e
|
276
|
+
@logger.log "Failed to move file #{file.url}: #{e.message}"
|
277
|
+
return false
|
278
|
+
end
|
267
279
|
end
|
268
280
|
|
269
281
|
def delete_file!(file_path)
|
data/lib/filbunke/daemon.rb
CHANGED
@@ -11,42 +11,6 @@ module Filbunke
|
|
11
11
|
def setup_clients!(local = false)
|
12
12
|
@logger = Logger.new(@config["log_file"], local)
|
13
13
|
@logger.log("Initializing filbunked")
|
14
|
-
|
15
|
-
if(@config["version"] && @config["version"].to_i == 2)
|
16
|
-
version_2_configure
|
17
|
-
else
|
18
|
-
version_1_configure
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def version_2_configure
|
23
|
-
@config["repositories"].each do |repository_name, local_repository_config|
|
24
|
-
@logger.log("Initializing repository (version 2): #{repository_name}")
|
25
|
-
repository_file = File.read("#{@config["repository_files_path"]}#{repository_name}.yml")
|
26
|
-
static_repository_config = YAML.load(repository_file)
|
27
|
-
@clients << begin
|
28
|
-
repository = Repository.new(static_repository_config["filbunke_server_repository"],
|
29
|
-
static_repository_config["filbunke_server_host"],
|
30
|
-
static_repository_config["filbunke_server_port"],
|
31
|
-
local_repository_config["local_path"],
|
32
|
-
@config["file_umask"].to_i,
|
33
|
-
@config["directory_umask"].to_i,
|
34
|
-
static_repository_config["file_url_username"],
|
35
|
-
static_repository_config["file_url_password"],
|
36
|
-
@config["hadoop_binary"])
|
37
|
-
callbacks = []
|
38
|
-
local_repository_config["callbacks"].each do |callback_name, callback_config|
|
39
|
-
require ::File.join(@config["callback_path"], callback_name.to_s)
|
40
|
-
callback_class = Module.const_get(callback_name.split("_").map(&:capitalize).join)
|
41
|
-
callbacks << callback_class.new(@logger, callback_config)
|
42
|
-
end if local_repository_config["callbacks"]
|
43
|
-
run_every = local_repository_config["run_every"] ? local_repository_config["run_every"].to_i : @config["run_every"].to_i
|
44
|
-
Client.new(repository, @logger, run_every, callbacks)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def version_1_configure
|
50
14
|
@config["repositories"].each do |repository_name, repository_config|
|
51
15
|
@logger.log("Initializing repository: #{repository_name}")
|
52
16
|
@clients << begin
|
@@ -65,32 +29,26 @@ module Filbunke
|
|
65
29
|
callback_class = Module.const_get(callback_name.split("_").map(&:capitalize).join)
|
66
30
|
callbacks << callback_class.new(@logger, callback_config)
|
67
31
|
end
|
68
|
-
Client.new(repository, @logger,
|
32
|
+
Client.new(repository, @logger, callbacks)
|
69
33
|
end
|
70
34
|
end
|
71
35
|
end
|
72
36
|
|
73
|
-
|
74
|
-
|
75
37
|
def run!
|
76
38
|
version = ::File.read(::File.expand_path(::File.join(::File.dirname(__FILE__), "../../VERSION"))).chomp
|
77
39
|
@logger.log("Starting filbunked version #{version}")
|
78
|
-
counter = 0
|
79
40
|
while true
|
80
|
-
counter++
|
81
41
|
begin
|
82
42
|
@clients.each do |client|
|
83
|
-
|
84
|
-
|
85
|
-
update_checkpoint_for_repository(client.repository, new_checkpoint)
|
86
|
-
end
|
43
|
+
new_checkpoint = client.update_files!(checkpoint_for_repository(client.repository))
|
44
|
+
update_checkpoint_for_repository(client.repository, new_checkpoint)
|
87
45
|
end
|
88
46
|
rescue StandardError => e
|
89
47
|
@logger.log("Died.. #{e.message}")
|
90
48
|
@logger.log(e.backtrace.join("\n"))
|
91
49
|
exit 1
|
92
50
|
end
|
93
|
-
sleep
|
51
|
+
sleep @config["run_every"]
|
94
52
|
end
|
95
53
|
end
|
96
54
|
|
metadata
CHANGED
@@ -1,30 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filbunke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 63
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 8
|
8
|
-
-
|
9
|
-
version: 1.8.
|
9
|
+
- 4
|
10
|
+
version: 1.8.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
- Wouter de Bie
|
13
13
|
- "Bj\xC3\xB6rn Sperber"
|
14
|
+
- Karl Ravn
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2012-
|
19
|
+
date: 2012-10-01 00:00:00 +02:00
|
19
20
|
default_executable: filbunked
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: thoughtbot-shoulda
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
28
31
|
segments:
|
29
32
|
- 0
|
30
33
|
version: "0"
|
@@ -34,9 +37,11 @@ dependencies:
|
|
34
37
|
name: json
|
35
38
|
prerelease: false
|
36
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
37
41
|
requirements:
|
38
42
|
- - ">="
|
39
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 29
|
40
45
|
segments:
|
41
46
|
- 1
|
42
47
|
- 1
|
@@ -48,9 +53,11 @@ dependencies:
|
|
48
53
|
name: typhoeus
|
49
54
|
prerelease: false
|
50
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
51
57
|
requirements:
|
52
58
|
- - "="
|
53
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 21
|
54
61
|
segments:
|
55
62
|
- 0
|
56
63
|
- 3
|
@@ -62,9 +69,11 @@ dependencies:
|
|
62
69
|
name: open4
|
63
70
|
prerelease: false
|
64
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
65
73
|
requirements:
|
66
74
|
- - ">="
|
67
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 21
|
68
77
|
segments:
|
69
78
|
- 1
|
70
79
|
- 0
|
@@ -73,7 +82,7 @@ dependencies:
|
|
73
82
|
type: :runtime
|
74
83
|
version_requirements: *id004
|
75
84
|
description: Filbunke client and library
|
76
|
-
email:
|
85
|
+
email: info@deltaprojects.com
|
77
86
|
executables:
|
78
87
|
- filbunked
|
79
88
|
extensions: []
|
@@ -111,23 +120,27 @@ rdoc_options: []
|
|
111
120
|
require_paths:
|
112
121
|
- lib
|
113
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
114
124
|
requirements:
|
115
125
|
- - ">="
|
116
126
|
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
117
128
|
segments:
|
118
129
|
- 0
|
119
130
|
version: "0"
|
120
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
121
133
|
requirements:
|
122
134
|
- - ">="
|
123
135
|
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
124
137
|
segments:
|
125
138
|
- 0
|
126
139
|
version: "0"
|
127
140
|
requirements: []
|
128
141
|
|
129
142
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
143
|
+
rubygems_version: 1.6.2
|
131
144
|
signing_key:
|
132
145
|
specification_version: 3
|
133
146
|
summary: Filbunke client
|