cwb 0.1.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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +49 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +31 -0
  9. data/Rakefile +8 -0
  10. data/bin/cwb +4 -0
  11. data/cwb.gemspec +31 -0
  12. data/lib/cwb/benchmark.rb +22 -0
  13. data/lib/cwb/benchmark_suite.rb +35 -0
  14. data/lib/cwb/cli.rb +18 -0
  15. data/lib/cwb/client.rb +138 -0
  16. data/lib/cwb/config.rb +54 -0
  17. data/lib/cwb/directory_parser.rb +60 -0
  18. data/lib/cwb/directory_suite_parser.rb +30 -0
  19. data/lib/cwb/file_parser.rb +32 -0
  20. data/lib/cwb/parser.rb +40 -0
  21. data/lib/cwb/parser_factory.rb +17 -0
  22. data/lib/cwb/version.rb +3 -0
  23. data/lib/cwb.rb +19 -0
  24. data/lib/hash_extension.rb +27 -0
  25. data/lib/inflection.rb +13 -0
  26. data/node.yml +10 -0
  27. data/spec/cwb/benchmark_spec.rb +22 -0
  28. data/spec/cwb/cli_spec.rb +53 -0
  29. data/spec/cwb/client_spec.rb +33 -0
  30. data/spec/cwb_spec.rb +7 -0
  31. data/spec/data/benchmarks/benchmarks.txt +5 -0
  32. data/spec/data/benchmarks/disabled/disabled.rb +7 -0
  33. data/spec/data/benchmarks/my-disabled-suite/my_disabled_suite.rb +7 -0
  34. data/spec/data/benchmarks/node.rb +15 -0
  35. data/spec/data/benchmarks/node.yml +11 -0
  36. data/spec/data/benchmarks/shell-example/shell_example.rb +11 -0
  37. data/spec/data/benchmarks/sysbench/metrics.csv +3 -0
  38. data/spec/data/benchmarks/sysbench/node.yml +10 -0
  39. data/spec/data/benchmarks/sysbench/sysbench.rb +19 -0
  40. data/spec/data/benchmarks-suite/benchmark_suite.txt +3 -0
  41. data/spec/data/benchmarks-suite/benchmarks.txt +3 -0
  42. data/spec/data/benchmarks-suite/disabled/disabled.rb +7 -0
  43. data/spec/data/benchmarks-suite/my-custom-benchmark/my_custom_benchmark.rb +11 -0
  44. data/spec/data/benchmarks-suite/my-custom-suite/my_custom_suite.rb +14 -0
  45. data/spec/data/benchmarks-suite/my-disabled-suite/my_disabled_suite.rb +7 -0
  46. data/spec/data/benchmarks-suite/shell-example/shell_example.rb +11 -0
  47. data/spec/data/benchmarks-suite/sysbench/sysbench.rb +11 -0
  48. data/spec/hash_spec.rb +43 -0
  49. data/spec/spec_helper.rb +35 -0
  50. metadata +242 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 563d71bbe20f53566a06c0629a80ce6e33db05a1
