Skip to content

Commit 936faba

Browse files
author
Paul Sanwald
authored
Add delete rollup job support to HL REST Client (#34066)
Add support for delete rollup job to HL REST Client.
1 parent d43a1fa commit 936faba

File tree

12 files changed

+501
-57
lines changed

12 files changed

+501
-57
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.client;
2121

2222
import org.elasticsearch.action.ActionListener;
23+
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
24+
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
2325
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2426
import org.elasticsearch.client.rollup.GetRollupJobResponse;
2527
import org.elasticsearch.client.rollup.PutRollupJobRequest;
@@ -76,6 +78,40 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option
7678
listener, Collections.emptySet());
7779
}
7880

81+
/**
82+
* Delete a rollup job from the cluster
83+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-delete-job.html">
84+
* the docs</a> for more.
85+
* @param request the request
86+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
87+
* @return the response
88+
* @throws IOException in case there is a problem sending the request or parsing back the response
89+
*/
90+
public DeleteRollupJobResponse deleteRollupJob(DeleteRollupJobRequest request, RequestOptions options) throws IOException {
91+
return restHighLevelClient.performRequestAndParseEntity(request,
92+
RollupRequestConverters::deleteJob,
93+
options,
94+
DeleteRollupJobResponse::fromXContent,
95+
Collections.emptySet());
96+
}
97+
/**
98+
* Asynchronously delete a rollup job from the cluster
99+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-delete-job.html">
100+
* The docs</a> for details.
101+
* @param request the request
102+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
103+
* @param listener the listener to be notified upon request completion
104+
*/
105+
public void deleteRollupJobAsync(DeleteRollupJobRequest request,
106+
RequestOptions options,
107+
ActionListener<DeleteRollupJobResponse> listener) {
108+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
109+
RollupRequestConverters::deleteJob,
110+
options,
111+
DeleteRollupJobResponse::fromXContent,
112+
listener, Collections.emptySet());
113+
}
114+
79115
/**
80116
* Get a rollup job from the cluster.
81117
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html">

client/rest-high-level/src/main/java/org/elasticsearch/client/RollupRequestConverters.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
*/
1919
package org.elasticsearch.client;
2020

21+
import org.apache.http.client.methods.HttpDelete;
2122
import org.apache.http.client.methods.HttpGet;
2223
import org.apache.http.client.methods.HttpPut;
24+
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
2325
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2426
import org.elasticsearch.client.rollup.PutRollupJobRequest;
2527

