Skip to content

Commit 8150a37

Browse files
committed
Merge remote-tracking branch 'elastic/master' into delete-license-hlrc
2 parents 9b139de + e641fcc commit 8150a37

File tree

42 files changed

+662
-93
lines changed

Some content is hidden

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

42 files changed

+662
-93
lines changed

buildSrc/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jts = 1.15.0
77
jackson = 2.8.10
88
snakeyaml = 1.17
99
# when updating log4j, please update also docs/java-api/index.asciidoc
10-
log4j = 2.9.1
10+
log4j = 2.11.1
1111
slf4j = 1.6.2
1212

1313
# when updating the JNA version, also update the version in buildSrc/build.gradle

client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,27 @@
1919

2020
package org.elasticsearch.client;
2121

22+
import org.apache.http.HttpEntity;
2223
import org.elasticsearch.action.ActionListener;
24+
import org.elasticsearch.common.Strings;
25+
import org.elasticsearch.common.io.Streams;
26+
import org.elasticsearch.common.xcontent.DeprecationHandler;
27+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
28+
import org.elasticsearch.common.xcontent.XContentBuilder;
29+
import org.elasticsearch.common.xcontent.XContentFactory;
30+
import org.elasticsearch.common.xcontent.XContentParser;
31+
import org.elasticsearch.common.xcontent.XContentType;
2332
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
2433
import org.elasticsearch.protocol.xpack.license.DeleteLicenseResponse;
34+
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
35+
import org.elasticsearch.protocol.xpack.license.GetLicenseResponse;
2536
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
2637
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
2738

2839
import java.io.IOException;
40+
import java.io.InputStream;
41+
import java.io.InputStreamReader;
42+
import java.nio.charset.StandardCharsets;
2943

3044
import static java.util.Collections.emptySet;
3145

@@ -65,6 +79,27 @@ public void putLicenseAsync(PutLicenseRequest request, RequestOptions options, A
6579
PutLicenseResponse::fromXContent, listener, emptySet());
6680
}
6781

82+
/**
83+
* Returns the current license for the cluster.
84+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
85+
* @return the response
86+
* @throws IOException in case there is a problem sending the request or parsing back the response
87+
*/
88+
public GetLicenseResponse getLicense(GetLicenseRequest request, RequestOptions options) throws IOException {
89+
return restHighLevelClient.performRequest(request, RequestConverters::getLicense, options,
90+
response -> new GetLicenseResponse(convertResponseToJson(response)), emptySet());
91+
}
92+
93+
/**
94+
* Asynchronously returns the current license for the cluster cluster.
95+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
96+
* @param listener the listener to be notified upon request completion
97+
*/
98+
public void getLicenseAsync(GetLicenseRequest request, RequestOptions options, ActionListener<GetLicenseResponse> listener) {
99+
restHighLevelClient.performRequestAsync(request, RequestConverters::getLicense, options,
100+
response -> new GetLicenseResponse(convertResponseToJson(response)), listener, emptySet());
101+
}
102+
68103
/**
69104
* Deletes license from the cluster.
70105
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
@@ -86,4 +121,37 @@ public void deleteLicenseAsync(DeleteLicenseRequest request, RequestOptions opti
86121
DeleteLicenseResponse::fromXContent, listener, emptySet());
87122
}
88123

124+
/**
125+
* Converts an entire response into a json sting
126+
*
127+
* This is useful for responses that we don't parse on the client side, but instead work as string
128+
* such as in case of the license JSON
129+
*/
130+
static String convertResponseToJson(Response response) throws IOException {
131+
HttpEntity entity = response.getEntity();
132+
if (entity == null) {
133+
throw new IllegalStateException("Response body expected but not returned");
134+
}
135+
if (entity.getContentType() == null) {
136+
throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body");
137+
}
138+
XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue());
139+
if (xContentType == null) {
140+
throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
141+
}
142+
if (xContentType == XContentType.JSON) {
143+
// No changes is required
144+
return Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
145+
} else {
146+
// Need to convert into JSON
147+
try (InputStream stream = response.getEntity().getContent();
148+
XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY,
149+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)) {
150+
parser.nextToken();
151+
XContentBuilder builder = XContentFactory.jsonBuilder();
152+
builder.copyCurrentStructure(parser);
153+
return Strings.toString(builder);
154+
}
155+
}
156+
}
89157
}

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@
108108
import org.elasticsearch.index.rankeval.RankEvalRequest;
109109
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
110110
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
111+
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
112+
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
111113
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
112114
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
113115
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
114-
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
115116
import org.elasticsearch.rest.action.search.RestSearchAction;
116117
import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
117118
import org.elasticsearch.script.mustache.SearchTemplateRequest;
@@ -1155,7 +1156,11 @@ static Request xpackUsage(XPackUsageRequest usageRequest) {
11551156
}
11561157

