storazzo 0.4.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,154 +1,165 @@
1
1
  module Storazzo::Media
2
- class Storazzo::Media::AbstractRicDisk
3
- #include Storazzo::Common
4
- extend Storazzo::Common
5
-
6
- #DefaultStatsFilename = Storazzo::RicDiskStatsFile.default_name
7
-
8
- # looks like there's not Abstract Class in Ruby, but also SO says he best
9
- # way to do this is this:
10
-
11
- # attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
12
- attr_accessor :description
13
- ########################
14
- # Abstract methods START
15
- ########################
16
- def initialize(local_mount)
17
- deb "[AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
18
- @description ||= "Not provided"
19
- #validate
20
- end
21
- def self.list_all
22
- raise "[AbstractRicDiskc::self.list_all] You should override this, says StackOverflow and Riccardo"
23
- end
24
- def self.list_all_with_type
25
- raise "[AbstractRicDiskc::self.list_all_with_type] You should override this, says StackOverflow and Riccardo"
26
- end
27
- def self.super_duper_list_all_with_type
28
- deb "Would be cool to be able to enumerate them all.."
29
- GcsBucket.list_all_with_type +
30
- MountPoint.list_all_with_type +
31
- LocalFolder.list_all_with_type
32
- end
33
- def parse(opts={})
34
- raise "[AbstractRicDiskc::parse] You should override this, says StackOverflow and Riccardo"
35
- end
36
- def writeable?
37
- raise "[AbstractRicDiskc::writeable] You should override this in #{self.class}, says StackOverflow and Riccardo"
38
- end
39
- def get_local_mountpoint
40
- #raise "[AbstractRicDiskc::get_local_mountpoint] You should override this, says StackOverflow and Riccardo"
41
- raise "You forgot to set local_mountpoint in the constructor for your class, you cheeky little one!" if local_mountpoint.nil?
42
- local_mountpoint
43
- end
44
- def check_implemented_correctly
45
- # raise "[AbstractRicDiskc] You should override this, says StackOverflow and Riccardo"
46
- raise "no @local_mountpoint" unless exists?(@local_mountpoint)
47
- end
48
- ########################
49
- # Abstract methods END
50
- ########################
51
-
52
-
53
-
54
- ########################
55
- # Automated methods now...
56
- ########################
57
- def stats_file_smart_fullpath # stats_file_default_location()
58
- # if its writeable... if not we'll think about it later.
59
- if writeable?
60
- return "#{get_local_mountpoint}/#{self.default_stats_filename}"
61
- else
62
- # if not writeable, I will:
63
- # 1. create a dir based on its unique format.
64
- # 2. create a file of same look and feel (alternative - used a DASH)
65
- return "TODO FIXME {get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
66
- #"{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}"
67
- end
68
- end
69
- # Needs to be some unique id based on its thingy, but might change in the future:
70
- # Solutions:
71
- # {PHILOSOPHY}::{ID}
72
- def unique_id
73
- # Expand path to make it as unique as possible...
74
- hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
75
- "MD5::v1::#{hash}"
76
- end
77
-
78
- def to_s(verbose=false)
79
- return to_verbose_s() if verbose
80
- readable_class = self.class.to_s.split('::').last # Storazzo::Media::LocalFolder => LocalFolder
81
- my_keys = self.instance_variables # wow!
82
- "S:M:#{readable_class}(path=#{path}, r/w=#{wr}, keys=#{my_keys})"
83
- end
84
-
85
- def to_verbose_s
86
- h = {}
87
- h[:class] = self.class
88
- h[:unique_id] = self.unique_id
89
- h[:inspect] = self.inspect
90
- h[:to_s] = self.to_s
91
- h[:local_mountpoint] = local_mountpoint
92
- h[:writeable] = self.writeable?
93
- h[:stats_file_smart_fullpath] = stats_file_smart_fullpath
94
- return h
95
- end
96
-
97
- # # Todo check on instances these 3 methods exist
98
- def self.abstract_class_mandatory_methods
99
- %W{
100
- self.list_all
101
- self.list_all_with_type
102
- local_mountpoint
103
- parse
104
- writeable?
105
- }
106
- end
107
-
108
- # Putting here since its same code for MountPoint or generic folder.
109
- def parse_block_storage_folder(opts={})
110
- #Storazzo::RicDiskUgly.calculate_stats_files(get_local_mountpoint)
111
- rd = Storazzo::RicDisk.new(self)
112
- #Storazzo::RicDisk
113
- rd.compute_stats_files(opts)
114
- #return "42"
115
- end
116
-
117
- def self.default_stats_filename
118
- raise "Unknown Storazzo::RicDiskStatsFile.default_name 1!!" if Storazzo::RicDiskStatsFile.default_name.nil?
119
- Storazzo::RicDiskStatsFile.default_name
120
- end
121
-
122
- def stats_filename_default_fullpath # if not writeable we need to pick another from stats_file_smart_fullpath()
123
- # REDUNDANT, should use stats_file_smart_fullpath instead except on the writeable? part since it would go recursive otherwise.
124
- my_stats_filename = self.default_stats_filename
125
- #raise "Unknown Storazzo::RicDiskStatsFile.default_name 2 !!" if Storazzo::RicDiskStatsFile.default_name.nil?
126
- "#{local_mountpoint}/#{my_stats_filename}"
127
- end
128
-
129
- def validate(opts={})
130
- verbose = opts.fetch(:verbose, true)
131
- puts "[VERBOSE] validate(): We're trying to see if your object is valid, across 3 possible sub-classes." if verbose
132
- #1. check for
133
- raise "Unknown local mount " unless local_mount.is_a?(String)
134
- #2. check thaty writeable? is true or false
135
- my_writeable = wr
136
- raise "Writeable is not boolean" unless (my_writeable.is_a? TrueClass or my_writeable.is_a? FalseClass )
137
- end
138
-
139
- # TODO use a proper Factory pattern.
140
- def self.DirFactory(path)
141
- raise "I need a path/directory string: #{path}" unless path.is_a?(String)
142
-
143
- deb "TODO: if coincides with MountPoint, instance THAT"
144
- # if path in Storazzo::Media::MountPoint.list_all_mount_points
145
- # then return ...
146
- if path =~ /^gs:\/\//
147
- deb "Smells like GCS"
148
- return GcsBucket.new(path)
149
- end
150
- deb "Smells like LocalFolder :)"
151
- return LocalFolder.new(path)
152
- end
2
+ class Storazzo::Media::AbstractRicDisk
3
+ # include Storazzo::Common
4
+ extend Storazzo::Common
5
+
6
+ # DefaultStatsFilename = Storazzo::RicDiskStatsFile.default_name
7
+
8
+ # looks like there's not Abstract Class in Ruby, but also SO says he best
9
+ # way to do this is this:
10
+
11
+ # attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
12
+ attr_accessor :description
13
+
14
+ ########################
15
+ # Abstract methods START
16
+ ########################
17
+ def initialize(local_mount)
18
+ deb "[AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
19
+ @description ||= "Not provided"
20
+ # validate
21
+ end
22
+
23
+ def self.list_all
24
+ raise "[AbstractRicDiskc::self.list_all] You should override this, says StackOverflow and Riccardo"
25
+ end
26
+
27
+ def self.list_all_with_type
28
+ raise "[AbstractRicDiskc::self.list_all_with_type] You should override this, says StackOverflow and Riccardo"
29
+ end
30
+
31
+ def self.super_duper_list_all_with_type
32
+ deb "Would be cool to be able to enumerate them all.."
33
+ GcsBucket.list_all_with_type +
34
+ MountPoint.list_all_with_type +
35
+ LocalFolder.list_all_with_type
36
+ end
37
+
38
+ def parse(opts = {})
39
+ raise "[AbstractRicDiskc::parse] You should override this, says StackOverflow and Riccardo"
40
+ end
41
+
42
+ def writeable?
43
+ raise "[AbstractRicDiskc::writeable] You should override this in #{self.class}, says StackOverflow and Riccardo"
44
+ end
45
+
46
+ def get_local_mountpoint
47
+ # raise "[AbstractRicDiskc::get_local_mountpoint] You should override this, says StackOverflow and Riccardo"
48
+ raise "You forgot to set local_mountpoint in the constructor for your class, you cheeky little one!" if local_mountpoint.nil?
49
+
50
+ local_mountpoint
51
+ end
52
+
53
+ def check_implemented_correctly
54
+ # raise "[AbstractRicDiskc] You should override this, says StackOverflow and Riccardo"
55
+ raise "no @local_mountpoint" unless exists?(@local_mountpoint)
56
+ end
57
+ ########################
58
+ # Abstract methods END
59
+ ########################
60
+
61
+ ########################
62
+ # Automated methods now...
63
+ ########################
64
+ def stats_file_smart_fullpath # stats_file_default_location()
65
+ # if its writeable... if not we'll think about it later.
66
+ if writeable?
67
+ return "#{get_local_mountpoint}/#{self.default_stats_filename}"
68
+ else
69
+ # if not writeable, I will:
70
+ # 1. create a dir based on its unique format.
71
+ # 2. create a file of same look and feel (alternative - used a DASH)
72
+ return "TODO FIXME {get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
73
+ # "{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}"
74
+ end
75
+ end
76
+
77
+ # Needs to be some unique id based on its thingy, but might change in the future:
78
+ # Solutions:
79
+ # {PHILOSOPHY}::{ID}
80
+ def unique_id
81
+ # Expand path to make it as unique as possible...
82
+ hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
83
+ "MD5::v1::#{hash}"
84
+ end
85
+
86
+ def to_s(verbose = false)
87
+ return to_verbose_s() if verbose
88
+
89
+ readable_class = self.class.to_s.split('::').last # Storazzo::Media::LocalFolder => LocalFolder
90
+ my_keys = self.instance_variables # wow!
91
+ "S:M:#{readable_class}(path=#{path}, r/w=#{wr}, keys=#{my_keys})"
92
+ end
93
+
94
+ def to_verbose_s
95
+ h = {}
96
+ h[:class] = self.class
97
+ h[:unique_id] = self.unique_id
98
+ h[:inspect] = self.inspect
99
+ h[:to_s] = self.to_s
100
+ h[:local_mountpoint] = local_mountpoint
101
+ h[:writeable] = self.writeable?
102
+ h[:stats_file_smart_fullpath] = stats_file_smart_fullpath
103
+ return h
104
+ end
105
+
106
+ # # Todo check on instances these 3 methods exist
107
+ def self.abstract_class_mandatory_methods
108
+ %W{
109
+ self.list_all
110
+ self.list_all_with_type
111
+ local_mountpoint
112
+ parse
113
+ writeable?
114
+ }
115
+ end
116
+
117
+ # Putting here since its same code for MountPoint or generic folder.
118
+ def parse_block_storage_folder(opts = {})
119
+ # Storazzo::RicDiskUgly.calculate_stats_files(get_local_mountpoint)
120
+ rd = Storazzo::RicDisk.new(self)
121
+ # Storazzo::RicDisk
122
+ rd.compute_stats_files(opts)
123
+ # return "42"
124
+ end
125
+
126
+ def self.default_stats_filename
127
+ raise "Unknown Storazzo::RicDiskStatsFile.default_name 1!!" if Storazzo::RicDiskStatsFile.default_name.nil?
128
+
129
+ Storazzo::RicDiskStatsFile.default_name
130
+ end
131
+
132
+ def stats_filename_default_fullpath # if not writeable we need to pick another from stats_file_smart_fullpath()
133
+ # REDUNDANT, should use stats_file_smart_fullpath instead except on the writeable? part since it would go recursive otherwise.
134
+ my_stats_filename = self.default_stats_filename
135
+ # raise "Unknown Storazzo::RicDiskStatsFile.default_name 2 !!" if Storazzo::RicDiskStatsFile.default_name.nil?
136
+ "#{local_mountpoint}/#{my_stats_filename}"
137
+ end
138
+
139
+ def validate(opts = {})
140
+ verbose = opts.fetch(:verbose, true)
141
+ puts "[VERBOSE] validate(): We're trying to see if your object is valid, across 3 possible sub-classes." if verbose
142
+ # 1. check for
143
+ raise "Unknown local mount " unless local_mount.is_a?(String)
144
+
145
+ # 2. check thaty writeable? is true or false
146
+ my_writeable = wr
147
+ raise "Writeable is not boolean" unless (my_writeable.is_a? TrueClass or my_writeable.is_a? FalseClass)
148
+ end
149
+
150
+ # TODO use a proper Factory pattern.
151
+ def self.DirFactory(path)
152
+ raise "I need a path/directory string: #{path}" unless path.is_a?(String)
153
+
154
+ deb "TODO: if coincides with MountPoint, instance THAT"
155
+ # if path in Storazzo::Media::MountPoint.list_all_mount_points
156
+ # then return ...
157
+ if path =~ /^gs:\/\//
158
+ deb "Smells like GCS"
159
+ return GcsBucket.new(path)
160
+ end
161
+ deb "Smells like LocalFolder :)"
162
+ return LocalFolder.new(path)
153
163
  end