4
+ data.tar.gz: 38e305e7cdfe54117c905894be79b6dbaf7507f7
5
+ SHA512:
6
+ metadata.gz: 832d40d55657589d91d9963e676dd361e6ce989bdcd7b732a7a1fa993be1c702dc188ed71e15103f5bf9cb2122f87426e5d5f1f9fa5e0b78fc230b1a09878c6c
7
+ data.tar.gz: 356ce42953d81ada654d99e51f7aa6d52300b9e4b8686df98ecb714a5787aedb38af16998401820cd6a3324b0908fd96a52b2bae806f3c1e6e4a25b01ff90b38
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ # Run the tests with console colored output
2
+ --color
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (2015-04-25)
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cwb.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,49 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
33
+ # * 'just' rspec: 'rspec'
34
+
35
+ guard :rspec, cmd: "bundle exec rspec" do
36
+ require "guard/rspec/dsl"
37
+ dsl = Guard::RSpec::Dsl.new(self)
38
+
39
+ # RSpec files
40
+ rspec = dsl.rspec
41
+ watch(rspec.spec_helper) { rspec.spec_dir }
42
+ watch(rspec.spec_support) { rspec.spec_dir }
43
+ watch(rspec.spec_files)
44
+
45
+ # Ruby files
46
+ ruby = dsl.ruby
47
+ dsl.watch_spec_files_for(ruby.lib_files)
48
+
49
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Joel Scheuner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Cloud WorkBench Client (CWB Client)
2
+
3
+ Command line utility [cwb-client] acts as the client library in cloud VMs and allows for local testing (if not configured against a cwb-server).
4
+ CWB Client helps you implement your own suites of benchmarks and optionally integrates them with the CWB framework.
5
+ See https://github.com/sealuzh/cloud-workbench
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'cwb'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cwb
20
+
21
+ ## Usage
22
+
23
+ See `Cwb::Client` Yardoc
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/cwb/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
8
+ task :test => :spec
data/bin/cwb ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "cwb"
4
+ Cwb::Cli.start(ARGV)
data/cwb.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cwb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cwb"
8
+ spec.version = Cwb::VERSION
9
+ spec.executables << 'cwb'
10
+ spec.authors = ["Joel Scheuner"]
11
+ spec.email = ["joel.scheuner.dev@gmail.com"]
12
+ spec.summary = %q{Provides Cloud WorkBench (CWB) infrastructure for cloud VMs and local testing.}
13
+ spec.homepage = "https://github.com/sealuzh/cloud-workbench"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor", "~> 0.19"
22
+ spec.add_runtime_dependency "faraday", "~> 0.9.1"
23
+ spec.add_runtime_dependency "faraday_middleware", "~> 0.9.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "rspec", "~> 3.2"
29
+ spec.add_development_dependency "simplecov", "~> 0.9"
30
+ spec.add_development_dependency "guard-rspec", "~> 4.5"
31
+ end
@@ -0,0 +1,22 @@
1
+ require "cwb/client"
2
+
3
+ module Cwb
4
+ class Benchmark
5
+ def initialize(working_dir = Dir.pwd)
6
+ @cwb = Cwb::Client.instance
7
+ @working_dir = working_dir
8
+ end
9
+
10
+ def execute_in_working_dir
11
+ Dir.chdir @working_dir do
12
+ execute
13
+ end
14
+ end
15
+
16
+ # Intended to override
17
+ # @api
18
+ def execute
19
+ # Empty benchmarks do nothing
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module Cwb
2
+ class BenchmarkSuite
3
+ def initialize(working_dir = Dir.pwd)
4
+ @cwb = Cwb::Client.instance
5
+ @working_dir = working_dir
6
+ end
7
+
8
+ def execute_suite(cwb_benchmarks)
9
+ execute_all(cwb_benchmarks)
10
+ @cwb.notify_finished_execution
11
+ rescue => error
12
+ @cwb.notify_failed_execution(error.message)
13
+ raise error
14
+ end
15
+
16
+ def execute_all(cwb_benchmarks)
17
+ cwb_benchmarks.each do |cwb_benchmark|
18
+ cwb_benchmark.execute_in_working_dir
19
+ end
20
+ end
21
+
22
+ # Lookup the implementation of a certain benchmark
23
+ def get(clazz, cwb_benchmarks)
24
+ cwb_benchmarks.select{|cwb_benchmark| cwb_benchmark.instance_of?(clazz) }.first
25
+ end
26
+
27
+ def get_list(clazzes, cwb_benchmarks)
28
+ list = []
29
+ clazzes.each do |clazz|
30
+ list << get(clazz, cwb_benchmarks)
31
+ end
32
+ list
33
+ end
34
+ end
35
+ end
data/lib/cwb/cli.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "thor"
2
+ require "cwb/parser_factory"
3
+
4
+ module Cwb
5
+ class Cli < Thor
6
+ desc "execute BENCHMARK_FILE|BENCHMARK_DIRECTORY", "execute a benchmark or an entire collection of benchmark in a given directory with cwb"
7
+ option :aliases => :e
8
+ def execute(path)
9
+ Cwb::ParserFactory.build(path).execute
10
+ end
11
+
12
+ desc "validates BENCHMARK_FILE|BENCHMARK_DIRECTORY", "performs basic validation of the class files and directory structure."
13
+ option :aliases => :v
14
+ def validate(path)
15
+ Cwb::ParserFactory.build(path).validate
16
+ end
17
+ end
18
+ end
data/lib/cwb/client.rb ADDED
@@ -0,0 +1,138 @@
1
+ require "singleton"
2
+ require "csv"
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "cwb/config"
6
+
7
+ module Cwb
8
+ # Serves as cwb-server client library in cloud VMs (if configured against a cwb-server)
9
+ # or as standalone utility otherwise where cwb-server communication (e.g., metric submission)
10
+ # is logged to stdout.
11
+ # @api
12
+ class Client
13
+ include Singleton
14
+
15
+ # RESTful endpoints
16
+ VM_INSTANCE = "virtual_machine_instances"
17
+ METRIC_OBSERVATIONS = "metric_observations"
18
+
19
+ # Reconfigures the Client with a configuration object against a cwb-server.
20
+ # @api private
21
+ # @return [void]
22
+ def reconfigure(config)
23
+ @config = config
24
+ if @config.complete?
25
+ @connection = Faraday.new(:url => "http://#{@config.server}") do |f|
26
+ f.request :multipart
27
+ f.request :json
28
+ f.adapter Faraday.default_adapter
29
+ end
30
+ end
31
+ end
32
+
33
+ # Securly access nested attributes.
34
+ # @example Acess benchmark attribute hash
35
+ # @cwb.deep_fetch("sysbench", "cli_options")
36
+ # @example Access node attribute (collected by ohai)
37
+ # @cwb.deep_fetch("cpu", "0", "model_name")
38
+ # @return [String] an empty string if attribute cannot be found
39
+ def deep_fetch(*keys)
40
+ @config.deep_fetch(*keys)
41
+ end
42
+
43
+ # Submit a single metric
44
+ # @param metric_definition_id [String] the name of the CWB metric
45
+ # @param time [Integer] the UNIX timestamp when the metric was captured
46
+ # @param value [String (nominal-scale) or Numeric (otherwise)] the value of the metric
47
+ # @return [void]
48
+ def submit_metric(metric_definition_id, time, value)
49
+ if @config.complete?
50
+ submit_remote_metric(metric_definition_id, time, value)
51
+ else
52
+ puts "#{metric_definition_id},#{time},#{value}"
53
+ end
54
+ end
55
+
56
+ # Submit a csv file with metrics
57
+ # @param metric_definition_id [String] the name of the CWB metric
58
+ # @param csv_file [String] the path to the csv file containing the metrics
59
+ # @note the csv file must:
60
+ # * have two columns: 'time' [Integer], 'value' [String (nominal-scale) or Numeric (otherwise)]
61
+ # * be formatted without headers
62
+ # @return [void]
63
+ def submit_metrics(metric_definition_id, csv_file)
64
+ if @config.complete?
65
+ submit_remote_metrics(metric_definition_id, csv_file)
66
+ else
67
+ CSV.foreach(csv_file) do |row|
68
+ puts row.join(',')
69
+ end
70
+ end
71
+ end
72
+
73
+ # Notifies the cwb-server that the benchmark successfully completed.
74
+ # @note The cwb-server will shutdown all VMs of this executions.
75
+ # @return [void]
76
+ def notify_finished_execution
77
+ if @config.complete?
78
+ post_notify("/#{VM_INSTANCE}/complete_postprocessing", true)
79
+ else
80
+ puts "Notify finished postprocessing."
81
+ end
82
+ end
83
+
84
+ # Notifies the cwb-server that the benchmark failed during the execution
85
+ # @note The cwb-server will shutdown all VMs of this execution after a timeout (~15').
86
+ # @return [void]
87
+ def notify_failed_execution(message = "")
88
+ if @config.complete?
89
+ post_notify("/#{VM_INSTANCE}/complete_benchmark", false, message)
90
+ else
91
+ puts "Notify failure on running. (message suppressed to avoid redundant logging)"
92
+ end
93
+ end
94
+
95
+
96
+ private
97
+
98
+ # Create a standalone instance with an empty config per default
99
+ def initialize
100
+ @config = Cwb::Config.new
101
+ end
102
+
103
+ def submit_remote_metric(metric_definition_id, time, value)
104
+ body = {
105
+ :metric_observation => {
106
+ metric_definition_id: metric_definition_id,
107
+ provider_name: @config.provider_name,
108
+ provider_instance_id: @config.provider_instance_id,
109
+ time: time,
110
+ value: value
111
+ }
112
+ }
113
+ @connection.post "/#{METRIC_OBSERVATIONS}", body
114
+ end
115
+
116
+ def submit_remote_metrics(metric_definition_id, csv_file)
117
+ payload = {
118
+ metric_observation: {
119
+ metric_definition_id: metric_definition_id,
120
+ provider_name: @config.provider_name,
121
+ provider_instance_id: @config.provider_instance_id,
122
+ file: Faraday::UploadIO.new(csv_file, 'text/csv')
123
+ }
124
+ }
125
+ @connection.post "/#{METRIC_OBSERVATIONS}/import", payload
126
+ end
127
+
128
+ def post_notify(path, success = true, message = "", opts = {})
129
+ body = {
130
+ provider_name: @config.provider_name,
131
+ provider_instance_id: @config.provider_instance_id,
132
+ success: success.to_s,
133
+ message: message,
134
+ }.merge(opts)
135
+ @connection.post path, body
136
+ end
137
+ end
138
+ end
data/lib/cwb/config.rb ADDED
@@ -0,0 +1,54 @@
1
+ require "yaml"
2
+
3
+ module Cwb
4
+ class Config
5
+ attr_accessor :node
6
+
7
+ def self.exists_in_dir?(dir)
8
+ File.exists?(self.config_file(dir))
9
+ end
10
+
11
+ def self.from_dir(dir)
12
+ self.from_file(self.config_file(dir))
13
+ end
14
+
15
+ def self.from_file(file)
16
+ self.new(YAML.load_file(file))
17
+ end
18
+
19
+ def initialize(node = {})
20
+ @node = node
21
+ end
22
+
23
+ def deep_fetch(*keys)
24
+ @node.deep_fetch(*keys, default: '')
25
+ end
26
+
27
+ # Determines whether all strictly required attributes
28
+ # that are necessary for communication with the cwb-server
29
+ # are available.
30
+ def complete?
31
+ args = [server, provider_name, provider_instance_id]
32
+ args.map { |value| value.empty? }.none?
33
+ end
34
+
35
+ def server
36
+ deep_fetch("cwb", "server")
37
+ end
38
+
39
+ def provider_name
40
+ deep_fetch("benchmark", "provider_name")
41
+ end
42
+
43
+ def provider_instance_id
44
+ deep_fetch("benchmark", "provider_instance_id")
45
+ end
46
+
47
+
48
+ private
49
+
50
+ def self.config_file(dir)
51
+ File.join(dir, "node.yml")
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,60 @@
1
+ require "cwb/parser"
2
+ require "cwb/benchmark_suite"
3
+
4
+ module Cwb
5
+ class DirectoryParser < Parser
6
+ def validate
7
+ check_file_exists(benchmarks_file_path)
8
+ require_all(read_lines(benchmarks_file_path))
9
+ end
10
+
11
+ def delegate_execution
12
+ cwb_benchmarks = init_classes(read_lines(benchmarks_file_path))
13
+ benchmark_suite.execute_suite(cwb_benchmarks)
14
+ end
15
+
16
+ private
17
+
18
+ def read_lines(file)
19
+ benchmarks = []
20
+ File.readlines(file).each do |line|
21
+ stripped = line.strip
22
+ benchmarks << stripped unless stripped.empty?
23
+ end
24
+ benchmarks
25
+ end
26
+
27
+ def init_classes(benchmarks)
28
+ cwb_benchmarks = []
29
+ benchmarks.each do |benchmark|
30
+ stripped_benchmark = benchmark
31
+ cwb_benchmarks << Cwb.const_get(benchmark_class_name(stripped_benchmark)).new(working_dir(stripped_benchmark))
32
+ end
33
+ cwb_benchmarks
34
+ end
35
+
36
+ def working_dir(benchmark)
37
+ File.join(@path, benchmark)
38
+ end
39
+
40
+ def benchmark_class_name(benchmark)
41
+ benchmark.underscore.camelize
42
+ end
43
+
44
+ def require_all(benchmarks)
45
+ benchmarks.each do |benchmark|
46
+ class_file = benchmark_file(benchmark)
47
+ check_file_exists(class_file)
48
+ require class_file
49
+ end
50
+ end
51
+
52
+ def benchmark_file(benchmark)
53
+ File.join(@path, benchmark, "#{benchmark.underscore}.rb")
54
+ end
55
+
56
+ def benchmarks_file_path
57
+ File.join(@path, "benchmarks.txt")
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ require "cwb/directory_parser"
2
+
3
+ module Cwb
4
+ class DirectorySuiteParser < DirectoryParser
5
+ def self.suite_file_present?(path)
6
+ File.exists?(self.suite_file_path(path)) && !File.read(self.suite_file_path(path)).empty?
7
+ end
8
+
9
+ # Suite file does definitely exist, otherwise the usual
10
+ # direcoy parser implementation would have been chosen instead.
11
+ def validate
12
+ super
13
+ require_all(read_lines(suite_file_path))
14
+ end
15
+
16
+ def benchmark_suite
17
+ init_classes(read_lines(suite_file_path)).first
18
+ end
19
+
20
+ private
21
+
22
+ def self.suite_file_path(path)
23
+ File.join(path, "benchmark_suite.txt")
24
+ end
25
+
26
+ def suite_file_path
27
+ self.class.suite_file_path(@path)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ require "cwb/parser"
2
+
3
+ module Cwb
4
+ class FileParser < Parser
5
+ def initialize(path)
6
+ super(path)
7
+ init_config(parent_dir)
8
+ init_config(working_dir)
9
+ end
10
+
11
+ def delegate_execution
12
+ filename = File.basename(@path, ".rb")
13
+ class_name = filename.camelize
14
+ cwb_benchmark = Cwb.const_get(class_name).new(working_dir)
15
+ benchmark_suite.execute_suite([cwb_benchmark])
16
+ end
17
+
18
+ def validate
19
+ check_file_exists(@path)
20
+ require @path
21
+ end
22
+
23
+ private
24
+ def working_dir
25
+ File.dirname(@path)
26
+ end
27
+
28
+ def parent_dir
29
+ File.dirname(working_dir)
30
+ end
31
+ end
32
+ end
data/lib/cwb/parser.rb ADDED
@@ -0,0 +1,40 @@
1
+ module Cwb
2
+ class Parser
3
+ def initialize(path)
4
+ @path = File.expand_path(path)
5
+ init_config(@path)
6
+ end
7
+
8
+ def init_config(dir)
9
+ if Cwb::Config.exists_in_dir?(dir)
10
+ config = Cwb::Config.from_dir(dir)
11
+ Cwb::Client.instance.reconfigure(config)
12
+ end
13
+ end
14
+
15
+ def execute
16
+ validate
17
+ delegate_execution
18
+ end
19
+
20
+ def validate
21
+ fail "Not implemented in abstract base class"
22
+ end
23
+
24
+ def delegate_execution
25
+ fail "Not implemented in abstract base class"
26
+ end
27
+
28
+ def benchmark_suite
29
+ Cwb::BenchmarkSuite.new(@path)
30
+ end
31
+
32
+ private
33
+
34
+ def check_file_exists(file)
35
+ unless File.exists?(file)
36
+ fail "No file found at: #{file}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ require "cwb/file_parser"
2
+ require "cwb/directory_parser"
3
+ require "cwb/directory_suite_parser"
4
+
5
+ module Cwb
6
+ module ParserFactory
7
+ def self.build(path)
8
+ if File.directory?(path) && Cwb::DirectorySuiteParser.suite_file_present?(path)
9
+ Cwb::DirectorySuiteParser.new(path)
10
+ elsif File.directory?(path)
11
+ Cwb::DirectoryParser.new(path)
12
+ else
13
+ Cwb::FileParser.new(path)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Cwb
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cwb.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "cwb/version"
2
+
3
+ module Cwb
4
+ def self.root
5
+ File.expand_path '../..', __FILE__
6
+ end
7
+
8
+ # Add inflection methods to string
9
+ require "inflection"
10
+ String.send(:include, Inflection)
11
+
12
+ # Add deep_fetch to hash
13
+ require "hash_extension"
14
+ Hash.send(:include, HashExtension)
15
+
16
+ require "cwb/benchmark"
17
+ require "cwb/benchmark_suite"
18
+ require "cwb/cli"
19
+ end