|
@@ -35,12 +35,17 @@ import org.elasticsearch.protocol.xpack.XPackInfoResponse;
|
|
|
import org.elasticsearch.protocol.xpack.XPackInfoResponse.BuildInfo;
|
|
|
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo;
|
|
|
import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo;
|
|
|
+import org.elasticsearch.protocol.xpack.XPackUsageRequest;
|
|
|
+import org.elasticsearch.protocol.xpack.XPackUsageResponse;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.EnumSet;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.is;
|
|
|
+
|
|
|
/**
|
|
|
* Documentation for miscellaneous APIs in the high level java client.
|
|
|
* Code wrapped in {@code tag} and {@code end} tags is included in the docs.
|
|
@@ -129,6 +134,50 @@ public class MiscellaneousDocumentationIT extends ESRestHighLevelClientTestCase
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testXPackUsage() throws Exception {
|
|
|
+ RestHighLevelClient client = highLevelClient();
|
|
|
+ {
|
|
|
+ //tag::x-pack-usage-execute
|
|
|
+ XPackUsageRequest request = new XPackUsageRequest();
|
|
|
+ XPackUsageResponse response = client.xpack().usage(request, RequestOptions.DEFAULT);
|
|
|
+ //end::x-pack-usage-execute
|
|
|
+
|
|
|
+ //tag::x-pack-usage-response
|
|
|
+ Map<String, Map<String, Object>> usages = response.getUsages();
|
|
|
+ Map<String, Object> monitoringUsage = usages.get("monitoring");
|
|
|
+ assertThat(monitoringUsage.get("available"), is(true));
|
|
|
+ assertThat(monitoringUsage.get("enabled"), is(true));
|
|
|
+ assertThat(monitoringUsage.get("collection_enabled"), is(false));
|
|
|
+ //end::x-pack-usage-response
|
|
|
+ }
|
|
|
+ {
|
|
|
+ XPackUsageRequest request = new XPackUsageRequest();
|
|
|
+ // tag::x-pack-usage-execute-listener
|
|
|
+ ActionListener<XPackUsageResponse> listener = new ActionListener<XPackUsageResponse>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(XPackUsageResponse response) {
|
|
|
+ // <1>
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Exception e) {
|
|
|
+ // <2>
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // end::x-pack-usage-execute-listener
|
|
|
+
|
|
|
+ // Replace the empty listener by a blocking listener in test
|
|
|
+ final CountDownLatch latch = new CountDownLatch(1);
|
|
|
+ listener = new LatchedActionListener<>(listener, latch);
|
|
|
+
|
|
|
+ // tag::x-pack-usage-execute-async
|
|
|
+ client.xpack().usageAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
|
|
+ // end::x-pack-usage-execute-async
|
|
|
+
|
|
|
+ assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testInitializationFromClientBuilder() throws IOException {
|
|
|
//tag::rest-high-level-client-init
|
|
|
RestHighLevelClient client = new RestHighLevelClient(
|