164
+ end
154
165
  end
@@ -1,57 +1,58 @@
1
1
  module Storazzo::Media
2
+ class Storazzo::RicDisk::GcsBucket
3
+ extend Storazzo::Common
2
4
 
3
- class Storazzo::RicDisk::GcsBucket
4
-
5
- extend Storazzo::Common
6
-
7
- attr_accessor :project_id
8
-
9
- def initialize(local_mount, project_id=nil)
10
- deb "[Storazzo::Media::GcsBucket] initialize"
11
-
12
- @local_mountpoint = File.expand_path(local_mount)
13
- @description = "MountPoint in '#{local_mount}' pointing at TODO with mount options = TODO"
14
- @project_id = project_id
15
- raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
16
- @wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
17
- super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
18
- end
19
-
20
- def self.list_all(config=nil)
21
- # get lisrts from Config singletone
22
- #puts " self.list_all: loading config "
23
- config ||= Storazzo::RicDiskConfig.instance # # ).get_config
24
-
25
- config.load # in case I need to load it for the first time
26
- #puts config['Config']['AdditionalMountDirs']
27
- #puts "TODO see config: #{config}"
28
- #[42, 43]
29
- #deb config.get_local_folders
30
- # TODO
31
- pverbose true, "TODO(ricc): also add gsutil ls. For that please use the new 'list_all_with_type' (Id refactor it but Im afraid of leaving bad code dangling so before a proper refactor lets implement both side by side"
32
- config.get_bucket_paths
33
- end
34
- def self.list_all_with_type(config=nil)
35
- config ||= Storazzo::RicDiskConfig.instance
36
- config.load # in case I need to load it for the first time
37
- deb "TODO(ricc): also add gsutil ls"
38
- # getFromConfig
39
- deb "I'm now returning a 'complex' array to tell the caller what kind of element they're getting, eg: GCS from Config Yaml, vs GCS from gsutil ls "
40
- list_from_config_with_type = config.get_bucket_paths.map{|path| [:config_gcs_bucket, path] }
41
- if (config.project_id)
42
- # so I concatenate Apples with Bananas with names
43
- return list_from_config_with_type + list_available_buckets(config.project_id).map{|path| [:gsutil_ls_gcs_bucket, path] }
44
- end
45
- return list_from_config_with_type
46
- end
47
-
48
- def self.list_available_buckets(project_id, opts={})
49
- list_of_buckets = `gsutil ls --project '#{project_id}'`.chomp.split("\n")
50
- deb "list_of_buckets: #{list_of_buckets}"
51
- list_of_buckets
52
- end
5
+ attr_accessor :project_id
53
6
 
