scalastic 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scalastic/config.rb +2 -2
- data/lib/scalastic/partition.rb +29 -0
- data/lib/scalastic/partitions_client.rb +2 -1
- data/lib/scalastic/version.rb +1 -1
- data/regression/regression_tests/endpoints.rb +52 -0
- data/regression/regression_tests/index_destinations.rb +40 -0
- data/regression/regression_tests/list_partitions.rb +3 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a323230b42e70b738a01c5ad1dcdba2ce284155
|
4
|
+
data.tar.gz: 2fe66cdd753c110c60daa3bbd17355d72a5eecd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9bbd87a04f3ab5ebd0012bd6e47bb28f1572e706fa12ea1abbca9f6289773bc47bfd2932907dae3ebd26215173fbca93b231b8239a7a9b9b22db0af8fb2e5b0
|
7
|
+
data.tar.gz: f042ba5eb5743a51684643c032fa6421a2b2c088cf438c2772e08c515147265f49b1f2c42cdf2ddca20d109641b21da2aea3656c01cadfd29ea0b3a523e0be03
|
data/lib/scalastic/config.rb
CHANGED
@@ -24,7 +24,7 @@ module Scalastic
|
|
24
24
|
|
25
25
|
def get_partition_id(alias_name)
|
26
26
|
m = partition_regex.match(alias_name)
|
27
|
-
m && m[1]
|
27
|
+
m && m[1]
|
28
28
|
end
|
29
29
|
|
30
30
|
def partition_prefix=(value)
|
@@ -39,7 +39,7 @@ module Scalastic
|
|
39
39
|
|
40
40
|
def partition_selector_type=(value)
|
41
41
|
value = value.to_s
|
42
|
-
raise(ArgumentError, "Unsupported selector type: #{value}. Supported types are: (string, long)") unless %w(string long).include?(value)
|
42
|
+
raise(ArgumentError, "Unsupported selector type: #{value}. Supported types are: (string, long)") unless %w(string long integer).include?(value)
|
43
43
|
@partition_selector_type = value
|
44
44
|
end
|
45
45
|
|
data/lib/scalastic/partition.rb
CHANGED
@@ -3,6 +3,9 @@ require 'scalastic/partition_selector'
|
|
3
3
|
|
4
4
|
module Scalastic
|
5
5
|
class Partition
|
6
|
+
Endpoint = Struct.new(:index, :routing)
|
7
|
+
Endpoints = Struct.new(:index, :search)
|
8
|
+
|
6
9
|
attr_reader(:es_client)
|
7
10
|
attr_reader(:config)
|
8
11
|
attr_reader(:id)
|
@@ -82,6 +85,32 @@ module Scalastic
|
|
82
85
|
"ES partition #{id}"
|
83
86
|
end
|
84
87
|
|
88
|
+
def get_endpoints
|
89
|
+
sa = config.search_endpoint(id)
|
90
|
+
ia = config.index_endpoint(id)
|
91
|
+
aliases = es_client.indices.get_aliases name: [sa, ia].join(',')
|
92
|
+
sas = aliases.map{|i, d| [i, d['aliases'][sa]]}.reject{|_i, sa| sa.nil?}
|
93
|
+
ias = aliases.map{|i, d| [i, d['aliases'][ia]]}.reject{|_i, ia| ia.nil?}
|
94
|
+
Endpoints.new(
|
95
|
+
ias.map{|i, ia| Endpoint.new(i, ia['index_routing']).freeze}.first,
|
96
|
+
sas.map{|i, sa| Endpoint.new(i, sa['search_routing']).freeze}.freeze
|
97
|
+
).freeze
|
98
|
+
end
|
99
|
+
|
100
|
+
def index_to(args)
|
101
|
+
ie = config.index_endpoint(id)
|
102
|
+
eps = get_endpoints
|
103
|
+
actions = []
|
104
|
+
actions << {remove: {index: eps.index.index, alias: ie}} if eps.index
|
105
|
+
actions << {add: EsActionsGenerator.new_index_alias(config, args.merge(id: id))} unless args.nil?
|
106
|
+
#TODO: log a warning if there're no updates
|
107
|
+
es_client.indices.update_aliases(body: {actions: actions}) if actions.any?
|
108
|
+
end
|
109
|
+
|
110
|
+
def readonly?
|
111
|
+
get_endpoints.index.nil?
|
112
|
+
end
|
113
|
+
|
85
114
|
private
|
86
115
|
|
87
116
|
def operation_name(entry)
|
@@ -25,7 +25,8 @@ module Scalastic
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def delete(args = {})
|
28
|
-
id = args[:id]
|
28
|
+
id = args[:id].to_s
|
29
|
+
raise(ArgumentError, 'Missing required argument :id') if id.nil? || id.empty?
|
29
30
|
pairs = es_client.indices.get_aliases.map{|i, d| d['aliases'].keys.select{|a| config.get_partition_id(a) == id}.map{|a| [i, a]}}.flatten(1)
|
30
31
|
unless pairs.any?
|
31
32
|
#TODO: log a warning
|
data/lib/scalastic/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
module RegressionTests
|
2
|
+
module Endpoints
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def cleanup
|
6
|
+
client = Elasticsearch::Client.new
|
7
|
+
%w(endpoints_1 endpoints_2).each do |i|
|
8
|
+
client.indices.delete index: i if client.indices.exists? index: i
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
client = Elasticsearch::Client.new
|
14
|
+
partitions = client.partitions
|
15
|
+
|
16
|
+
client.indices.create index: 'endpoints_1'
|
17
|
+
client.indices.create index: 'endpoints_2'
|
18
|
+
partitions.prepare_index index: 'endpoints_1'
|
19
|
+
partitions.prepare_index index: 'endpoints_2'
|
20
|
+
|
21
|
+
p = partitions[1]
|
22
|
+
raise 'Partition should not exist!' if p.exists?
|
23
|
+
raise 'Partition should be read only!' unless p.readonly?
|
24
|
+
|
25
|
+
eps = p.get_endpoints
|
26
|
+
raise 'Index endpoint is not nil!' unless eps.index.nil?
|
27
|
+
raise 'Search endpoints must be empty!' if eps.search.any?
|
28
|
+
|
29
|
+
p.index_to index: 'endpoints_1'
|
30
|
+
eps = p.get_endpoints
|
31
|
+
raise 'Partition shoudl exist!' unless p.exists?
|
32
|
+
raise 'Unexpected index endpoint' unless eps.index == Scalastic::Partition::Endpoint.new('endpoints_1', nil)
|
33
|
+
raise 'Partition should not be read only!' if p.readonly?
|
34
|
+
|
35
|
+
p.index_to index: 'endpoints_2', routing: 123
|
36
|
+
eps = p.get_endpoints
|
37
|
+
raise 'Unexpected index endpoint' unless eps.index == Scalastic::Partition::Endpoint.new('endpoints_2', '123')
|
38
|
+
|
39
|
+
p.index_to nil
|
40
|
+
raise 'Partition should not exist' if p.exists?
|
41
|
+
raise 'Partition is not read only' unless p.readonly?
|
42
|
+
|
43
|
+
p.extend_to index: 'endpoints_1'
|
44
|
+
eps = p.get_endpoints
|
45
|
+
raise 'Unexpected search endpoints' unless eps.search == [Scalastic::Partition::Endpoint.new('endpoints_1', nil)]
|
46
|
+
p.extend_to index: 'endpoints_2', routing: '22'
|
47
|
+
eps = p.get_endpoints
|
48
|
+
expected = [Scalastic::Partition::Endpoint.new('endpoints_1', nil), Scalastic::Partition::Endpoint.new('endpoints_2', '22')]
|
49
|
+
raise 'Unexpected search endpoints' unless eps.search.size == expected.size && expected.all?{|ep| eps.search.include?(ep)}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RegressionTests
|
2
|
+
module IndexDestinations
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def cleanup
|
6
|
+
client = Elasticsearch::Client.new
|
7
|
+
client.indices.delete index: 'destinations_1' if client.indices.exists? index: 'destinations_1'
|
8
|
+
client.indices.delete index: 'destinations_2' if client.indices.exists? index: 'destinations_2'
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
client = Elasticsearch::Client.new
|
13
|
+
partitions = client.partitions
|
14
|
+
|
15
|
+
client.indices.create index: 'destinations_1'
|
16
|
+
client.indices.create index: 'destinations_2'
|
17
|
+
|
18
|
+
partitions.prepare_index index: 'destinations_1'
|
19
|
+
partitions.prepare_index index: 'destinations_2'
|
20
|
+
|
21
|
+
p = partitions.create id: 1, index: 'destinations_1'
|
22
|
+
p.extend_to(index: 'destinations_2')
|
23
|
+
|
24
|
+
expected = {"destinations_1"=>{"aliases"=>{"scalastic_1_search"=>{"filter"=>{"term"=>{"scalastic_partition_id"=>1}}}}}, "destinations_2"=>{"aliases"=>{"scalastic_1_index"=>{}, "scalastic_1_search"=>{"filter"=>{"term"=>{"scalastic_partition_id"=>1}}}}}}
|
25
|
+
actual = client.indices.get_aliases index: 'destinations_1,destinations_2', name: 'scalastic_1_*'
|
26
|
+
raise "Expected #{expected}, got: #{actual}" unless expected == actual
|
27
|
+
|
28
|
+
p = partitions[2]
|
29
|
+
raise 'Partition should not exist!' if p.exists?
|
30
|
+
p = partitions.create id: 2, index: 'destinations_1'
|
31
|
+
raise 'Partition should exist!' unless p.exists?
|
32
|
+
|
33
|
+
p.index_to nil
|
34
|
+
|
35
|
+
expected = {"destinations_1"=>{"aliases"=>{"scalastic_2_search"=>{"filter"=>{"term"=>{"scalastic_partition_id"=>2}}}}}, "destinations_2"=>{"aliases"=>{}}}
|
36
|
+
actual = client.indices.get_aliases index: 'destinations_1,destinations_2', name: "scalastic_2_*"
|
37
|
+
raise "Expected: #{expected}, got: #{actual}" unless expected == actual
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -28,8 +28,9 @@ module RegressionTests
|
|
28
28
|
sleep 1.5
|
29
29
|
|
30
30
|
# List all partitions
|
31
|
-
ids = partitions.to_a.map{|p| p.id}
|
32
|
-
|
31
|
+
ids = partitions.to_a.map{|p| p.id}.sort
|
32
|
+
expected_ids = %w(1 2 3)
|
33
|
+
raise "Expected partitions #{expected_ids}, got #{ids}" unless ids == expected_ids
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scalastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksei Baturytski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,7 +111,9 @@ files:
|
|
111
111
|
- regression/regression_tests/delete_by_query.rb
|
112
112
|
- regression/regression_tests/delete_partition.rb
|
113
113
|
- regression/regression_tests/document_get.rb
|
114
|
+
- regression/regression_tests/endpoints.rb
|
114
115
|
- regression/regression_tests/extend_partition.rb
|
116
|
+
- regression/regression_tests/index_destinations.rb
|
115
117
|
- regression/regression_tests/list_partitions.rb
|
116
118
|
- regression/regression_tests/nested_selector.rb
|
117
119
|
- regression/regression_tests/nested_selector_bulk.rb
|