filecluster 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,3 +1,4 @@
1
+ ! что делать с error is?
1
2
  периодически удалять пустые папки
2
3
  при создании item-а по папке проверять что папка не пустая
3
4
  проработать item-ы папки
@@ -54,6 +54,8 @@ module FC
54
54
  self.class.table_fields.each do |key|
55
55
  db_val = @database_fields[key]
56
56
  val = self.send(key)
57
+ val = 1 if val == true
58
+ val = 0 if val == false
57
59
  if val.to_s != db_val.to_s || val.nil? && !db_val.nil? || !val.nil? && db_val.nil?
58
60
  fields << "#{key}=#{val ? (val.class == String ? "'#{FC::DB.connect.escape(val)}'" : val.to_i) : 'NULL'}"
59
61
  end
@@ -40,11 +40,15 @@ module FC
40
40
  def copy_path(local_path, file_name)
41
41
  dst_path = "#{self.path}#{file_name}"
42
42
 
43
- cmd = self.class.curr_host == host ? "mkdir -p #{File.dirname(dst_path)}" : "ssh -oBatchMode=yes #{self.host} 'mkdir -p #{File.dirname(dst_path)}'"
43
+ cmd = self.class.curr_host == host ?
44
+ "mkdir -p #{File.dirname(dst_path)}" :
45
+ "ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'mkdir -p #{File.dirname(dst_path)}'"
44
46
  r = `#{cmd} 2>&1`
45
47
  raise r if $?.exitstatus != 0
46
48
 
47
- cmd = self.class.curr_host == host ? "cp -r #{local_path} #{dst_path}" : "scp -rB #{local_path} #{self.host}:#{dst_path}"
49
+ cmd = self.class.curr_host == host ?
50
+ "cp -r #{local_path} #{dst_path}" :
51
+ "scp -rB #{local_path} #{self.host}:#{dst_path}"
48
52
  r = `#{cmd} 2>&1`
49
53
  raise r if $?.exitstatus != 0
50
54
  end
@@ -56,7 +60,9 @@ module FC
56
60
  r = `mkdir -p #{File.dirname(local_path)} 2>&1`
57
61
  raise r if $?.exitstatus != 0
58
62
 
59
- cmd = self.class.curr_host == host ? "cp -r #{src_path} #{local_path}" : "scp -rB #{self.host}:#{src_path} #{local_path}"
63
+ cmd = self.class.curr_host == host ?
64
+ "cp -r #{src_path} #{local_path}" :
65
+ "scp -rB #{self.host}:#{src_path} #{local_path}"
60
66
  r = `#{cmd} 2>&1`
61
67
  raise r if $?.exitstatus != 0
62
68
  end
@@ -64,11 +70,15 @@ module FC
64
70
  # delete object from storage
65
71
  def delete_file(file_name)
66
72
  dst_path = "#{self.path}#{file_name}"
67
- cmd = self.class.curr_host == host ? "rm -rf #{dst_path}" : "ssh -oBatchMode=yes #{self.host} 'rm -rf #{dst_path}'"
73
+ cmd = self.class.curr_host == host ?
74
+ "rm -rf #{dst_path}" :
75
+ "ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'rm -rf #{dst_path}'"
68
76
  r = `#{cmd} 2>&1`
69
77
  raise r if $?.exitstatus != 0
70
78
 
71
- cmd = self.class.curr_host == host ? "ls -la #{dst_path}" : "ssh -oBatchMode=yes #{self.host} 'ls -la #{dst_path}'"
79
+ cmd = self.class.curr_host == host ?
80
+ "ls -la #{dst_path}" :
81
+ "ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'ls -la #{dst_path}'"
72
82
  r = `#{cmd} 2>/dev/null`
73
83
  raise "Path #{dst_path} not deleted" unless r.empty?
74
84
  end
@@ -77,7 +87,9 @@ module FC
77
87
  def file_size(file_name)
78
88
  dst_path = "#{self.path}#{file_name}"
79
89
 
80
- cmd = self.class.curr_host == host ? "du -sb #{dst_path}" : "ssh -oBatchMode=yes #{self.host} 'du -sb #{dst_path}'"
90
+ cmd = self.class.curr_host == host ?
91
+ "du -sb #{dst_path}" :
92
+ "ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'du -sb #{dst_path}'"
81
93
  r = `#{cmd} 2>&1`
82
94
  raise r if $?.exitstatus != 0
83
95
  r.to_i
@@ -1,3 +1,3 @@
1
1
  module FC
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -50,6 +50,11 @@ def show_items_info
50
50
  counts.each do |r|
