Browse Source

Clean up licensing APIs (#109121)

Fixes trappy timeouts related to #107984 and also cleans up all the
indirection via unnecessary request builders.
David Turner 1 year ago
parent
commit
0e03920560
37 changed files with 231 additions and 388 deletions
  1. 2 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/ClusterStateLicenseService.java
  2. 3 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequest.java
  3. 0 17
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java
  4. 0 30
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetLicenseRequestBuilder.java
  5. 3 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequest.java
  6. 0 17
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java
  7. 0 42
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java
  8. 3 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicRequest.java
  9. 0 22
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicRequestBuilder.java
  10. 3 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequest.java
  11. 0 22
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java
  12. 3 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseRequest.java
  13. 0 49
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseRequestBuilder.java
  14. 4 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java
  15. 2 1
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java
  16. 4 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java
  17. 1 3
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java
  18. 2 1
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java
  19. 1 3
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java
  20. 5 1
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/TransportDeleteLicenseAction.java
  21. 2 1
      x-pack/plugin/core/src/main/java/org/elasticsearch/license/internal/MutableLicenseService.java
  22. 3 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/license/GetLicenseRequest.java
  23. 17 0
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/AbstractLicensesIntegrationTestCase.java
  24. 22 10
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/ClusterStateLicenseServiceClusterTests.java
  25. 2 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/ClusterStateLicenseServiceTests.java
  26. 2 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseFIPSTests.java
  27. 1 1
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseTLSTests.java
  28. 2 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesAcknowledgementTests.java
  29. 1 1
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesManagerServiceTests.java
  30. 55 67
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesTransportTests.java
  31. 38 27
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartBasicLicenseTests.java
  32. 25 41
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartTrialLicenseTests.java
  33. 4 1
      x-pack/plugin/core/src/test/java/org/elasticsearch/license/TestUtils.java
  34. 6 1
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/XPackPluginTests.java
  35. 2 1
      x-pack/plugin/old-lucene-versions/src/internalClusterTest/java/org/elasticsearch/xpack/lucene/bwc/AbstractArchiveTestCase.java
  36. 8 3
      x-pack/plugin/old-lucene-versions/src/internalClusterTest/java/org/elasticsearch/xpack/lucene/bwc/ArchiveLicenseIntegTests.java
  37. 5 2
      x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java

+ 2 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/ClusterStateLicenseService.java

@@ -303,8 +303,8 @@ public class ClusterStateLicenseService extends AbstractLifecycleComponent
      * Remove license from the cluster state metadata
      */
     @Override
-    public void removeLicense(ActionListener<? extends AcknowledgedResponse> listener) {
-        final PostStartBasicRequest startBasicRequest = new PostStartBasicRequest().acknowledge(true);
+    public void removeLicense(TimeValue masterNodeTimeout, TimeValue ackTimeout, ActionListener<? extends AcknowledgedResponse> listener) {
+        final PostStartBasicRequest startBasicRequest = new PostStartBasicRequest(masterNodeTimeout, ackTimeout).acknowledge(true);
         @SuppressWarnings("unchecked")
         final StartBasicClusterTask task = new StartBasicClusterTask(
             logger,

+ 3 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequest.java

@@ -9,13 +9,14 @@ package org.elasticsearch.license;
 import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.support.master.MasterNodeReadRequest;
 import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.core.TimeValue;
 
 import java.io.IOException;
 
 public class GetBasicStatusRequest extends MasterNodeReadRequest<GetBasicStatusRequest> {
 
-    public GetBasicStatusRequest() {
-        super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
+    public GetBasicStatusRequest(TimeValue masterNodeTimeout) {
+        super(masterNodeTimeout);
     }
 
     public GetBasicStatusRequest(StreamInput in) throws IOException {

+ 0 - 17
x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java

@@ -1,17 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.action.ActionRequestBuilder;
-import org.elasticsearch.client.internal.ElasticsearchClient;
-
-class GetBasicStatusRequestBuilder extends ActionRequestBuilder<GetBasicStatusRequest, GetBasicStatusResponse> {
-
-    GetBasicStatusRequestBuilder(ElasticsearchClient client) {
-        super(client, GetBasicStatusAction.INSTANCE, new GetBasicStatusRequest());
-    }
-}

+ 0 - 30
x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetLicenseRequestBuilder.java

@@ -1,30 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
-import org.elasticsearch.client.internal.ElasticsearchClient;
-import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
-
-public class GetLicenseRequestBuilder extends MasterNodeReadOperationRequestBuilder<
-    GetLicenseRequest,
-    GetLicenseResponse,
-    GetLicenseRequestBuilder> {
-
-    public GetLicenseRequestBuilder(ElasticsearchClient client) {
-        this(client, GetLicenseAction.INSTANCE);
-    }
-
-    /**
-     * Creates new get licenses request builder
-     *
-     * @param client elasticsearch client
-     */
-    public GetLicenseRequestBuilder(ElasticsearchClient client, GetLicenseAction action) {
-        super(client, action, new GetLicenseRequest());
-    }
-}

+ 3 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequest.java

@@ -9,13 +9,14 @@ package org.elasticsearch.license;
 import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.support.master.MasterNodeReadRequest;
 import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.core.TimeValue;
 
 import java.io.IOException;
 
 public class GetTrialStatusRequest extends MasterNodeReadRequest<GetTrialStatusRequest> {
 
-    public GetTrialStatusRequest() {
-        super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
+    public GetTrialStatusRequest(TimeValue masterNodeTimeout) {
+        super(masterNodeTimeout);
     }
 
     public GetTrialStatusRequest(StreamInput in) throws IOException {

+ 0 - 17
x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java

@@ -1,17 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.action.ActionRequestBuilder;
-import org.elasticsearch.client.internal.ElasticsearchClient;
-
-class GetTrialStatusRequestBuilder extends ActionRequestBuilder<GetTrialStatusRequest, GetTrialStatusResponse> {
-
-    GetTrialStatusRequestBuilder(ElasticsearchClient client) {
-        super(client, GetTrialStatusAction.INSTANCE, new GetTrialStatusRequest());
-    }
-}

+ 0 - 42
x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java

@@ -1,42 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.client.internal.ElasticsearchClient;
-
-public class LicensingClient {
-
-    private final ElasticsearchClient client;
-
-    public LicensingClient(ElasticsearchClient client) {
-        this.client = client;
-    }
-
-    public PutLicenseRequestBuilder preparePutLicense(License license) {
-        return new PutLicenseRequestBuilder(client).setLicense(license);
-    }
-
-    public GetLicenseRequestBuilder prepareGetLicense() {
-        return new GetLicenseRequestBuilder(client);
-    }
-
-    public PostStartTrialRequestBuilder preparePostStartTrial() {
-        return new PostStartTrialRequestBuilder(client);
-    }
-
-    public GetTrialStatusRequestBuilder prepareGetStartTrial() {
-        return new GetTrialStatusRequestBuilder(client);
-    }
-
-    public PostStartBasicRequestBuilder preparePostStartBasic() {
-        return new PostStartBasicRequestBuilder(client);
-    }
-
-    public GetBasicStatusRequestBuilder prepareGetStartBasic() {
-        return new GetBasicStatusRequestBuilder(client);
-    }
-}

+ 3 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicRequest.java

@@ -9,6 +9,7 @@ package org.elasticsearch.license;
 import org.elasticsearch.action.support.master.AcknowledgedRequest;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.core.TimeValue;
 
 import java.io.IOException;
 
@@ -16,8 +17,8 @@ public class PostStartBasicRequest extends AcknowledgedRequest<PostStartBasicReq
 
     private boolean acknowledge = false;
 
-    public PostStartBasicRequest() {
-        super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT, DEFAULT_ACK_TIMEOUT);
+    public PostStartBasicRequest(TimeValue masterNodeTimeout, TimeValue ackTimeout) {
+        super(masterNodeTimeout, ackTimeout);
     }
 
     public PostStartBasicRequest(StreamInput in) throws IOException {

+ 0 - 22
x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicRequestBuilder.java

@@ -1,22 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.action.ActionRequestBuilder;
-import org.elasticsearch.client.internal.ElasticsearchClient;
-
-class PostStartBasicRequestBuilder extends ActionRequestBuilder<PostStartBasicRequest, PostStartBasicResponse> {
-
-    PostStartBasicRequestBuilder(ElasticsearchClient client) {
-        super(client, PostStartBasicAction.INSTANCE, new PostStartBasicRequest());
-    }
-
-    public PostStartBasicRequestBuilder setAcknowledge(boolean acknowledge) {
-        request.acknowledge(acknowledge);
-        return this;
-    }
-}

+ 3 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequest.java

@@ -10,6 +10,7 @@ import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.support.master.MasterNodeRequest;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.core.TimeValue;
 
 import java.io.IOException;
 
@@ -18,8 +19,8 @@ public class PostStartTrialRequest extends MasterNodeRequest<PostStartTrialReque
     private boolean acknowledge = false;
     private String type;
 
-    public PostStartTrialRequest() {
-        super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
+    public PostStartTrialRequest(TimeValue masterNodeTimeout) {
+        super(masterNodeTimeout);
     }
 
     public PostStartTrialRequest(StreamInput in) throws IOException {

+ 0 - 22
x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java

@@ -1,22 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.action.ActionRequestBuilder;
-import org.elasticsearch.client.internal.ElasticsearchClient;
-
-class PostStartTrialRequestBuilder extends ActionRequestBuilder<PostStartTrialRequest, PostStartTrialResponse> {
-
-    PostStartTrialRequestBuilder(ElasticsearchClient client) {
-        super(client, PostStartTrialAction.INSTANCE, new PostStartTrialRequest());
-    }
-
-    public PostStartTrialRequestBuilder setAcknowledge(boolean acknowledge) {
-        request.acknowledge(acknowledge);
-        return this;
-    }
-}

+ 3 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseRequest.java

@@ -12,6 +12,7 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.xcontent.XContentType;
 
 import java.io.IOException;
@@ -27,8 +28,8 @@ public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
         acknowledge = in.readBoolean();
     }
 
-    public PutLicenseRequest() {
-        super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT, DEFAULT_ACK_TIMEOUT);
+    public PutLicenseRequest(TimeValue masterNodeTimeout, TimeValue ackTimeout) {
+        super(masterNodeTimeout, ackTimeout);
     }
 
     @Override

+ 0 - 49
x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseRequestBuilder.java

@@ -1,49 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-package org.elasticsearch.license;
-
-import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
-import org.elasticsearch.client.internal.ElasticsearchClient;
-import org.elasticsearch.common.bytes.BytesReference;
-import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
-import org.elasticsearch.xcontent.XContentType;
-
-/**
- * Register license request builder
- */
-public class PutLicenseRequestBuilder extends AcknowledgedRequestBuilder<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder> {
-
-    /**
-     * Constructs register license request
-     *
-     * @param client elasticsearch client
-     */
-    public PutLicenseRequestBuilder(ElasticsearchClient client) {
-        super(client, PutLicenseAction.INSTANCE, new PutLicenseRequest());
-    }
-
-    /**
-     * Sets the license
-     *
-     * @param license license
-     * @return this builder
-     */
-    public PutLicenseRequestBuilder setLicense(License license) {
-        request.license(license);
-        return this;
-    }
-
-    public PutLicenseRequestBuilder setLicense(BytesReference licenseSource, XContentType xContentType) {
-        request.license(licenseSource, xContentType);
-        return this;
-    }
-
-    public PutLicenseRequestBuilder setAcknowledge(boolean acknowledge) {
-        request.acknowledge(acknowledge);
-        return this;
-    }
-}

+ 4 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java

@@ -11,6 +11,7 @@ import org.elasticsearch.client.internal.node.NodeClient;
 import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.RestUtils;
 import org.elasticsearch.rest.action.RestToXContentListener;
 
 import java.util.List;
@@ -29,8 +30,9 @@ public class RestGetBasicStatus extends BaseRestHandler {
     }
 
     @Override
-    protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
-        return channel -> new GetBasicStatusRequestBuilder(client).execute(new RestToXContentListener<>(channel));
+    protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) {
+        final var request = new GetBasicStatusRequest(RestUtils.getMasterNodeTimeout(restRequest));
+        return channel -> client.execute(GetBasicStatusAction.INSTANCE, request, new RestToXContentListener<>(channel));
     }
 
     @Override

+ 2 - 1
x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java

@@ -16,6 +16,7 @@ import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.RestResponse;
+import org.elasticsearch.rest.RestUtils;
 import org.elasticsearch.rest.Scope;
 import org.elasticsearch.rest.ServerlessScope;
 import org.elasticsearch.rest.action.RestBuilderListener;
@@ -84,7 +85,7 @@ public class RestGetLicenseAction extends BaseRestHandler {
         }
 
         final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
-        GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
+        GetLicenseRequest getLicenseRequest = new GetLicenseRequest(RestUtils.getMasterNodeTimeout(request));
         getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));
         return channel -> client.admin()
             .cluster()

+ 4 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java

@@ -11,6 +11,7 @@ import org.elasticsearch.client.internal.node.NodeClient;
 import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.RestUtils;
 import org.elasticsearch.rest.action.RestToXContentListener;
 
 import java.util.List;
@@ -29,8 +30,9 @@ public class RestGetTrialStatus extends BaseRestHandler {
     }
 
     @Override
-    protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
-        return channel -> new GetTrialStatusRequestBuilder(client).execute(new RestToXContentListener<>(channel));
+    protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) {
+        final var request = new GetTrialStatusRequest(RestUtils.getMasterNodeTimeout(restRequest));
+        return channel -> client.execute(GetTrialStatusAction.INSTANCE, request, new RestToXContentListener<>(channel));
     }
 
     @Override

+ 1 - 3
x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java

@@ -33,10 +33,8 @@ public class RestPostStartBasicLicense extends BaseRestHandler {
 
     @Override
     protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
-        PostStartBasicRequest startBasicRequest = new PostStartBasicRequest();
+        PostStartBasicRequest startBasicRequest = new PostStartBasicRequest(getMasterNodeTimeout(request), getAckTimeout(request));
         startBasicRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
-        startBasicRequest.ackTimeout(getAckTimeout(request));
-        startBasicRequest.masterNodeTimeout(getMasterNodeTimeout(request));
         return channel -> client.execute(
             PostStartBasicAction.INSTANCE,
             startBasicRequest,

+ 2 - 1
x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java

@@ -12,6 +12,7 @@ import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.RestResponse;
+import org.elasticsearch.rest.RestUtils;
 import org.elasticsearch.rest.action.RestBuilderListener;
 import org.elasticsearch.xcontent.XContentBuilder;
 
@@ -34,7 +35,7 @@ public class RestPostStartTrialLicense extends BaseRestHandler {
 
     @Override
     protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
-        PostStartTrialRequest startTrialRequest = new PostStartTrialRequest();
+        PostStartTrialRequest startTrialRequest = new PostStartTrialRequest(RestUtils.getMasterNodeTimeout(request));
         startTrialRequest.setType(request.param("type", License.LicenseType.TRIAL.getTypeName()));
         startTrialRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
         return channel -> client.execute(PostStartTrialAction.INSTANCE, startTrialRequest, new RestBuilderListener<>(channel) {

+ 1 - 3
x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java

@@ -44,11 +44,9 @@ public class RestPutLicenseAction extends BaseRestHandler {
         if (request.hasContent() == false) {
             throw new IllegalArgumentException("The license must be provided in the request body");
         }
-        PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
+        PutLicenseRequest putLicenseRequest = new PutLicenseRequest(getMasterNodeTimeout(request), getAckTimeout(request));
         putLicenseRequest.license(request.content(), request.getXContentType());
         putLicenseRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
-        putLicenseRequest.ackTimeout(getAckTimeout(request));
-        putLicenseRequest.masterNodeTimeout(getMasterNodeTimeout(request));
 
         if (License.LicenseType.isBasic(putLicenseRequest.license().type())) {
             throw new IllegalArgumentException(

+ 5 - 1
x-pack/plugin/core/src/main/java/org/elasticsearch/license/TransportDeleteLicenseAction.java

@@ -63,6 +63,10 @@ public class TransportDeleteLicenseAction extends AcknowledgedTransportMasterNod
         ClusterState state,
         final ActionListener<AcknowledgedResponse> listener
     ) throws ElasticsearchException {
-        licenseService.removeLicense(listener.map(r -> AcknowledgedResponse.of(r.isAcknowledged())));
+        licenseService.removeLicense(
+            request.masterNodeTimeout(),
+            request.ackTimeout(),
+            listener.map(r -> AcknowledgedResponse.of(r.isAcknowledged()))
+        );
     }
 }

+ 2 - 1
x-pack/plugin/core/src/main/java/org/elasticsearch/license/internal/MutableLicenseService.java

@@ -10,6 +10,7 @@ package org.elasticsearch.license.internal;
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.support.master.AcknowledgedResponse;
 import org.elasticsearch.common.component.LifecycleComponent;
+import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.license.LicenseService;
 import org.elasticsearch.license.LicensesMetadata;
 import org.elasticsearch.license.PostStartBasicRequest;
@@ -35,7 +36,7 @@ public interface MutableLicenseService extends LicenseService, LifecycleComponen
      * Removes the current license. Implementations should remove the current license and ensure that attempts to read returns
      * {@link LicensesMetadata#LICENSE_TOMBSTONE} if a license was removed. Additionally the {@link XPackLicenseState} must be updated.
      */
-    void removeLicense(ActionListener<? extends AcknowledgedResponse> listener);
+    void removeLicense(TimeValue masterNodeTimeout, TimeValue ackTimeout, ActionListener<? extends AcknowledgedResponse> listener);
 
     /**
      * Installs a basic license.

+ 3 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/license/GetLicenseRequest.java

@@ -9,13 +9,14 @@ package org.elasticsearch.protocol.xpack.license;
 import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.support.master.MasterNodeReadRequest;
 import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.core.TimeValue;
 
 import java.io.IOException;
 
 public class GetLicenseRequest extends MasterNodeReadRequest<GetLicenseRequest> {
 
-    public GetLicenseRequest() {
-        super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
+    public GetLicenseRequest(TimeValue masterNodeTimeout) {
+        super(masterNodeTimeout);
     }
 
     public GetLicenseRequest(StreamInput in) throws IOException {

+ 17 - 0
x-pack/plugin/core/src/test/java/org/elasticsearch/license/AbstractLicensesIntegrationTestCase.java

@@ -14,6 +14,7 @@ import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.core.Nullable;
 import org.elasticsearch.plugins.Plugin;
+import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
 import org.elasticsearch.test.ESIntegTestCase;
 import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
 import org.elasticsearch.xpack.core.XPackSettings;
@@ -100,4 +101,20 @@ public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCas
         });
     }
 
+    protected static GetLicenseResponse getLicense() {
+        return safeGet(clusterAdmin().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)));
+    }
+
+    protected static GetTrialStatusResponse getTrialStatus() {
+        return safeGet(clusterAdmin().execute(GetTrialStatusAction.INSTANCE, new GetTrialStatusRequest(TEST_REQUEST_TIMEOUT)));
+    }
+
+    protected static PostStartBasicResponse startBasic() {
+        return safeGet(
+            clusterAdmin().execute(
+                PostStartBasicAction.INSTANCE,
+                new PostStartBasicRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).acknowledge(true)
+            )
+        );
+    }
 }

+ 22 - 10
x-pack/plugin/core/src/test/java/org/elasticsearch/license/ClusterStateLicenseServiceClusterTests.java

@@ -10,6 +10,7 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest;
 import org.elasticsearch.cluster.node.DiscoveryNodeRole;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.core.TimeValue;
+import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
 import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
 
 import java.util.Set;
@@ -40,18 +41,22 @@ public class ClusterStateLicenseServiceClusterTests extends AbstractLicensesInte
         ensureGreen();
 
         logger.info("--> put signed license");
-        LicensingClient licensingClient = new LicensingClient(client());
         License license = TestUtils.generateSignedLicense(TimeValue.timeValueMinutes(1));
         putLicense(license);
-        assertThat(licensingClient.prepareGetLicense().get().license(), equalTo(license));
+        assertThat(
+            client().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)).get().license(),
+            equalTo(license)
+        );
         assertOperationMode(license.operationMode());
 
         logger.info("--> restart all nodes");
         internalCluster().fullRestart();
         ensureYellow();
-        licensingClient = new LicensingClient(client());
         logger.info("--> get and check signed license");
-        assertThat(licensingClient.prepareGetLicense().get().license(), equalTo(license));
+        assertThat(
+            client().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)).get().license(),
+            equalTo(license)
+        );
         logger.info("--> remove licenses");
 
         assertAcked(
@@ -62,9 +67,12 @@ public class ClusterStateLicenseServiceClusterTests extends AbstractLicensesInte
 
         logger.info("--> restart all nodes");
         internalCluster().fullRestart();
-        licensingClient = new LicensingClient(client());
         ensureYellow();
-        assertTrue(License.LicenseType.isBasic(licensingClient.prepareGetLicense().get().license().type()));
+        assertTrue(
+            License.LicenseType.isBasic(
+                client().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)).get().license().type()
+            )
+        );
         assertOperationMode(License.OperationMode.BASIC);
 
         wipeAllLicenses();
@@ -103,15 +111,19 @@ public class ClusterStateLicenseServiceClusterTests extends AbstractLicensesInte
         ensureGreen();
         assertLicenseActive(true);
         putLicense(TestUtils.generateSignedLicenseOldSignature());
-        LicensingClient licensingClient = new LicensingClient(client());
-        assertThat(licensingClient.prepareGetLicense().get().license().version(), equalTo(License.VERSION_START_DATE));
+        assertThat(
+            client().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)).get().license().version(),
+            equalTo(License.VERSION_START_DATE)
+        );
         logger.info("--> restart node");
         internalCluster().fullRestart(); // restart so that license is updated
         ensureYellow();
         logger.info("--> await node for enabled");
         assertLicenseActive(true);
-        licensingClient = new LicensingClient(client());
-        assertThat(licensingClient.prepareGetLicense().get().license().version(), equalTo(License.VERSION_CURRENT)); // license updated
+        assertThat(
+            client().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)).get().license().version(),
+            equalTo(License.VERSION_CURRENT)
+        ); // license updated
         internalCluster().fullRestart(); // restart once more and verify updated license is active
         ensureYellow();
         logger.info("--> await node for enabled");

+ 2 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/license/ClusterStateLicenseServiceTests.java

@@ -202,7 +202,7 @@ public class ClusterStateLicenseServiceTests extends ESTestCase {
             assertThat(response.getStatus(), equalTo(PostStartBasicResponse.Status.GENERATED_BASIC));
         };
         final PlainActionFuture<PostStartBasicResponse> future = new PlainActionFuture<>();
-        service.startBasicLicense(new PostStartBasicRequest(), future);
+        service.startBasicLicense(new PostStartBasicRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT), future);
 
         if (future.isDone()) {
             // If validation failed, the future might be done without calling the updater task.
@@ -289,7 +289,7 @@ public class ClusterStateLicenseServiceTests extends ESTestCase {
             new FeatureService(List.of())
         );
 
-        final PutLicenseRequest request = new PutLicenseRequest();
+        final PutLicenseRequest request = new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
         request.license(toSpec(license), XContentType.JSON);
         final PlainActionFuture<PutLicenseResponse> future = new PlainActionFuture<>();
         service.registerLicense(request, future);

+ 2 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseFIPSTests.java

@@ -21,7 +21,7 @@ public class LicenseFIPSTests extends AbstractClusterStateLicenseServiceTestCase
 
     public void testFIPSCheckWithAllowedLicense() throws Exception {
         License newLicense = TestUtils.generateSignedLicense(randomFrom("trial", "platinum"), TimeValue.timeValueHours(24L));
-        PutLicenseRequest request = new PutLicenseRequest();
+        PutLicenseRequest request = new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
         request.acknowledge(true);
         request.license(newLicense);
         Settings settings = Settings.builder()
@@ -45,7 +45,7 @@ public class LicenseFIPSTests extends AbstractClusterStateLicenseServiceTestCase
 
     public void testFIPSCheckWithoutAllowedLicense() throws Exception {
         License newLicense = TestUtils.generateSignedLicense(randomFrom("gold", "standard"), TimeValue.timeValueHours(24L));
-        PutLicenseRequest request = new PutLicenseRequest();
+        PutLicenseRequest request = new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
         request.acknowledge(true);
         request.license(newLicense);
         Settings settings = Settings.builder()

+ 1 - 1
x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseTLSTests.java

@@ -31,7 +31,7 @@ public class LicenseTLSTests extends AbstractClusterStateLicenseServiceTestCase
 
     public void testApplyLicenseInDevMode() throws Exception {
         License newLicense = TestUtils.generateSignedLicense(randomFrom("gold", "platinum"), TimeValue.timeValueHours(24L));
-        PutLicenseRequest request = new PutLicenseRequest();
+        PutLicenseRequest request = new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
         request.acknowledge(true);
         request.license(newLicense);
         Settings settings = Settings.builder().put("xpack.security.enabled", true).build();

+ 2 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesAcknowledgementTests.java

@@ -29,14 +29,14 @@ public class LicensesAcknowledgementTests extends AbstractClusterStateLicenseSer
         // try installing a signed license
         long issueDate = System.currentTimeMillis() - TimeValue.timeValueHours(24 * 2).getMillis();
         License signedLicense = TestUtils.generateSignedLicense("trial", License.VERSION_CURRENT, issueDate, timeValueHours(10));
-        PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense);
+        PutLicenseRequest putLicenseRequest = new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).license(signedLicense);
         // ensure acknowledgement message was part of the response
         licenseService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(false, LicensesStatus.VALID, true));
         assertThat(licenseService.getLicense(), not(signedLicense));
         verify(clusterService, times(0)).submitUnbatchedStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class));
 
         // try installing a signed license with acknowledgement
-        putLicenseRequest = new PutLicenseRequest().license(signedLicense).acknowledge(true);
+        putLicenseRequest = new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).license(signedLicense).acknowledge(true);
         // ensure license was installed and no acknowledgment message was returned
         licenseService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(true, LicensesStatus.VALID, false));
         verify(clusterService, times(1)).submitUnbatchedStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class));

+ 1 - 1
x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesManagerServiceTests.java

@@ -127,7 +127,7 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
     private void removeAndAckSignedLicenses(final MutableLicenseService licenseService) {
         final CountDownLatch latch = new CountDownLatch(1);
         final AtomicBoolean success = new AtomicBoolean(false);
-        licenseService.removeLicense(new ActionListener<PostStartBasicResponse>() {
+        licenseService.removeLicense(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, new ActionListener<PostStartBasicResponse>() {
             @Override
             public void onResponse(PostStartBasicResponse postStartBasicResponse) {
                 if (postStartBasicResponse.isAcknowledged()) {

+ 55 - 67
x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicensesTransportTests.java

@@ -6,13 +6,13 @@
  */
 package org.elasticsearch.license;
 
-import org.elasticsearch.action.ActionFuture;
 import org.elasticsearch.action.support.master.AcknowledgedRequest;
 import org.elasticsearch.action.support.master.AcknowledgedResponse;
 import org.elasticsearch.common.bytes.BytesArray;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.plugins.Plugin;
+import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
 import org.elasticsearch.protocol.xpack.license.LicensesStatus;
 import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
 import org.elasticsearch.test.ESSingleNodeTestCase;
@@ -24,6 +24,9 @@ import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.function.UnaryOperator;
 
 import static org.elasticsearch.license.TestUtils.dateMath;
 import static org.elasticsearch.license.TestUtils.generateExpiredNonBasicLicense;
@@ -59,12 +62,7 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
         // basic license is added async, we should wait for it
         assertBusy(() -> {
             try {
-                final ActionFuture<GetLicenseResponse> getLicenseFuture = new GetLicenseRequestBuilder(
-                    clusterAdmin(),
-                    GetLicenseAction.INSTANCE
-                ).execute();
-                final GetLicenseResponse getLicenseResponse;
-                getLicenseResponse = getLicenseFuture.get();
+                final GetLicenseResponse getLicenseResponse = getLicense();
                 assertNotNull(getLicenseResponse.license());
                 assertThat(getLicenseResponse.license().operationMode(), equalTo(License.OperationMode.BASIC));
             } catch (Exception e) {
@@ -77,15 +75,12 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
         License signedLicense = generateSignedLicense(TimeValue.timeValueMinutes(2));
 
         // put license
-        PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(clusterAdmin()).setLicense(signedLicense)
-            .setAcknowledge(true);
-        PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
+        final var putLicenseResponse = putLicense(plr -> plr.license(signedLicense).acknowledge(true));
         assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
 
         // get and check license
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), equalTo(signedLicense));
+        assertThat(getLicense().license(), equalTo(signedLicense));
     }
 
     public void testPutLicenseFromString() throws Exception {
@@ -93,17 +88,14 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
         String licenseString = TestUtils.dumpLicense(signedLicense);
 
         // put license source
-        PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(clusterAdmin()).setLicense(
-            new BytesArray(licenseString.getBytes(StandardCharsets.UTF_8)),
-            XContentType.JSON
-        ).setAcknowledge(true);
-        PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
+        final var putLicenseResponse = putLicense(
+            plr -> plr.license(new BytesArray(licenseString.getBytes(StandardCharsets.UTF_8)), XContentType.JSON).acknowledge(true)
+        );
         assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
 
         // get and check license
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), equalTo(signedLicense));
+        assertThat(getLicense().license(), equalTo(signedLicense));
     }
 
     public void testPutInvalidLicense() throws Exception {
@@ -115,81 +107,57 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
             .expiryDate(signedLicense.expiryDate() + 10 * 24 * 60 * 60 * 1000L)
             .validate()
             .build();
-
-        PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(clusterAdmin());
-        builder.setLicense(tamperedLicense);
-
-        // try to put license (should be invalid)
-        final PutLicenseResponse putLicenseResponse = builder.get();
+        final var putLicenseResponse = putLicense(plr -> plr.license(tamperedLicense).acknowledge(randomBoolean()));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.INVALID));
 
         // try to get invalid license
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), not(tamperedLicense));
+        assertThat(getLicense().license(), not(tamperedLicense));
     }
 
     public void testPutBasicLicenseIsInvalid() throws Exception {
         License signedLicense = generateSignedLicense("basic", License.VERSION_CURRENT, -1, TimeValue.timeValueMinutes(2));
 
-        PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(clusterAdmin());
-        builder.setLicense(signedLicense);
-
         // try to put license (should be invalid)
-        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, builder::get);
+        final var putLicenseFuture = putLicenseFuture(plr -> plr.license(signedLicense).acknowledge(randomBoolean()));
+        IllegalArgumentException iae = expectThrows(ExecutionException.class, IllegalArgumentException.class, putLicenseFuture::get);
         assertEquals(iae.getMessage(), "Registering basic licenses is not allowed.");
 
         // try to get invalid license
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), not(signedLicense));
+        assertThat(getLicense().license(), not(signedLicense));
     }
 
     public void testPutExpiredLicense() throws Exception {
         License expiredLicense = generateExpiredNonBasicLicense();
-        PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(clusterAdmin());
-        builder.setLicense(expiredLicense);
-        PutLicenseResponse putLicenseResponse = builder.get();
+        final var putLicenseResponse = putLicense(plr -> plr.license(expiredLicense).acknowledge(randomBoolean()));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.EXPIRED));
         // get license should not return the expired license
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), not(expiredLicense));
+        assertThat(getLicense().license(), not(expiredLicense));
     }
 
     public void testPutLicensesSimple() throws Exception {
         License goldSignedLicense = generateSignedLicense("gold", TimeValue.timeValueMinutes(5));
-        PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(clusterAdmin()).setLicense(goldSignedLicense)
-            .setAcknowledge(true);
-        PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
-        assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), equalTo(goldSignedLicense));
+        final var putGoldLicenseResponse = putLicense(plr -> plr.license(goldSignedLicense).acknowledge(true));
+        assertThat(putGoldLicenseResponse.status(), equalTo(LicensesStatus.VALID));
+        assertThat(getLicense().license(), equalTo(goldSignedLicense));
 
         License platinumSignedLicense = generateSignedLicense("platinum", TimeValue.timeValueMinutes(2));
-        putLicenseRequestBuilder.setLicense(platinumSignedLicense);
-        putLicenseResponse = putLicenseRequestBuilder.get();
-        assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
-        assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
-        getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), equalTo(platinumSignedLicense));
+        final var putPlatinumLicenseResponse = putLicense(plr -> plr.license(platinumSignedLicense).acknowledge(true));
+        assertThat(putPlatinumLicenseResponse.isAcknowledged(), equalTo(true));
+        assertThat(putPlatinumLicenseResponse.status(), equalTo(LicensesStatus.VALID));
+        assertThat(getLicense().license(), equalTo(platinumSignedLicense));
     }
 
     public void testRemoveLicensesSimple() throws Exception {
         License goldLicense = generateSignedLicense("gold", TimeValue.timeValueMinutes(5));
-        PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(clusterAdmin()).setLicense(goldLicense)
-            .setAcknowledge(true);
-        PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
+        PutLicenseResponse putLicenseResponse = putLicense(plr -> plr.license(goldLicense).acknowledge(true));
         assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
-        GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertThat(getLicenseResponse.license(), equalTo(goldLicense));
+        assertThat(getLicense().license(), equalTo(goldLicense));
         // delete all licenses
-        AcknowledgedResponse deleteLicenseResponse = clusterAdmin().execute(
-            TransportDeleteLicenseAction.TYPE,
-            new AcknowledgedRequest.Plain(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT)
-        ).get();
+        AcknowledgedResponse deleteLicenseResponse = deleteLicense();
         assertThat(deleteLicenseResponse.isAcknowledged(), equalTo(true));
         // get licenses (expected no licenses)
-        getLicenseResponse = new GetLicenseRequestBuilder(clusterAdmin(), GetLicenseAction.INSTANCE).get();
-        assertTrue(License.LicenseType.isBasic(getLicenseResponse.license().type()));
+        assertTrue(License.LicenseType.isBasic(getLicense().license().type()));
     }
 
     public void testLicenseIsRejectWhenStartDateLaterThanNow() throws Exception {
@@ -206,9 +174,7 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
             .maxNodes(5);
         License license = TestUtils.generateSignedLicense(builder);
 
-        PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(clusterAdmin()).setLicense(license)
-            .setAcknowledge(true);
-        PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
+        PutLicenseResponse putLicenseResponse = putLicense(plr -> plr.license(license).acknowledge(true));
         assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.INVALID));
     }