7
+ def initialize(local_mount, project_id = nil)
8
+ deb "[Storazzo::Media::GcsBucket] initialize"
54
9
 
10
+ @local_mountpoint = File.expand_path(local_mount)
11
+ @description = "MountPoint in '#{local_mount}' pointing at TODO with mount options = TODO"
12
+ @project_id = project_id
13
+ raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
14
+
15
+ @wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
16
+ super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
17
+ end
18
+
19
+ def self.list_all(config = nil)
20
+ # get lisrts from Config singletone
21
+ # puts " self.list_all: loading config "
22
+ config ||= Storazzo::RicDiskConfig.instance # # ).get_config
23
+
24
+ config.load # in case I need to load it for the first time
25
+ # puts config['Config']['AdditionalMountDirs']
26
+ # puts "TODO see config: #{config}"
27
+ # [42, 43]
28
+ # deb config.get_local_folders
29
+ # TODO
30
+ pverbose true,
31
+ "TODO(ricc): also add gsutil ls. For that please use the new 'list_all_with_type' (Id refactor it but Im afraid of leaving bad code dangling so before a proper refactor lets implement both side by side"
32
+ config.get_bucket_paths
55
33
  end
56
34
 
57
- end
35
+ def self.list_all_with_type(config = nil)
36
+ config ||= Storazzo::RicDiskConfig.instance
37
+ config.load # in case I need to load it for the first time
38
+ deb "TODO(ricc): also add gsutil ls"
39
+ # getFromConfig
40
+ deb "I'm now returning a 'complex' array to tell the caller what kind of element they're getting, eg: GCS from Config Yaml, vs GCS from gsutil ls "
41
+ list_from_config_with_type = config.get_bucket_paths.map { |path| [:config_gcs_bucket, path] }
42
+ if (config.project_id)
43
+ # so I concatenate Apples with Bananas with names
44
+ return list_from_config_with_type + list_available_buckets(config.project_id).map { |path|
45
+ [:gsutil_ls_gcs_bucket, path]
46
+ }
47
+ end
48
+
49
+ return list_from_config_with_type
50
+ end
51
+
52
+ def self.list_available_buckets(project_id, opts = {})
53
+ list_of_buckets = `gsutil ls --project '#{project_id}'`.chomp.split("\n")
54
+ deb "list_of_buckets: #{list_of_buckets}"
55
+ list_of_buckets
56
+ end
57
+ end
58
+ end
@@ -1,49 +1,48 @@
1
- #require "storazzo/ric_disk/abstract_ric_disk"
2
- #require "abstract_ric_disk"
1
+ # require "storazzo/ric_disk/abstract_ric_disk"
2
+ # require "abstract_ric_disk"
3
3
 
