boutons 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3725cdf57857dd843adbd07ea4d50ec2701031b6
4
+ data.tar.gz: 9d8f50f07a9dee59dbf35e95b50d8630a511af07
5
+ SHA512:
6
+ metadata.gz: 7239f94d033e3ed5abb780a7d8bbd1fd8c759456c657bbcffac447ee1625e50d3ddf30cd38379fa6dd5bd8921a1651b0307854f63b91cb4740e3a8723bf6c3dd
7
+ data.tar.gz: b178bd4562b97c38751bdd3ce61aaccc8b9169a0e6a5a958b498d9cc47e400d4bcbc7ab0ae41a9a36efbbb257d3a847107bf0514312fc7f09e37c94eb20e5ce9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boutons.gemspec
4
+ gemspec
@@ -0,0 +1,39 @@
1
+ # Boutons
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/boutons`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'boutons'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install boutons
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, 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` to 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
+ 1. Fork it ( https://github.com/[my-github-username]/boutons/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boutons"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boutons/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boutons"
8
+ spec.version = Boutons::VERSION
9
+ spec.authors = ["Mathias Kaufmann"]
10
+ spec.email = ["me@stei.gr"]
11
+
12
+ spec.summary = %q{Boutons organizes your Synapse configuration.}
13
+ spec.description = %q{Boutons organizes your Synapse configuration. It handle rconfiguration and adding frontend at runtime.}
14
+ spec.homepage = "https://synapse.stei.gr/boutons"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "synapse", "~> 0.11"
22
+ spec.add_dependency "synapse-easy", "~> 0.1"
23
+ spec.add_dependency "synapse-config", "~> 0.1"
24
+ spec.add_dependency "synapse-logging-interchangeable", "~> 0.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "unirest"
29
+ end
@@ -0,0 +1,108 @@
1
+ require "boutons/version"
2
+ require "synapse"
3
+ require "synapse/easy"
4
+ require "synapse/config"
5
+ require "active_support/core_ext/hash/indifferent_access"
6
+ require "zookeeper"
7
+ require "boutons/synapse"
8
+ require "synapse/logging/interchangeable"
9
+
10
+ module Boutons
11
+ class SynapseNotFound < Exception; end
12
+ class << self
13
+ @@haproxy = Synapse::Config::Haproxy.new Synapse::Easy::Haproxy.new
14
+ @@services = Synapse::Config::Services.new
15
+ @@config = { services: @@services, haproxy: @@haproxy }.with_indifferent_access
16
+ @@logger = Logger.new(STDERR,progname:"Boutons")
17
+ @@mapping = {}
18
+ def add synapse
19
+ return if @@services[synapse.name]
20
+ @@services[synapse.name] = synapse
21
+ refresh
22
+ update
23
+ end
24
+ def remove name
25
+ @@services[@@mapping[name]] = nil
26
+ refresh
27
+ update
28
+ end
29
+ def with_loggers
30
+ [@@logger,@@synapse.logger,@@synapse.service_watchers.collect{|s|s.logger}].each do |logger|
31
+ yield(logger) if block_given
32
+ end
33
+ end
34
+ def log_with logger, synapses:nil
35
+ @@logger.info "Replace logger #{@@logger} with #{logger}"
36
+ @@logger=logger
37
+ @@synapse.logger=@@logger
38
+ return unless synapses
39
+ if synapses.to_sym == :all
40
+ return @@synapse.service_watchers.map{|s|s.logger=@@logger}
41
+ end
42
+ @@synapse.service_watchers.each do |services_watcher|
43
+ if synapses==services_watcher.name
44
+ services_watcher.logger = @@logger
45
+ end
46
+ end
47
+ end
48
+ def haproxy
49
+ @@haproxy
50
+ end
51
+ def all
52
+ @@services
53
+ end
54
+ private
55
+ def refresh
56
+ return if defined? @@synapse
57
+ @@synapse ||= Synapse::Synapse.new @@config # rescue nil
58
+ return unless @@synapse
59
+ @@services.map{|n,s|s.active=true}
60
+ @@haproxy.inform @@synapse
61
+ @@services.inform @@synapse
62
+ @@synapse.services = @@services
63
+ @@synapse_thread = Thread.new do
64
+ @@synapse.run
65
+ end
66
+ wait
67
+ at_exit do
68
+ @@logger.info "Clean up!"
69
+ end
70
+ end
71
+ def wait
72
+ loop do
73
+ break unless restart_required
74
+ sleep 0.01
75
+ end
76
+ end
77
+ def restart_required
78
+ @@synapse.instance_variable_get("@haproxy").instance_variable_get("@restart_required")
79
+ end
80
+ def update
81
+ @@mapping = {}
82
+ @@services.each do |name,synapse|
83
+ next if @@mapping[normalize synapse.name]
84
+ @@mapping[normalize synapse.name] = name
85
+ end
86
+ @@services.each do |name,synapse|
87
+ synapse.aliases.each do |synapse_alias|
88
+ next if @@mapping[normalize synapse_alias]
89
+ @@mapping[normalize synapse_alias] = name
90
+ end
91
+ end
92
+ end
93
+ def normalize name
94
+ name.gsub(/\./,"_").to_sym
95
+ end
96
+ def method_missing method, *args, &block
97
+ name = @@mapping[method]
98
+ unless name
99
+ return @@services.send(method, *args, &block) if @@services.respond_to? method
100
+ raise SynapseNotFound.new("The Synapse #{method} cannot be resolved") unless name
101
+ end
102
+ synapse = @@services[name]
103
+ raise SynapseNotFound.new("The Synapse #{method} cannot be resolved") unless synapse
104
+ return synapse if args.empty?
105
+ synapse.send(args[0],*args,&block)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,27 @@
1
+ module Synapse
2
+ class Synapse
3
+ def services= services
4
+ @services = services
5
+ end
6
+ def add_service service
7
+ @service_watchers ||= []
8
+ @service_watchers << ServiceWatcher.create(service.name, service, self)
9
+ end
10
+ def service_watchers
11
+ @service_watchers
12
+ end
13
+ def reconfigure!
14
+ return if @reconfiguring
15
+ @reconfiguring=true
16
+ @services.select{|n,s|!s.active}.each do |name,config|
17
+ log.info "attach service #{name}"
18
+ watcher = ServiceWatcher.create(name, config, self)
19
+ watcher.start
20
+ config.active=true
21
+ @service_watchers << watcher
22
+ end
23
+ @reconfiguring=false
24
+ @config_updated = true
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Boutons
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boutons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mathias Kaufmann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: synapse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: synapse-easy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: synapse-config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: synapse-logging-interchangeable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: unirest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Boutons organizes your Synapse configuration. It handle rconfiguration
112
+ and adding frontend at runtime.
113
+ email:
114
+ - me@stei.gr
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - boutons.gemspec
127
+ - lib/boutons.rb
128
+ - lib/boutons/synapse.rb
129
+ - lib/boutons/version.rb
130
+ homepage: https://synapse.stei.gr/boutons
131
+ licenses: []
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.6
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Boutons organizes your Synapse configuration.
153
+ test_files: []