odania 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/odania/consul.rb +1 -29
- data/lib/odania/plugin.rb +49 -0
- data/lib/odania/service.rb +33 -0
- data/lib/odania/version.rb +1 -1
- data/lib/odania.rb +28 -0
- data/spec/{odania_spec.rb → odania/plugin_spec.rb} +4 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98f1b35d343d29593bd92072acba51056e07f691
|
4
|
+
data.tar.gz: 1473ba35af554c2addb4b67b328b456667f8dabe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a2ea5dce9d5d95f5cf14256f085a1a6c4be5175abb8c9cbb7aac82f76dd8bf01e3d735413cd4357b957cc96020b3c3400c6501b9aad8ea6ed7d679ff170383
|
7
|
+
data.tar.gz: 26ad3362b23cd99dbc1df1a7099c1fd0c16ea488759336b828550947addc3e12a8c9a8cc98d630068b4befb6d0820b370e205df5796d5b14d92bbe428304d55c
|
data/Gemfile.lock
CHANGED
data/lib/odania/consul.rb
CHANGED
@@ -1,34 +1,6 @@
|
|
1
1
|
module Odania
|
2
2
|
class Consul
|
3
|
-
|
4
|
-
consul_url = "http://#{ENV['CONSUL_PORT_8500_TCP_ADDR']}:#{ENV['CONSUL_PORT_8500_TCP_PORT']}"
|
5
|
-
puts "Consul: #{consul_url}"
|
6
|
-
|
7
|
-
Diplomat.configure do |config|
|
8
|
-
# Set up a custom Consul URL
|
9
|
-
config.url = consul_url
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_config
|
14
|
-
configs = retrieve_value 'plugins'
|
15
|
-
puts
|
16
|
-
puts 'Configs'
|
17
|
-
puts configs.inspect
|
18
|
-
puts
|
19
|
-
puts
|
20
|
-
|
21
|
-
result = {}
|
22
|
-
configs.each do |json_data|
|
23
|
-
config = JSON.parse json_data[:value]
|
24
|
-
# TODO merge
|
25
|
-
puts config.inspect
|
26
|
-
result = config
|
27
|
-
end
|
28
|
-
result
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
3
|
+
protected
|
32
4
|
|
33
5
|
def retrieve_value(plugin_path)
|
34
6
|
begin
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Odania
|
2
|
+
class Plugin < Odania::Consul
|
3
|
+
def plugins_config
|
4
|
+
configs = retrieve_value 'plugins'
|
5
|
+
puts
|
6
|
+
puts 'Configs'
|
7
|
+
puts configs.inspect
|
8
|
+
puts
|
9
|
+
puts
|
10
|
+
|
11
|
+
result = {}
|
12
|
+
configs.each do |json_data|
|
13
|
+
config = JSON.parse json_data[:value]
|
14
|
+
# TODO merge
|
15
|
+
puts config.inspect
|
16
|
+
result = config
|
17
|
+
end
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_plugin(plugin_config)
|
22
|
+
plugin_name = plugin_config['name']
|
23
|
+
plugin_instance_name = get_plugin_instance_name plugin_name
|
24
|
+
|
25
|
+
puts "Writing plugin instance config: #{plugin_instance_name}"
|
26
|
+
Diplomat::Kv.put("#{get_plugin_path(plugin_name)}#{plugin_instance_name}", JSON.dump(plugin_config))
|
27
|
+
|
28
|
+
Odania.service.add_service(plugin_name, plugin_instance_name, plugin_config['ip'])
|
29
|
+
|
30
|
+
Diplomat::Event.fire('updated_plugin_config', "#{plugin_name}|#{plugin_instance_name}")
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def get_plugin_path(plugin_name)
|
36
|
+
"plugins/#{plugin_name}/"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Generate a unique number for this instance of the plugin
|
40
|
+
def get_plugin_instance_name(plugin_name)
|
41
|
+
available_plugins = retrieve_value(get_plugin_path(plugin_name))
|
42
|
+
|
43
|
+
puts 'Current plugins'
|
44
|
+
puts available_plugins.inspect
|
45
|
+
|
46
|
+
"#{plugin_name}_#{available_plugins.length + 1}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Odania
|
2
|
+
class Service < Odania::Consul
|
3
|
+
def register_service(plugin_name, plugin_instance_name, ip)
|
4
|
+
puts "Registering service #{plugin_name} as instance #{plugin_instance_name}"
|
5
|
+
if Diplomat::Service.register consul_service_config(plugin_name, plugin_instance_name, ip)
|
6
|
+
puts 'Service registered'
|
7
|
+
else
|
8
|
+
puts 'Error registering service'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def consul_service_config(plugin_name, plugin_instance_name, ip)
|
15
|
+
{
|
16
|
+
'id' => plugin_instance_name,
|
17
|
+
'name' => plugin_name,
|
18
|
+
'tags' => ['odania-static'],
|
19
|
+
'port' => 80,
|
20
|
+
'token' => plugin_instance_name,
|
21
|
+
'checks' => [
|
22
|
+
{
|
23
|
+
'id' => plugin_name,
|
24
|
+
'name' => 'HTTP on port 80',
|
25
|
+
'http' => "http://#{ip}:80/health",
|
26
|
+
'interval' => '10s',
|
27
|
+
'timeout' => '1s'
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/odania/version.rb
CHANGED
data/lib/odania.rb
CHANGED
@@ -3,4 +3,32 @@ require 'diplomat'
|
|
3
3
|
|
4
4
|
module Odania
|
5
5
|
autoload :Consul, 'odania/consul'
|
6
|
+
autoload :Service, 'odania/service'
|
7
|
+
autoload :Plugin, 'odania/plugin'
|
8
|
+
|
9
|
+
def self.service(consul_url=nil)
|
10
|
+
if @service.nil?
|
11
|
+
Odania.configure
|
12
|
+
@service = Service.new(consul_url)
|
13
|
+
end
|
14
|
+
@service
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.plugin
|
18
|
+
Odania.configure
|
19
|
+
@plugin = Plugin.new if @plugin.nil?
|
20
|
+
@plugin
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configure(consul_url=nil)
|
24
|
+
if @configured.nil?
|
25
|
+
consul_url = "http://#{ENV['CONSUL_PORT_8500_TCP_ADDR']}:#{ENV['CONSUL_PORT_8500_TCP_PORT']}" if consul_url.nil?
|
26
|
+
puts "Consul URL: #{consul_url}"
|
27
|
+
Diplomat.configure do |config|
|
28
|
+
# Set up a custom Consul URL
|
29
|
+
config.url = consul_url
|
30
|
+
end
|
31
|
+
@configured = true
|
32
|
+
end
|
33
|
+
end
|
6
34
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Odania::
|
4
|
-
subject { Odania::
|
3
|
+
describe Odania::Plugin do
|
4
|
+
subject { Odania::Plugin.new }
|
5
5
|
|
6
|
-
describe '
|
7
|
-
let(:output) { subject.
|
6
|
+
describe 'plugins_config' do
|
7
|
+
let(:output) { subject.plugins_config }
|
8
8
|
|
9
9
|
it 'retrieves config' do
|
10
10
|
allow(subject).to receive(:retrieve_value) do |plugin_path|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odania
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Petersen
|
@@ -81,9 +81,11 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/odania.rb
|
83
83
|
- lib/odania/consul.rb
|
84
|
+
- lib/odania/plugin.rb
|
85
|
+
- lib/odania/service.rb
|
84
86
|
- lib/odania/version.rb
|
85
87
|
- odania.gemspec
|
86
|
-
- spec/
|
88
|
+
- spec/odania/plugin_spec.rb
|
87
89
|
- spec/spec_helper.rb
|
88
90
|
- tasks/rspec.rake
|
89
91
|
homepage: http://www.odania.com
|
@@ -111,5 +113,5 @@ signing_key:
|
|
111
113
|
specification_version: 4
|
112
114
|
summary: Helper for the odania portal
|
113
115
|
test_files:
|
114
|
-
- spec/
|
116
|
+
- spec/odania/plugin_spec.rb
|
115
117
|
- spec/spec_helper.rb
|