cassie 1.0.0.beta.12 → 1.0.0.beta.15

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: 6cc848c2d95df8ae4b40ca89c5e0caf669702a03
4
- data.tar.gz: 24e4e0ae4ac0126188989b7bb1df546a2b30a4e2
3
+ metadata.gz: 0e721aa1ae662ceda68b8697144f11d97f34dba6
4
+ data.tar.gz: 3d20bae28f27b55de84ad4e09fae5d1784f56c56
5
5
  SHA512:
6
- metadata.gz: 7bda8956589af26de1c044ad5a58e91f59f9720f13a62418da490eeb597b6c14effd688cc7a49a24e189a7b7d81ae7503b12dc421bcefa15c0597ab144d4f017
7
- data.tar.gz: 429db02e54722fc845026787ee565fef40fb9a808b44b7cee89a3540225f0e8de91d8df6ce65f7652292c5d91b239d578ecc8a75cc8808e0c4a1db8f355a0bb4
6
+ metadata.gz: 943b14b4e9cf8ce70aef2a68b5867491ea9f1beb8bd8c2b15927c292f68b74e7b77d34c5577bbb29ab88f3b83a876e4a03598a7d473d94083c852b480068fa0b
7
+ data.tar.gz: 228d3abb2b48ca6c4e846ae3d130293c2134d51a5292552df7b541639361bec3d874d4c6a3b82b7738e15af4953eceb072285be883b646cf4a1af38b11007c54
data/bin/cassie CHANGED
@@ -1,11 +1,10 @@
1
1
  #! ruby
2
- require_relative '../lib/cassie/configuration/generator'
3
-
4
2
  def color(message)
5
3
  "\e[1;31m#{message}\e[0m"
6
4
  end
7
5
 
8
6
  def generate_config
7
+ require_relative '../lib/cassie'
9
8
  opts = {}
10
9
  if ARGV[1]
11
10
  opts[:destination_path] = if ARGV[1][0] == "/"
@@ -18,12 +17,49 @@ def generate_config
18
17
  end
19
18
  opts[:app_name] = ARGV[2] if ARGV[2]
20
19
 
21
- Cassie::Configuration::Generator.new(opts).save
20
+ generator = Cassie::Configuration::Generator.new(opts)
21
+ generator.save
22
+ puts "[✓] Cassandra configuration written to #{generator.destination_path}"
23
+ end
24
+
25
+ def dump_structure
26
+ require_relative '../lib/cassie'
27
+ opts = {}
28
+ opts[:destination_path] = Cassie.paths[:schema_structure]
29
+
30
+ args = ["-e", "'DESCRIBE SCHEMA'"]
31
+
32
+ runner = Cassie::Support::CommandRunner.new("cqlsh", args)
33
+ runner.run!
34
+
35
+ dir = File.dirname(opts[:destination_path])
36
+ Dir.mkdir(dir) unless File.directory?(dir)
37
+ File.open(opts[:destination_path], "w+") do |f|
38
+ f.write(runner.output)
39
+ end
40
+ puts "[✓] Cassandra schema written to #{opts[:destination_path]}"
41
+ end
42
+
43
+ def load_structure
44
+ require_relative '../lib/cassie'
45
+ opts = {}
46
+ opts[:source_path] = Cassie.paths[:schema_structure]
47
+
48
+ args = ["-f", opts[:source_path]]
49
+
50
+ runner = Cassie::Support::CommandRunner.new("cqlsh", args)
51
+ runner.run!
52
+
53
+ puts "[✓] Cassandra schema loaded from #{opts[:source_path]}"
22
54
  end
23
55
 
24
56
  case ARGV[0]
25
57
  when "configuration:generate"
26
58
  generate_config
59
+ when "structure:dump"
60
+ dump_structure
61
+ when "structure:load"
62
+ load_structure
27
63
  else
28
- puts color("`#{ARGV[0]}` is not a supported command. Did you mean `cassie configuration:generate`?")
64
+ puts color("`#{ARGV[0]}` is not a supported command.")
29
65
  end
data/lib/cassie.rb CHANGED
@@ -12,6 +12,7 @@ require 'active_support'
12
12
  require 'cassandra'
13
13
 
14
14
  module Cassie
15
+ require_relative 'cassie/support'
15
16
  require_relative 'cassie/logger'
16
17
  require_relative 'cassie/configuration'
17
18
  require_relative 'cassie/connection_handler'
@@ -10,6 +10,7 @@ module Cassie::Configuration
10
10
 
11
11
  def self.extended(extender)
12
12
  extender.paths["cluster_configurations"] = "config/cassandra.yml"
13
+ extender.paths["schema_structure"] = "db/structure.cql"
13
14
  end
14
15
 
15
16
  def env
@@ -421,19 +421,38 @@ end
421
421
 
422
422
  #### Logging
423
423
 
424
- Set the log level to debug to log execution details.
424
+ Cassie Query objects use the Cassie logger unless overridden. This logs to STDOUT by default. Set any log stream you wish.
425
425
 