@@ -54,4 +56,16 @@ static Request getJob(final GetRollupJobRequest getRollupJobRequest) {
5456
.build();
5557
return new Request(HttpGet.METHOD_NAME, endpoint);
5658
}
59+
60+
static Request deleteJob(final DeleteRollupJobRequest deleteRollupJobRequest) throws IOException {
61+
String endpoint = new RequestConverters.EndpointBuilder()
62+
.addPathPartAsIs("_xpack")
63+
.addPathPartAsIs("rollup")
64+
.addPathPartAsIs("job")
65+
.addPathPart(deleteRollupJobRequest.getId())
66+
.build();
67+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
68+
request.setEntity(createEntity(deleteRollupJobRequest, REQUEST_BODY_CONTENT_TYPE));
69+
return request;
70+
}
5771
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.rollup;
21+
22+
import org.elasticsearch.common.xcontent.ToXContent;
23+
import org.elasticsearch.common.xcontent.ToXContentObject;
24+
import org.elasticsearch.common.xcontent.XContentBuilder;
25+
26+
import java.io.IOException;
27+
import java.util.Objects;
28+
29+
public abstract class AcknowledgedResponse implements ToXContentObject {
30+
private final boolean acknowledged;
31+
32+
public AcknowledgedResponse(final boolean acknowledged) {
33+
this.acknowledged = acknowledged;
34+
}
35+
36+
public boolean isAcknowledged() {
37+
return acknowledged;
38+
}
39+
40+
@Override
41+
public boolean equals(Object o) {
42+
if (this == o) {
43+
return true;
44+
}
45+
if (o == null || getClass() != o.getClass()) {
46+
return false;
47+
}
48+
final AcknowledgedResponse that = (AcknowledgedResponse) o;
49+
return isAcknowledged() == that.isAcknowledged();
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
return Objects.hash(acknowledged);
55+
}
56+
57+
@Override
58+
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
59+
builder.startObject();
60+
{
61+
builder.field("acknowledged", isAcknowledged());
62+
}
63+
builder.endObject();
64+
return builder;
65+
}
66+
67+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.client.rollup;
20+
21+
import org.elasticsearch.client.Validatable;
22+
import org.elasticsearch.common.ParseField;
23+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
24+
import org.elasticsearch.common.xcontent.ToXContentObject;
25+
import org.elasticsearch.common.xcontent.XContentBuilder;
26+
import org.elasticsearch.common.xcontent.XContentParser;
27+
28+
import java.io.IOException;
29+
import java.util.Objects;
30+
31+
32+
public class DeleteRollupJobRequest implements Validatable, ToXContentObject {
33+
34+
private static final ParseField ID_FIELD = new ParseField("id");
35+
private final String id;
36+
37+
38+
public DeleteRollupJobRequest(String id) {
39+
this.id = Objects.requireNonNull(id, "id parameter must not be null");
40+
}
41+
42+
public String getId() {
43+
return id;
44+
}
45+
46+
private static final ConstructingObjectParser<DeleteRollupJobRequest, Void> PARSER =
47+
new ConstructingObjectParser<>("request", a -> {
48+
return new DeleteRollupJobRequest((String) a[0]);
49+
});
50+
51+
static {
52+
PARSER.declareString(ConstructingObjectParser.constructorArg(), ID_FIELD);
53+
}
54+
55+
public static DeleteRollupJobRequest fromXContent(XContentParser parser) {
56+
return PARSER.apply(parser, null);
57+
}
58+
59+
@Override
60+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
61+
builder.startObject();
62+
builder.field(ID_FIELD.getPreferredName(), this.id);
63+
builder.endObject();
64+
return builder;
65+
}
66+
67+
@Override
68+
public boolean equals(Object o) {
69+
if (this == o) return true;
70+
if (o == null || getClass() != o.getClass()) return false;
71+
DeleteRollupJobRequest that = (DeleteRollupJobRequest) o;
72+
return Objects.equals(id, that.id);
73+
}
74+
75+
@Override
76+
public int hashCode() {
77+
return Objects.hash(id);
78+
}
79+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.rollup;
21+
22+
import org.elasticsearch.common.ParseField;
23+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
24+
import org.elasticsearch.common.xcontent.XContentParser;
25+
26+
import java.io.IOException;
27+
28+
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
29+
30+
public class DeleteRollupJobResponse extends AcknowledgedResponse {
31+
32+
public DeleteRollupJobResponse(boolean acknowledged) {
33+
super(acknowledged);
34+
}
35+
36+
public static DeleteRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
37+
return PARSER.parse(parser, null);
38+
}
39+
40+
private static final ConstructingObjectParser<DeleteRollupJobResponse, Void> PARSER
41+
= new ConstructingObjectParser<>("delete_rollup_job_response", true,
42+
args -> new DeleteRollupJobResponse((boolean) args[0]));
43+
static {
44+
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged"));
45+
}
46+
}

client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,26 @@
2020

2121
import org.elasticsearch.common.ParseField;
2222
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
23-
import org.elasticsearch.common.xcontent.ToXContentObject;
24-
import org.elasticsearch.common.xcontent.XContentBuilder;
2523
import org.elasticsearch.common.xcontent.XContentParser;
2624

2725
import java.io.IOException;
28-
import java.util.Objects;
2926

3027
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
3128

32-
public class PutRollupJobResponse implements ToXContentObject {
29+
public class PutRollupJobResponse extends AcknowledgedResponse {
3330

34-
private final boolean acknowledged;
3531

36-
public PutRollupJobResponse(final boolean acknowledged) {
37-
this.acknowledged = acknowledged;
32+
public PutRollupJobResponse(boolean acknowledged) {
33+
super(acknowledged);
3834
}
3935

40-
public boolean isAcknowledged() {
41-
return acknowledged;
42-
}
43-
44-
@Override
45-
public boolean equals(Object o) {
46-
if (this == o) {
47-
return true;
48-
}
49-
if (o == null || getClass() != o.getClass()) {
50-
return false;
51-
}
52-
final PutRollupJobResponse that = (PutRollupJobResponse) o;
53-
return isAcknowledged() == that.isAcknowledged();
54-
}
55-
56-
@Override
57-
public int hashCode() {
58-
return Objects.hash(acknowledged);
59-
}
60-
61-
@Override
62-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
63-
builder.startObject();
64-
{
65-
builder.field("acknowledged", isAcknowledged());
66-
}
67-
builder.endObject();
68-
return builder;
36+
public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
37+
return PARSER.parse(parser, null);
6938
}
7039

7140
private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER
7241
= new ConstructingObjectParser<>("put_rollup_job_response", true, args -> new PutRollupJobResponse((boolean) args[0]));
7342
static {
7443
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged"));
7544
}
76-
77-
public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
78-
return PARSER.parse(parser, null);
79-
}
8045
}

0 commit comments

Comments
 (0)