storazzo 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -4
  3. data/Makefile +20 -1
  4. data/README.md +23 -0
  5. data/Rakefile +35 -8
  6. data/VERSION +1 -1
  7. data/bin/hello-storazzo +5 -0
  8. data/bin/ricdisk-magic +50 -57
  9. data/bin/stats-with-md5 +268 -297
  10. data/lib/storazzo/colors.rb +43 -45
  11. data/lib/storazzo/common.rb +80 -17
  12. data/lib/storazzo/debug.rb +5 -8
  13. data/lib/storazzo/hashify.rb +44 -43
  14. data/lib/storazzo/main.rb +44 -40
  15. data/lib/storazzo/media/abstract_ric_disk.rb +163 -104
  16. data/lib/storazzo/media/gcs_bucket.rb +51 -15
  17. data/lib/storazzo/media/local_folder.rb +43 -46
  18. data/lib/storazzo/media/mount_point.rb +12 -2
  19. data/lib/storazzo/ric_disk.rb +223 -251
  20. data/lib/storazzo/ric_disk_config.rb +230 -193
  21. data/lib/storazzo/ric_disk_sample_config.rb +12 -16
  22. data/lib/storazzo/ric_disk_statsfile.rb +17 -16
  23. data/lib/storazzo/ric_disk_ugly.rb +35 -38
  24. data/lib/storazzo/version.rb +7 -7
  25. data/lib/storazzo.rb +34 -29
  26. data/storazzo.gemspec +22 -20
  27. data/test/media/test_abstract_ric_disk.rb +19 -0
  28. data/test/media/test_gcs_bucket.rb +58 -0
  29. data/test/media/test_local_folder.rb +145 -0
  30. data/test/media/test_mount_point.rb +25 -0
  31. data/test/test_ric_disk.rb +16 -0
  32. data/test/test_ric_disk_config.rb +20 -29
  33. data/test/test_ric_disk_stats_file.rb +13 -14
  34. data/test/test_storazzo.rb +26 -26
  35. data/var/dumps/file_stat.linux.yaml +15 -0
  36. data/var/dumps/file_stat.macosx.yaml +15 -0
  37. data/var/test/disks/disk02-full/Rakefile +13 -0
  38. data/var/test/disks/ricdisk_stats_v11.rds +11 -0
  39. metadata +38 -10
  40. data/test/test_gcs_bucket.rb +0 -70
  41. data/test/test_local_folder.rb +0 -121
@@ -1,106 +1,165 @@
1
1
  module Storazzo::Media
2
- class Storazzo::Media::AbstractRicDisk
3
-
4
- #@@default_stats_filename = Storazzo::RicDiskStatsFile.default_name
5
-
6
- # looks like there's not Abstract Class in Ruby, but also SO says he best
7
- # way to do this is this:
8
-
9
- # attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
10
-
11
- ########################
12
- # Abstract methods START
13
- ########################
14
- def initialize(local_mount)
15
- puts "[DEB] [AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore..
16
- validate
17
- end
18
- def self.list_all
19
- raise "[AbstractRicDiskc::self.list_all] You should override this, says StackOverflow and Riccardo"
20
- end
21
- def parse(opts={})
22
- raise "[AbstractRicDiskc::parse] You should override this, says StackOverflow and Riccardo"
23
- end
24
- def writeable?
25
- raise "[AbstractRicDiskc::writeable] You should override this in #{self.class}, says StackOverflow and Riccardo"
26
- end
27
- def get_local_mountpoint
28
- #raise "[AbstractRicDiskc::get_local_mountpoint] You should override this, says StackOverflow and Riccardo"
29
- raise "You forgot to set local_mountpoint in the constructor for your class, you cheeky little one!" if local_mountpoint.nil?
30
- local_mountpoint
31
- end
32
- def check_implemented_correctly
33
- # raise "[AbstractRicDiskc] You should override this, says StackOverflow and Riccardo"
34
- raise "no @local_mountpoint" unless exists?(@local_mountpoint)
35
- end
36
- ########################
37
- # Abstract methods END
38
- ########################
39
-
40
-
41
-
42
- ########################
43
- # Automated methods now...
44
- ########################
45
- def stats_file_smart_fullpath # stats_file_default_location()
46
- # if its writeable... if not we'll think about it later.
47
- if writeable?
48
- return "#{get_local_mountpoint}/#{self.default_stats_filename}"
49
- else
50
- # if not writeable, I will:
51
- # 1. create a dir based on its unique format.
52
- # 2. create a file of same look and feel (alternative - used a DASH)
53
- return "{get_local_folder}/#{unique_id}::#{self.default_stats_filename}"
54
- #"{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}"
55
- end
56
- end
57
- # Needs to be some unique id based on its thingy, but might change in the future:
58
- # Solutions:
59
- # {PHILOSOPHY}::{ID}
60
- def unique_id
61
- # Expand path to make it as unique as possible...
62
- hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
63
- "MD5::v1::#{hash}"
64
- end
65
-
66
- # # Todo check on instances these 3 methods exist
67
- def self.abstract_class_mandatory_methods
68
- %W{
69
- self.list_all
70
- local_mountpoint
71
- parse
72
- writeable?
73
- }
74
- end
75
-
76
- # Putting here since its same code for MountPoint or generic folder.
77
- def parse_block_storage_folder(opts={})
78
- #Storazzo::RicDiskUgly.calculate_stats_files(get_local_mountpoint)
79
- Storazzo::RicDisk.calculate_stats_files(get_local_mountpoint, opts)
80
- #return "42"
81
- end
82
-
83
- def self.default_stats_filename
84
- raise "Unknown Storazzo::RicDiskStatsFile.default_name 1!!" if Storazzo::RicDiskStatsFile.default_name.nil?
85
- Storazzo::RicDiskStatsFile.default_name
86
- end
87
-
88
- def stats_filename_default_fullpath # if not writeable we need to pick another from stats_file_smart_fullpath()
89
- # REDUNDANT, should use stats_file_smart_fullpath instead except on the writeable? part since it would go recursive otherwise.
90
- my_stats_filename = self.default_stats_filename
91
- #raise "Unknown Storazzo::RicDiskStatsFile.default_name 2 !!" if Storazzo::RicDiskStatsFile.default_name.nil?
92
- "#{local_mountpoint}/#{my_stats_filename}"
93
- end
94
-
95
- def validate
96
- puts "DEB We're trying to see if your object is valid, across 3 possible sub-classes."
97
- #1. check for
98
- raise "Unknown local mount " unless local_mount.is_a?(String)
99
- #2. check thaty writeable? is true or false
100
- my_writeable = wr
101
- raise "Writeable is not boolean" unless (my_writeable.is_a? TrueClass or my_writeable.is_a? FalseClass )
102
- end
103
- end
104
- #puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD inside module"
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)
163
+ end
164
+ end
105
165
  end
