cassie 1.0.5 → 1.0.6.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc013f89eb9dd8179dd4d301047728a98324d7cc
4
- data.tar.gz: 4c63fcea715da5f1638dfde6136f8b9dce3aea17
3
+ metadata.gz: a666b2c1cd7989d7ae10dc0ffd994f7cd942d54b
4
+ data.tar.gz: 94075bcf8311158255ccd5174d8b883a8004ccb1
5
5
  SHA512:
6
- metadata.gz: 9e1ea84d903b80375ba5ee5e863481d8b594f6ebb2bfb75baca920ee13fe2a0a5528144717131f9e3845bc0db281571ab305e48d7e5eb506f2a60083d2b4fc02
7
- data.tar.gz: 8001a250cf5aa92d8a8fcfd77b65a0e712a8b4897312b328776db56e87a6401f7cbfe446de75cb068a2d051035832d3864c4559960bbdddd8b48cc0d9a2ad036
6
+ metadata.gz: '011389da5a2e79dfd9fd909290e109667e933d75c9465fd5be878149e7f4a8e8a682544f6d38a00697ea21a58ee0b6fefd25dea9f86f576d3271afc84a3b1c29'
7
+ data.tar.gz: ca04b1f8ae1a515d51476cafb9e24e21c51300a052978818a3f18a9812dd61004bb8b5c3601559f90d31e12a8a377ac5f65ae111a5fa20e3ef30ab2f4cb7ae45
data/bin/cassie CHANGED
@@ -3,10 +3,6 @@
3
3
  require_relative '../lib/cassie'
4
4
  require_relative "../lib/cassie/tasks"
5
5
 
6
- runner = Cassie::Tasks::TaskRunner.new
7
- if ARGV.length > 0
8
- runner.run_command(ARGV)
9
- else
10
- runner.print_documentation
11
- end
6
+ runner = Cassie::Tasks::TaskRunner.new(ARGV).run
7
+
12
8
 
@@ -3,6 +3,8 @@ module Cassie
3
3
  class ServerProcess
4
4
 
5
5
  attr_reader :pid
6
+ # @return [Array<String>] The Cassandra output lines tagged with ERROR
7
+ attr_reader :errors
6
8
 
7
9
  # Scan the system for cassandra processes running
8
10
  # @return [Array<ServerProcess>] Running cassandra processes
@@ -26,6 +28,7 @@ module Cassie
26
28
  # Starts a cassandra server process. {#running?} will be true if it started correctly.
27
29
  def initialize(pid=nil)
28
30
  @pid = pid
31
+ @errors = []
29
32
 
30
33
  if pid
31
34
  @running = true
@@ -59,13 +62,6 @@ module Cassie
59
62
  details[:command]
60
63
  end
61
64
 
62
- # @return [Array<String>] The Cassandra output lines tagged with ERROR
63
- # @!parse attr_reader :errors
64
- def errors
65
- return [] unless command && command.output
66
- command.output.split("\n").grep(/ERROR/)
67
- end
68
-
69
65
  protected
70
66
 
71
67
  def self.pids
@@ -83,6 +79,7 @@ module Cassie
83
79
  Cassie.logger.warn "[WARN] - Multiple cassandra processes started, using first one." if new_pids.length > 1
84
80
 
85
81
  @running = !!(cassandra.output =~ /state jump to NORMAL/)
82
+ @errors = cassandra.output.split("\n").grep(/ERROR/)
86
83
  @pid = new_pids.first
87
84
  end
88
85
 
@@ -27,7 +27,7 @@ namespace :cassie do
27
27
  puts " > #{green("created")} #{generator.destination_path}"
28
28
  puts "-- done"
29
29
  rescue => e
30
- puts red("Error:\n #{e.message}")
30
+ output_error(e)
31
31
  abort
32
32
  end
33
33
  end
@@ -4,6 +4,19 @@ module Cassie::Tasks
4
4
  io.puts(*args)
5
5
  end
6
6
 
7
+ def output_error(exception)
8
+ puts red("Error: #{exception.message}")
9
+
10
+ return unless exception.backtrace.try(:any?)
11
+
12
+ if argv.include?("--trace")
13
+ puts " #{exception.class}:"
14
+ puts " #{exception.backtrace.join("\n ")}"
15
+ else
16
+ puts " (use --trace for exception info)"
17
+ end
18
+ end
19
+
7
20
  def io
8
21
  $stdout
9
22
  end