51
51
  puts " #{r['status']}: #{r['cnt']}"
52
52
  end
53
+ puts "Items storages by status:"
54
+ counts = FC::DB.connect.query("SELECT status, count(*) as cnt FROM #{FC::ItemStorage.table_name} WHERE 1 GROUP BY status")
55
+ counts.each do |r|
56
+ puts " #{r['status']}: #{r['cnt']}"
57
+ end
53
58
  count = FC::DB.connect.query("SELECT count(*) as cnt FROM #{FC::Item.table_name} as i, #{FC::Policy.table_name} as p WHERE i.policy_id = p.id AND i.copies > 0 AND i.copies < p.copies AND i.status = 'ready'").first['cnt']
54
59
  puts "Items to copy: #{count}"
55
60
  count = FC::DB.connect.query("SELECT count(*) as cnt FROM #{FC::Item.table_name} as i, #{FC::Policy.table_name} as p WHERE i.policy_id = p.id AND i.copies > p.copies AND i.status = 'ready'").first['cnt']
@@ -32,9 +32,13 @@ class DaemonTest < Test::Unit::TestCase
32
32
  `rm -rf /tmp/host*-sd*`
33
33
  `mkdir -p /tmp/host1-sda/ /tmp/host1-sdb/ /tmp/host1-sdc/`
34
34
 
35
- # test file to copy
35
+ # test files to copy
36
36
  @@test_file_path = '/tmp/fc_test_file'
37
37
  `dd if=/dev/urandom of=#{@@test_file_path} bs=1M count=1 2>&1`
38
+ @@test_dir_path = '/tmp/fc_test_dir'
39
+ `mkdir -p #{@@test_dir_path}/aaa #{@@test_dir_path}/bbb`
40
+ `cp #{@@test_file_path} #{@@test_dir_path}/aaa/test1`
41
+ `cp #{@@test_file_path} #{@@test_dir_path}/bbb/test2`
38
42
 
39
43
  @@storages = []
40
44
  @@storages << FC::Storage.new(:name => 'host1-sda', :host => 'host1', :path => '/tmp/host1-sda/', :copy_id => 1, :size_limit => 1000000000)
@@ -59,7 +63,9 @@ class DaemonTest < Test::Unit::TestCase
59
63
  FC::DB.connect.query("DELETE FROM items")
60
64
  FC::DB.connect.query("DELETE FROM policies")
61
65
  FC::DB.connect.query("DELETE FROM storages")
62
- `rm -rf /tmp/host1-sda /tmp/host1-sdb /tmp/host1-sdc`
66
+ `rm -rf /tmp/host*-sd*`
67
+ `rm -rf #{@@test_file_path}`
68
+ `rm -rf #{@@test_dir_path}`
63
69
  end
64
70
  end
65
71
 
@@ -72,7 +78,7 @@ class DaemonTest < Test::Unit::TestCase
72
78
  FC::Storage.stubs(:curr_host).returns('host1')
73
79
  assert_nothing_raised { @item1 = FC::Item.create_from_local(@@test_file_path, 'bla/bla/test1', @@policy, {:tag => 'test1'}) }
74
80
  assert_nothing_raised { @item2 = FC::Item.create_from_local(@@test_file_path, 'bla/bla/test2', @@policy, {:tag => 'test2'}) }
75
- assert_nothing_raised { @item3 = FC::Item.create_from_local(@@test_file_path, 'bla/bla/test3', @@policy, {:tag => 'test3'}) }
81
+ assert_nothing_raised { @item3 = FC::Item.create_from_local(@@test_dir_path, 'bla/bla/test3', @@policy, {:tag => 'test3'}) }
76
82
 
77
83
  @@policy.copies = 3
78
84
  @@policy.save
@@ -81,7 +87,7 @@ class DaemonTest < Test::Unit::TestCase
81
87
  # wait for copy
82
88
  [1, 2, 3].each do |i|
83
89
  ['b', 'c'].each do |j|
84
- assert_equal `du -b /tmp/host1-sda/bla/bla/test$i 2>&1`.to_i, `du -b /tmp/host$i-sd$j/bla/bla/test$i 2>&1`.to_i
90
+ assert_equal `du -sb /tmp/host1-sda/bla/bla/test$i 2>&1`.to_i, `du -sb /tmp/host$i-sd$j/bla/bla/test$i 2>&1`.to_i
85
91
  end
86
92
  end
87
93
 
@@ -91,7 +97,7 @@ class DaemonTest < Test::Unit::TestCase
91
97
  item_storage.status = 'delete'
92
98
  item_storage.save