11571158
static Request putLicense(PutLicenseRequest putLicenseRequest) {
1158-
Request request = new Request(HttpPut.METHOD_NAME, "/_xpack/license");
1159+
String endpoint = new EndpointBuilder()
1160+
.addPathPartAsIs("_xpack")
1161+
.addPathPartAsIs("license")
1162+
.build();
1163+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
11591164
Params parameters = new Params(request);
11601165
parameters.withTimeout(putLicenseRequest.timeout());
11611166
parameters.withMasterTimeout(putLicenseRequest.masterNodeTimeout());
@@ -1166,6 +1171,17 @@ static Request putLicense(PutLicenseRequest putLicenseRequest) {
11661171
return request;
11671172
}
11681173

1174+
static Request getLicense(GetLicenseRequest getLicenseRequest) {
1175+
String endpoint = new EndpointBuilder()
1176+
.addPathPartAsIs("_xpack")
1177+
.addPathPartAsIs("license")
1178+
.build();
1179+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
1180+
Params parameters = new Params(request);
1181+
parameters.withLocal(getLicenseRequest.local());
1182+
return request;
1183+
}
1184+
11691185
static Request deleteLicense(DeleteLicenseRequest deleteLicenseRequest) {
11701186
Request request = new Request(HttpDelete.METHOD_NAME, "/_xpack/license");
11711187
Params parameters = new Params(request);

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.elasticsearch.common.Booleans;
2929
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
3030
import org.elasticsearch.protocol.xpack.license.DeleteLicenseResponse;
31+
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
32+
import org.elasticsearch.protocol.xpack.license.GetLicenseResponse;
3133
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
3234
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
3335
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
@@ -36,6 +38,8 @@
3638
import java.util.concurrent.CountDownLatch;
3739
import java.util.concurrent.TimeUnit;
3840

41+
import static org.hamcrest.Matchers.containsString;
42+
import static org.hamcrest.Matchers.endsWith;
3943
import static org.hamcrest.Matchers.hasSize;
4044
import static org.hamcrest.Matchers.not;
4145
import static org.hamcrest.Matchers.startsWith;
@@ -153,4 +157,62 @@ public void onFailure(Exception e) {
153157
assertTrue(latch.await(30L, TimeUnit.SECONDS));
154158
}
155159
}
160+
161+
public void testGetLicense() throws Exception {
162+
RestHighLevelClient client = highLevelClient();
163+
{
164+
//tag::get-license-execute
165+
GetLicenseRequest request = new GetLicenseRequest();
166+
167+
GetLicenseResponse response = client.license().getLicense(request, RequestOptions.DEFAULT);
168+
//end::get-license-execute
169+
170+
//tag::get-license-response
171+
String currentLicense = response.getLicenseDefinition(); // <1>
172+
//end::get-license-response
173+
174+
assertThat(currentLicense, containsString("trial"));
175+
assertThat(currentLicense, containsString("client_rest-high-level_integTestCluster"));
176+
}
177+
{
178+
GetLicenseRequest request = new GetLicenseRequest();
179+
// tag::get-license-execute-listener
180+
ActionListener<GetLicenseResponse> listener = new ActionListener<GetLicenseResponse>() {
181+
@Override
182+
public void onResponse(GetLicenseResponse indexResponse) {
183+
// <1>
184+
}
185+
186+
@Override
187+
public void onFailure(Exception e) {
188+
// <2>
189+
}
190+
};
191+
// end::get-license-execute-listener
192+
193+
// Replace the empty listener by a blocking listener in test
194+
final CountDownLatch latch = new CountDownLatch(1);
195+
listener = new LatchedActionListener<>(listener, latch);
196+
197+
// tag::get-license-execute-async
198+
client.license().getLicenseAsync(
199+
request, RequestOptions.DEFAULT, listener); // <1>
200+
// end::get-license-execute-async
201+
202+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
203+
}
204+
{
205+
GetLicenseRequest request = new GetLicenseRequest();
206+
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
207+
// Make sure that it still works in other formats
208+
builder.addHeader("Accept", randomFrom("application/smile", "application/cbor"));
209+
RequestOptions options = builder.build();
210+
GetLicenseResponse response = client.license().getLicense(request, options);
211+
String currentLicense = response.getLicenseDefinition();
212+
assertThat(currentLicense, startsWith("{"));
213+
assertThat(currentLicense, containsString("trial"));
214+
assertThat(currentLicense, containsString("client_rest-high-level_integTestCluster"));
215+
assertThat(currentLicense, endsWith("}"));
216+
}
217+
}
156218
}

docs/java-api/index.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You need to also include Log4j 2 dependencies:
8181
<dependency>
8282
<groupId>org.apache.logging.log4j</groupId>
8383
<artifactId>log4j-core</artifactId>
84-
<version>2.9.1</version>
84+
<version>2.11.1</version>
8585
</dependency>
8686
--------------------------------------------------
8787

