ubiquity 0.0.2

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODY2OTNjOWZkNTQ0OWM3NGM2ZDk2ZjNlOWNjNDUyNTM2NGM4YWEzZQ==
5
+ data.tar.gz: !binary |-
6
+ ZDI2NDc4NjhlOGY3MmU2ZDZiMzM0YzVlMDQ0NzVjNGZjODUwMDYxOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTZhNGFjNTI0NzY0MDQ2YjEwZTc5YzMzYzk0OWJiY2I5MTAwMmE5ZjIyNmJh
10
+ OTkwZWIwOTQ3OGZkZmMxYWJhNTZjY2NhZTg0MzgyMDk0OTkyZTM1YzY1YTY4
11
+ YjYwODQ0NmFmN2FhYmMyMmJjOGQ1MjZjMTJkNWIwNDgyMmU0OTI=
12
+ data.tar.gz: !binary |-
13
+ NDJkZTdjMGIwYmE5MTdhOTdiNjMzYmNiMWVkNTZjNDk1ZjRkZDQ4ZGVkM2Fi
14
+ Njc3NTk0NmQ5ZjYzMjI2NTBmYmFjYjU1NWE4OGYyMmE4M2FmNGFhYTFkZTAy
15
+ NTdkOTcxYzg0YTc1MTMxMTEyY2NlNTA3MDhkMjNmY2U0NjVkZWE=
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Luca Cervasio
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # ubiquity
2
+
3
+ Run code everywhere and orchestrate multiple nodes.
4
+
5
+ Let's say you have two machines and want to run some code on the first, some other on the second and you
6
+ want the logic to stay on a control script interacting with the two slave nodes.
7
+
8
+ node1:
9
+
10
+ s = Ubiquity::Server.new
11
+
12
+ node2:
13
+
14
+ s = Ubiquity::Server.new
15
+
16
+ on third machine (your lap):
17
+
18
+ node1 = Ubiquity::Client.new IP_NODE1
19
+ node2 = Ubiquity::Client.new IP_NODE2
20
+
21
+ node2.on "event" do
22
+ log "event was triggered"
23
+ end
24
+
25
+ node1.exec do |scope|
26
+ log "this code is running on first node"
27
+ end
28
+
29
+ node2.exec do |scope|
30
+ log "while this one is running on 2nd node !"
31
+ sleep 2
32
+ notify "event"
33
+ end
34
+
35
+ ## License
36
+
37
+ [MIT License](https://github.com/lucacervasio/ubiquity/blob/master/LICENSE) © Luca Cervasio
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ubiquity'
4
+
5
+ c = Ubiquity::Client.new
6
+
7
+
8
+ c.on "got hello request" do
9
+ puts "eccoci"
10
+ end
11
+
12
+ c.exec do |scope|
13
+
14
+ require "sinatra/base"
15
+
16
+ class Example < Sinatra::Base
17
+ get "/hello" do
18
+ notify "got hello request"
19
+ "Hello"
20
+ end
21
+ end
22
+
23
+
24
+ Thread.new {
25
+ Example.run!
26
+ }
27
+
28
+ scope["web"] = "ciao bello"
29
+ end
30
+
31
+
32
+ c.exec do |scope|
33
+ log scope["web"]
34
+ end
35
+
36
+
37
+
38
+ sleep 10
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ubiquity'
4
+
5
+ s = Ubiquity::Server.new
6
+
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sourcify'
4
+ require 'socket'
5
+ require 'json'
6
+
7
+ module Kernel
8
+ def notify msg
9
+ puts "notify #{msg}"
10
+ $client.puts "NOTIFY:#{msg}"
11
+ end
12
+
13
+ def log msg
14
+ puts "log"
15
+ $client.puts "PUTS:#{msg}"
16
+ end
17
+
18
+ end
19
+
20
+ module Ubiquity
21
+
22
+ class Server
23
+ def initialize port=1978
24
+ @scope = {}
25
+ server = TCPServer.new port
26
+ puts "Ubiquity server listening on port 0.0.0.0:#{port}"
27
+ $client = server.accept
28
+ while line = $client.gets
29
+ block = JSON.parse(line)
30
+ c = eval(block["cmd"])
31
+ c.call @scope, self
32
+ end
33
+ $client.close
34
+ end
35
+
36
+
37
+ end
38
+
39
+ class Client
40
+ def initialize remote_ip='localhost', port=1978
41
+ @hooks = []
42
+ @client = TCPSocket.new remote_ip, port
43
+ Thread.new {
44
+ while line = @client.gets
45
+ if line =~ /NOTIFY:(.+)/
46
+ notify_msg = $1.gsub("\n", "")
47
+ @hooks.each do |h|
48
+ if notify_msg == h[:hook]
49
+ h[:cb].call
50
+ end
51
+ end
52
+ elsif line =~ /PUTS:(.+)/
53
+ puts $1
54
+ end
55
+
56
+ end
57
+ }
58
+ end
59
+
60
+ def exec &block
61
+ a = block.to_source
62
+ @client.puts ({:cmd => a}.to_json)
63
+ end
64
+
65
+ def on msg, &block
66
+ @hooks << {:hook => msg, :cb => block}
67
+ end
68
+ end
69
+
70
+ end
71
+
@@ -0,0 +1,3 @@
1
+ module Ubiquity
2
+ VERSION = "0.0.2"
3
+ end
data/lib/ubiquity.rb ADDED
@@ -0,0 +1,2 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "ubiquity")
2
+ require 'protocol'
data/ubiquity.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ require './lib/ubiquity/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'ubiquity'
5
+ spec.version = Ubiquity::VERSION
6
+ spec.date = Date.today.to_s
7
+ spec.summary = "Run code everywhere and orchestrate multiple nodes"
8
+ spec.description = "A ruby library for running code on remote nodes."
9
+ spec.authors = ["Luca Cervasio"]
10
+ spec.email = 'luca.cervasio@gmail.com'
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.homepage = 'https://github.com/lucacervasio/ubiquity'
13
+ spec.license = 'MIT'
14
+
15
+ spec.add_dependency('sourcify', '~> 0.6', '>= 0.6.0')
16
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubiquity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Luca Cervasio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sourcify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.6.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.6'
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.0
33
+ description: A ruby library for running code on remote nodes.
34
+ email: luca.cervasio@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - LICENSE
41
+ - README.md
42
+ - examples/client.rb
43
+ - examples/server.rb
44
+ - lib/ubiquity.rb
45
+ - lib/ubiquity/protocol.rb
46
+ - lib/ubiquity/version.rb
47
+ - ubiquity.gemspec
48
+ homepage: https://github.com/lucacervasio/ubiquity
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.6
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Run code everywhere and orchestrate multiple nodes
72
+ test_files: []