astapor 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.
- checksums.yaml +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +121 -0
- data/Rakefile +2 -0
- data/astapor.gemspec +23 -0
- data/lib/astapor/version.rb +3 -0
- data/lib/astapor.rb +57 -0
- metadata +79 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
OGMxNjI0ZTQxMzcwOWNhNDViMmFhNWIzYzkxNzMzM2UyNmM3MDgzMQ==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
MTlhZThjNDYxNzAyYzk3ZTE4NTNlNGRiN2NiNzk3ODJlYmNmY2VjZg==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
ZjYzNjY1ZTAzOGEzMzFlYmMyOTlmMzQ5YTE3MGI2NmJiMDMyYTVkMTI2ODE2
|
|
10
|
+
OWMxNzAyYzQxNjFmYzNjZWFjNjA5NDliM2E4MWM2NWZiNWI1ODI2MGMxOGFj
|
|
11
|
+
ZmM0OGZjMjIwNTY5YjM4NGQ5NjE4Njk4OWMxZjcwZTNmMThjYWU=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
NzhkMTJlNmQwYjY4OTQ1ZWQzODFhN2M2MDJmNjdjNWJlZjk0ZjgxMDI0NjFl
|
|
14
|
+
NzI3OWUwZDU4YTMzNjA1OTc0ZDRhOTVlZmYzZjZmYmEwOTM1YzU2YTkxOWJm
|
|
15
|
+
YzA3ZjE4YmU5ODNjZDJmN2Q4YjMzMTNjYWFmY2RiMzIzOGRlY2U=
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 MTN Satellite Communications
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Astapor
|
|
2
|
+
|
|
3
|
+
A ruby port of https://github.com/garethr/serf-master
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'astapor'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install astapor
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Create a ~/handler.rb handler file like so:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
#!/usr/bin/env ruby
|
|
25
|
+
|
|
26
|
+
require 'astapor'
|
|
27
|
+
|
|
28
|
+
class HelloHandler < Astapor::SerfHandler
|
|
29
|
+
def hello_world
|
|
30
|
+
puts "SOMEONE SAID HELLO with payload of #{ARGF.read}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class MemberJoinHandler < Astapor::SerfHandler
|
|
35
|
+
def member_join
|
|
36
|
+
puts "A member joined! Hello member!"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
handler = Astapor::SerfHandlerProxy.new
|
|
41
|
+
handler.register("responder", HelloHandler.new)
|
|
42
|
+
handler.register("default", MemberJoinHandler.new)
|
|
43
|
+
handler.run
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Run serf agent:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
serf agent -tag="role=default" -event-handler="~/handler.rb" -log-level=debug
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
you will see something like:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
==> Starting Serf agent...
|
|
56
|
+
==> Starting Serf agent RPC...
|
|
57
|
+
==> Serf agent running!
|
|
58
|
+
Node name: 'yourmachine.local'
|
|
59
|
+
Bind addr: '0.0.0.0:7946'
|
|
60
|
+
RPC addr: '127.0.0.1:7373'
|
|
61
|
+
Encrypted: false
|
|
62
|
+
Snapshot: false
|
|
63
|
+
Profile: lan
|
|
64
|
+
|
|
65
|
+
==> Log data will now stream in as it occurs:
|
|
66
|
+
|
|
67
|
+
2014/06/04 13:10:54 [INFO] agent: Serf agent starting
|
|
68
|
+
2014/06/04 13:10:54 [INFO] serf: EventMemberJoin: yourmachine.local 10.200.17.37
|
|
69
|
+
2014/06/04 13:10:55 [INFO] agent: Received event: member-join
|
|
70
|
+
2014/06/04 13:10:55 [DEBUG] agent: Event 'member-join' script output: A member joined! Hello member!
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
exit serf agent and restart with:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
serf agent -tag="role=responder" -event-handler="~/handler.rb" -log-level=d
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
you will see something like:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
==> Starting Serf agent...
|
|
83
|
+
==> Starting Serf agent RPC...
|
|
84
|
+
==> Serf agent running!
|
|
85
|
+
Node name: 'yourmachine.local'
|
|
86
|
+
Bind addr: '0.0.0.0:7946'
|
|
87
|
+
RPC addr: '127.0.0.1:7373'
|
|
88
|
+
Encrypted: false
|
|
89
|
+
Snapshot: false
|
|
90
|
+
Profile: lan
|
|
91
|
+
|
|
92
|
+
==> Log data will now stream in as it occurs:
|
|
93
|
+
|
|
94
|
+
2014/06/04 13:12:07 [INFO] agent: Serf agent starting
|
|
95
|
+
2014/06/04 13:12:07 [INFO] serf: EventMemberJoin: yourmachine.local 10.200.17.37
|
|
96
|
+
2014/06/04 13:12:08 [INFO] agent: Received event: member-join
|
|
97
|
+
2014/06/04 13:12:08 [DEBUG] agent: Event 'member-join' script output: Astapor::SerfHandlerProxy: 2014-06-04 13:12:08 -0700: INFO: event member_join not implemented by HelloHandler class
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Now issue a serf event from another terminal:
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
serf event hello_world world
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
You will see this in agent output:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
2014/06/04 13:13:33 [INFO] agent.ipc: Accepted client: 127.0.0.1:63048
|
|
110
|
+
2014/06/04 13:13:33 [DEBUG] agent: Requesting user event send: hello_world. Coalesced: true. Payload: "world"
|
|
111
|
+
2014/06/04 13:13:34 [INFO] agent: Received event: user-event: hello_world
|
|
112
|
+
2014/06/04 13:13:34 [DEBUG] agent: Event 'user' script output: SOMEONE SAID HELLO with payload of world
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
|
|
117
|
+
1. Fork it ( https://github.com/[my-github-username]/astapor/fork )
|
|
118
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
119
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
120
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
121
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/astapor.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 'astapor/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "astapor"
|
|
8
|
+
spec.version = Astapor::VERSION
|
|
9
|
+
spec.authors = ["2014 MTN Satellite Communications"]
|
|
10
|
+
spec.email = ["maratoid@gmail.com"]
|
|
11
|
+
spec.summary = %q{Serf event router. Ported from https://github.com/garethr/serf-master}
|
|
12
|
+
spec.description = %q{Serf event router. Ported from https://github.com/garethr/serf-master}
|
|
13
|
+
spec.homepage = "https://github.com/MTNSatelliteComm/astapor"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
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 = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
end
|
data/lib/astapor.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "astapor/version"
|
|
2
|
+
require 'logger'
|
|
3
|
+
|
|
4
|
+
module Astapor
|
|
5
|
+
class SerfHandler
|
|
6
|
+
def initialize
|
|
7
|
+
@name = ENV['SERF_SELF_NAME']
|
|
8
|
+
@role = ENV['SERF_TAG_ROLE'] || ENV['SERF_SELF_ROLE']
|
|
9
|
+
@logger = Logger.new(STDOUT)
|
|
10
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
|
11
|
+
"#{self.class.name}: #{datetime}: #{severity}: #{msg}\n"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if ENV['SERF_EVENT'] == 'user'
|
|
15
|
+
@event = ENV['SERF_USER_EVENT'].gsub '-', '_'
|
|
16
|
+
else
|
|
17
|
+
@event = ENV['SERF_EVENT'].gsub '-', '_'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class SerfHandlerProxy < SerfHandler
|
|
23
|
+
def initialize
|
|
24
|
+
super()
|
|
25
|
+
@handlers = Hash.new
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def register(role, handler)
|
|
29
|
+
@handlers[role] = handler
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_klass
|
|
33
|
+
klass = nil
|
|
34
|
+
if @handlers.has_key?(@role)
|
|
35
|
+
klass = @handlers[@role]
|
|
36
|
+
elsif @handlers.has_key?('default')
|
|
37
|
+
klass = @handlers['default']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
klass
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def run
|
|
44
|
+
klass = get_klass
|
|
45
|
+
if klass.nil?
|
|
46
|
+
@logger.info("no handler for role #{@role}")
|
|
47
|
+
else
|
|
48
|
+
begin
|
|
49
|
+
method_object = klass.method(@event.to_sym)
|
|
50
|
+
method_object.call
|
|
51
|
+
rescue NameError => e
|
|
52
|
+
@logger.info("event #{@event} not implemented by #{klass.class.name} class")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: astapor
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- 2014 MTN Satellite Communications
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ! '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ! '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: Serf event router. Ported from https://github.com/garethr/serf-master
|
|
42
|
+
email:
|
|
43
|
+
- maratoid@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- Gemfile
|
|
49
|
+
- LICENSE.txt
|
|
50
|
+
- README.md
|
|
51
|
+
- Rakefile
|
|
52
|
+
- astapor.gemspec
|
|
53
|
+
- lib/astapor.rb
|
|
54
|
+
- lib/astapor/version.rb
|
|
55
|
+
homepage: https://github.com/MTNSatelliteComm/astapor
|
|
56
|
+
licenses:
|
|
57
|
+
- MIT
|
|
58
|
+
metadata: {}
|
|
59
|
+
post_install_message:
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ! '>='
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ! '>='
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubyforge_project:
|
|
75
|
+
rubygems_version: 2.2.2
|
|
76
|
+
signing_key:
|
|
77
|
+
specification_version: 4
|
|
78
|
+
summary: Serf event router. Ported from https://github.com/garethr/serf-master
|
|
79
|
+
test_files: []
|