Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
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.GetRollupCapsRequest;
Expand Down Expand Up @@ -219,4 +221,40 @@ public void getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOpti
listener,
Collections.emptySet());
}

/**
* Get the Rollup Index Capabilities of a rollup index or pattern
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">
* the docs</a> for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetRollupIndexCapsResponse getRollupIndexCapabilities(GetRollupIndexCapsRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
RollupRequestConverters::getRollupIndexCaps,
options,
GetRollupIndexCapsResponse::fromXContent,
Collections.emptySet());
}

/**
* Asynchronously Get the Rollup Index Capabilities of a rollup index or pattern
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">
* the docs</a> for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void getRollupIndexCapabilitiesAsync(GetRollupIndexCapsRequest request, RequestOptions options,
ActionListener<GetRollupIndexCapsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
RollupRequestConverters::getRollupIndexCaps,
options,
GetRollupIndexCapsResponse::fromXContent,
listener,
Collections.emptySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest;
import org.elasticsearch.client.rollup.GetRollupJobRequest;
import org.elasticsearch.client.rollup.PutRollupJobRequest;
import org.elasticsearch.client.rollup.StartRollupJobRequest;
Expand Down Expand Up @@ -85,4 +86,14 @@ static Request getRollupCaps(final GetRollupCapsRequest getRollupCapsRequest) th
request.setEntity(createEntity(getRollupCapsRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request getRollupIndexCaps(final GetRollupIndexCapsRequest getRollupIndexCapsRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addCommaSeparatedPathParts(getRollupIndexCapsRequest.indices())
.addPathPartAsIs("_xpack", "rollup", "data")
.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
request.setEntity(createEntity(getRollupIndexCapsRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
package org.elasticsearch.client.rollup;

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
Expand All @@ -30,7 +26,7 @@
import java.util.Map;
import java.util.Objects;

public class GetRollupCapsResponse implements ToXContentObject {
public class GetRollupCapsResponse {

private final Map<String, RollableIndexCaps> jobs;

Expand All @@ -42,16 +38,6 @@ public Map<String, RollableIndexCaps> getJobs() {
return jobs;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject();
for (Map.Entry<String, RollableIndexCaps> entry : jobs.entrySet()) {
entry.getValue().toXContent(builder, params);
}
builder.endObject();
return builder;
}

public static GetRollupCapsResponse fromXContent(final XContentParser parser) throws IOException {
Map<String, RollableIndexCaps> jobs = new HashMap<>();
XContentParser.Token token = parser.nextToken();
Expand Down Expand Up @@ -84,9 +70,4 @@ public boolean equals(Object obj) {
GetRollupCapsResponse other = (GetRollupCapsResponse) obj;
return Objects.equals(jobs, other.jobs);
}

@Override
public final String toString() {
return Strings.toString(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.rollup;

import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

public class GetRollupIndexCapsRequest implements Validatable, ToXContentObject {
private static final String INDICES = "indices";
private static final String INDICES_OPTIONS = "indices_options";

private String[] indices;
private IndicesOptions options;

public GetRollupIndexCapsRequest(final String... indices) {
this(indices, IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED);
}

public GetRollupIndexCapsRequest(final String[] indices, final IndicesOptions options) {
if (indices == null || indices.length == 0) {
throw new IllegalArgumentException("[indices] must not be null or empty");
}
for (String index : indices) {
if (Strings.isNullOrEmpty(index)) {
throw new IllegalArgumentException("[index] must not be null or empty");
}
}
this.indices = indices;
this.options = Objects.requireNonNull(options);
}

public IndicesOptions indicesOptions() {
return options;
}

public String[] indices() {
return indices;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
{
builder.array(INDICES, indices);
builder.startObject(INDICES_OPTIONS);
{
options.toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}

@Override
public int hashCode() {
return Objects.hash(Arrays.hashCode(indices), options);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
GetRollupIndexCapsRequest other = (GetRollupIndexCapsRequest) obj;
return Arrays.equals(indices, other.indices)
&& Objects.equals(options, other.options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.rollup;

import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class GetRollupIndexCapsResponse {

private final Map<String, RollableIndexCaps> jobs;

public GetRollupIndexCapsResponse(final Map<String, RollableIndexCaps> jobs) {
this.jobs = Collections.unmodifiableMap(Objects.requireNonNull(jobs));
}

public Map<String, RollableIndexCaps> getJobs() {
return jobs;
}

public static GetRollupIndexCapsResponse fromXContent(final XContentParser parser) throws IOException {
Map<String, RollableIndexCaps> jobs = new HashMap<>();
XContentParser.Token token = parser.nextToken();
if (token.equals(XContentParser.Token.START_OBJECT)) {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token.equals(XContentParser.Token.FIELD_NAME)) {
String pattern = parser.currentName();

RollableIndexCaps cap = RollableIndexCaps.PARSER.apply(pattern).apply(parser, null);
jobs.put(pattern, cap);
}
}
}
return new GetRollupIndexCapsResponse(jobs);
}

@Override
public int hashCode() {
return Objects.hash(jobs);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
GetRollupIndexCapsResponse other = (GetRollupIndexCapsResponse) obj;
return Objects.equals(jobs, other.jobs);
}
}
Loading