pgpool-pcpwrapper 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea74c8c4046641b7d2b9097a194af0bccdd32b9f
4
+ data.tar.gz: 7140469102d3a3200a61ff9b822d8e06cedd309d
5
+ SHA512:
6
+ metadata.gz: 87608b0b0d054b56a67d1e0c2b0e585d7e417ebffaefae068bf9950c8389e8fe11535e3f19c570401b42762cb15a0eb06194a889c4a1b13e4acd8daa504281c1
7
+ data.tar.gz: 9e6bdb31f19725cdaa76dffb998a87a71c176b87f39fd2020d2d83ca1e49350b67cc1187bc36d674d9d6edf1a390f4399f8e8aeef9a38f7d5ccb535ca24d1d37
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.ruby-version
4
+ /.rubocop.yml
5
+ /**/.*.swp
6
+ /Gemfile.lock
7
+ /_yardoc/
8
+ /coverage/
9
+ /doc/
10
+ /pkg/
11
+ /spec/reports/
12
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ Metrics/LineLength:
2
+ Max: 155
3
+ Enable: false
4
+
5
+ Metrics/MethodLength:
6
+ Max: 40
7
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pgpool-pcpwrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Javier Juarez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # PGPool::Wrapper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pgpool/pcpwrapper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ This is a little gem to help with the PGPool PCP administration interface
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pgpool-pcpwrapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pgpool-pcpwrapper
22
+
23
+ ## Usage
24
+
25
+ So simple, instantiate a Pgpoll::Wrapper::CommandLauncher and send the appropiate commands through the PCP interface. There are only two commands implemented ad this moment, pcp_node_count and pcp_node_info
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jjuarez/pgpool-pcpwrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pgpool/pcpwrapper'
5
+ require 'pry'
6
+
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ # A bit of spicy monkey patching
2
+ class String
3
+ def percentage?
4
+ /\A[-+]?\d+\z/ =~ self && to_i >= 0 && to_i <= 100
5
+ end
6
+ end
@@ -0,0 +1,63 @@
1
+ require 'mixlib/shellout'
2
+ require 'pgpool/response'
3
+
4
+ module PGPool
5
+ #
6
+ # = class: CommandLauncher, a simple wrapper for PCP PGPool management CLI
7
+ class CommandLauncher
8
+ DEFAULT_PREFIX = '/usr/sbin'
9
+ PCP_NODE_COUNT_EXE = 'pcp_node_count'
10
+ PCP_NODE_INFO_EXE = 'pcp_node_info'
11
+
12
+ private
13
+
14
+ def launch(command_str)
15
+ command = ::Mixlib::ShellOut.new(command_str)
16
+
17
+ command.run_command
18
+ command.error!
19
+ command
20
+ end
21
+
22
+ def extract_number_of_nodes
23
+ launch(@pcp_node_count_command).stdout.to_i
24
+ end
25
+
26
+ public
27
+
28
+ attr_reader :number_of_nodes
29
+
30
+ def initialize(hostname, port, user, password, timeout, options = {})
31
+ options = { prefix: DEFAULT_PREFIX }.merge(options)
32
+
33
+ @hostname = hostname
34
+ @port = port
35
+ @user = user
36
+ @password = password
37
+ @timeout = timeout
38
+
39
+ @pcp_command_options = "#{@timeout} #{@hostname} #{@port} #{@user} #{@password}"
40
+ @pcp_node_count_command = "#{File.join(options[:prefix], PCP_NODE_COUNT_EXE)} #{@pcp_command_options}"
41
+ @pcp_node_info_command = "#{File.join(options[:prefix], PCP_NODE_INFO_EXE)} #{@pcp_command_options}"
42
+
43
+ self
44
+ end
45
+
46
+ def number_of_nodes
47
+ @number_of_nodes ||= extract_number_of_nodes
48
+ end
49
+
50
+ def valid_node_id?(node_id)
51
+ node_id >= 0 && node_id < number_of_nodes
52
+ end
53
+
54
+ def node_information(node_id)
55
+ fail("Invalid node id(#{node_id}) must be between 0 and #{number_of_nodes - 1}") unless valid_node_id?(node_id)
56
+ Response.new(node_id, launch("#{@pcp_node_info_command} #{node_id}"))
57
+ end
58
+
59
+ def nodes_information
60
+ number_of_nodes.times.map { |node_id| node_information(node_id) }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,63 @@
1
+ module PGPool
2
+ #
3
+ # = class: NodeInfo, PORO
4
+ class NodeInfo
5
+ INITIALIZING = 0 # This state is only used during the initialization.
6
+ UP_NO_CONNECTIONS = 1 # Node is up. No connections yet.
7
+ UP = 2 # Node is up. Connections are pooled.
8
+ DOWN = 3 # Node is down.
9
+
10
+ private
11
+
12
+ def status=(status)
13
+ fail("Invalid status: #{status}") unless [INITIALIZING, UP_NO_CONNECTIONS, UP, DOWN].include?(status)
14
+
15
+ @status = status
16
+ end
17
+
18
+ public
19
+
20
+ def self.build_from_raw_data(id, command_raw_data)
21
+ hostname, port, status, weight = command_raw_data.split(' ')
22
+
23
+ NodeInfo.new(id, hostname, port, status, weight)
24
+ end
25
+
26
+ attr_reader :id, :hostname, :port, :weight, :status
27
+
28
+ def initialize(id, hostname, port, status, weight)
29
+ @id = id.to_i
30
+ @hostname = hostname
31
+ @port = port.to_i
32
+ @weight = weight.to_f
33
+
34
+ self.status = status.to_i
35
+
36
+ self
37
+ end
38
+
39
+ def initializing?
40
+ status == INITIALIZING
41
+ end
42
+
43
+ def up?
44
+ (status == UP || status == UP_NO_CONNECTIONS)
45
+ end
46
+
47
+ def down?
48
+ status == DOWN
49
+ end
50
+
51
+ def to_hash
52
+ { id: id, hostname: hostname, port: port, status: status, weight: weight }
53
+ end
54
+
55
+ def inspect
56
+ to_hash.inspect
57
+ end
58
+
59
+ def to_s
60
+ inspect
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,42 @@
1
+ require 'forwardable'
2
+ require 'core_extensions/string/percentage'
3
+ require 'pgpool/command_launcher'
4
+ require 'pgpool/response'
5
+ require 'pgpool/node_info'
6
+ require 'pgpool/version'
7
+
8
+ #
9
+ # = module: PGPool module as namespace
10
+ module PGPool
11
+ #
12
+ # = class: PCPWrapper, the main gem module
13
+ class PCPWrapper
14
+ extend Forwardable
15
+
16
+ DEFAULT_TIMEOUT = 10
17
+ DEFAULT_HOSTNAME = 'localhost'
18
+ DEFAULT_PORT = 9898
19
+ DEFAULT_USER = 'postgres'
20
+ DEFAULT_PASSWORD = 'postgres'
21
+
22
+ def_delegators :@command_launcher, :valid_node_id?, :node_information, :nodes_information
23
+
24
+ def initialize(parameters = {})
25
+ parameters = {
26
+ hostname: DEFAULT_HOSTNAME,
27
+ port: DEFAULT_PORT,
28
+ user: DEFAULT_USER,
29
+ password: DEFAULT_PASSWORD,
30
+ timeout: DEFAULT_TIMEOUT
31
+ }.merge(parameters)
32
+
33
+ @command_launcher = CommandLauncher.new(
34
+ parameters[:hostname],
35
+ parameters[:port],
36
+ parameters[:user],
37
+ parameters[:password],
38
+ parameters[:timeout])
39
+ self
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,72 @@
1
+ require 'pgpool/node_info'
2
+
3
+ module PGPool
4
+ #
5
+ # = class: Response
6
+ class Response
7
+ OK = 0
8
+ UNKNOWN = 1 # Unknown Error (should not occur)
9
+ EOF = 2 # EOF Error
10
+ NOMEM = 3 # Memory shortage
11
+ READ = 4 # Error while reading from the server
12
+ WRITE = 5 # Error while writing to the server
13
+ TIMEOUT = 6 # Timeout
14
+ INVAL = 7 # Argument(s) to the PCP command was invalid
15
+ CONN = 8 # Server connection error
16
+ NOCONN = 9 # No connection exists
17
+ SOCK = 10 # Socket error
18
+ HOST = 11 # Hostname resolution error
19
+ BACKEND = 12 # PCP process error on the server
20
+ AUTH = 13 # Authorization failure
21
+
22
+ ERROR_MESSAGES = {
23
+ OK: 'No error',
24
+ UNKNOWN: 'Unknown Error',
25
+ EOF: 'EOF Error',
26
+ NOMEM: 'Memory shortage',
27
+ READ: 'Error while reading from the server',
28
+ WRITE: 'Error while writing to the server',
29
+ TIMEOUT: 'Timeout',
30
+ INVAL: 'Argument(s) to the PCP command was invalid',
31
+ CONN: 'Server connection error',
32
+ NOCONN: 'No connection exists',
33
+ SOCK: 'Socket error',
34
+ HOST: 'Hostname resolution error',
35
+ BACKEND: 'PCP process error on the server',
36
+ AUTH: 'Authorization failure'
37
+ }
38
+
39
+ attr_reader :status, :node_info
40
+
41
+ def initialize(node_id, command)
42
+ @status = command.exitstatus
43
+ @node_info = success? ? NodeInfo.build_from_raw_data(node_id, command.stdout) : command.stderr
44
+
45
+ self
46
+ end
47
+
48
+ def success?
49
+ status == OK
50
+ end
51
+
52
+ def error?
53
+ status != OK
54
+ end
55
+
56
+ def error_message
57
+ ERROR_MESSAGES[@status]
58
+ end
59
+
60
+ def to_hash
61
+ { status: @status, node_info: @node_info }
62
+ end
63
+
64
+ def inspect
65
+ to_hash.inspect
66
+ end
67
+
68
+ def to_s
69
+ "#{inspect}"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ #
2
+ # = module: PGPool namespace
3
+ module PGPool
4
+ VERSION = '0.1.3'
5
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pgpool/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pgpool-pcpwrapper'
8
+ spec.version = PGPool::VERSION
9
+ spec.authors = ['Javier Juarez']
10
+ spec.email = ['jjuarez@tuenti.com']
11
+
12
+ spec.summary = 'A PGPool PCP interface wrapper.'
13
+ spec.description = 'A PGPool PCP interface wrapper.'
14
+ spec.homepage = 'https://github.com/jjuarez/pgpool-pcpwrapper'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.required_ruby_version = '>= 1.9'
31
+ spec.required_rubygems_version = '>= 1.8'
32
+
33
+ spec.add_dependency 'mixlib-shellout', '~> 2.1'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.10'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'pry', '~> 0.10'
38
+ spec.add_development_dependency 'rspec', '~> 3.3'
39
+ spec.add_development_dependency 'rubocop', '~> 0.34'
40
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pgpool-pcpwrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Javier Juarez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixlib-shellout
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.34'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.34'
97
+ description: A PGPool PCP interface wrapper.
98
+ email:
99
+ - jjuarez@tuenti.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/core_extensions/string/percentage.rb
117
+ - lib/pgpool/command_launcher.rb
118
+ - lib/pgpool/node_info.rb
119
+ - lib/pgpool/pcpwrapper.rb
120
+ - lib/pgpool/response.rb
121
+ - lib/pgpool/version.rb
122
+ - pgpool-pcpwrapper.gemspec
123
+ homepage: https://github.com/jjuarez/pgpool-pcpwrapper
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '1.9'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '1.8'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.5.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A PGPool PCP interface wrapper.
148
+ test_files: []