gofer 0.3.1 → 0.4.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.
- checksums.yaml +8 -8
- data/CHANGELOG.md +5 -0
- data/README.md +13 -6
- data/lib/gofer/cluster.rb +38 -41
- data/lib/gofer/version.rb +1 -1
- data/spec/gofer/integration_spec.rb +3 -6
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            !binary "U0hBMQ==":
         | 
| 3 3 | 
             
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                NjZkNzBmMjZlMWI5ODk4MDE0ZDNmNTFlYzAxNjU4NTFlNzgyMDQ4NQ==
         | 
| 5 5 | 
             
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                ZjMwYjNmMTAwMWQ2NDJlOWUzZTE1MTdmODBkNjg2ZWVlMTQ2OTZiOA==
         | 
| 7 7 | 
             
            !binary "U0hBNTEy":
         | 
| 8 8 | 
             
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                N2MwNTRkYzQzZDM4MGIyN2Q0ZTJmNmY3MDY2NWFhZTgwNTg2ZmFhOWU1OGRk
         | 
| 10 | 
            +
                NWE3ZGRjZWJkMjM2OGFkOTA0Mjk4NTIyMDA4YTcwYjlhYWM0NmE1OWU2Mzdm
         | 
| 11 | 
            +
                YzNlZjU1MzYxY2ExYWJkOGY5NTVjYmUxZGMzOGVlNzIzMzMwNzQ=
         | 
| 12 12 | 
             
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
                 | 
| 15 | 
            -
                 | 
| 13 | 
            +
                ZTYyNDAxYTU2MTdjNTQ1YWRjMjNmODFkYWI4MTA4YTVkYmQxZDlmMWIxMTE0
         | 
| 14 | 
            +
                NTU2NmQ1MTJiOThkMTBkMjNhNGZhYzBjNTIwY2U2M2UzMGI0ZmU1MjVjYTAw
         | 
| 15 | 
            +
                MDA1NmUxYWZlNzcxY2U5M2M2MTZmMzFmNGQzNjM1Zjc4OWI1YWE=
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,10 @@ | |
| 1 1 | 
             
            # Revision History
         | 
| 2 2 |  | 
| 3 | 
            +
            ### v0.4.0
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              * Rework `Gofer::Cluster` to be a direct proxy, rather than requiring a block
         | 
| 6 | 
            +
              * Add all `Gofer::Host` methods to the `Gofer::Cluster` proxy (@rich0h)
         | 
| 7 | 
            +
             | 
| 3 8 | 
             
            ### v0.3.1
         | 
| 4 9 |  | 
| 5 10 | 
             
             * Prefix stderr/stdout per host with `:output_prefix`
         | 
    
        data/README.md
    CHANGED
    
    | @@ -90,13 +90,20 @@ cluster = Gopher::Cluster.new | |
| 90 90 | 
             
            cluster << Gofer::Host.new('my.host.com', 'ubuntu', :keys => ['key.pem'], :output_prefix => "   my")
         | 
| 91 91 | 
             
            cluster << Gofer::Host.new('other.host.com', 'ubuntu', :keys => ['key.pem'], :output_prefix => "other")
         | 
| 92 92 |  | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
            end
         | 
| 93 | 
            +
            # Run on all the hosts at once
         | 
| 94 | 
            +
            cluster.run "hostname"
         | 
| 96 95 |  | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 96 | 
            +
            # Run on only one host at a time
         | 
| 97 | 
            +
            cluster.max_concurrency = 1
         | 
| 98 | 
            +
            cluster.run("sudo /etc/init.d/apache2 restart")
         | 
| 99 | 
            +
             | 
| 100 | 
            +
            # Run a command on only one host
         | 
| 101 | 
            +
            host = cluster.shuffle.first
         | 
| 102 | 
            +
            host.run("rake migrations")
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            # Inspect the results from each host
         | 
| 105 | 
            +
            results = cluster.run "echo hostname"
         | 
| 106 | 
            +
            puts results.values.join(", ") # will print "my.host.com, other.host.com"
         | 