@@ -227,10 +193,32 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
             .maxNodes(5);
         License license = TestUtils.generateSignedLicense(builder);
 
-        PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(clusterAdmin()).setLicense(license)
-            .setAcknowledge(true);
-        PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
+        PutLicenseResponse putLicenseResponse = putLicense(plr -> plr.license(license).acknowledge(true));
         assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
         assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
     }
+
+    private GetLicenseResponse getLicense() {
+        return safeGet(clusterAdmin().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(TEST_REQUEST_TIMEOUT)));
+    }
+
+    private Future<PutLicenseResponse> putLicenseFuture(UnaryOperator<PutLicenseRequest> onRequest) {
+        return clusterAdmin().execute(
+            PutLicenseAction.INSTANCE,
+            onRequest.apply(new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))
+        );
+    }
+
+    private PutLicenseResponse putLicense(UnaryOperator<PutLicenseRequest> onRequest) {
+        return safeGet(putLicenseFuture(onRequest));
+    }
+
+    private AcknowledgedResponse deleteLicense() {
+        return safeGet(
+            clusterAdmin().execute(
+                TransportDeleteLicenseAction.TYPE,
+                new AcknowledgedRequest.Plain(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT)
+            )
+        );
+    }
 }

+ 38 - 27
x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartBasicLicenseTests.java

