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 4 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 @@ -81,13 +81,11 @@ public String name() {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
readTimeout(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(name);
writeTimeout(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ public void readFrom(StreamInput in) throws IOException {
name = in.readString();
type = in.readString();
settings = readSettingsFromStream(in);
readTimeout(in);
verify = in.readBoolean();
}

Expand All @@ -230,7 +229,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
out.writeString(type);
writeSettingsToStream(settings, out);
writeTimeout(out);
out.writeBoolean(verify);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ public String name() {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
readTimeout(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(name);
writeTimeout(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public void readFrom(StreamInput in) throws IOException {
dryRun = in.readBoolean();
explain = in.readBoolean();
retryFailed = in.readBoolean();
readTimeout(in);
}

@Override
Expand All @@ -138,7 +137,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(dryRun);
out.writeBoolean(explain);
out.writeBoolean(retryFailed);
writeTimeout(out);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,12 @@ public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
transientSettings = readSettingsFromStream(in);
persistentSettings = readSettingsFromStream(in);
readTimeout(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeSettingsToStream(transientSettings, out);
writeSettingsToStream(persistentSettings, out);
writeTimeout(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,12 @@ public ActionRequestValidationException validate() {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
allAliasActions = in.readList(AliasActions::new);
readTimeout(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeList(allAliasActions);
writeTimeout(out);
}

public IndicesOptions indicesOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ public CloseIndexRequest indicesOptions(IndicesOptions indicesOptions) {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = in.readStringArray();
readTimeout(in);
indicesOptions = IndicesOptions.readIndicesOptions(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
writeTimeout(out);
indicesOptions.writeIndicesOptions(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ public void readFrom(StreamInput in) throws IOException {
cause = in.readString();
index = in.readString();
settings = readSettingsFromStream(in);
readTimeout(in);
int size = in.readVInt();
for (int i = 0; i < size; i++) {
final String type = in.readString();
Expand Down Expand Up @@ -518,7 +517,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(cause);
out.writeString(index);
writeSettingsToStream(settings, out);
writeTimeout(out);
out.writeVInt(mappings.size());
for (Map.Entry<String, String> entry : mappings.entrySet()) {
out.writeString(entry.getKey());
Expand Down
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 @@ -313,7 +313,6 @@ public void readFrom(StreamInput in) throws IOException {
source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source));
}
updateAllTypes = in.readBoolean();
readTimeout(in);
concreteIndex = in.readOptionalWriteable(Index::new);
}

Expand All @@ -325,7 +324,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(type);
out.writeString(source);
out.writeBoolean(updateAllTypes);
writeTimeout(out);
out.writeOptionalWriteable(concreteIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ public OpenIndexRequest indicesOptions(IndicesOptions indicesOptions) {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = in.readStringArray();
readTimeout(in);
indicesOptions = IndicesOptions.readIndicesOptions(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
writeTimeout(out);
indicesOptions.writeIndicesOptions(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public void readFrom(StreamInput in) throws IOException {
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
settings = readSettingsFromStream(in);
readTimeout(in);
preserveExisting = in.readBoolean();
}

Expand All @@ -176,7 +175,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringArrayNullable(indices);
indicesOptions.writeIndicesOptions(out);
writeSettingsToStream(settings, out);
writeTimeout(out);
out.writeBoolean(preserveExisting);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void readFrom(StreamInput in) throws IOException {
String oldestLuceneSegment = in.readString();
versions.put(index, new Tuple<>(upgradeVersion, oldestLuceneSegment));
}
readTimeout(in);
}

@Override
Expand All @@ -98,6 +97,5 @@ public void writeTo(StreamOutput out) throws IOException {
Version.writeVersion(entry.getValue().v1(), out);
out.writeString(entry.getValue().v2());
}
writeTimeout(out);
}
}
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 @@ -70,22 +71,20 @@ public final TimeValue timeout() {
return timeout;
}

/**
* Reads the timeout value
*/
protected void readTimeout(StreamInput in) throws IOException {
timeout = new TimeValue(in);
@Override
public TimeValue ackTimeout() {
return timeout;
}

/**
* writes the timeout value
*/
protected void writeTimeout(StreamOutput out) throws IOException {
timeout.writeTo(out);
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
timeout = new TimeValue(in);
}

@Override
public TimeValue ackTimeout() {
return timeout;
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
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