Skip to content

Commit a8abf0f

Browse files
committed
Merge branch 'master' into ccr
* master: Upgrade to Lucene-7.4.0-snapshot-518d303506 (#31360) Rankeval: Fold template test project into main module (#31203) Add QA project and fixture based test for discovery-ec2 plugin (#31107) [Docs] Remove reference to repository-s3 plugin creating an S3 bucket (#31359) REST Client: NodeSelector for node attributes (#31296) LLClient: Fix assertion on windows Add details section for dcg ranking metric (#31177) [ML] Re-enable tests muted in #30982
2 parents 73c9dd9 + 8453ca6 commit a8abf0f

File tree

90 files changed

+1614
-832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1614
-832
lines changed

buildSrc/version.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
elasticsearch = 7.0.0-alpha1
2-
lucene = 7.4.0-snapshot-0a7c3f462f
2+
lucene = 7.4.0-snapshot-518d303506
33

44
# optional dependencies
55
spatial4j = 0.7

client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.client;
2121

2222
import com.fasterxml.jackson.core.JsonParseException;
23+
2324
import org.apache.http.Header;
2425
import org.apache.http.HttpEntity;
2526
import org.apache.http.HttpHost;
@@ -607,7 +608,7 @@ public void testDefaultNamedXContents() {
607608

608609
public void testProvidedNamedXContents() {
609610
List<NamedXContentRegistry.Entry> namedXContents = RestHighLevelClient.getProvidedNamedXContents();
610-
assertEquals(7, namedXContents.size());
611+
assertEquals(8, namedXContents.size());
611612
Map<Class<?>, Integer> categories = new HashMap<>();
612613
List<String> names = new ArrayList<>();
613614
for (NamedXContentRegistry.Entry namedXContent : namedXContents) {
@@ -625,9 +626,10 @@ public void testProvidedNamedXContents() {
625626
assertTrue(names.contains(PrecisionAtK.NAME));
626627
assertTrue(names.contains(DiscountedCumulativeGain.NAME));
627628
assertTrue(names.contains(MeanReciprocalRank.NAME));
628-
assertEquals(Integer.valueOf(2), categories.get(MetricDetail.class));
629+
assertEquals(Integer.valueOf(3), categories.get(MetricDetail.class));
629630
assertTrue(names.contains(PrecisionAtK.NAME));
630631
assertTrue(names.contains(MeanReciprocalRank.NAME));
632+
assertTrue(names.contains(DiscountedCumulativeGain.NAME));
631633
}
632634

633635
private static class TrackingActionListener implements ActionListener<Integer> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client;
21+
22+
import java.util.Iterator;
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
/**
27+
* A {@link NodeSelector} that selects nodes that have a particular value
28+
* for an attribute.
29+
*/
30+
public final class HasAttributeNodeSelector implements NodeSelector {
31+
private final String key;
32+
private final String value;
33+
34+
public HasAttributeNodeSelector(String key, String value) {
35+
this.key = key;
36+
this.value = value;
37+
}
38+
39+
@Override
40+
public void select(Iterable<Node> nodes) {
41+
Iterator<Node> itr = nodes.iterator();
42+
while (itr.hasNext()) {
43+
Map<String, List<String>> allAttributes = itr.next().getAttributes();
44+
if (allAttributes == null) continue;
45+
List<String> values = allAttributes.get(key);
46+
if (values == null || false == values.contains(value)) {
47+
itr.remove();
48+
}
49+
}
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return key + "=" + value;
55+
}
56+
}

client/rest/src/main/java/org/elasticsearch/client/Node.java

+23-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.client;
2121

22+
import java.util.List;
23+
import java.util.Map;
2224
import java.util.Objects;
2325
import java.util.Set;
2426

@@ -52,13 +54,18 @@ public class Node {
5254
* if we don't know what roles the node has.
5355
*/
5456
private final Roles roles;
57+
/**
58+
* Attributes declared on the node.
59+
*/
60+
private final Map<String, List<String>> attributes;
5561

5662
/**
5763
* Create a {@linkplain Node} with metadata. All parameters except
5864
* {@code host} are nullable and implementations of {@link NodeSelector}
5965
* need to decide what to do in their absence.
6066
*/
61-
public Node(HttpHost host, Set<HttpHost> boundHosts, String name, String version, Roles roles) {
67+
public Node(HttpHost host, Set<HttpHost> boundHosts, String name, String version,
68+
Roles roles, Map<String, List<String>> attributes) {
6269
if (host == null) {
6370
throw new IllegalArgumentException("host cannot be null");
6471
}
@@ -67,13 +74,14 @@ public Node(HttpHost host, Set<HttpHost> boundHosts, String name, String version
6774
this.name = name;
6875
this.version = version;
6976
this.roles = roles;
77+
this.attributes = attributes;
7078
}
7179

7280
/**
7381
* Create a {@linkplain Node} without any metadata.
7482
*/
7583
public Node(HttpHost host) {
76-
this(host, null, null, null, null);
84+
this(host, null, null, null, null, null);
7785
}
7886

7987
/**
@@ -115,6 +123,13 @@ public Roles getRoles() {
115123
return roles;
116124
}
117125

126+
/**
127+
* Attributes declared on the node.
128+
*/
129+
public Map<String, List<String>> getAttributes() {
130+
return attributes;
131+
}
132+
118133
@Override
119134
public String toString() {
120135
StringBuilder b = new StringBuilder();
@@ -131,6 +146,9 @@ public String toString() {
131146
if (roles != null) {
132147
b.append(", roles=").append(roles);
133148
}
149+
if (attributes != null) {
150+
b.append(", attributes=").append(attributes);
151+
}
134152
return b.append(']').toString();
135153
}
136154

@@ -144,12 +162,13 @@ public boolean equals(Object obj) {
144162
&& Objects.equals(boundHosts, other.boundHosts)
145163
&& Objects.equals(name, other.name)
146164
&& Objects.equals(version, other.version)
147-
&& Objects.equals(roles, other.roles);
165+
&& Objects.equals(roles, other.roles)
166+
&& Objects.equals(attributes, other.attributes);
148167
}
149168

150169
@Override
151170
public int hashCode() {
152-
return Objects.hash(host, boundHosts, name, version, roles);
171+
return Objects.hash(host, boundHosts, name, version, roles, attributes);
153172
}
154173

155174
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client;
21+
22+
import org.apache.http.HttpHost;
23+
import org.elasticsearch.client.Node.Roles;
24+
25+
import java.util.ArrayList;
26+
import java.util.Arrays;
27+
import java.util.Collections;
28+
import java.util.List;
29+
import java.util.Map;
30+
31+
import static java.util.Collections.singletonList;
32+
import static java.util.Collections.singletonMap;
33+
import static org.junit.Assert.assertEquals;
34+
35+
public class HasAttributeNodeSelectorTests extends RestClientTestCase {
36+
public void testHasAttribute() {
37+
Node hasAttributeValue = dummyNode(singletonMap("attr", singletonList("val")));
38+
Node hasAttributeButNotValue = dummyNode(singletonMap("attr", singletonList("notval")));
39+
Node hasAttributeValueInList = dummyNode(singletonMap("attr", Arrays.asList("val", "notval")));
40+
Node notHasAttribute = dummyNode(singletonMap("notattr", singletonList("val")));
41+
List<Node> nodes = new ArrayList<>();
42+
nodes.add(hasAttributeValue);
43+
nodes.add(hasAttributeButNotValue);
44+
nodes.add(hasAttributeValueInList);
45+
nodes.add(notHasAttribute);
46+
List<Node> expected = new ArrayList<>();
47+
expected.add(hasAttributeValue);
48+
expected.add(hasAttributeValueInList);
49+
new HasAttributeNodeSelector("attr", "val").select(nodes);
50+
assertEquals(expected, nodes);
51+
}
52+
53+
private static Node dummyNode(Map<String, List<String>> attributes) {
54+
return new Node(new HttpHost("dummy"), Collections.<HttpHost>emptySet(),
55+
randomAsciiAlphanumOfLength(5), randomAsciiAlphanumOfLength(5),
56+
new Roles(randomBoolean(), randomBoolean(), randomBoolean()),
57+
attributes);
58+
}
59+
}

client/rest/src/test/java/org/elasticsearch/client/NodeSelectorTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ public void testNotMasterOnly() {
6363
assertEquals(expected, nodes);
6464
}
6565

66-
private Node dummyNode(boolean master, boolean data, boolean ingest) {
66+
private static Node dummyNode(boolean master, boolean data, boolean ingest) {
6767
return new Node(new HttpHost("dummy"), Collections.<HttpHost>emptySet(),
6868
randomAsciiAlphanumOfLength(5), randomAsciiAlphanumOfLength(5),
69-
new Roles(master, data, ingest));
69+
new Roles(master, data, ingest),
70+
Collections.<String, List<String>>emptyMap());
7071
}
7172
}

client/rest/src/test/java/org/elasticsearch/client/NodeTests.java

+34-16
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,67 @@
2323
import org.elasticsearch.client.Node.Roles;
2424

2525
import java.util.Arrays;
26+
import java.util.HashMap;
2627
import java.util.HashSet;
28+
import java.util.List;
29+
import java.util.Map;
2730

2831
import static java.util.Collections.singleton;
32+
import static java.util.Collections.singletonList;
33+
import static java.util.Collections.singletonMap;
2934
import static org.junit.Assert.assertEquals;
3035
import static org.junit.Assert.assertFalse;
3136
import static org.junit.Assert.assertTrue;
3237

3338
public class NodeTests extends RestClientTestCase {
3439
public void testToString() {
40+
Map<String, List<String>> attributes = new HashMap<>();
41+
attributes.put("foo", singletonList("bar"));
42+
attributes.put("baz", Arrays.asList("bort", "zoom"));
3543
assertEquals("[host=http://1]", new Node(new HttpHost("1")).toString());
44+
assertEquals("[host=http://1, attributes={foo=[bar], baz=[bort, zoom]}]",
45+
new Node(new HttpHost("1"), null, null, null, null, attributes).toString());
3646
assertEquals("[host=http://1, roles=mdi]", new Node(new HttpHost("1"),
37-
null, null, null, new Roles(true, true, true)).toString());
47+
null, null, null, new Roles(true, true, true), null).toString());
3848
assertEquals("[host=http://1, version=ver]", new Node(new HttpHost("1"),
39-
null, null, "ver", null).toString());
49+
null, null, "ver", null, null).toString());
4050
assertEquals("[host=http://1, name=nam]", new Node(new HttpHost("1"),
41-
null, "nam", null, null).toString());
51+
null, "nam", null, null, null).toString());
4252
assertEquals("[host=http://1, bound=[http://1, http://2]]", new Node(new HttpHost("1"),
43-
new HashSet<>(Arrays.asList(new HttpHost("1"), new HttpHost("2"))), null, null, null).toString());
44-
assertEquals("[host=http://1, bound=[http://1, http://2], name=nam, version=ver, roles=m]",
53+
new HashSet<>(Arrays.asList(new HttpHost("1"), new HttpHost("2"))), null, null, null, null).toString());
54+
assertEquals(
55+
"[host=http://1, bound=[http://1, http://2], name=nam, version=ver, roles=m, attributes={foo=[bar], baz=[bort, zoom]}]",
4556
new Node(new HttpHost("1"), new HashSet<>(Arrays.asList(new HttpHost("1"), new HttpHost("2"))),
46-
"nam", "ver", new Roles(true, false, false)).toString());
57+
"nam", "ver", new Roles(true, false, false), attributes).toString());
4758

