Skip to content

Commit d319cc3

Browse files
committed
Merge remote-tracking branch 'elastic/master' into settings-version
* elastic/master: Mute PartitionedRoutingIT#testShrinking on Windows Mute testToQuery test [TEST] Make sure there are shards started so that `ESIntegTestCase#assertSameDocIdsOnShards()` does not fail with shard not found. Change shard changes api's threadpool from get to search (elastic#34421) Update TESTING.asciidoc title (elastic#34401) Tests: Fix DateFormatter equals tests with locale (elastic#34435) Docs: Remove unnecessary qualifier from wildcard import note (elastic#34419) CCR/TEST: AwaitsFix testFailOverOnFollower [Painless] Add a Map for java names to classes for use in the custom classloader (elastic#34424) TEST: Fix indentation in FullClusterRestartIT (elastic#34420) [WIP] Ingest Attachement: Upgrade tika to v1.19.1 (elastic#33896) NETWORKING: Upgrade Netty to 4.1.30 (elastic#34417) Allow an AuthenticationResult to return metadata (elastic#34382) [ML] Add an ingest pipeline definition to structure finder (elastic#34350) Handle pre-6.x time fields (elastic#34373) ListenableFuture should preserve ThreadContext (elastic#34394)
2 parents e762281 + 9bb620e commit d319cc3

File tree

96 files changed

+746
-271
lines changed

Some content is hidden

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

96 files changed

+746
-271
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Please follow these formatting guidelines:
161161
* Line width is 140 characters
162162
* The rest is left to Java coding standards
163163
* Disable “auto-format on save” to prevent unnecessary format changes. This makes reviews much harder as it generates unnecessary formatting changes. If your IDE supports formatting only modified chunks that is fine to do.
164-
* Wildcard imports (`import foo.bar.baz.*`) are forbidden and will cause the build to fail. Please attempt to tame your IDE so it doesn't make them and please send a PR against this document with instructions for your IDE if it doesn't contain them.
164+
* Wildcard imports (`import foo.bar.baz.*`) are forbidden and will cause the build to fail. This can be done automatically by your IDE:
165165
* Eclipse: `Preferences->Java->Code Style->Organize Imports`. There are two boxes labeled "`Number of (static )? imports needed for .*`". Set their values to 99999 or some other absurdly high value.
166166
* IntelliJ: `Preferences/Settings->Editor->Code Style->Java->Imports`. There are two configuration options: `Class count to use import with '*'` and `Names count to use static import with '*'`. Set their values to 99999 or some other absurdly high value.
167167
* Don't worry too much about import order. Try not to change it but don't worry about fighting your IDE to stop it from doing so.

TESTING.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[[Testing Framework Cheatsheet]]
1+
[[TestingFrameworkCheatsheet]]
22
= Testing
33

44
[partintro]

buildSrc/version.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ slf4j = 1.6.2
1515
# when updating the JNA version, also update the version in buildSrc/build.gradle
1616
jna = 4.5.1
1717

18+
netty = 4.1.30.Final
19+
1820
# test dependencies
1921
randomizedrunner = 2.7.0
2022
junit = 4.12

