filecluster 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fc-manage CHANGED
@@ -64,6 +64,15 @@ Command:
64
64
  list show all FC::Var-s
65
65
  show <variable> show current value for variable
66
66
  change <variable> change variable
67
+ }],
68
+ 'item' => [
69
+ 'show and manage items',
70
+ %q{Usage: fc-manage [options] item <command>
71
+ Command:
72
+ info <name> show item info, name can contain ? and *
73
+ add_local <storage name> <path> <policy id/name> add file in local storage as item (as <path> name) with policy
74
+ add <path> <name> <policy id/name> add file as item <name> with policy
75
+ rm <name> delete item
67
76
  }]
68
77
  }
69
78
  desc = %q{Get info and manage for storages, policies and items.
@@ -60,9 +60,6 @@ class GlobalDaemonThread < BaseThread
60
60
  storage = src_storage.get_proper_storage_for_copy(row['size'], item_storages) unless storage
61
61
  end
62
62
  if storage
63
- puts row
64
- puts src_storage.name+'>'
65
- puts storage.name
66
63
  FC::Item.new(:id => row['item_id']).make_item_storage(storage, 'copy')
67
64
  else
68
65
  error 'No available storage', :item_id => row['item_id']
data/lib/fc/item.rb CHANGED
@@ -24,7 +24,7 @@ module FC
24
24
  raise 'Name is empty' if item_params[:name].empty?
25
25
  raise 'Zero size path' if item_params[:size] == 0
26
26
 
27
- if local_path.include?(item_name)
27
+ if local_path.include?(item_name) && !options[:not_local]
28
28
  storage = policy.get_create_storages.detect do |s|
29
29
  s.host == FC::Storage.curr_host && local_path.index(s.path) == 0 && local_path.sub(s.path, '') == item_params[:name]
30
30
  end
data/lib/fc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FC
2
- VERSION = "0.3.10"
2
+ VERSION = "0.3.11"
3
3
  end
@@ -0,0 +1,96 @@
1
+ def item_info
2
+ name = ARGV[2] || ''
3
+ name = name.gsub('_', '\\_').gsub('%', '\\%').gsub('?', '_').gsub('*', '%')
4
+ count = FC::DB.query("SELECT count(*) as cnt FROM #{FC::Item.table_name} WHERE name like '#{name}'").first['cnt']
5
+ puts "Find #{count} items:"
6
+ if (count > 1)
7
+ items = FC::DB.query("SELECT name FROM #{FC::Item.table_name} WHERE name like '#{name}' ORDER BY id DESC LIMIT 100")
8
+ items.each{|r| puts r["name"]}
9
+ puts "Last item:"
10
+ end
11
+ item = FC::DB.query("SELECT i.id, i.name, tag, outer_id, p.name as policy, size, status, time, i.copies FROM #{FC::Item.table_name} as i, #{FC::Policy.table_name} as p WHERE i.name like '#{name}' AND p.id=policy_id ORDER BY i.id DESC LIMIT 1").first
12
+ if item
13
+ item_storages = FC::DB.query("SELECT storage_name, status, time FROM #{FC::ItemStorage.table_name} WHERE item_id=#{item["id"]}")
14
+ puts %Q{
15
+ ID: #{item["id"]}
16
+ Outer id: #{item["outer_id"]}
17
+ Name: #{item["name"]}
18
+ Status: #{item["status"]}
19
+ Tag: #{item["tag"]}
20
+ Policy: #{item["policy"]}
21
+ Size: #{size_to_human(item["size"])}
22
+ Time: #{Time.at(item["time"])}
23
+ Copies: #{item["copies"]}}
24
+ if item_storages.size > 0
25
+ puts "Item on storages:"
26
+ item_storages.each do |r|
27
+ s = " #{r["storage_name"]}:"
28
+ s << " "*[(22-s.length), 1].max
29
+ s << case r["status"]
30
+ when "ready" then colorize_string("ready", :green)
31
+ when "error" then colorize_string("ready", :red)
32
+ else r["status"]
33
+ end
34
+ s << " - #{Time.at(r["time"])}"
35
+ puts s
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def item_add
42
+ path = ARGV[2] || ''
43
+ name = ARGV[3] || ''
44
+ policy = FC::Policy.where('id = ?', ARGV[4]).first
45
+ policy = FC::Policy.where('name = ?', ARGV[4]).first unless policy
46
+ puts "Policy #{ARGV[4]} not found." unless policy
47
+
48
+ if policy
49
+ begin
50
+ item = FC::Item.create_from_local(path, name, policy, :tag => 'fc-manage-add', :replace => true, :not_local => true)
51
+ item_storage = item.get_item_storages.first
52
+ storage = FC::Storage.where('name = ?', item_storage.storage_name).first
53
+ puts "Saved as #{storage.name+':'+storage.path+item.name}"
54
+ rescue Exception => e
55
+ puts e.message
56
+ end
57
+ end
58
+ end
59
+
60
+ def item_add_local
61
+ storage = FC::Storage.where('name = ?', ARGV[2]).first
62
+ puts "Storage #{ARGV[2]} not found." unless storage
63
+ name = ARGV[3] || ''
64
+ policy = FC::Policy.where('id = ?', ARGV[4]).first
65
+ policy = FC::Policy.where('name = ?', ARGV[4]).first unless policy
66
+ puts "Policy #{ARGV[4]} not found." unless policy
67
+
68
+ if policy && storage
69
+ path = (storage.path+name).gsub('//', '/') unless name.index(storage.path) == 0
70
+ begin
71
+ item = FC::Item.create_from_local(path, name, policy, :tag => 'fc-manage-add-local', :replace => true)
72
+ item_storage = item.get_item_storages.first
73
+ storage = FC::Storage.where('name = ?', item_storage.storage_name).first
74
+ puts "Saved as #{storage.name+':'+storage.path+item.name}"
75
+ rescue Exception => e
76
+ puts e.message
77
+ end
78
+ end
79
+ end
80
+
81
+ def item_rm
82
+ name = ARGV[2] || ''
83
+ item = FC::Item.where('name = ?', name).first
84
+ if !item
85
+ puts "Item #{name} not found."
86
+ else
87
+ s = Readline.readline("Delete? (y/n) ", false).strip.downcase
88
+ puts ""
89
+ if s == "y" || s == "yes"
90
+ item.mark_deleted
91
+ puts "ok"
92
+ else
93
+ puts "Canceled."
94
+ end
95
+ end
96
+ end
data/lib/manage.rb CHANGED
@@ -4,3 +4,4 @@ require "manage/storages"
4
4
  require "manage/show"
5
5
  require "manage/copy_rules"
6
6
  require "manage/var"
7
+ require "manage/item"
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.3.10
4
+ version: 0.3.11
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: 2014-08-15 00:00:00.000000000 Z
12
+ date: 2014-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mysql2
@@ -148,6 +148,7 @@ files:
148
148
  - lib/filecluster.rb
149
149
  - lib/manage.rb
150
150
  - lib/manage/copy_rules.rb
151
+ - lib/manage/item.rb
151
152
  - lib/manage/policies.rb
152
153
  - lib/manage/show.rb
153
154
  - lib/manage/storages.rb
@@ -180,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  segments:
182
183
  - 0
183
- hash: 3207562445207537797
184
+ hash: -2994617914936702479
184
185
  required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  none: false
186
187
  requirements:
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  version: '0'
190
191
  segments:
191
192
  - 0
192
- hash: 3207562445207537797
193
+ hash: -2994617914936702479
193
194
  requirements: []
194
195
  rubyforge_project:
195
196
  rubygems_version: 1.8.24