@@ -109,7 +109,7 @@ If you want to use another logger than Log4j 2, you can use http://www.slf4j.org
109109
<dependency>
110110
<groupId>org.apache.logging.log4j</groupId>
111111
<artifactId>log4j-to-slf4j</artifactId>
112-
<version>2.9.1</version>
112+
<version>2.11.1</version>
113113
</dependency>
114114
<dependency>
115115
<groupId>org.slf4j</groupId>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[[java-rest-high-get-license]]
2+
=== Get License
3+
4+
[[java-rest-high-get-license-execution]]
5+
==== Execution
6+
7+
The license can be added or updated using the `getLicense()` method:
8+
9+
["source","java",subs="attributes,callouts,macros"]
10+
--------------------------------------------------
11+
include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-execute]
12+
--------------------------------------------------
13+
14+
[[java-rest-high-get-license-response]]
15+
==== Response
16+
17+
The returned `GetLicenseResponse` contains the license in the JSON format.
18+
19+
["source","java",subs="attributes,callouts,macros"]
20+
--------------------------------------------------
21+
include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-response]
22+
--------------------------------------------------
23+
<1> The text of the license.
24+
25+
[[java-rest-high-get-license-async]]
26+
==== Asynchronous Execution
27+
28+
This request can be executed asynchronously:
29+
30+
["source","java",subs="attributes,callouts,macros"]
31+
--------------------------------------------------
32+
include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-execute-async]
33+
--------------------------------------------------
34+
<1> The `GetLicenseRequest` to execute and the `ActionListener` to use when
35+
the execution completes
36+
37+
The asynchronous method does not block and returns immediately. Once it is
38+
completed the `ActionListener` is called back using the `onResponse` method
39+
if the execution successfully completed or using the `onFailure` method if
40+
it failed.
41+
42+
A typical listener for `GetLicenseResponse` looks like:
43+
44+
["source","java",subs="attributes,callouts,macros"]
45+
--------------------------------------------------
46+
include-tagged::{doc-tests}/LicensingDocumentationIT.java[get-license-execute-listener]
47+
--------------------------------------------------
48+
<1> Called when the execution is successfully completed. The response is
49+
provided as an argument
50+
<2> Called in case of failure. The raised exception is provided as an argument

plugins/repository-hdfs/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ thirdPartyAudit.excludes = [
564564
// we are not pulling in slf4j-ext, this is okay, Log4j will fallback gracefully
565565
'org.slf4j.ext.EventData',
566566

567-
'org.apache.log4j.AppenderSkeleton',
568567
'org.apache.log4j.AsyncAppender',
569568
'org.apache.log4j.helpers.ISO8601DateFormat',
570569
'org.apache.log4j.spi.ThrowableInformation',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4b41b53a3a2d299ce381a69d165381ca19f62912

plugins/repository-hdfs/licenses/log4j-slf4j-impl-2.9.1.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ thirdPartyAudit.excludes = [
220220
'com.fasterxml.jackson.dataformat.xml.JacksonXmlModule',
221221
'com.fasterxml.jackson.dataformat.xml.XmlMapper',
222222
'com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter',
223-
'com.fasterxml.jackson.databind.node.JsonNodeFactory',
224223
'com.fasterxml.jackson.databind.node.ObjectNode',
225224
'org.fusesource.jansi.Ansi',
226225
'org.fusesource.jansi.AnsiRenderer$Code',
@@ -262,12 +261,6 @@ thirdPartyAudit.excludes = [
262261
'javax.mail.internet.MimeMultipart',
263262
'javax.mail.internet.MimeUtility',
264263
'javax.mail.util.ByteArrayDataSource',
265-
'javax.persistence.AttributeConverter',
266-
'javax.persistence.EntityManager',
267-
'javax.persistence.EntityManagerFactory',
268-
'javax.persistence.EntityTransaction',
269-
'javax.persistence.Persistence',
270-
'javax.persistence.PersistenceException',
271264
'org.apache.commons.compress.compressors.CompressorStreamFactory',
272265
'org.apache.commons.compress.utils.IOUtils',
273266
'org.apache.commons.csv.CSVFormat',
@@ -311,6 +304,16 @@ thirdPartyAudit.excludes = [
311304
'com.google.common.geometry.S2LatLng',
312305
]
313306

307+
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
308+
// Used by Log4J 2.11.1
309+
thirdPartyAudit.excludes += [
310+
'java.io.ObjectInputFilter',
311+
'java.io.ObjectInputFilter$Config',
312+
'java.io.ObjectInputFilter$FilterInfo',
313+
'java.io.ObjectInputFilter$Status'
314+
]
315+
}
316+
314317
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
315318
thirdPartyAudit.excludes += ['javax.xml.bind.DatatypeConverter']
316319
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3aba3398fe064a3eab4331f88161c7480e848418

server/licenses/log4j-1.2-api-2.9.1.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+
268f0fe4df3eefe052b57c87ec48517d64fb2a10

server/licenses/log4j-api-2.9.1.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+
592a48674c926b01a9a747c7831bcd82a9e6d6e4

server/licenses/log4j-core-2.9.1.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)