mamiya 0.0.1.alpha6 → 0.0.1.alpha7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0f7a6c651243bbb6688a23b99f6a227b9f43100
4
- data.tar.gz: db21e18cb16baad91bb16fef86b5c764d8f395b4
3
+ metadata.gz: c740e295861a9dc89bd72f70e1f693136306783a
4
+ data.tar.gz: 4ee69a07bdb07d69a945e150c6a45775c9cc451e
5
5
  SHA512:
6
- metadata.gz: 228af2b0c3e35452f515868590cde85131b79818a0b0e2c174a23e89adad56cd9ae03d3fb30aef16fbb0656dbfd581ad4b4113bc00c3dcca2d656605f8c95236
7
- data.tar.gz: 7eb0f6684de2155783e43ed516217fc5743ebdb01b708e0dc30e32e01fad6f777ae82c49a72f086ad5c29d1501190741f77d97947519fc660830e1eb3b483e72
6
+ metadata.gz: 71de35f8913cf2e1dc0af2ed38210cfe0524c8c4c5af7ae3bd7ec1ff974ea57d5aedfccaa86d8307aa9ec157b09e904b1566463c59db41eeae01ff4ad84d604d
7
+ data.tar.gz: fee51b6ef754f2770ff03edf07a37f4c0a015015d167143c1d0be27f3e24df03a049246427e1d65740f022be371d084476c4bf5f4a12ee024255eaba52cceef1
@@ -2,6 +2,7 @@ require 'mamiya/cli'
2
2
 
3
3
  require 'net/http'
4
4
  require 'net/https'
5
+ require 'rack/utils'
5
6
  require 'uri'
6
7
  require 'json'
7
8
  require 'thor'
@@ -128,6 +129,11 @@ number of agents don't have package: #{dist['not_distributed_count']}
128
129
  def rollback
129
130
  end
130
131
 
132
+ desc "join HOST", "let serf to join to HOST"
133
+ def join(host)
134
+ master_post('/join', host: host)
135
+ end
136
+
131
137
  private
132
138
 
133
139
  def fatal!(msg)
@@ -146,10 +152,19 @@ number of agents don't have package: #{dist['not_distributed_count']}
146
152
  end
147
153
 
148
154
  def master_post(path, data='')
155
+ response = nil
149
156
  master_http.start do |http|
150
- response = http.post(path, data).tap(&:value)
151
- response.code == '204' ? true : JSON.parse(response.tap(&:value).body)
157
+ if Hash === data
158
+ data = Rack::Utils.build_nested_query(data)
159
+ end
160
+
161
+ response = http.post(path, data)
162
+ response.value
163
+ response.code == '204' ? true : JSON.parse(response.body)
152
164
  end
165
+ rescue Net::HTTPExceptions => e
166
+ puts response.body rescue nil
167
+ raise e
153
168
  end
154
169
 
155
170
  def master_http
@@ -143,6 +143,19 @@ module Mamiya
143
143
  agent_monitor.refresh
144
144
  status 204
145
145
  end
146
+
147
+ post '/join' do
148
+ begin
149
+ master.serf.join(params[:host])
150
+ status 204
151
+ rescue Villein::Client::SerfError => e
152
+ raise e unless /Error joining the cluster/ === e.message
153
+
154
+ content_type :json
155
+ status 400
156
+ {error: e.message}.to_json
157
+ end
158
+ end
146
159
  end
147
160
  end
148
161
  end
@@ -1,3 +1,3 @@
1
1
  module Mamiya
2
- VERSION = "0.0.1.alpha6"
2
+ VERSION = "0.0.1.alpha7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mamiya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha6
4
+ version: 0.0.1.alpha7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Fukumori (sora_h)