93
99
  sleep 2
94
- assert_equal 0, `du -b /tmp/host1-sdc/bla/bla/test1 2>&1`.to_i
100
+ assert_equal 0, `du -sb /tmp/host1-sdc/bla/bla/test1 2>&1`.to_i
95
101
 
96
102
  assert_equal @@errors_count, FC::Error.where.count, "new errors in errors table"
97
103
  end
@@ -6,10 +6,16 @@ class FunctionalTest < Test::Unit::TestCase
6
6
  # tmp fake storages dirs
7
7
  `rm -rf /tmp/host*-sd*`
8
8
  `mkdir -p /tmp/host1-sda/ /tmp/host2-sda/`
9
+ `rm -rf /tmp/fc_test_dir`
10
+ `mkdir -p /tmp/fc_test_dir`
9
11
 
10
12
  # test file to copy
11
13
  @@test_file_path = '/tmp/fc_test_file'
12
14
  `dd if=/dev/urandom of=#{@@test_file_path} bs=100K count=1 2>&1`
15
+ @@test_dir_path = '/tmp/fc_test_dir'
16
+ `mkdir -p #{@@test_dir_path}/aaa #{@@test_dir_path}/bbb`
17
+ `cp #{@@test_file_path} #{@@test_dir_path}/aaa/test1`
18
+ `cp #{@@test_file_path} #{@@test_dir_path}/bbb/test2`
13
19
 
14
20
  @@storages = []
15
21
  @@storages << FC::Storage.new(:name => 'host1-sda', :host => 'host1', :path => '/tmp/host1-sda/', :size_limit => 1000000, :check_time => Time.new.to_i)
@@ -31,7 +37,9 @@ class FunctionalTest < Test::Unit::TestCase
31
37
  FC::DB.connect.query("DELETE FROM items")
32
38
  FC::DB.connect.query("DELETE FROM policies")
33
39
  FC::DB.connect.query("DELETE FROM storages")
34
- `rm -rf /tmp/host1-sda /tmp/host2-sda`
40
+ `rm -rf /tmp/host*-sd*`
41
+ `rm -rf #{@@test_file_path}`
42
+ `rm -rf #{@@test_dir_path}`
35
43
  end
36
44
  end
37
45
 
@@ -43,8 +51,22 @@ class FunctionalTest < Test::Unit::TestCase
43
51
  should "item create_from_local successful" do
44
52
  assert_nothing_raised { @item = FC::Item.create_from_local(@@test_file_path, '/bla/bla/test1', @@policies[0], {:tag => 'test'}) }
45
53
  assert_kind_of FC::Item, @item
46
- assert_equal `du -b /tmp/host1-sda/bla/bla/test1 2>&1`.to_i, `du -b #{@@test_file_path} 2>&1`.to_i
47
- assert_equal `du -b /tmp/host1-sda/bla/bla/test1 2>&1`.to_i, @item.size
54
+ assert_equal `du -sb /tmp/host1-sda/bla/bla/test1 2>&1`.to_i, `du -sb #{@@test_file_path} 2>&1`.to_i
55
+ assert_equal `du -sb /tmp/host1-sda/bla/bla/test1 2>&1`.to_i, @item.size
56
+ assert_equal 'ready', @item.status
57
+ item_storages = @item.get_item_storages
58
+ assert_equal 1, item_storages.count
59
+ item_storage = item_storages.first
60
+ assert_equal 'ready', item_storage.status
61
+ assert_equal 'host1-sda', item_storage.storage_name
62
+ end
63
+
64
+ should "item create_from_local dir successful" do
65
+ assert_nothing_raised { @item = FC::Item.create_from_local(@@test_dir_path, '/bla/bla/test_dir', @@policies[0], {:tag => 'test_dir'}) }
66
+ assert_kind_of FC::Item, @item
67
+ assert_equal true, @item.dir?
68
+ assert_equal `du -sb /tmp/host1-sda/bla/bla/test_dir 2>&1`.to_i, `du -sb #{@@test_dir_path} 2>&1`.to_i
69
+ assert_equal `du -sb /tmp/host1-sda/bla/bla/test_dir 2>&1`.to_i, @item.size
48
70
  assert_equal 'ready', @item.status
49
71
  item_storages = @item.get_item_storages
50
72
  assert_equal 1, item_storages.count
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filecluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-17 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-readline
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: 4000916111344436581
189
+ hash: 2481106043269937193
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: 4000916111344436581
198
+ hash: 2481106043269937193
199
199
  requirements: []
200
200
  rubyforge_project:
201
201
  rubygems_version: 1.8.24