@@ -20,6 +20,7 @@ import java.util.Set;
 
 import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
 import static org.elasticsearch.test.NodeRoles.addRoles;
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
 
 @ESIntegTestCase.ClusterScope(scope = SUITE)
 public class StartBasicLicenseTests extends AbstractLicensesIntegrationTestCase {
@@ -38,38 +39,28 @@ public class StartBasicLicenseTests extends AbstractLicensesIntegrationTestCase
     }
 
     public void testStartBasicLicense() throws Exception {
-        LicensingClient licensingClient = new LicensingClient(client());
-        License license = TestUtils.generateSignedLicense("trial", License.VERSION_CURRENT, -1, TimeValue.timeValueHours(24));
-        licensingClient.preparePutLicense(license).get();
+        generateAndPutTestLicense();
 
-        assertBusy(() -> {
-            GetLicenseResponse getLicenseResponse = licensingClient.prepareGetLicense().get();
-            assertEquals("trial", getLicenseResponse.license().type());
-        });
+        assertBusy(() -> assertEquals("trial", getLicense().license().type()));
 
-        GetBasicStatusResponse response = licensingClient.prepareGetStartBasic().get();
-        assertTrue(response.isEligibleToStartBasic());
+        assertTrue(getBasicStatus().isEligibleToStartBasic());
 
-        PostStartBasicResponse startResponse = licensingClient.preparePostStartBasic().setAcknowledge(true).get();
+        PostStartBasicResponse startResponse = startBasic(true);
         assertTrue(startResponse.isAcknowledged());
         assertTrue(startResponse.getStatus().isBasicStarted());
 
-        assertBusy(() -> {
-            GetLicenseResponse currentLicense = licensingClient.prepareGetLicense().get();
-            assertEquals("basic", currentLicense.license().type());
-        });
+        assertBusy(() -> assertEquals("basic", getLicense().license().type()));
 
-        long expirationMillis = licensingClient.prepareGetLicense().get().license().expiryDate();
+        long expirationMillis = getLicense().license().expiryDate();
         assertEquals(LicenseSettings.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS, expirationMillis);
 
-        GetLicenseResponse licenseResponse = licensingClient.prepareGetLicense().get();
+        GetLicenseResponse licenseResponse = getLicense();
         assertEquals("basic", licenseResponse.license().type());
         assertEquals(XPackInfoResponse.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS, licenseResponse.license().expiryDate());
 
-        GetBasicStatusResponse response4 = licensingClient.prepareGetStartBasic().get();
-        assertFalse(response4.isEligibleToStartBasic());
+        assertFalse(getBasicStatus().isEligibleToStartBasic());
 
-        PostStartBasicResponse response5 = licensingClient.preparePostStartBasic().setAcknowledge(true).get();
+        PostStartBasicResponse response5 = startBasic(true);
         assertEquals(403, response5.status().getStatus());
         assertFalse(response5.getStatus().isBasicStarted());
         assertTrue(response5.isAcknowledged());
@@ -77,16 +68,11 @@ public class StartBasicLicenseTests extends AbstractLicensesIntegrationTestCase
     }
 
     public void testUnacknowledgedStartBasicLicense() throws Exception {
-        LicensingClient licensingClient = new LicensingClient(client());
-        License license = TestUtils.generateSignedLicense("trial", License.VERSION_CURRENT, -1, TimeValue.timeValueHours(24));
-        licensingClient.preparePutLicense(license).get();
+        generateAndPutTestLicense();
 
-        assertBusy(() -> {
-            GetLicenseResponse getLicenseResponse = licensingClient.prepareGetLicense().get();
-            assertEquals("trial", getLicenseResponse.license().type());
-        });
+        assertBusy(() -> assertEquals("trial", getLicense().license().type()));
 
-        PostStartBasicResponse response = licensingClient.preparePostStartBasic().get();
+        PostStartBasicResponse response = startBasic(false);
         assertEquals(200, response.status().getStatus());
         assertFalse(response.isAcknowledged());
         assertFalse(response.getStatus().isBasicStarted());
@@ -97,4 +83,29 @@ public class StartBasicLicenseTests extends AbstractLicensesIntegrationTestCase
             response.getAcknowledgeMessage()
         );
     }