@@ -40,7 +40,7 @@ namespace :cassie do
40
40
  puts " > #{green('created')} #{rel_path}"
41
41
  puts "-- done"
42
42
  rescue => e
43
- puts red("Error:\n #{e.message}")
43
+ output_error(e)
44
44
  abort
45
45
  end
46
46
  end
@@ -31,8 +31,8 @@ namespace :cassie do
31
31
  importer.import
32
32
  puts "-- done"
33
33
  rescue => e
34
- importer.imported_paths.each {|f| File.delete(f) }
35
- puts red("Error:\n #{e.message}")
34
+ importer.imported_paths.each {|f| File.delete(f) } if importer
35
+ output_error(e)
36
36
  abort
37
37
  end
38
38
  end
@@ -20,7 +20,7 @@ namespace :cassie do
20
20
  end
21
21
  puts "-- done"
22
22
  rescue => e
23
- puts red("Error:\n #{e.message}")
23
+ output_error(e)
24
24
  abort
25
25
  end
26
26
  end
@@ -13,7 +13,7 @@ namespace :cassie do
13
13
  puts "-- done"
14
14
 
15
15
  rescue => e
16
- puts red("Error: \n#{e.message}")
16
+ output_error(e)
17
17
  abort
18
18
  end
19
19
  end
@@ -10,7 +10,7 @@ namespace :cassie do
10
10
  begin
11
11
  print_versions(Cassie::Schema.applied_versions)
12
12
  rescue Cassie::Schema::UninitializedError => e
13
- puts red("Error:\n #{e.message}")
13
+ output_error(e)
14
14
  abort
15
15
  end
16
16
  end
@@ -28,7 +28,7 @@ namespace :cassie do
28
28
  puts " - done"
29
29
  puts "-- done"
30
30
  rescue => e
31
- puts red("Error:\n #{e.message}")
31
+ output_error(e)
32
32
  abort
33
33
  end
34
34
  end
@@ -2,52 +2,44 @@ namespace :cassie do
2
2
  namespace :schema do
3
3
 
4
4
  desc "Initialize versioning schema and the keyspace for this environment"
5
- task :init => [:init_versioning, :init_keyspace]
6
-
7
- desc "Initialize cassie schema versioning"
8
- task :init_versioning do
9
- include Cassie::Tasks::IO
5
+ task :init => :init_versioning do
6
+ opts = {}
7
+ OptionParser.new do |args|
8
+ args.on("-v", "--version VERSION", "Set an initial schema version representing the currenet version of the schema.") do |v|
9
+ opts[:version] = v
10
+ end
11
+ end.parse!(argv)
10
12
 
11
- begin
12
- puts "-- Initializing Cassie Versioning"
13
- Cassie::Schema.initialize_versioning
14
- puts "-- done"
15
- rescue Cassie::Schema::AlreadyInitiailizedError
16
- puts " > Cassie Versioning already initialized "
17
- puts " > Schema is at version #{Cassie::Schema.version}"
18
- puts "-- done"
19
- rescue => e
20
- puts red("Error:\n #{e.message}")
21
- abort
13
+ not_found = Proc.new do
14
+ str = "Version #{version} was not found locally, can't fast-forward there."
15
+ str += " Did you mean one of these local versions?" if Cassie::Schema.local_versions
16
+ Cassie::Schema.local_versions.reverse.each do |v|
17
+ str += " - #{v.to_s.ljust(10)} # #{v.description}"
18
+ end
19
+ raise str
22
20
  end
23
- end
24
-
25
- desc "Initialize the keyspace for the current environment"
26
- task :init_keyspace do
27
- include Cassie::Tasks::IO
28
21
 
29
22
  begin
30
- name = Cassie.configuration[:keyspace]
31
- puts "-- Initializing '#{name}' Keyspace"
32
- query = Cassie::Schema::CreateKeyspaceQuery.new
33
- query.name = name
34
- if Cassie.configuration[:replication]
35
- #@todo fill in
36
- end
23
+ if opts[:version]
24
+ version = Cassie::Schema::Version.new(opts[:version])
25
+ version = Cassie::Schema.local_versions.find(not_found){|v| version == v}
26
+ versions = Cassie::Schema.local_versions.select{|v| v <= version}.sort
27
+ puts "-- Fast-forwarding to version #{version}"
28
+ versions.each do |v|
29
+ Cassie::Schema.record_version(v, false)
30
+ puts " > Recorded version #{version}"
31
+ end
32
+ puts "-- done"
37
33
 