4
4
  module Storazzo::Media
5
- class Storazzo::Media::LocalFolder < Storazzo::Media::AbstractRicDisk
6
- #extend Storazzo::Common
7
- include Storazzo::Common
8
-
9
- attr_accessor :local_mountpoint, :wr
10
-
11
- def initialize(local_mount)
12
- deb "[Storazzo::Media::LocalFolder] initialize"
13
-
14
- @local_mountpoint = File.expand_path(local_mount)
15
- @description = "Local Folder originally in '#{local_mount}'"
16
- raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
17
- @wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
18
- #super.initialize(local_mount) rescue "SUPER_ERROR: #{$!}"
19
- super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
20
- end
21
-
22
- def self.list_all(config=nil)
23
- # get lists from Config singleton
24
- config ||= Storazzo::RicDiskConfig.instance # # ).get_config
25
- config.load
26
- config.get_local_folders
27
- end
28
-
29
- def parse(opts={})
30
- puts "LF.parse(#{opts}): TODO Sbrodola inside the dir: #{local_mountpoint}"
31
- parse_block_storage_folder()
32
- end
33
-
34
- def path
35
- @local_mountpoint
36
- end
37
-
38
- def writeable?
39
- File.writable?(@local_mountpoint)
40
- end
41
-
42
- def default_stats_filename
43
- #'42'
44
- Storazzo::RicDiskStatsFile.default_name
45
- end
5
+ class Storazzo::Media::LocalFolder < Storazzo::Media::AbstractRicDisk
6
+ # extend Storazzo::Common
7
+ include Storazzo::Common
46
8
 