+
+    private static GetBasicStatusResponse getBasicStatus() {
+        return safeGet(clusterAdmin().execute(GetBasicStatusAction.INSTANCE, new GetBasicStatusRequest(TEST_REQUEST_TIMEOUT)));
+    }
+
+    private static PostStartBasicResponse startBasic(boolean acknowledged) {
+        return safeGet(
+            clusterAdmin().execute(
+                PostStartBasicAction.INSTANCE,
+                new PostStartBasicRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).acknowledge(acknowledged)
+            )
+        );
+    }
+
+    private static void generateAndPutTestLicense() throws Exception {
+        final var license = TestUtils.generateSignedLicense("trial", License.VERSION_CURRENT, -1, TimeValue.timeValueHours(24));
+        assertAcked(
+            safeGet(
+                client().execute(
+                    PutLicenseAction.INSTANCE,
+                    new PutLicenseRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).license(license).acknowledge(randomBoolean())
+                )
+            )
+        );
+    }
 }

+ 25 - 41
x-pack/plugin/core/src/test/java/org/elasticsearch/license/StartTrialLicenseTests.java

@@ -6,6 +6,7 @@
  */
 package org.elasticsearch.license;
 
+import org.elasticsearch.action.ActionFuture;
 import org.elasticsearch.cluster.node.DiscoveryNodeRole;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.plugins.Plugin;