38
- if Cassie.keyspace_exists?(query.name)
39
- puts " > '#{name}' already exists"
40
- else
41
- query.execute
42
34
  end
43
- puts "-- done"
44
-
45
35
  rescue => e
46
- puts red("Couldn't create keyspace, check #{Cassie.paths[:cluster_configurations]}:\n#{query.to_cql}")
47
- puts "\t"
48
- puts red("Error:\n #{e.message}")
36
+ output_error(e)
49
37
  abort
50
38
  end
51
39
  end
40
+
41
+ Rake::Task["cassie:schema:init"].enhance do
42
+ Rake::Task["cassie:schema:init_keyspace"].invoke
43
+ end
52
44
  end
53
45
  end
@@ -0,0 +1,35 @@
1
+ namespace :cassie do
2
+ namespace :schema do
3
+
4
+ desc "Initialize the keyspace for the current environment"
5
+ task :init_keyspace do
6
+ include Cassie::Tasks::IO
7
+
8
+ begin
9
+ name = Cassie.configuration[:keyspace]
10
+ puts "-- Initializing '#{name}' Keyspace"
11
+
12
+ query = Cassie::Schema::CreateKeyspaceQuery.new
13
+ query.name = name
14
+ if replicaiton = Cassie.configuration[:replication]
15
+ query.replication_class = replication[:class] if replication.has_key?(:class)
16
+ query.replication_factor = replication[:replication_factor] if replication.has_key?(:replication_factor)
17
+ end
18
+ query.durable_writes = Cassie.configuration[:durable_writes] if Cassie.configuration.has_key?(:durable_writes)
19
+
20
+ if Cassie.keyspace_exists?(query.name)
21
+ puts " > '#{name}' already exists"
22
+ else
23
+ query.execute!
24
+ end
25
+ puts "-- done"
26
+
27
+ rescue => e
28
+ puts red("Couldn't create keyspace, check #{Cassie.paths[:cluster_configurations]}:\n#{query.to_cql}")
29
+ puts "\t"
30
+ output_error(e)
31
+ abort
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ namespace :cassie do
2
+ namespace :schema do
3
+
4
+ desc "Initialize cassie schema versioning"
5
+ task :init_versioning do
6
+ include Cassie::Tasks::IO
7
+
8
+ begin
9
+ puts "-- Initializing Cassie Versioning"
10
+ Cassie::Schema.initialize_versioning
11
+ puts "-- done"
12
+ rescue Cassie::Schema::AlreadyInitiailizedError
13
+ puts " > Cassie Versioning already initialized "
14
+ puts " > Schema is at version #{Cassie::Schema.version}"
15
+ puts "-- done"
16
+ rescue => e
17
+ output_error(e)
18
+ abort
19
+ end
20
+ end
21
+ end
22
+ end
@@ -11,7 +11,7 @@ namespace :cassie do
11
11
  puts " > Schema is now at version #{Cassie::Schema.version}"
12
12
  puts "-- done"
13
13
  rescue => e
14
- puts red("Error:\n #{e.message}")
14
+ output_error(e)
15
15
  abort
16
16
  end
17
17
  end
@@ -28,7 +28,7 @@ namespace :cassie do
28
28
  puts "-- done"
29
29
  end
30
30
  rescue => e
31
- puts red("Error:\n #{e.message}")
31
+ output_error(e)
32
32
  abort
33
33
  end
34
34
  end
@@ -11,7 +11,7 @@ namespace :cassie do
11
11
  all_versions = Cassie::Schema.applied_versions.to_a | Cassie::Schema.local_versions.to_a
12
12
  print_statuses(all_versions.sort.reverse)
13
13
  rescue Cassie::Schema::UninitializedError => e
14
- puts red("Error:\n #{e.message}")
14
+ output_error(e)
15
15
  abort
16
16
  end
17
17
  end
@@ -1,28 +1,57 @@
1
1
  module Cassie
2
2
  module Tasks
3
3
  class TaskRunner
4
+ attr_reader :raw_args
5
+ attr_reader :args
6
+ attr_reader :command
7
+ attr_reader :options
4
8
 
5
- def run_command(args)
6
- cmd = args.delete_at(0) if args.first !~ /^-/
7
- task = "cassie:#{cmd}"
9
+ def initialize(raw_args)
10
+ @raw_args = raw_args
11
+ @args = raw_args.dup
12
+ @command = nil
13
+ @command = args.delete_at(0) if args.first =~ /\A[^-]/
14
+ @options = {}
15
+ end
16
+
17
+ def run
18
+ build_options
19
+ Cassie.logger.level = ::Logger::WARN unless options[:debug]
20
+ Cassie.env = options[:environment] if options[:environment]
21
+
22
+ run_command || display_info
23
+ rescue OptionParser::InvalidOption => e
24
+ puts("#{e.message}\n\n")
25
+ display_info
26
+ end
8
27
 