4859
}
4960

5061
public void testEqualsAndHashCode() {
5162
HttpHost host = new HttpHost(randomAsciiAlphanumOfLength(5));
5263
Node node = new Node(host,
53-
randomBoolean() ? null : singleton(host),
54-
randomBoolean() ? null : randomAsciiAlphanumOfLength(5),
55-
randomBoolean() ? null : randomAsciiAlphanumOfLength(5),
56-
randomBoolean() ? null : new Roles(true, true, true));
64+
randomBoolean() ? null : singleton(host),
65+
randomBoolean() ? null : randomAsciiAlphanumOfLength(5),
66+
randomBoolean() ? null : randomAsciiAlphanumOfLength(5),
67+
randomBoolean() ? null : new Roles(true, true, true),
68+
randomBoolean() ? null : singletonMap("foo", singletonList("bar")));
5769
assertFalse(node.equals(null));
5870
assertTrue(node.equals(node));
5971
assertEquals(node.hashCode(), node.hashCode());
60-
Node copy = new Node(host, node.getBoundHosts(), node.getName(), node.getVersion(), node.getRoles());
72+
Node copy = new Node(host, node.getBoundHosts(), node.getName(), node.getVersion(),
73+
node.getRoles(), node.getAttributes());
6174
assertTrue(node.equals(copy));
6275
assertEquals(node.hashCode(), copy.hashCode());
6376
assertFalse(node.equals(new Node(new HttpHost(host.toHostString() + "changed"), node.getBoundHosts(),
64-
node.getName(), node.getVersion(), node.getRoles())));
77+
node.getName(), node.getVersion(), node.getRoles(), node.getAttributes())));
6578
assertFalse(node.equals(new Node(host, new HashSet<>(Arrays.asList(host, new HttpHost(host.toHostString() + "changed"))),
66-
node.getName(), node.getVersion(), node.getRoles())));
67-
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName() + "changed", node.getVersion(), node.getRoles())));
68-
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), node.getVersion() + "changed", node.getRoles())));
69-
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), node.getVersion(), new Roles(false, false, false))));
79+
node.getName(), node.getVersion(), node.getRoles(), node.getAttributes())));
80+
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName() + "changed",
81+
node.getVersion(), node.getRoles(), node.getAttributes())));
82+
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(),
83+
node.getVersion() + "changed", node.getRoles(), node.getAttributes())));
84+
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(),
85+
node.getVersion(), new Roles(false, false, false), node.getAttributes())));
86+
assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(),
87+
node.getVersion(), node.getRoles(), singletonMap("bort", singletonList("bing")))));
7088
}
7189
}