@@ -15,9 +16,11 @@ import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Set;
+import java.util.function.UnaryOperator;
 
 import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
 import static org.elasticsearch.test.NodeRoles.addRoles;
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
 import static org.hamcrest.Matchers.containsString;
 
 @ESIntegTestCase.ClusterScope(scope = SUITE)
@@ -37,74 +40,55 @@ public class StartTrialLicenseTests extends AbstractLicensesIntegrationTestCase
     }
 
     public void testStartTrial() throws Exception {
-        LicensingClient licensingClient = new LicensingClient(client());
         ensureStartingWithBasic();
 
-        GetTrialStatusResponse response = licensingClient.prepareGetStartTrial().get();
-        assertTrue(response.isEligibleToStartTrial());
+        assertTrue(getTrialStatus().isEligibleToStartTrial());
+
+        License.LicenseType type = randomFrom(LicenseSettings.VALID_TRIAL_TYPES);
 
         // Test that starting will fail without acknowledgement
-        PostStartTrialRequestBuilder builder = licensingClient.preparePostStartTrial();
-        builder.request().setType(randomFrom(LicenseSettings.VALID_TRIAL_TYPES).getTypeName());
-        PostStartTrialResponse response2 = builder.get();
+        final PostStartTrialResponse response2 = startTrial(pstr -> pstr.setType(type.getTypeName()));
         assertEquals(200, response2.getStatus().getRestStatus().getStatus());
         assertFalse(response2.getStatus().isTrialStarted());
         assertEquals("Operation failed: Needs acknowledgement.", response2.getStatus().getErrorMessage());
 
-        assertBusy(() -> {
-            GetLicenseResponse getLicenseResponse = licensingClient.prepareGetLicense().get();
-            assertEquals("basic", getLicenseResponse.license().type());
-        });
-
-        License.LicenseType type = randomFrom(LicenseSettings.VALID_TRIAL_TYPES);
+        assertBusy(() -> assertEquals("basic", getLicense().license().type()));
 
-        PostStartTrialRequestBuilder builder2 = licensingClient.preparePostStartTrial();
-        builder2.setAcknowledge(true);
-        builder2.request().setType(type.getTypeName());
-        PostStartTrialResponse response3 = builder2.get();
+        final PostStartTrialResponse response3 = startTrial(pstr -> pstr.setType(type.getTypeName()).acknowledge(true));
         assertEquals(200, response3.getStatus().getRestStatus().getStatus());
         assertTrue(response3.getStatus().isTrialStarted());
 
-        assertBusy(() -> {
-            GetLicenseResponse postTrialLicenseResponse = licensingClient.prepareGetLicense().get();
-            assertEquals(type.getTypeName(), postTrialLicenseResponse.license().type());
-        });
+        assertBusy(() -> assertEquals(type.getTypeName(), getLicense().license().type()));
 
-        GetTrialStatusResponse response4 = licensingClient.prepareGetStartTrial().get();
-        assertFalse(response4.isEligibleToStartTrial());
+        assertFalse(getTrialStatus().isEligibleToStartTrial());
 
         License.LicenseType secondAttemptType = randomFrom(LicenseSettings.VALID_TRIAL_TYPES);
-
-        PostStartTrialRequestBuilder builder3 = licensingClient.preparePostStartTrial();
-        builder3.setAcknowledge(true);
-        builder3.request().setType(secondAttemptType.getTypeName());
-        PostStartTrialResponse response5 = builder3.get();
+        PostStartTrialResponse response5 = startTrial(pstr -> pstr.setType(secondAttemptType.getTypeName()).acknowledge(true));
         assertEquals(403, response5.getStatus().getRestStatus().getStatus());
         assertFalse(response5.getStatus().isTrialStarted());
         assertEquals("Operation failed: Trial was already activated.", response5.getStatus().getErrorMessage());
     }
 
     public void testInvalidType() throws Exception {
-        LicensingClient licensingClient = new LicensingClient(client());
         ensureStartingWithBasic();
-
-        PostStartTrialRequestBuilder builder = licensingClient.preparePostStartTrial();
-        builder.request().setType("basic");
-        IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::get);
+        final var future = startTrialFuture(pstr -> pstr.setType("basic").acknowledge(randomBoolean()));
+        IllegalArgumentException e = expectThrows(IllegalArgumentException.class, future::actionGet);
         assertThat(e.getMessage(), containsString("Cannot start trial of type [basic]. Valid trial types are ["));
     }
 
     private void ensureStartingWithBasic() throws Exception {
-        LicensingClient licensingClient = new LicensingClient(client());
-        GetLicenseResponse getLicenseResponse = licensingClient.prepareGetLicense().get();
-
-        if ("basic".equals(getLicenseResponse.license().type()) == false) {
-            licensingClient.preparePostStartBasic().setAcknowledge(true).get();
+        if ("basic".equals(getLicense().license().type()) == false) {
+            assertAcked(startBasic());
         }
 
-        assertBusy(() -> {
-            GetLicenseResponse postTrialLicenseResponse = licensingClient.prepareGetLicense().get();
-            assertEquals("basic", postTrialLicenseResponse.license().type());
-        });
+        assertBusy(() -> assertEquals("basic", getLicense().license().type()));
+    }
+
+    private ActionFuture<PostStartTrialResponse> startTrialFuture(UnaryOperator<PostStartTrialRequest> onRequest) {
+        return client().execute(PostStartTrialAction.INSTANCE, onRequest.apply(new PostStartTrialRequest(TEST_REQUEST_TIMEOUT)));
+    }
+
+    private PostStartTrialResponse startTrial(UnaryOperator<PostStartTrialRequest> onRequest) {
+        return safeGet(startTrialFuture(onRequest));
     }
 }