9
- Cassie.logger.level = ::Logger::WARN unless args.delete('--debug')
28
+ # @returns [Boolean] if task was invoked
29
+ def run_command
30
+ task && task.invoke
31
+ end
32
+
33
+ # @returns [Rake::Task, nil] nil if task is not defined, otherwise the task object itself
34
+ def task
35
+ task_name = "cassie:#{command}"
36
+ Rake::Task[task_name] if Rake::Task.task_defined?(task_name)
37
+ end
10
38
 
11
- if Rake::Task.task_defined?(task)
12
- Rake::Task[task].invoke
39
+ def display_info
40
+ case
41
+ when command && !task
42
+ puts "'#{command}' is not a supported command.\n\n"
43
+ print_documentation
44
+ when options[:show_help]
45
+ print_documentation
46
+ when options[:show_version]
47
+ puts Cassie::VERSION
13
48
  else
14
- case args.delete_at(0)
15
- when "--help"
16
- print_documentation
17
- when "-v"
18
- puts Cassie::VERSION
19
- else
20
- puts "'#{cmd}' is not a supported command.\n\n"
21
- print_documentation
22
- end
49
+ print_documentation
23
50
  end
24
51
  end
25
52
 
53
+ protected
54
+
26
55
  def print_documentation
27
56
  docs = <<-EOS
28
57
  Usage:
@@ -38,12 +67,37 @@ EOS
38
67
  Options:
39
68
  -h, --help # Print this documentation
40
69
  -v, --version # List the library version
70
+ -d, --debug # Show debug log lines
71
+ -e, --env # The Cassie.env to use
41
72
  <command> --help # List options for a given command
73
+ <command> --trace # Show exception backtrace
42
74
 
43
75
  EOS
44
76
 
45
77
  puts docs
46
78
  end
79
+
80
+ def build_options
81
+ @options.tap do |h|
82
+ # Options Parsers doesn't work well unles
83
+ # all options are passed up to a single parser.
84
+ # Since we don't want to shadow options and we
85
+ # do want sub-task --help to work
86
+ #
87
+ # As is, a sub task with dependencies
88
+ # may cause issues since the pre-task could
89
+ # have optiosn that cause a parsing error.
90
+ # Need to revisit and probably ditch rake tasks.
91
+ h[:trace] = args.delete("-t") || args.delete("--trace")
92
+ h[:debug] = args.delete("-d") || args.delete("--debug")
93
+ if env_index = (args.index("-e") || args.index("--env"))
94
+ h[:environment] = args.delete_at(env_index + 1)
95
+ args.delete_at(env_index)
96
+ end
97
+ h[:show_version] = args.include?("-v") || args.include?("--version")
98
+ h[:show_help] = args.include?("-h") || args.include?("--help")
99
+ end
100
+ end
47
101
  end
48
102
  end
49
103
  end
@@ -1,3 +1,3 @@
1
1
  module Cassie
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6.pre1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Prothro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-15 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cassandra-driver
@@ -227,6 +227,8 @@ files:
227
227
  - lib/cassie/tasks/schema/history.rake
228
228
  - lib/cassie/tasks/schema/import.rake
229
229
  - lib/cassie/tasks/schema/init.rake
230
+ - lib/cassie/tasks/schema/init_keyspace.rake
231
+ - lib/cassie/tasks/schema/init_versioning.rake
230
232
  - lib/cassie/tasks/schema/load.rake
231
233
  - lib/cassie/tasks/schema/migrate.rake
232
234
  - lib/cassie/tasks/schema/reset.rake
@@ -263,12 +265,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
265
  version: '0'
264
266
  required_rubygems_version: !ruby/object:Gem::Requirement
265
267
  requirements:
266
- - - ">="
268
+ - - ">"
267
269
  - !ruby/object:Gem::Version
268
- version: '0'
270
+ version: 1.3.1
269
271
  requirements: []
270
272
  rubyforge_project:
271
- rubygems_version: 2.4.5.2
273
+ rubygems_version: 2.5.2
272
274
  signing_key:
273
275
  specification_version: 4
274
276
  summary: Apache Cassandra application support