tops-turn 0.0.1
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.
- data/Rakefile +32 -0
- data/lib/turn.rb +12 -0
- data/lib/turn/bucket_map.rb +28 -0
- data/lib/turn/servers/kv.rb +28 -0
- data/lib/turn/term.rb +43 -0
- data/lib/turn/version.rb +5 -0
- data/spec/integration/term_spec.rb +21 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/unit/bucket_map_spec.rb +20 -0
- data/spec/unit/servers/kv_spec.rb +32 -0
- data/spec/unit/term_spec.rb +20 -0
- data/turn.gemspec +23 -0
- metadata +96 -0
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
task default: [:rubocop, :spec]
|
8
|
+
|
9
|
+
Rubocop::RakeTask.new
|
10
|
+
|
11
|
+
task spec: :'spec:unit'
|
12
|
+
|
13
|
+
namespace :spec do
|
14
|
+
desc 'run all tests'
|
15
|
+
task all: [:'spec:unit', :'spec:integration']
|
16
|
+
|
17
|
+
desc 'run unit tests'
|
18
|
+
task :unit do |task|
|
19
|
+
RSpec::Core::RakeTask.new(task) do |t|
|
20
|
+
t.pattern = 'spec/unit/**/*_spec.rb'
|
21
|
+
t.rspec_opts = %w(--format documentation --color)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'run integration tests'
|
26
|
+
task :integration do |task|
|
27
|
+
RSpec::Core::RakeTask.new(task) do |t|
|
28
|
+
t.pattern = 'spec/integration/**/*_spec.rb'
|
29
|
+
t.rspec_opts = %w(--format documentation --color)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/turn.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'overlord'
|
4
|
+
|
5
|
+
module Turn
|
6
|
+
class BucketMap
|
7
|
+
attr_accessor :buckets, :count
|
8
|
+
|
9
|
+
def initialize(term)
|
10
|
+
@term = term
|
11
|
+
@buckets = []
|
12
|
+
@count = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def load(dc)
|
16
|
+
parse(@term.dump_bucket_map(dc))
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(map)
|
20
|
+
map.each_with_index do |bucket, index|
|
21
|
+
if /(?<id>\S+):\s+(?<value>\d+)/ =~ bucket
|
22
|
+
@count = value.to_i
|
23
|
+
@buckets[index] = id
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Turn::Server
|
4
|
+
class KV
|
5
|
+
def initialize(hostname, port)
|
6
|
+
@hostname = hostname
|
7
|
+
@port = port
|
8
|
+
end
|
9
|
+
|
10
|
+
def disk_usage
|
11
|
+
# ssh
|
12
|
+
# df -h | grep kv-data
|
13
|
+
end
|
14
|
+
|
15
|
+
def cpu_info
|
16
|
+
# ssh
|
17
|
+
# cat /proc/cpuinfo | grep \'model name\' | uniq | cut -d\':\' -f2
|
18
|
+
end
|
19
|
+
|
20
|
+
def pair_count
|
21
|
+
metrics = Turn::Term.new(@hostname, @port).dump_public_metrics('KeyValueStorePopulation')
|
22
|
+
metrics.values.reduce { |a, e| a + e }
|
23
|
+
end
|
24
|
+
|
25
|
+
def agent_info
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/turn/term.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
module Turn
|
6
|
+
class Term
|
7
|
+
def initialize(hostname, port)
|
8
|
+
@hostname = hostname
|
9
|
+
@port = port
|
10
|
+
end
|
11
|
+
|
12
|
+
def dump_bucket_map(dc)
|
13
|
+
hash = get('dump profile bucket map', dc: dc)
|
14
|
+
|
15
|
+
fail hash['errors'] unless hash['errors'].empty?
|
16
|
+
|
17
|
+
hash['info']
|
18
|
+
end
|
19
|
+
|
20
|
+
def dump_public_metrics(prefix)
|
21
|
+
metrics = {}
|
22
|
+
|
23
|
+
hash = get('dump public metrics', prefix: prefix)
|
24
|
+
hash['rows'].each do |metric|
|
25
|
+
metrics[metric.first] = metric.last.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
metrics
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(command, query)
|
32
|
+
q = { command: command, 'response-formatter' => 'json' }
|
33
|
+
uri = URI("http://#{@hostname}:#{@port}/execute")
|
34
|
+
uri.query = URI.encode_www_form(q.merge(query))
|
35
|
+
json = RestClient.get(uri.to_s)
|
36
|
+
hash = JSON.parse(json)
|
37
|
+
|
38
|
+
fail unless hash['errors'].empty? && hash['warnings'].empty?
|
39
|
+
|
40
|
+
hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/turn/version.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Turn::Term do
|
6
|
+
let(:hostname) { 'prof034.ams1.turn.com' }
|
7
|
+
let(:port) { '4700' }
|
8
|
+
subject { described_class.new(hostname, port) }
|
9
|
+
|
10
|
+
describe '#dump_bucket_map' do
|
11
|
+
it 'should dump bucket map for a dc' do
|
12
|
+
expect(subject.dump_bucket_map('ams1')).to be_a(Array)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#dump_public_metrics' do
|
17
|
+
it 'should dump public metrics' do
|
18
|
+
expect(subject.dump_public_metrics('KeyValueStorePopulation')).to be_a(Hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'turn'
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
8
|
+
# loaded once.
|
9
|
+
#
|
10
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Turn::BucketMap do
|
6
|
+
subject { described_class.new(term) }
|
7
|
+
|
8
|
+
let(:term) { double(Turn::Term) }
|
9
|
+
let(:bucket_map) { ['pf28-ams1: 25000', 'pf21-ams1: 25000'] }
|
10
|
+
|
11
|
+
it 'should initialize the bucket map from a server list' do
|
12
|
+
expect(term).to receive(:dump_bucket_map).with('dc').and_return(bucket_map)
|
13
|
+
|
14
|
+
subject.load('dc')
|
15
|
+
|
16
|
+
expect(subject.buckets.size).to eq(2)
|
17
|
+
expect(subject.buckets.first).to eq('pf28-ams1')
|
18
|
+
expect(subject.count).to eq(25_000)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Turn::Server::KV do
|
6
|
+
let(:hostname) { 'hostname' }
|
7
|
+
let(:port) { 'port' }
|
8
|
+
subject { described_class.new(hostname, port) }
|
9
|
+
|
10
|
+
it 'should fetch disk usage' do
|
11
|
+
pending do
|
12
|
+
expect(subject.disk_usage).to eq(100)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should fetch cpu info' do
|
17
|
+
pending do
|
18
|
+
expect(subject.cpu_info).to eq('foo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#pair_count' do
|
23
|
+
let(:metrics) { { 'x' => 1, 'y' => 2 } }
|
24
|
+
let(:term) { double(Turn::Term, dump_public_metrics: metrics) }
|
25
|
+
|
26
|
+
it 'should fetch kv pair count' do
|
27
|
+
expect(Turn::Term).to receive(:new).and_return(term)
|
28
|
+
|
29
|
+
expect(subject.pair_count).to eq(3)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Turn::Term do
|
6
|
+
let(:hostname) { 'hostname' }
|
7
|
+
let(:port) { 'port' }
|
8
|
+
subject { described_class.new(hostname, port) }
|
9
|
+
|
10
|
+
describe '#dump_bucket_map' do
|
11
|
+
let(:info) { %w[foo] }
|
12
|
+
let(:json) { { 'errors' => [], 'info' => info } }
|
13
|
+
|
14
|
+
it 'should dump bucket map for a dc' do
|
15
|
+
expect(subject).to receive(:get).with('dump profile bucket map', dc: 'dc').and_return(json)
|
16
|
+
|
17
|
+
expect(subject.dump_bucket_map('dc')).to eq(info)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/turn.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'turn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tops-turn'
|
8
|
+
spec.version = Turn::VERSION
|
9
|
+
spec.authors = ['Martin Englund']
|
10
|
+
spec.email = %w[menglund@turn.com]
|
11
|
+
spec.description = %q{Gem to interact with the Turn terminal}
|
12
|
+
spec.summary = %q{Gem to interact with the Turn terminal}
|
13
|
+
spec.homepage = 'http://turn.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($RS)
|
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 = %w(lib)
|
20
|
+
|
21
|
+
spec.add_dependency 'rest_client'
|
22
|
+
spec.add_dependency 'tops-overlord'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tops-turn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Martin Englund
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest_client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: tops-overlord
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Gem to interact with the Turn terminal
|
47
|
+
email:
|
48
|
+
- menglund@turn.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- Rakefile
|
54
|
+
- lib/turn.rb
|
55
|
+
- lib/turn/bucket_map.rb
|
56
|
+
- lib/turn/servers/kv.rb
|
57
|
+
- lib/turn/term.rb
|
58
|
+
- lib/turn/version.rb
|
59
|
+
- spec/integration/term_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
- spec/unit/bucket_map_spec.rb
|
62
|
+
- spec/unit/servers/kv_spec.rb
|
63
|
+
- spec/unit/term_spec.rb
|
64
|
+
- turn.gemspec
|
65
|
+
homepage: http://turn.com
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.23
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Gem to interact with the Turn terminal
|
90
|
+
test_files:
|
91
|
+
- spec/integration/term_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/unit/bucket_map_spec.rb
|
94
|
+
- spec/unit/servers/kv_spec.rb
|
95
|
+
- spec/unit/term_spec.rb
|
96
|
+
has_rdoc:
|