+ 4 - 1
x-pack/plugin/core/src/test/java/org/elasticsearch/license/TestUtils.java

@@ -20,6 +20,7 @@ import org.elasticsearch.license.internal.XPackLicenseStatus;
 import org.elasticsearch.license.licensor.LicenseSigner;
 import org.elasticsearch.protocol.xpack.license.LicensesStatus;
 import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
+import org.elasticsearch.test.ESTestCase;
 import org.elasticsearch.xcontent.ToXContent;
 import org.elasticsearch.xcontent.XContentBuilder;
 import org.elasticsearch.xcontent.XContentFactory;
@@ -381,7 +382,9 @@ public class TestUtils {
         License license,
         final LicensesStatus expectedStatus
     ) {
-        PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(license).acknowledge(true);
+        PutLicenseRequest putLicenseRequest = new PutLicenseRequest(ESTestCase.TEST_REQUEST_TIMEOUT, ESTestCase.TEST_REQUEST_TIMEOUT)
+            .license(license)
+            .acknowledge(true);
         final CountDownLatch latch = new CountDownLatch(1);
         final AtomicReference<LicensesStatus> status = new AtomicReference<>();
         licenseService.registerLicense(putLicenseRequest, new ActionListener<PutLicenseResponse>() {

+ 6 - 1
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/XPackPluginTests.java

@@ -18,6 +18,7 @@ import org.elasticsearch.common.component.Lifecycle;
 import org.elasticsearch.common.component.LifecycleListener;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.core.PathUtils;
+import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.env.Environment;
 import org.elasticsearch.license.ClusterStateLicenseService;
 import org.elasticsearch.license.License;
@@ -211,7 +212,11 @@ public class XPackPluginTests extends ESTestCase {
         public void registerLicense(PutLicenseRequest request, ActionListener<PutLicenseResponse> listener) {}
 
         @Override
-        public void removeLicense(ActionListener<? extends AcknowledgedResponse> listener) {}
+        public void removeLicense(
+            TimeValue masterNodeTimeout,
+            TimeValue ackTimeout,
+            ActionListener<? extends AcknowledgedResponse> listener
+        ) {}
 
         @Override
         public void startBasicLicense(PostStartBasicRequest request, ActionListener<PostStartBasicResponse> listener) {}

+ 2 - 1
x-pack/plugin/old-lucene-versions/src/internalClusterTest/java/org/elasticsearch/xpack/lucene/bwc/AbstractArchiveTestCase.java

@@ -118,7 +118,8 @@ public abstract class AbstractArchiveTestCase extends AbstractSnapshotIntegTestC
 
         assertAcked(client().admin().indices().prepareDelete(indexName));
 
-        PostStartTrialRequest request = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()).acknowledge(true);
+        PostStartTrialRequest request = new PostStartTrialRequest(TEST_REQUEST_TIMEOUT).setType(License.LicenseType.TRIAL.getTypeName())
+            .acknowledge(true);
         client().execute(PostStartTrialAction.INSTANCE, request).get();
     }
 }

+ 8 - 3
x-pack/plugin/old-lucene-versions/src/internalClusterTest/java/org/elasticsearch/xpack/lucene/bwc/ArchiveLicenseIntegTests.java

@@ -61,7 +61,9 @@ public class ArchiveLicenseIntegTests extends AbstractArchiveTestCase {
             client().execute(TransportDeleteLicenseAction.TYPE, new AcknowledgedRequest.Plain(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))
                 .get()
         );
-        assertAcked(client().execute(PostStartBasicAction.INSTANCE, new PostStartBasicRequest()).get());
+        assertAcked(
+            client().execute(PostStartBasicAction.INSTANCE, new PostStartBasicRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT)).get()
+        );
 
         ensureClusterSizeConsistency();
         ensureClusterStateConsistency();