106
- #puts "DEB lib/storazzo/media/abstract_ric_disk Media::ARD outside module"
@@ -1,22 +1,58 @@
1
1
  module Storazzo::Media
2
+ class Storazzo::RicDisk::GcsBucket
3
+ extend Storazzo::Common
2
4
 
3
- class Storazzo::RicDisk::GcsBucket
5
+ attr_accessor :project_id
4
6
 
5
-
6
- def self.list_all(config=nil)
7
- # get lisrts from Config singletone
8
- #puts " self.list_all: loading config "
9
- config ||= Storazzo::RicDiskConfig.instance # # ).get_config
10
-
11
- config.load # in case I need to load it for the first time
12
- #puts config['Config']['AdditionalMountDirs']
13
- #puts "TODO see config: #{config}"
14
- #[42, 43]
15
- #deb config.get_local_folders
16
- config.get_bucket_paths
17
- end
7
+ def initialize(local_mount, project_id = nil)
8
+ deb "[Storazzo::Media::GcsBucket] initialize"
18
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)
19
14
 
15
+ @wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
16
+ super(local_mount) rescue "SUPER_ERROR(#{local_mount}): #{$!}"
20
17
  end
21
18
 
22
- end
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
33
+ end
34
+
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,51 +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
-
7
- attr_accessor :local_mountpoint, :wr
8
-
9
- def initialize(local_mount)
10
- puts "[Storazzo::Media::LocalFolder] initialize"
11
-
12
- @local_mountpoint = File.expand_path(local_mount)
13
- raise "Sorry local mount doesnt exist!" unless File.exist?(@local_mountpoint)
14
- @wr = File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath
15
-
16
- #super.initialize(local_mount) rescue "SUPER_ERROR: #{$!}"
17
- super(local_mount) rescue "SUPER_ERROR: #{$!}"
18
- end
19
-
20
- def self.list_all
21
- # get lisrts from Config singletone
22
- #puts " self.list_all: loading config "
23
- config = Storazzo::RicDiskConfig.instance # # ).get_config
24
- #puts config['Config']['AdditionalMountDirs']
25
- #puts "TODO see config: #{config}"
26
- #[42, 43]
27
- #deb config.get_local_folders
28
- config.get_local_folders
29
- end
30
-
31
- def parse(opts={})
32
- puts "LF.parse(#{opts}): TODO Sbrodola inside the dir: #{local_mountpoint}"
33
- parse_block_storage_folder()
34
- end
35
-
36
- def path
37
- @local_mountpoint
38
- end
39
-
40
- def writeable?
41
- File.writable?(@local_mountpoint)
42
- end
43
-
44
- def default_stats_filename
45
- #'42'
46
- Storazzo::RicDiskStatsFile.default_name
47
- end
5
+ class Storazzo::Media::LocalFolder < Storazzo::Media::AbstractRicDisk
6
+ # extend Storazzo::Common
7
+ include Storazzo::Common
48
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
49
37
  end
50
38
 
51
- 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,5 +1,15 @@
1
1
  # TODO
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 :)"
5
+
6
+ def self.list_local_mount_points()
7
+ deb "Maybe its abuot time you refactor that method here :)"
8
+ RicDisk.interesting_mount_points()
9
+ end
10
+ end
11
+ end
2
12
 
3
13
  # def writeable?
4
- #File.writable?(@local_mountpoint)
5
- #end
14
+ # File.writable?(@local_mountpoint)
15
+ # end