[TEST] add missing doc tests for HLRC GetRollupIndexCaps API
This commit is contained in:
parent
2da239fb5e
commit
711d703ffc
|
@ -38,6 +38,8 @@ import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
|
|||
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
|
||||
import org.elasticsearch.client.rollup.GetRollupCapsResponse;
|
||||
import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest;
|
||||
import org.elasticsearch.client.rollup.GetRollupIndexCapsResponse;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper;
|
||||
|
@ -406,6 +408,120 @@ public class RollupDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testGetRollupIndexCaps() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
DateHistogramGroupConfig dateHistogram =
|
||||
new DateHistogramGroupConfig("timestamp", DateHistogramInterval.HOUR, new DateHistogramInterval("7d"), "UTC"); // <1>
|
||||
TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter");
|
||||
HistogramGroupConfig histogram = new HistogramGroupConfig(5L, "load", "net_in", "net_out");
|
||||
GroupConfig groups = new GroupConfig(dateHistogram, histogram, terms);
|
||||
List<MetricConfig> metrics = new ArrayList<>(); // <1>
|
||||
metrics.add(new MetricConfig("temperature", Arrays.asList("min", "max", "sum")));
|
||||
metrics.add(new MetricConfig("voltage", Arrays.asList("avg", "value_count")));
|
||||
|
||||
//tag::x-pack-rollup-get-rollup-index-caps-setup
|
||||
final String indexPattern = "docs";
|
||||
final String rollupIndexName = "rollup";
|
||||
final String cron = "*/1 * * * * ?";
|
||||
final int pageSize = 100;
|
||||
final TimeValue timeout = null;
|
||||
|
||||
String id = "job_1";
|
||||
RollupJobConfig config = new RollupJobConfig(id, indexPattern, rollupIndexName, cron,
|
||||
pageSize, groups, metrics, timeout);
|
||||
|
||||
PutRollupJobRequest request = new PutRollupJobRequest(config);
|
||||
PutRollupJobResponse response = client.rollup().putRollupJob(request, RequestOptions.DEFAULT);
|
||||
|
||||
boolean acknowledged = response.isAcknowledged();
|
||||
//end::x-pack-rollup-get-rollup-index-caps-setup
|
||||
assertTrue(acknowledged);
|
||||
|
||||
ClusterHealthRequest healthRequest = new ClusterHealthRequest(config.getRollupIndex()).waitForYellowStatus();
|
||||
ClusterHealthResponse healthResponse = client.cluster().health(healthRequest, RequestOptions.DEFAULT);
|
||||
assertFalse(healthResponse.isTimedOut());
|
||||
assertThat(healthResponse.getStatus(), isOneOf(ClusterHealthStatus.YELLOW, ClusterHealthStatus.GREEN));
|
||||
|
||||
// Now that the job is created, we should have a rollup index with metadata.
|
||||
// We can test out the caps API now.
|
||||
|
||||
//tag::x-pack-rollup-get-rollup-index-caps-request
|
||||
GetRollupIndexCapsRequest getRollupIndexCapsRequest = new GetRollupIndexCapsRequest("rollup");
|
||||
//end::x-pack-rollup-get-rollup-index-caps-request
|
||||
|
||||
//tag::x-pack-rollup-get-rollup-index-caps-execute
|
||||
GetRollupIndexCapsResponse capsResponse = client.rollup()
|
||||
.getRollupIndexCapabilities(getRollupIndexCapsRequest, RequestOptions.DEFAULT);
|
||||
//end::x-pack-rollup-get-rollup-index-caps-execute
|
||||
|
||||
//tag::x-pack-rollup-get-rollup-index-caps-response
|
||||
Map<String, RollableIndexCaps> rolledPatterns = capsResponse.getJobs();
|
||||
|
||||
RollableIndexCaps docsPattern = rolledPatterns.get("rollup");
|
||||
|
||||
// indexName will be "rollup", the target index we requested
|
||||
String indexName = docsPattern.getIndexName();
|
||||
|
||||
// Each index pattern can have multiple jobs that rolled it up, so `getJobCaps()`
|
||||
// returns a list of jobs that rolled up the pattern
|
||||
List<RollupJobCaps> rollupJobs = docsPattern.getJobCaps();
|
||||
RollupJobCaps jobCaps = rollupJobs.get(0);
|
||||
|
||||
// jobID is the identifier we used when we created the job (e.g. `job1`)
|
||||
String jobID = jobCaps.getJobID();
|
||||
|
||||
// rollupIndex is the location that the job stored it's rollup docs (e.g. `rollup`)
|
||||
String rollupIndex = jobCaps.getRollupIndex();
|
||||
|
||||
// Finally, fieldCaps are the capabilities of individual fields in the config
|
||||
// The key is the field name, and the value is a RollupFieldCaps object which
|
||||
// provides more info.
|
||||
Map<String, RollupJobCaps.RollupFieldCaps> fieldCaps = jobCaps.getFieldCaps();
|
||||
|
||||
// If we retrieve the "timestamp" field, it returns a list of maps. Each list
|
||||
// item represents a different aggregation that can be run against the "timestamp"
|
||||
// field, and any additional details specific to that agg (interval, etc)
|
||||
List<Map<String, Object>> timestampCaps = fieldCaps.get("timestamp").getAggs();
|
||||
assert timestampCaps.get(0).toString().equals("{agg=date_histogram, delay=7d, interval=1h, time_zone=UTC}");
|
||||
|
||||
// In contrast to the timestamp field, the temperature field has multiple aggs configured
|
||||
List<Map<String, Object>> temperatureCaps = fieldCaps.get("temperature").getAggs();
|
||||
assert temperatureCaps.toString().equals("[{agg=min}, {agg=max}, {agg=sum}]");
|
||||
//end::x-pack-rollup-get-rollup-index-caps-response
|
||||
|
||||
assertThat(indexName, equalTo("rollup"));
|
||||
assertThat(jobID, equalTo("job_1"));
|
||||
assertThat(rollupIndex, equalTo("rollup"));
|
||||
assertThat(fieldCaps.size(), equalTo(8));
|
||||
|
||||
// tag::x-pack-rollup-get-rollup-index-caps-execute-listener
|
||||
ActionListener<GetRollupIndexCapsResponse> listener = new ActionListener<GetRollupIndexCapsResponse>() {
|
||||
@Override
|
||||
public void onResponse(GetRollupIndexCapsResponse response) {
|
||||
|
||||
// <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::x-pack-rollup-get-rollup-index-caps-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-rollup-get-rollup-index-caps-execute-async
|
||||
client.rollup().getRollupIndexCapabilitiesAsync(getRollupIndexCapsRequest, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::x-pack-rollup-get-rollup-index-caps-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testDeleteRollupJob() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
|
Loading…
Reference in New Issue