-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create rollup job api to high level rest client
This pull request adds the Create Rollup Job API to the high level REST client. It supersedes #32703 and adds dedicated request/response objects so that it does not depend on server side components. Related #29827
- Loading branch information
Showing
26 changed files
with
2,738 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.client.rollup.PutRollupJobRequest; | ||
import org.elasticsearch.client.rollup.PutRollupJobResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
/** | ||
* A wrapper for the {@link RestHighLevelClient} that provides methods for | ||
* accessing the Elastic Rollup-related methods | ||
* <p> | ||
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-apis.html"> | ||
* X-Pack Rollup APIs on elastic.co</a> for more information. | ||
*/ | ||
public class RollupClient { | ||
|
||
private final RestHighLevelClient restHighLevelClient; | ||
|
||
RollupClient(final RestHighLevelClient restHighLevelClient) { | ||
this.restHighLevelClient = restHighLevelClient; | ||
} | ||
|
||
/** | ||
* Put a rollup job into the cluster | ||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.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 PutRollupJobResponse putRollupJob(PutRollupJobRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, | ||
RollupRequestConverters::putJob, | ||
options, | ||
PutRollupJobResponse::fromXContent, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Asynchronously put a rollup job into the cluster | ||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.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 putRollupJobAsync(PutRollupJobRequest request, RequestOptions options, ActionListener<PutRollupJobResponse> listener) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity(request, | ||
RollupRequestConverters::putJob, | ||
options, | ||
PutRollupJobResponse::fromXContent, | ||
listener, Collections.emptySet()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
client/rest-high-level/src/main/java/org/elasticsearch/client/RollupRequestConverters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.http.client.methods.HttpPut; | ||
import org.elasticsearch.client.rollup.PutRollupJobRequest; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE; | ||
import static org.elasticsearch.client.RequestConverters.createEntity; | ||
|
||
final class RollupRequestConverters { | ||
|
||
private RollupRequestConverters() { | ||
} | ||
|
||
static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOException { | ||
String endpoint = new RequestConverters.EndpointBuilder() | ||
.addPathPartAsIs("_xpack") | ||
.addPathPartAsIs("rollup") | ||
.addPathPartAsIs("job") | ||
.addPathPart(putRollupJobRequest.getConfig().getId()) | ||
.build(); | ||
Request request = new Request(HttpPut.METHOD_NAME, endpoint); | ||
request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE)); | ||
return request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...nt/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.client.Validatable; | ||
import org.elasticsearch.client.ValidationException; | ||
import org.elasticsearch.client.rollup.job.config.RollupJobConfig; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class PutRollupJobRequest implements Validatable, ToXContentObject { | ||
|
||
private final RollupJobConfig config; | ||
|
||
public PutRollupJobRequest(final RollupJobConfig config) { | ||
this.config = Objects.requireNonNull(config, "rollup job configuration is required"); | ||
} | ||
|
||
public RollupJobConfig getConfig() { | ||
return config; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return config.toXContent(builder, params); | ||
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { | ||
return config.validate(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
final PutRollupJobRequest that = (PutRollupJobRequest) o; | ||
return Objects.equals(config, that.config); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(config); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...t/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
public class PutRollupJobResponse implements ToXContentObject { | ||
|
||
private final boolean acknowledged; | ||
|
||
public PutRollupJobResponse(final boolean acknowledged) { | ||
this.acknowledged = acknowledged; | ||
} | ||
|
||
public boolean isAcknowledged() { | ||
return acknowledged; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final PutRollupJobResponse that = (PutRollupJobResponse) o; | ||
return isAcknowledged() == that.isAcknowledged(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(acknowledged); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field("acknowledged", isAcknowledged()); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER | ||
= new ConstructingObjectParser<>("put_rollup_job_response", true, args -> new PutRollupJobResponse((boolean) args[0])); | ||
static { | ||
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged")); | ||
} | ||
|
||
public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
} |
Oops, something went wrong.