9
+ attr_accessor :local_mountpoint, :wr
10
+
11
+ def initialize(local_mount)
12
+ deb "[Storazzo::Media::LocalFolder] initialize"
13
+
14
+ @local_mountpoint = File.expand_path(local_mount)
15
+ @description = "Local Folder originally in '#{local_mount}'"
16
+ raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
17
+
18
+ @wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
19
+ # super.initialize(local_mount) rescue "SUPER_ERROR: #{$!}"
20
+ super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
21
+ end
22
+
23
+ def self.list_all(config = nil)
24
+ # get lists from Config singleton
25
+ config ||= Storazzo::RicDiskConfig.instance # # ).get_config
26
+ config.load
27
+ config.get_local_folders
28
+ end
29
+
30
+ def parse(opts = {})
31
+ puts "LF.parse(#{opts}): TODO Sbrodola inside the dir: #{local_mountpoint}"
32
+ parse_block_storage_folder()
33
+ end
34
+
35
+ def path
36
+ @local_mountpoint
47
37
  end
48
38
 
49
- end
39
+ def writeable?
40
+ File.writable?(@local_mountpoint)
41
+ end
42
+
43
+ def default_stats_filename
44
+ # '42'
45
+ Storazzo::RicDiskStatsFile.default_name
46
+ end
47
+ end
48
+ end
@@ -1,16 +1,15 @@
1
1
  # TODO
2
2
  module Storazzo::Media
3
- class Storazzo::Media::MountPoint < Storazzo::Media::AbstractRicDisk
4
- #puts "[REMOVEME] Storazzo::Media::MountPoint being read. REMOVEME when you see this :)"
3
+ class Storazzo::Media::MountPoint < Storazzo::Media::AbstractRicDisk
4
+ # puts "[REMOVEME] Storazzo::Media::MountPoint being read. REMOVEME when you see this :)"
5
5
 
6
-
7
- def self.list_local_mount_points()
8
- deb "Maybe its abuot time you refactor that method here :)"
9
- RicDisk.interesting_mount_points()
10
- end
6
+ def self.list_local_mount_points()
7
+ deb "Maybe its abuot time you refactor that method here :)"
8
+ RicDisk.interesting_mount_points()
11
9
  end
10
+ end
12
11
  end
13
12
 
14
13
  # def writeable?
15
- #File.writable?(@local_mountpoint)
16
- #end
14
+ # File.writable?(@local_mountpoint)
15
+ # end