| 100 107 | 
             
            ```
         | 
| 101 108 |  | 
| 102 109 | 
             
            ## Testing
         | 
    
        data/lib/gofer/cluster.rb
    CHANGED
    
    | @@ -2,72 +2,69 @@ require 'thread' | |
| 2 2 |  | 
| 3 3 | 
             
            module Gofer
         | 
| 4 4 | 
             
              class Cluster
         | 
| 5 | 
            +
             | 
| 5 6 | 
             
                attr_reader :hosts
         | 
| 6 7 | 
             
                attr_accessor :max_concurrency
         | 
| 7 | 
            -
             | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(parties=[], opts={})
         | 
| 8 10 | 
             
                  @hosts = []
         | 
| 9 | 
            -
                  @max_concurrency =  | 
| 11 | 
            +
                  @max_concurrency = opts.delete(:max_concurrency)
         | 
| 10 12 |  | 
| 11 | 
            -
                  parties.each  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 13 | 
            +
                  parties.each { |i| self << i }
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def concurrency
         | 
| 17 | 
            +
                  max_concurrency.nil? ? hosts.length : [max_concurrency, hosts.length].min
         | 
| 14 18 | 
             
                end
         | 
| 15 19 |  | 
| 16 20 | 
             
                def <<(other)
         | 
| 17 21 | 
             
                  case other
         | 
| 18 22 | 
             
                  when Cluster
         | 
| 19 | 
            -
                    other.hosts.each  | 
| 20 | 
            -
                      @hosts << host
         | 
| 21 | 
            -
                    end
         | 
| 23 | 
            +
                    other.hosts.each { |host| self << host }
         | 
| 22 24 | 
             
                  when Host
         | 
| 23 25 | 
             
                    @hosts << other
         | 
| 24 26 | 
             
                  end
         | 
| 25 27 | 
             
                end
         | 
| 26 28 |  | 
| 27 | 
            -
                 | 
| 28 | 
            -
                   | 
| 29 | 
            -
             | 
| 29 | 
            +
                %w{run exist? read directory? ls upload read write}.each do |host_method|
         | 
| 30 | 
            +
                  define_method host_method do |*args|
         | 
| 31 | 
            +
                    threaded(host_method, *args)
         | 
| 32 | 
            +
                  end
         | 
| 30 33 | 
             
                end
         | 
| 31 34 |  | 
| 32 | 
            -
                 | 
| 33 | 
            -
                  def initialize(hosts, concurrency)
         | 
| 34 | 
            -
                    @concurrency = concurrency
         | 
| 35 | 
            -
                    @hosts = hosts
         | 
| 36 | 
            -
                  end
         | 
| 35 | 
            +
                private
         | 
| 37 36 |  | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 37 | 
            +
                # Spawn +concurrency+ worker threads, each of which pops work off the
         | 
| 38 | 
            +
                # +_in+ queue, and writes values to the +_out+ queue for syncronisation.
         | 
| 39 | 
            +
                def threaded(meth, *args)
         | 
| 40 | 
            +
                  _in = run_queue
         | 
| 41 | 
            +
                  length = run_queue.length
         | 
| 42 | 
            +
                  _out = Queue.new
         | 
| 43 | 
            +
                  results = {}
         | 
| 44 | 
            +
                  (0...concurrency).map do
         | 
| 45 | 
            +
                    Thread.new do
         | 
| 46 | 
            +
                      loop do
         | 
| 47 | 
            +
                        host = _in.pop(false) rescue Thread.exit
         | 
| 49 48 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
                        end
         | 
| 49 | 
            +
                        results[host] = host.send(meth, *args)
         | 
| 50 | 
            +
                        _out << true
         | 
| 53 51 | 
             
                      end
         | 
| 54 52 | 
             
                    end
         | 
| 53 | 
            +
                  end
         | 
| 55 54 |  | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                    end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                    return results
         | 
| 55 | 
            +
                  length.times do
         | 
| 56 | 
            +
                    _out.pop
         | 
| 61 57 | 
             
                  end
         | 
| 62 58 |  | 
| 63 | 
            -
                   | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 59 | 
            +
                  results
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                def run_queue
         | 
| 63 | 
            +
                  Queue.new.tap do |q|
         | 
| 64 | 
            +
                    @hosts.each do |h|
         | 
| 65 | 
            +
                      q << h
         | 
| 68 66 | 
             
                    end
         | 
| 69 67 | 
             
                  end
         | 
| 70 68 | 
             
                end
         | 
| 71 | 
            -
             | 
| 72 69 | 
             
              end
         | 
| 73 70 | 
             
            end
         | 
    
        data/lib/gofer/version.rb
    CHANGED
    
    
| @@ -251,9 +251,7 @@ describe Gofer do | |
| 251 251 | 
             
                end
         | 
| 252 252 |  | 
| 253 253 | 
             
                it "should run commands in parallel" do
         | 
| 254 | 
            -
                  results = @cluster.run  | 
| 255 | 
            -
                    c.run "ruby -e 'puts Time.now.to_f; sleep 0.1; puts Time.now.to_f'"
         | 
| 256 | 
            -
                  end
         | 
| 254 | 
            +
                  results = @cluster.run("ruby -e 'puts Time.now.to_f; sleep 0.1; puts Time.now.to_f'")
         | 
| 257 255 |  | 
| 258 256 | 
             
                  res1 = results[@host1].stdout.lines.to_a
         | 
| 259 257 | 
             
                  res2 = results[@host2].stdout.lines.to_a
         | 
| @@ -262,9 +260,8 @@ describe Gofer do | |
| 262 260 | 
             
                end
         | 
| 263 261 |  | 
| 264 262 | 
             
                it "should respect max_concurrency" do
         | 
| 265 | 
            -
                   | 
| 266 | 
            -
             | 
| 267 | 
            -
                  end
         | 
| 263 | 
            +
                  @cluster.max_concurrency = 1
         | 
| 264 | 
            +
                  results = @cluster.run("ruby -e 'puts Time.now.to_f; sleep 0.1; puts Time.now.to_f'")
         | 
| 268 265 |  | 
| 269 266 | 
             
                  res1 = results[@host1].stdout.lines.to_a
         | 
| 270 267 | 
             
                  res2 = results[@host2].stdout.lines.to_a
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: gofer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Michael Pearson
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2013- | 
| 11 | 
            +
            date: 2013-06-02 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: net-ssh
         |