426
426
  ```ruby
427
- Cassie::Queries::Logging.logger.level = Logger::DEBUG
427
+ Cassie.logger = my_app.config.logger
428
428
  ```
429
429
 
430
+ Set the log level to `debug` in order to log execution details.
431
+
432
+ ```ruby
433
+ Cassie::Query.logger.level = Logger::DEBUG
434
+ ```
435
+
436
+ #### Execution Time
437
+
438
+ Cassie Queries instrument execution time as `cassie.cql.execution` and logs a debug message.
439
+
430
440
  ```ruby
431
441
  SelectUserByUsernameQuery.new('some_user').execute
432
- (2.9ms) SELECT * FROM users_by_username WHERE username = ? LIMIT 1; [["some_user"]]
442
+ (5.5ms) SELECT * FROM users_by_username WHERE username = ? LIMIT 1; ["some_user"] [LOCAL_ONE]
433
443
  ```
444
+ This measures the time to build the CQL query (statement and bindings), transmit the query to the cassandra coordinator, receive the result from the cassandra coordinator, and have the cassandra ruby driver build the ruby representation of the results. It does not include the time it takes for the Cassie Query to build its resource objects.
445
+
446
+ #### Resource Loading
434
447
 
435
- Logs to STDOUT by default. Set any log stream you wish.
448
+ Cassie Queries instrument resource building as `cassie.building_resources` and logs a debug message.
436
449
 
437
450
  ```ruby
438
- Cassie::Queries::Logging.logger = my_app.config.logger
451
+ SelectUserByUsernameQuery.new('some_user').fetch
452
+ (5.5ms) SELECT * FROM users_by_username WHERE username = ? LIMIT 1; ["some_user"] [LOCAL_ONE]
453
+ (0.2ms) 1 resource object built from Cassandra query result
439
454
  ```
455
+
456
+ This measures the time it takes Cassie to build the resource objects (e.g. your domain objects) and is in addition to the execution time.
457
+
458
+ > fetch time = `cassie.cql.execution` time + `cassie.building_resources` time
@@ -0,0 +1,5 @@
1
+ module Cassie
2
+ module Support
3
+ require_relative 'support/command_runner'
4
+ end
5
+ end
@@ -0,0 +1,73 @@
1
+ module Cassie::Support
2
+ class CommandRunner
3
+ attr_reader :binary, :args, :command, :process, :duration, :output
4
+
5
+ # When a block is given, the command runs before yielding
6
+ def initialize(binary, args=[])
7
+ @binary = binary
8
+ @args = args
9
+ @command = (Array(binary) + args).join(" ")
10
+ @command = command + " 2>&1" unless command =~ / > /
11
+
12
+ if block_given?
13
+ run
14
+ yield self
15
+ end
16
+ end
17
+
18
+ # Runs the command
19
+ def run
20
+ t1=Time.now
21
+
22
+ IO.popen(command) do |io|
23
+ @output=io.read
24
+ @process=Process.waitpid2(io.pid)[1]
25
+ end
26
+
27
+ @duration=Time.now-t1
28
+ exitcode == 0
29
+ end
30
+
31
+ # Runs the command and raises if doesn't exit 0
32
+ def run!
33
+ Kernel.fail error_message unless exitcode == 0
34
+ end
35
+
36
+ # Returns false if the command hasn't been executed yet
37
+ def run?
38
+ !!process
39
+ end
40
+
41
+ # Returns the exit code for the command. Runs the command if it hasn't run yet.
42
+ def exitcode
43
+ ensure_run
44
+ process.exitstatus
45
+ end
46
+
47
+ # Returns true if the command completed execution.
48
+ # Will return false if the command hasn't been executed
49
+ def finished?
50
+ return false unless process
51
+ process.success?
52
+ end
53
+
54
+ protected
55
+
56
+ def ensure_run
57
+ run unless process
58
+ end
59
+
60
+ def error_message
61
+ msg = "\n"
62
+ msg << color(output)
63
+ msg << "\n---------------------"
64
+ msg << "\n\nfailed to execute `#{command}`.\n"
65
+ msg << "Please check the output above for any errors and make sure that `#{binary}` is installed in your PATH with proper permissions.\n"
66
+ msg
67
+ end
68
+
69
+ def color(message)
70
+ "\e[1m\e[31m#{message}\e[0m\e[22m"
71
+ end
72
+ end
73
+ 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.0.beta.12
4
+ version: 1.0.0.beta.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Prothro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cassandra-driver
@@ -157,6 +157,8 @@ files:
157
157
  - lib/cassie/queries/statement/selection.rb
158
158
  - lib/cassie/queries/statement/updating.rb
159
159
  - lib/cassie/query.rb
160
+ - lib/cassie/support.rb
161
+ - lib/cassie/support/command_runner.rb
160
162
  - lib/cassie/testing.rb
161
163
  - lib/cassie/testing/README.md
162
164
  - lib/cassie/testing/fake/execution_info.rb