-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[CCR] Added HLRC support for pause follow API #35216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
de3cb3e
2f4e2ed
7517fb8
3abf335
342310b
5686daa
d0f25b0
4e3c5df
6102637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.ccr.PauseFollowRequest; | ||
import org.elasticsearch.client.ccr.PauseFollowResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
/** | ||
* A wrapper for the {@link RestHighLevelClient} that provides methods for | ||
* accessing the Elastic ccr related methods | ||
* <p> | ||
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-apis.html"> | ||
* X-Pack Rollup APIs on elastic.co</a> for more information. | ||
*/ | ||
public final class CcrClient { | ||
|
||
private final RestHighLevelClient restHighLevelClient; | ||
|
||
CcrClient(RestHighLevelClient restHighLevelClient) { | ||
this.restHighLevelClient = restHighLevelClient; | ||
} | ||
|
||
/** | ||
* Instructs a follower index the pause the following of a leader index. | ||
* | ||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.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 PauseFollowResponse pauseFollow(PauseFollowRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity( | ||
request, | ||
CcrRequestConverters::pauseFollow, | ||
options, | ||
PauseFollowResponse::fromXContent, | ||
Collections.emptySet() | ||
); | ||
} | ||
|
||
/** | ||
* Asynchronously instruct a follower index the pause the following of a leader index. | ||
* | ||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.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 | ||
*/ | ||
public void pauseFollowAsync(PauseFollowRequest request, | ||
RequestOptions options, | ||
ActionListener<PauseFollowResponse> listener) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity( | ||
request, | ||
CcrRequestConverters::pauseFollow, | ||
options, | ||
PauseFollowResponse::fromXContent, | ||
listener, | ||
Collections.emptySet()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.HttpPost; | ||
import org.elasticsearch.client.ccr.PauseFollowRequest; | ||
|
||
final class CcrRequestConverters { | ||
|
||
static Request pauseFollow(PauseFollowRequest pauseFollowRequest) { | ||
String endpoint = new RequestConverters.EndpointBuilder() | ||
.addPathPart(pauseFollowRequest.getFollowerIndex()) | ||
.addPathPartAsIs("_ccr/pause_follow") | ||
.build(); | ||
return new Request(HttpPost.METHOD_NAME, endpoint); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.ccr; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
|
||
import java.util.Objects; | ||
|
||
public final class PauseFollowRequest implements Validatable { | ||
|
||
private final String followerIndex; | ||
|
||
public PauseFollowRequest(String followerIndex) { | ||
this.followerIndex = Objects.requireNonNull(followerIndex); | ||
} | ||
|
||
public String getFollowerIndex() { | ||
return followerIndex; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.ccr; | ||
|
||
import org.elasticsearch.client.rollup.AcknowledgedResponse; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
|
||
public final class PauseFollowResponse extends AcknowledgedResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reused Also many APIs have exactly this same response ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Id be perfectly happy with you moving it to the edit, suggested that exactly == we modified the code such that anyone can override the acknowledged field name, so it could be strings like submitted/deleted in the rollups code. |
||
|
||
private static final ConstructingObjectParser<PauseFollowResponse, Void> PARSER = AcknowledgedResponse | ||
.generateParser("pause_follow_response", PauseFollowResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME); | ||
|
||
public static PauseFollowResponse fromXContent(final XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
public PauseFollowResponse(boolean acknowledged) { | ||
super(acknowledged); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -786,7 +786,8 @@ public void testApiNamingConventions() throws Exception { | |
apiName.startsWith("graph.") == false && | ||
apiName.startsWith("migration.") == false && | ||
apiName.startsWith("security.") == false && | ||
apiName.startsWith("index_lifecycle.") == false) { | ||
apiName.startsWith("index_lifecycle.") == false && | ||
apiName.startsWith("ccr.") == false){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between |
||
apiNotFound.add(apiName); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.ccr; | ||
|
||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractXContentTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class PauseFollowResponseTests extends AbstractXContentTestCase<PauseFollowResponse> { | ||
|
||
@Override | ||
protected PauseFollowResponse createTestInstance() { | ||
return new PauseFollowResponse(randomBoolean()); | ||
} | ||
|
||
@Override | ||
protected PauseFollowResponse doParseInstance(XContentParser parser) throws IOException { | ||
return PauseFollowResponse.fromXContent(parser); | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return false; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.addPathPartAsIs("_ccr", "pause_follow")