homeaway-storm 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +209 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/homeaway-storm.gemspec +33 -0
- data/lib/homeaway/storm.rb +33 -0
- data/lib/homeaway/storm/adapters/faraday.rb +73 -0
- data/lib/homeaway/storm/client.rb +146 -0
- data/lib/homeaway/storm/domain/client_includes.rb +28 -0
- data/lib/homeaway/storm/domain/cluster.rb +31 -0
- data/lib/homeaway/storm/domain/ext/.gitkeep +0 -0
- data/lib/homeaway/storm/domain/supervisor.rb +26 -0
- data/lib/homeaway/storm/domain/topology.rb +52 -0
- data/lib/homeaway/storm/errors/storm_api_errors.rb +139 -0
- data/lib/homeaway/storm/response.rb +53 -0
- data/lib/homeaway/storm/util/defaults.rb +64 -0
- data/lib/homeaway/storm/util/validators.rb +123 -0
- data/lib/homeaway/storm/version.rb +20 -0
- metadata +261 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'homeaway/storm/domain/topology'
|
17
|
+
require 'homeaway/storm/domain/cluster'
|
18
|
+
require 'homeaway/storm/domain/supervisor'
|
19
|
+
|
20
|
+
module HomeAway
|
21
|
+
module Storm
|
22
|
+
class Client
|
23
|
+
include HomeAway::Storm::Domain::Topology
|
24
|
+
include HomeAway::Storm::Domain::Cluster
|
25
|
+
include HomeAway::Storm::Domain::Supervisor
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module HomeAway
|
17
|
+
module Storm
|
18
|
+
module Domain
|
19
|
+
module Cluster
|
20
|
+
|
21
|
+
def cluster_configuration
|
22
|
+
get '/api/v1/cluster/configuration'
|
23
|
+
end
|
24
|
+
|
25
|
+
def cluster_summary
|
26
|
+
get '/api/v1/cluster/summary'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module HomeAway
|
17
|
+
module Storm
|
18
|
+
module Domain
|
19
|
+
module Supervisor
|
20
|
+
def supervisor_summary
|
21
|
+
get '/api/v1/supervisor/summary'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module HomeAway
|
17
|
+
module Storm
|
18
|
+
module Domain
|
19
|
+
module Topology
|
20
|
+
def topology_summary
|
21
|
+
get '/api/v1/topology/summary'
|
22
|
+
end
|
23
|
+
|
24
|
+
def topology(id, opts={})
|
25
|
+
get "/api/v1/topology/#{id}", opts
|
26
|
+
end
|
27
|
+
|
28
|
+
def topology_component(id, component, opts={})
|
29
|
+
get "/api/v1/topology/#{id}/component/#{component}", opts
|
30
|
+
end
|
31
|
+
|
32
|
+
def topology_activate(id)
|
33
|
+
post "/api/v1/topology/#{id}/activate", {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def topology_deactivate(id)
|
37
|
+
post "/api/v1/topology/#{id}/deactivate", {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def topology_rebalance(id, wait_time, rebalance_opts={})
|
41
|
+
body = {}
|
42
|
+
body[:rebalanceOptions] = rebalance_opts unless rebalance_opts.empty?
|
43
|
+
post "/api/v1/topology/#{id}/rebalance/#{wait_time}", body
|
44
|
+
end
|
45
|
+
|
46
|
+
def topology_kill(id, wait_time)
|
47
|
+
post "/api/v1/topology/#{id}/kill/#{wait_time}", {}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module HomeAway
|
17
|
+
module Storm
|
18
|
+
# a collection of error classes corresponding to various errors that might be raised by the Storm API
|
19
|
+
module Errors
|
20
|
+
|
21
|
+
# @private
|
22
|
+
class StormAPIError < StandardError
|
23
|
+
|
24
|
+
attr_reader :response
|
25
|
+
|
26
|
+
# @private
|
27
|
+
def initialize(response=nil)
|
28
|
+
@response = response
|
29
|
+
end
|
30
|
+
|
31
|
+
# @private
|
32
|
+
def to_s
|
33
|
+
begin
|
34
|
+
buf = "#{self.class.name} #{@response._metadata.status_code} "
|
35
|
+
@response.violations.each do |violation|
|
36
|
+
buf << "#{violation.description} | "
|
37
|
+
end
|
38
|
+
buf = buf[0..-3] unless @response.violations.empty?
|
39
|
+
return buf
|
40
|
+
rescue
|
41
|
+
if @response.nil?
|
42
|
+
super
|
43
|
+
else
|
44
|
+
@response.to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @private
|
50
|
+
def self.method_missing(name, *args, &block)
|
51
|
+
if @response.respond_to? name
|
52
|
+
@response.send name
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# raised when the token a client is using has become expired
|
60
|
+
class TokenExpiredError < StandardError
|
61
|
+
end
|
62
|
+
|
63
|
+
# @private
|
64
|
+
class ClientError < StormAPIError
|
65
|
+
end
|
66
|
+
|
67
|
+
# represents a HTTP 400
|
68
|
+
class BadRequestError < ClientError
|
69
|
+
CODE = 400
|
70
|
+
end
|
71
|
+
|
72
|
+
# represents a HTTP 500
|
73
|
+
class InternalServerError < StormAPIError
|
74
|
+
CODE = 500
|
75
|
+
end
|
76
|
+
|
77
|
+
# represents a HTTP 404
|
78
|
+
class ResourceNotFoundError < ClientError
|
79
|
+
CODE = 404
|
80
|
+
end
|
81
|
+
|
82
|
+
# represents a HTTP 401
|
83
|
+
class UnauthorizedError < ClientError
|
84
|
+
CODE = 401
|
85
|
+
end
|
86
|
+
|
87
|
+
# represents a HTTP 403
|
88
|
+
class ForbiddenError < ClientError
|
89
|
+
CODE = 403
|
90
|
+
end
|
91
|
+
|
92
|
+
# represents a HTTP 405
|
93
|
+
class MethodNotAllowedError < ClientError
|
94
|
+
CODE = 405
|
95
|
+
end
|
96
|
+
|
97
|
+
# represents a HTTP 429. This will be raised when a client exceeds their rate limit
|
98
|
+
class TooManyRequestsError < ClientError
|
99
|
+
CODE = 429
|
100
|
+
end
|
101
|
+
|
102
|
+
# represents a HTTP 503
|
103
|
+
class APINotAvailableError < StormAPIError
|
104
|
+
CODE = 503
|
105
|
+
end
|
106
|
+
|
107
|
+
# represents a HTTP 406
|
108
|
+
class NotAcceptableError < ClientError
|
109
|
+
CODE = 406
|
110
|
+
end
|
111
|
+
|
112
|
+
# represents a HTTP 409
|
113
|
+
class ConflictError < ClientError
|
114
|
+
CODE = 409
|
115
|
+
end
|
116
|
+
|
117
|
+
# @private
|
118
|
+
class ImATeapotError < ClientError
|
119
|
+
#hopefully this is never ever used
|
120
|
+
CODE = 418
|
121
|
+
end
|
122
|
+
|
123
|
+
# @private
|
124
|
+
def self.for_http_code(status_code)
|
125
|
+
begin
|
126
|
+
self.const_get(self.constants.select do |c|
|
127
|
+
const = self.const_get c
|
128
|
+
Class === const &&
|
129
|
+
const.const_defined?(:CODE) &&
|
130
|
+
const.const_get(:CODE) == status_code.to_i
|
131
|
+
end.first)
|
132
|
+
rescue => _
|
133
|
+
StormAPIError
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module HomeAway
|
17
|
+
module Storm
|
18
|
+
# A container around the response that the Storm API returns.
|
19
|
+
# This object extends Hashie::Mash and can be accessed in an identical method
|
20
|
+
class Response < Hashie::Mash
|
21
|
+
|
22
|
+
# @private
|
23
|
+
def convert_key(key) #:nodoc:
|
24
|
+
if key.to_s.include? '_' #naive way of detecting snake case
|
25
|
+
HomeAway::Storm::Util::Validators.camel_case(key) #for reads
|
26
|
+
else
|
27
|
+
HomeAway::Storm::Util::Validators.snake_case(key) #for writes
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# a helper method to determine if this response has
|
32
|
+
# any particular fields in its payload, potentially
|
33
|
+
# nested
|
34
|
+
#
|
35
|
+
# @param attrs [Symbol] one or more symbols to search into this response with
|
36
|
+
def has?(*attrs)
|
37
|
+
entity = self
|
38
|
+
attrs.each do |attr|
|
39
|
+
return false unless entity.has_key?(attr.to_sym)
|
40
|
+
entity = entity.send(attr.to_sym)
|
41
|
+
end
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns information about the request that was just made. This includes
|
46
|
+
# things such as connection headers and status code
|
47
|
+
# @return [HomeAway::Storm::Response] information about the request that was made
|
48
|
+
def _metadata
|
49
|
+
@metadata ||= HomeAway::Storm::Response.new
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'singleton'
|
17
|
+
|
18
|
+
module HomeAway
|
19
|
+
module Storm
|
20
|
+
module Util
|
21
|
+
# @private
|
22
|
+
class Defaults
|
23
|
+
include Singleton
|
24
|
+
|
25
|
+
def port
|
26
|
+
'8080'
|
27
|
+
end
|
28
|
+
|
29
|
+
def scheme
|
30
|
+
:http
|
31
|
+
end
|
32
|
+
|
33
|
+
def logger
|
34
|
+
default_logger = Logger.new(STDOUT)
|
35
|
+
default_logger.level = Logger::WARN
|
36
|
+
default_logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def cache_control
|
40
|
+
'max-age: 0, must-revalidate'
|
41
|
+
end
|
42
|
+
|
43
|
+
def connection_opts
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
|
47
|
+
def adapter
|
48
|
+
:faraday
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash
|
52
|
+
keys = self.class.instance_methods(false)
|
53
|
+
keys.delete(:to_hash)
|
54
|
+
hash = {}
|
55
|
+
keys.each do |key|
|
56
|
+
hash[key] = send key
|
57
|
+
end
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
end.freeze
|
61
|
+
Defaults.instance.freeze
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Copyright (c) 2016 HomeAway.com, Inc.
|
2
|
+
# All rights reserved. http://www.homeaway.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'cgi'
|
17
|
+
require 'json'
|
18
|
+
|
19
|
+
module HomeAway
|
20
|
+
module Storm
|
21
|
+
module Util
|
22
|
+
|
23
|
+
# @private
|
24
|
+
module Validators
|
25
|
+
|
26
|
+
# @private
|
27
|
+
def self.uri_encoded(input)
|
28
|
+
CGI.escape input
|
29
|
+
end
|
30
|
+
|
31
|
+
# @private
|
32
|
+
def self.date(input)
|
33
|
+
if input.is_a? String
|
34
|
+
input = Chronic.parse(input, :ambiguous_time_range => :none)
|
35
|
+
end
|
36
|
+
raise ArgumentError.new('dates must be a parseable date string or a Ruby Time object') unless input.is_a? Time
|
37
|
+
input.to_time.utc.iso8601
|
38
|
+
end
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def self.float(input, min=nil, max=nil)
|
42
|
+
begin
|
43
|
+
input_s = input.to_s
|
44
|
+
!!Float(input_s)
|
45
|
+
f = input_s.to_f
|
46
|
+
unless min == nil
|
47
|
+
raise ArgumentError.new("Supplied argument #{f} must be greater than #{min}") if f < min
|
48
|
+
end
|
49
|
+
unless max == nil
|
50
|
+
raise ArgumentError.new("Supplied argument #{f} must be less than #{max}") if f > max
|
51
|
+
end
|
52
|
+
return f
|
53
|
+
rescue
|
54
|
+
raise ArgumentError.new("Supplied argument #{input} must be a valid float value")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @private
|
59
|
+
def self.integer(input, min=nil, max=nil)
|
60
|
+
begin
|
61
|
+
input_s = input.to_s
|
62
|
+
!!Integer(input_s)
|
63
|
+
i = input_s.to_i
|
64
|
+
unless min == nil
|
65
|
+
raise ArgumentError.new("Supplied argument #{i} must be greater than #{min}") if i < min
|
66
|
+
end
|
67
|
+
unless max == nil
|
68
|
+
raise ArgumentError.new("Supplied argument #{i} must be less than #{max}") if i > max
|
69
|
+
end
|
70
|
+
return i
|
71
|
+
rescue
|
72
|
+
raise ArgumentError.new("Supplied argument #{input} must be a valid integer value")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @private
|
77
|
+
def self.boolean(input)
|
78
|
+
input_s = input.to_s
|
79
|
+
return true if input_s =~ (/^(true)$/i)
|
80
|
+
return false if input_s.empty? || input_s =~ (/^(false)$/i)
|
81
|
+
raise ArgumentError.new("Supplied argument #{input} must be a valid boolean value")
|
82
|
+
end
|
83
|
+
|
84
|
+
# @private
|
85
|
+
def self.camel_case(input)
|
86
|
+
input.to_s.camelize(:lower)
|
87
|
+
end
|
88
|
+
|
89
|
+
# @private
|
90
|
+
def self.snake_case(input)
|
91
|
+
input.to_s.underscore
|
92
|
+
end
|
93
|
+
|
94
|
+
# @private
|
95
|
+
def self.query_keys(hash)
|
96
|
+
raise ArgumentError.new('arguments must be a hash') unless hash.is_a? Hash
|
97
|
+
transformed = {}
|
98
|
+
hash.each_key do |key|
|
99
|
+
transformed[self.camel_case(key)] = hash[key]
|
100
|
+
end
|
101
|
+
transformed
|
102
|
+
end
|
103
|
+
|
104
|
+
# @private
|
105
|
+
def self.uuid(input)
|
106
|
+
uuid_regex = /\A([0-9a-fA-F]{32}|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\z/
|
107
|
+
raise ArgumentError.new("#{uuid.to_s} must be a valid uuid") unless input.to_s =~ uuid_regex
|
108
|
+
input.to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
# @private
|
112
|
+
def self.json(input)
|
113
|
+
begin
|
114
|
+
input = input.to_json if input.respond_to? :to_json
|
115
|
+
JSON.parse(input).to_json
|
116
|
+
rescue
|
117
|
+
raise ArgumentError.new('Must supply properly formed JSON')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|