docs/reference/ml/apis/find-file-structure.asciidoc

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,20 @@ If the request does not encounter errors, you receive the following result:
613613
"type" : "double"
614614
}
615615
},
616+
"ingest_pipeline" : {
617+
"description" : "Ingest pipeline created by file structure finder",
618+
"processors" : [
619+
{
620+
"date" : {
621+
"field" : "tpep_pickup_datetime",
622+
"timezone" : "{{ beat.timezone }}",
623+
"formats" : [
624+
"YYYY-MM-dd HH:mm:ss"
625+
]
626+
}
627+
}
628+
]
629+
},
616630
"field_stats" : {
617631
"DOLocationID" : {
618632
"count" : 19998,
@@ -1366,6 +1380,33 @@ this:
13661380
"type" : "text"
13671381
}
13681382
},
1383+
"ingest_pipeline" : {
1384+
"description" : "Ingest pipeline created by file structure finder",
1385+
"processors" : [
1386+
{
1387+
"grok" : {
1388+
"field" : "message",
1389+
"patterns" : [
1390+
"\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel}.*"
1391+
]
1392+
}
1393+
},
1394+
{
1395+
"date" : {
1396+
"field" : "timestamp",
1397+
"timezone" : "{{ beat.timezone }}",
1398+
"formats" : [
1399+
"ISO8601"
1400+
]
1401+
}
1402+
},
1403+
{
1404+
"remove" : {
1405+
"field" : "timestamp"
1406+
}
1407+
}
1408+
]
1409+
},
13691410
"field_stats" : {
13701411
"loglevel" : {
13711412
"count" : 53,
@@ -1499,6 +1540,33 @@ this:
14991540
"type" : "keyword"
15001541
}
15011542
},
1543+
"ingest_pipeline" : {
1544+
"description" : "Ingest pipeline created by file structure finder",
1545+
"processors" : [
1546+
{
1547+
"grok" : {
1548+
"field" : "message",
1549+
"patterns" : [
1550+
"\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel} *\\]\\[%{JAVACLASS:class} *\\] \\[%{HOSTNAME:node}\\] %{JAVALOGMESSAGE:message}"
1551+
]
1552+
}
1553+
},
1554+
{
1555+
"date" : {
1556+
"field" : "timestamp",
1557+
"timezone" : "{{ beat.timezone }}",
1558+
"formats" : [
1559+
"ISO8601"
1560+
]
1561+
}
1562+
},
1563+
{
1564+
"remove" : {
1565+
"field" : "timestamp"
1566+
}
1567+
}
1568+
]
1569+
},
15021570
"field_stats" : { <2>
15031571
"class" : {
15041572
"count" : 53,

modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Class<?> findClass(String name) throws ClassNotFoundException {
9696
if (found != null) {
9797
return found;
9898
}
99-
found = painlessLookup.canonicalTypeNameToType(name.replace('$', '.'));
99+
found = painlessLookup.javaClassNameToClass(name);
100100

101101
return found != null ? found : super.findClass(name);
102102
}

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookup.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,39 @@
3434

3535
public final class PainlessLookup {
3636

37+
private final Map<String, Class<?>> javaClassNamesToClasses;
3738
private final Map<String, Class<?>> canonicalClassNamesToClasses;
3839
private final Map<Class<?>, PainlessClass> classesToPainlessClasses;
3940

4041
private final Map<String, PainlessMethod> painlessMethodKeysToImportedPainlessMethods;
4142
private final Map<String, PainlessClassBinding> painlessMethodKeysToPainlessClassBindings;
4243

43-
PainlessLookup(Map<String, Class<?>> canonicalClassNamesToClasses, Map<Class<?>, PainlessClass> classesToPainlessClasses,
44+
PainlessLookup(
45+
Map<String, Class<?>> javaClassNamesToClasses,
46+
Map<String, Class<?>> canonicalClassNamesToClasses,
47+
Map<Class<?>, PainlessClass> classesToPainlessClasses,
4448
Map<String, PainlessMethod> painlessMethodKeysToImportedPainlessMethods,
4549
Map<String, PainlessClassBinding> painlessMethodKeysToPainlessClassBindings) {
4650

51+
Objects.requireNonNull(javaClassNamesToClasses);
4752
Objects.requireNonNull(canonicalClassNamesToClasses);
4853
Objects.requireNonNull(classesToPainlessClasses);
4954

5055
Objects.requireNonNull(painlessMethodKeysToImportedPainlessMethods);
5156
Objects.requireNonNull(painlessMethodKeysToPainlessClassBindings);
5257

58+
this.javaClassNamesToClasses = javaClassNamesToClasses;
5359
this.canonicalClassNamesToClasses = Collections.unmodifiableMap(canonicalClassNamesToClasses);
5460
this.classesToPainlessClasses = Collections.unmodifiableMap(classesToPainlessClasses);
5561

5662
this.painlessMethodKeysToImportedPainlessMethods = Collections.unmodifiableMap(painlessMethodKeysToImportedPainlessMethods);
5763
this.painlessMethodKeysToPainlessClassBindings = Collections.unmodifiableMap(painlessMethodKeysToPainlessClassBindings);
5864
}
5965

66+
public Class<?> javaClassNameToClass(String javaClassName) {
67+
return javaClassNamesToClasses.get(javaClassName);
68+
}
69+
6070
public boolean isValidCanonicalClassName(String canonicalClassName) {
6171
Objects.requireNonNull(canonicalClassName);
6272

modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,23 @@ public static PainlessLookup buildFromWhitelists(List<Whitelist> whitelists) {
120120
return painlessLookupBuilder.build();
121121
}
122122

123+
// javaClassNamesToClasses is all the classes that need to be available to the custom classloader
124+
// including classes used as part of imported methods and class bindings but not necessarily whitelisted
125+
// individually. The values of javaClassNamesToClasses are a superset of the values of
126+
// canonicalClassNamesToClasses.
127+
private final Map<String, Class<?>> javaClassNamesToClasses;
128+
// canonicalClassNamesToClasses is all the whitelisted classes available in a Painless script including
129+
// classes with imported canonical names but does not include classes from imported methods or class
130+
// bindings unless also whitelisted separately. The values of canonicalClassNamesToClasses are a subset
131+
// of the values of javaClassNamesToClasses.
123132
private final Map<String, Class<?>> canonicalClassNamesToClasses;
124133
private final Map<Class<?>, PainlessClassBuilder> classesToPainlessClassBuilders;
125134

126135
private final Map<String, PainlessMethod> painlessMethodKeysToImportedPainlessMethods;
127136
private final Map<String, PainlessClassBinding> painlessMethodKeysToPainlessClassBindings;
128137

129138
public PainlessLookupBuilder() {
139+
javaClassNamesToClasses = new HashMap<>();
130140
canonicalClassNamesToClasses = new HashMap<>();
131141
classesToPainlessClassBuilders = new HashMap<>();
132142

@@ -189,7 +199,16 @@ public void addPainlessClass(Class<?> clazz, boolean importClassName) {
189199
throw new IllegalArgumentException("invalid class name [" + canonicalClassName + "]");
190200
}
191201

192-
Class<?> existingClass = canonicalClassNamesToClasses.get(canonicalClassName);
202+
Class<?> existingClass = javaClassNamesToClasses.get(clazz.getName());
203+
204+
if (existingClass == null) {
205+
javaClassNamesToClasses.put(clazz.getName(), clazz);
206+
} else if (existingClass != clazz) {
207+
throw new IllegalArgumentException("class [" + canonicalClassName + "] " +
208+
"cannot represent multiple java classes with the same name from different class loaders");
209+
}
210+
211+
existingClass = canonicalClassNamesToClasses.get(canonicalClassName);
193212

194213
if (existingClass != null && existingClass != clazz) {
195214
throw new IllegalArgumentException("class [" + canonicalClassName + "] " +
@@ -685,6 +704,14 @@ public void addImportedPainlessMethod(Class<?> targetClass, String methodName, C
685704
}
686705

687706
String targetCanonicalClassName = typeToCanonicalTypeName(targetClass);
707+
Class<?> existingTargetClass = javaClassNamesToClasses.get(targetClass.getName());
708+
709+
if (existingTargetClass == null) {
710+
javaClassNamesToClasses.put(targetClass.getName(), targetClass);
711+
} else if (existingTargetClass != targetClass) {
712+
throw new IllegalArgumentException("class [" + targetCanonicalClassName + "] " +
713+
"cannot represent multiple java classes with the same name from different class loaders");
714+
}
688715

689716
if (METHOD_NAME_PATTERN.matcher(methodName).matches() == false) {
690717
throw new IllegalArgumentException(
@@ -818,6 +845,14 @@ public void addPainlessClassBinding(Class<?> targetClass, String methodName, Cla
818845
}
819846

820847
String targetCanonicalClassName = typeToCanonicalTypeName(targetClass);
848+
Class<?> existingTargetClass = javaClassNamesToClasses.get(targetClass.getName());
849+
850+
if (existingTargetClass == null) {
851+
javaClassNamesToClasses.put(targetClass.getName(), targetClass);
852+
} else if (existingTargetClass != targetClass) {
853+
throw new IllegalArgumentException("class [" + targetCanonicalClassName + "] " +
854+
"cannot represent multiple java classes with the same name from different class loaders");
855+
}
821856

822857
Constructor<?>[] javaConstructors = targetClass.getConstructors();
823858
Constructor<?> javaConstructor = null;
@@ -952,7 +987,23 @@ public PainlessLookup build() {
952987
classesToPainlessClasses.put(painlessClassBuilderEntry.getKey(), painlessClassBuilderEntry.getValue().build());
953988
}
954989

955-
return new PainlessLookup(canonicalClassNamesToClasses, classesToPainlessClasses,
990+
if (javaClassNamesToClasses.values().containsAll(canonicalClassNamesToClasses.values()) == false) {
991+
throw new IllegalArgumentException("the values of java class names to classes " +
992+
"must be a superset of the values of canonical class names to classes");
993+
}
994+
995+
if (javaClassNamesToClasses.values().containsAll(classesToPainlessClasses.keySet()) == false) {
996+
throw new IllegalArgumentException("the values of java class names to classes " +
997+
"must be a superset of the keys of classes to painless classes");
998+
}
999+
1000+
if (canonicalClassNamesToClasses.values().containsAll(classesToPainlessClasses.keySet()) == false ||
1001+
classesToPainlessClasses.keySet().containsAll(canonicalClassNamesToClasses.values()) == false) {
1002+
throw new IllegalArgumentException("the values of canonical class names to classes " +
1003+
"must have the same classes as the keys of classes to painless classes");
1004+
}
1005+
1006+
return new PainlessLookup(javaClassNamesToClasses, canonicalClassNamesToClasses, classesToPainlessClasses,
9561007
painlessMethodKeysToImportedPainlessMethods, painlessMethodKeysToPainlessClassBindings);
9571008
}
9581009

modules/transport-netty4/build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-tr
3434

3535
dependencies {
3636
// network stack
37-
compile "io.netty:netty-buffer:4.1.29.Final"
38-
compile "io.netty:netty-codec:4.1.29.Final"
39-
compile "io.netty:netty-codec-http:4.1.29.Final"
40-
compile "io.netty:netty-common:4.1.29.Final"
41-
compile "io.netty:netty-handler:4.1.29.Final"
42-
compile "io.netty:netty-resolver:4.1.29.Final"
43-
compile "io.netty:netty-transport:4.1.29.Final"
37+
compile "io.netty:netty-buffer:${versions.netty}"
38+
compile "io.netty:netty-codec:${versions.netty}"
39+
compile "io.netty:netty-codec-http:${versions.netty}"
40+
compile "io.netty:netty-common:${versions.netty}"
41+
compile "io.netty:netty-handler:${versions.netty}"
42+
compile "io.netty:netty-resolver:${versions.netty}"
43+
compile "io.netty:netty-transport:${versions.netty}"
4444
}
4545

4646
dependencyLicenses {
@@ -111,6 +111,7 @@ thirdPartyAudit.excludes = [
111111
// from io.netty.util.internal.logging.InternalLoggerFactory (netty) - it's optional
112112
'org.slf4j.Logger',
113113
'org.slf4j.LoggerFactory',
114+
'org.slf4j.spi.LocationAwareLogger',
114115

115116
'com.google.protobuf.ExtensionRegistryLite',
116117
'com.google.protobuf.MessageLiteOrBuilder',
@@ -145,6 +146,7 @@ thirdPartyAudit.excludes = [
145146
'io.netty.util.internal.PlatformDependent0$1',
146147
'io.netty.util.internal.PlatformDependent0$2',
147148
'io.netty.util.internal.PlatformDependent0$3',
149+
'io.netty.util.internal.PlatformDependent0$5',
148150
'io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueueConsumerNodeRef',
149151
'io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueueProducerNodeRef',
150152
'io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields',

modules/transport-netty4/licenses/netty-buffer-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
597adb653306470fb3ec1af3c0f3f30a37b1310a

modules/transport-netty4/licenses/netty-codec-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
515c8f609aaca28a94f984d89a9667dd3359c1b1

modules/transport-netty4/licenses/netty-codec-http-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1384c630e8a0eeef33ad12a28791dce6e1d8767c

modules/transport-netty4/licenses/netty-common-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5dca0c34d8f38af51a2398614e81888f51cf811a

modules/transport-netty4/licenses/netty-handler-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ecc076332ed103411347f4806a44ee32d9d9cb5f

modules/transport-netty4/licenses/netty-resolver-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5106fd687066ffd712e5295d32af4e2ac6482613

modules/transport-netty4/licenses/netty-transport-4.1.29.Final.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3d27bb432a3b125167ac161b26415ad29ec17f02
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.example.painlesswhitelist;
21+
22+
public class ExampleStaticMethodClass {
23+
public static int exampleAddInts(int x, int y) {
24+
return x + y;
25+
}
26+
}

plugins/examples/painless-whitelist/src/main/resources/org/elasticsearch/example/painlesswhitelist/example_whitelist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ class java.lang.String {
3939
# existing classes can be "augmented" to have additional methods, which take the object
4040
# to operate on as the first argument to a static method
4141
int org.elasticsearch.example.painlesswhitelist.ExampleWhitelistedClass toInt()
42+
}
43+
44+
static_import {
45+
int exampleAddInts(int, int) from_class org.elasticsearch.example.painlesswhitelist.ExampleStaticMethodClass
4246
}

0 commit comments

Comments
 (0)