client/rest/src/test/java/org/elasticsearch/client/RestClientMultipleHostsIntegTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
import static org.elasticsearch.client.RestClientTestUtil.getAllStatusCodes;
4343
import static org.elasticsearch.client.RestClientTestUtil.randomErrorNoRetryStatusCode;
4444
import static org.elasticsearch.client.RestClientTestUtil.randomOkStatusCode;
45+
import static org.hamcrest.Matchers.startsWith;
4546
import static org.junit.Assert.assertEquals;
47+
import static org.junit.Assert.assertThat;
4648
import static org.junit.Assert.assertTrue;
4749
import static org.junit.Assert.fail;
4850

@@ -214,7 +216,8 @@ public void testNodeSelector() throws IOException {
214216
restClient.performRequest(request);
215217
fail("expected to fail to connect");
216218
} catch (ConnectException e) {
217-
assertEquals("Connection refused", e.getMessage());
219+
// This is different in windows and linux but this matches both.
220+
assertThat(e.getMessage(), startsWith("Connection refused"));
218221
}
219222
} else {
220223
Response response = restClient.performRequest(request);

client/rest/src/test/java/org/elasticsearch/client/RestClientMultipleHostsTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public void testSetNodes() throws IOException {
342342
List<Node> newNodes = new ArrayList<>(nodes.size());
343343
for (int i = 0; i < nodes.size(); i++) {
344344
Roles roles = i == 0 ? new Roles(false, true, true) : new Roles(true, false, false);
345-
newNodes.add(new Node(nodes.get(i).getHost(), null, null, null, roles));
345+
newNodes.add(new Node(nodes.get(i).getHost(), null, null, null, roles, null));
346346
}
347347
restClient.setNodes(newNodes);
348348
int rounds = between(1, 10);

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ public void testNullPath() throws IOException {
341341
}
342342

343343
public void testSelectHosts() throws IOException {
344-
Node n1 = new Node(new HttpHost("1"), null, null, "1", null);
345-
Node n2 = new Node(new HttpHost("2"), null, null, "2", null);
346-
Node n3 = new Node(new HttpHost("3"), null, null, "3", null);
344+
Node n1 = new Node(new HttpHost("1"), null, null, "1", null, null);
345+
Node n2 = new Node(new HttpHost("2"), null, null, "2", null, null);
346+
Node n3 = new Node(new HttpHost("3"), null, null, "3", null, null);
347347

348348
NodeSelector not1 = new NodeSelector() {
349349
@Override

0 commit comments

Comments
 (0)