@@ -100,7 +102,9 @@ public class ArchiveLicenseIntegTests extends AbstractArchiveTestCase {
             client().execute(TransportDeleteLicenseAction.TYPE, new AcknowledgedRequest.Plain(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))
                 .get()
         );
-        assertAcked(client().execute(PostStartBasicAction.INSTANCE, new PostStartBasicRequest()).get());
+        assertAcked(
+            client().execute(PostStartBasicAction.INSTANCE, new PostStartBasicRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT)).get()
+        );
 
         ensureClusterSizeConsistency();
         ensureClusterStateConsistency();
@@ -128,7 +132,8 @@ public class ArchiveLicenseIntegTests extends AbstractArchiveTestCase {
         waitNoPendingTasksOnAll();
         ensureClusterStateConsistency();
 
-        PostStartTrialRequest request = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()).acknowledge(true);
+        PostStartTrialRequest request = new PostStartTrialRequest(TEST_REQUEST_TIMEOUT).setType(License.LicenseType.TRIAL.getTypeName())
+            .acknowledge(true);
         final PostStartTrialResponse response = client().execute(PostStartTrialAction.INSTANCE, request).get();
         assertThat(
             response.getStatus(),

+ 5 - 2
x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java

@@ -82,7 +82,9 @@ public class SearchableSnapshotsLicenseIntegTests extends BaseFrozenSearchableSn
             client().execute(TransportDeleteLicenseAction.TYPE, new AcknowledgedRequest.Plain(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))
                 .get()
         );
-        assertAcked(client().execute(PostStartBasicAction.INSTANCE, new PostStartBasicRequest()).get());
+        assertAcked(
+            client().execute(PostStartBasicAction.INSTANCE, new PostStartBasicRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT)).get()
+        );
 
         ensureClusterSizeConsistency();
         ensureClusterStateConsistency();
@@ -163,7 +165,8 @@ public class SearchableSnapshotsLicenseIntegTests extends BaseFrozenSearchableSn
         waitNoPendingTasksOnAll();
         ensureClusterStateConsistency();
 
-        PostStartTrialRequest request = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()).acknowledge(true);
+        PostStartTrialRequest request = new PostStartTrialRequest(TEST_REQUEST_TIMEOUT).setType(License.LicenseType.TRIAL.getTypeName())
+            .acknowledge(true);
         final PostStartTrialResponse response = client().execute(PostStartTrialAction.INSTANCE, request).get();
         assertThat(
             response.getStatus(),