The license can be added or updated using the putLicense()
method:
PutLicenseRequest request = new PutLicenseRequest();
request.setLicenseDefinition(license);
request.setAcknowledge(false);
PutLicenseResponse response = client.license().putLicense(request, RequestOptions.DEFAULT);
|
Set the categories of information to retrieve. The default is to
return no information which is useful for checking if X-Pack is installed
but not much else.
|
|
A JSON document containing the license information.
|
The returned PutLicenseResponse
contains the LicensesStatus
,
acknowledged
flag and possible acknowledge messages. The acknowledge messages
are present if you previously had a license with more features than one you
are trying to update and you didn’t set the acknowledge
flag to true
. In this case
you need to display the messages to the end user and if they agree, resubmit the
license with the acknowledge
flag set to true
. Please note that the request will
still return a 200 return code even if requires an acknowledgement. So, it is
necessary to check the acknowledged
flag.
LicensesStatus status = response.status();
assertEquals(status, LicensesStatus.VALID);
boolean acknowledged = response.isAcknowledged();
String acknowledgeHeader = response.acknowledgeHeader();
Map<String, String[]> acknowledgeMessages = response.acknowledgeMessages();
|
The status of the license
|
|
Make sure that the license is valid.
|
|
Check the acknowledge flag. It should be true if license is acknowledged.
|
|
Otherwise we can see the acknowledge messages in acknowledgeHeader()
|
|
and check component-specific messages in acknowledgeMessages() .
|
Asynchronous Execution
edit
This request can be executed asynchronously:
client.license().putLicenseAsync(
request, RequestOptions.DEFAULT, listener);
|
The PutLicenseRequest to execute and the ActionListener to use when
the execution completes
|
The asynchronous method does not block and returns immediately. Once it is
completed the ActionListener
is called back using the onResponse
method
if the execution successfully completed or using the onFailure
method if
it failed.
A typical listener for PutLicenseResponse
looks like:
ActionListener<PutLicenseResponse> listener = new ActionListener<PutLicenseResponse>() {
@Override
public void onResponse(PutLicenseResponse putLicenseResponse) {
}
@Override
public void onFailure(Exception e) {
}
};
|
Called when the execution is successfully completed. The response is
provided as an argument
|
|
Called in case of failure. The raised exception is provided as an argument
|