Merge pull request elastic/elasticsearch#445 from kimchy/remove_content_unsafe

Remove rest content unsafe usage

Original commit: elastic/x-pack-elasticsearch@c290326f3f
This commit is contained in:
Shay Banon 2015-05-09 16:26:11 +02:00
commit 7ff92c8f96
3 changed files with 3 additions and 24 deletions

View File

@ -34,7 +34,7 @@ public class RestPutWatchAction extends WatcherRestHandler {
@Override
protected void handleRequest(final RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
PutWatchRequest putWatchRequest = new PutWatchRequest(request.param("id"), request.content(), request.contentUnsafe());
PutWatchRequest putWatchRequest = new PutWatchRequest(request.param("id"), request.content());
putWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putWatchRequest.masterNodeTimeout()));
client.putWatch(putWatchRequest, new RestBuilderListener<PutWatchResponse>(channel) {
@Override

View File

@ -28,20 +28,17 @@ public class PutWatchRequest extends MasterNodeOperationRequest<PutWatchRequest>
private String id;
private BytesReference source;
private boolean sourceUnsafe;
PutWatchRequest() {
this(null, null, false);
}
public PutWatchRequest(String id, WatchSourceBuilder source) {
this(id, source.buildAsBytes(XContentType.JSON), false);
this(id, source.buildAsBytes(XContentType.JSON));
}
public PutWatchRequest(String id, BytesReference source, boolean sourceUnsafe) {
public PutWatchRequest(String id, BytesReference source) {
this.id = id;
this.source = source;
this.sourceUnsafe = sourceUnsafe;
masterNodeTimeout(DEFAULT_TIMEOUT);
}
@ -78,22 +75,6 @@ public class PutWatchRequest extends MasterNodeOperationRequest<PutWatchRequest>
*/
public void setSource(BytesReference source) {
this.source = source;
this.sourceUnsafe = false;
}
/**
* Set the source of the watch with boolean to control source safety
*/
public void setSource(BytesReference source, boolean sourceUnsafe) {
this.source = source;
this.sourceUnsafe = sourceUnsafe;
}
void beforeLocalFork() {
if (sourceUnsafe) {
source = source.copyBytesArray();
sourceUnsafe = false;
}
}
@Override
@ -113,7 +94,6 @@ public class PutWatchRequest extends MasterNodeOperationRequest<PutWatchRequest>
super.readFrom(in);
id = in.readString();
source = in.readBytesReference();
sourceUnsafe = false;
}
@Override

View File

@ -62,7 +62,6 @@ public class TransportPutWatchAction extends WatcherTransportAction<PutWatchRequ
@Override
protected ClusterBlockException checkBlock(PutWatchRequest request, ClusterState state) {
request.beforeLocalFork(); // This is the best place to make the watch source safe
return state.blocks().indexBlockedException(ClusterBlockLevel.WRITE, WatchStore.INDEX);
}