Skip to content

Serialize and expose timeout of acknowledged requests in REST layer #26189

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

Merged
merged 5 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -20,34 +20,15 @@
package org.elasticsearch.action.admin.indices.delete;

import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.unit.TimeValue;

public class DeleteIndexRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteIndexRequest, DeleteIndexResponse, DeleteIndexRequestBuilder> {
public class DeleteIndexRequestBuilder extends AcknowledgedRequestBuilder<DeleteIndexRequest, DeleteIndexResponse, DeleteIndexRequestBuilder> {

public DeleteIndexRequestBuilder(ElasticsearchClient client, DeleteIndexAction action, String... indices) {
super(client, action, new DeleteIndexRequest(indices));
}

/**
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>60s</tt>.
*/
public DeleteIndexRequestBuilder setTimeout(TimeValue timeout) {
request.timeout(timeout);
return this;
}

/**
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public DeleteIndexRequestBuilder setTimeout(String timeout) {
request.timeout(timeout);
return this;
}

/**
* Specifies what type of requested indices to ignore and wildcard indices expressions.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.elasticsearch.action.support.master;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.ack.AckedRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -73,19 +74,45 @@ public final TimeValue timeout() {
/**
* Reads the timeout value
*/
@Deprecated
protected void readTimeout(StreamInput in) throws IOException {
timeout = new TimeValue(in);
// in older ES versions, we would explicitly call this method in subclasses
// now we properly serialize the timeout value as part of the readFrom method
if (in.getVersion().before(Version.V_7_0_0_alpha1)) {
timeout = new TimeValue(in);
}
}

/**
* writes the timeout value
*/
@Deprecated
protected void writeTimeout(StreamOutput out) throws IOException {
timeout.writeTo(out);
// in older ES versions, we would explicitly call this method in subclasses
// now we properly serialize the timeout value as part of the writeTo method
if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
timeout.writeTo(out);
}
}

@Override
public TimeValue ackTimeout() {
return timeout;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
timeout = new TimeValue(in);
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
timeout.writeTo(out);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public String getName() {
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String id = request.param("id");
DeleteStoredScriptRequest deleteStoredScriptRequest = new DeleteStoredScriptRequest(id);
deleteStoredScriptRequest.timeout(request.paramAsTime("timeout", deleteStoredScriptRequest.timeout()));
deleteStoredScriptRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteStoredScriptRequest.masterNodeTimeout()));

return channel -> client.admin().cluster().deleteStoredScript(deleteStoredScriptRequest, new AcknowledgedRestListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
StoredScriptSource source = StoredScriptSource.parse(content, xContentType);

PutStoredScriptRequest putRequest = new PutStoredScriptRequest(id, context, content, request.getXContentType(), source);
putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout()));
putRequest.timeout(request.paramAsTime("timeout", putRequest.timeout()));
return channel -> client.admin().cluster().putStoredScript(putRequest, new AcknowledgedRestListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
}
},
"params" : {
"timeout": {
"type" : "time",
"description" : "Explicit operation timeout"
},
"master_timeout": {
"type" : "time",
"description" : "Specify timeout for connection to master"
}
}
},
"body": null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
}
},
"params" : {
"timeout": {
"type" : "time",
"description" : "Explicit operation timeout"
},
"master_timeout": {
"type" : "time",
"description" : "Specify timeout for connection to master"
},
"context": {
"type" : "string",
"description" : "Context name to compile script against"
Expand Down