From 8b520111d0480a2fb025090223e49bbb57018b9f Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 20 Jan 2016 14:00:55 +0100 Subject: [PATCH] fix PutPipelineRequest comments --- .../action/ingest/PutPipelineRequest.java | 22 +++++++------------ .../ingest/PutPipelineRequestBuilder.java | 5 ++--- .../elasticsearch/ingest/PipelineStore.java | 8 +++---- .../action/ingest/RestPutPipelineAction.java | 4 ++-- .../elasticsearch/ingest/IngestClientIT.java | 8 +++---- .../ingest/PipelineStoreTests.java | 12 +++++----- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java b/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java index 6b199b2aa90..e04abb06cef 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -36,30 +37,23 @@ public class PutPipelineRequest extends AcknowledgedRequest @Override public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = null; - if (id == null) { - validationException = addValidationError("id is missing", validationException); - } - if (source == null) { - validationException = addValidationError("source is missing", validationException); - } - return validationException; + return null; } - public String id() { + public String getId() { return id; } - public void id(String id) { - this.id = id; + public void setId(String id) { + this.id = Objects.requireNonNull(id); } - public BytesReference source() { + public BytesReference getSource() { return source; } - public void source(BytesReference source) { - this.source = source; + public void setSource(BytesReference source) { + this.source = Objects.requireNonNull(source); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequestBuilder.java index 4236d7081aa..377a240caba 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequestBuilder.java @@ -20,7 +20,6 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.bytes.BytesReference; @@ -31,12 +30,12 @@ public class PutPipelineRequestBuilder extends ActionRequestBuilder listener) throws IllegalArgumentException { try { // validates the pipeline and processor configuration before submitting a cluster update task: - Map pipelineConfig = XContentHelper.convertToMap(request.source(), false).v2(); - constructPipeline(request.id(), pipelineConfig); + Map pipelineConfig = XContentHelper.convertToMap(request.getSource(), false).v2(); + constructPipeline(request.getId(), pipelineConfig); } catch (Exception e) { throw new IllegalArgumentException("Invalid pipeline configuration", e); } - clusterService.submitStateUpdateTask("put-pipeline-" + request.id(), new AckedClusterStateUpdateTask(request, listener) { + clusterService.submitStateUpdateTask("put-pipeline-" + request.getId(), new AckedClusterStateUpdateTask(request, listener) { @Override protected WritePipelineResponse newResponse(boolean acknowledged) { @@ -185,7 +185,7 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust pipelines = new HashMap<>(); } - pipelines.put(request.id(), new PipelineConfiguration(request.id(), request.source())); + pipelines.put(request.getId(), new PipelineConfiguration(request.getId(), request.getSource())); ClusterState.Builder newState = ClusterState.builder(currentState); newState.metaData(MetaData.builder(currentState.getMetaData()) .putCustom(IngestMetadata.TYPE, new IngestMetadata(pipelines)) diff --git a/core/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java b/core/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java index 7c2d9a717dc..c876c45a876 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java @@ -40,9 +40,9 @@ public class RestPutPipelineAction extends BaseRestHandler { @Override protected void handleRequest(RestRequest restRequest, RestChannel channel, Client client) throws Exception { PutPipelineRequest request = new PutPipelineRequest(); - request.id(restRequest.param("id")); + request.setId(restRequest.param("id")); if (restRequest.hasContent()) { - request.source(restRequest.content()); + request.setSource(restRequest.content()); } request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java b/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java index a613054feba..259392d3667 100644 --- a/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java @@ -129,8 +129,8 @@ public class IngestClientIT extends ESIntegTestCase { createIndex("index"); PutPipelineRequest putPipelineRequest = new PutPipelineRequest(); - putPipelineRequest.id("_id"); - putPipelineRequest.source(jsonBuilder().startObject() + putPipelineRequest.setId("_id"); + putPipelineRequest.setSource(jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") .startObject() @@ -167,8 +167,8 @@ public class IngestClientIT extends ESIntegTestCase { public void test() throws Exception { PutPipelineRequest putPipelineRequest = new PutPipelineRequest(); - putPipelineRequest.id("_id"); - putPipelineRequest.source(jsonBuilder().startObject() + putPipelineRequest.setId("_id"); + putPipelineRequest.setSource(jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") .startObject() diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java index a0e07169f8f..b10fc3d6d4c 100644 --- a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java @@ -85,8 +85,8 @@ public class PipelineStoreTests extends ESTestCase { // add a new pipeline: PutPipelineRequest putRequest = new PutPipelineRequest(); - putRequest.id(id); - putRequest.source(new BytesArray("{\"processors\": []}")); + putRequest.setId(id); + putRequest.setSource(new BytesArray("{\"processors\": []}")); clusterState = store.innerPut(putRequest, clusterState); store.innerUpdatePipelines(clusterState); pipeline = store.get(id); @@ -97,8 +97,8 @@ public class PipelineStoreTests extends ESTestCase { // overwrite existing pipeline: putRequest = new PutPipelineRequest(); - putRequest.id(id); - putRequest.source(new BytesArray("{\"processors\": [], \"description\": \"_description\"}")); + putRequest.setId(id); + putRequest.setSource(new BytesArray("{\"processors\": [], \"description\": \"_description\"}")); clusterState = store.innerPut(putRequest, clusterState); store.innerUpdatePipelines(clusterState); pipeline = store.get(id); @@ -170,8 +170,8 @@ public class PipelineStoreTests extends ESTestCase { ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build(); // Start empty PutPipelineRequest putRequest = new PutPipelineRequest(); - putRequest.id(id); - putRequest.source(new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}")); + putRequest.setId(id); + putRequest.setSource(new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}")); clusterState = store.innerPut(putRequest, clusterState); store.innerUpdatePipelines(clusterState); pipeline = store.get(id);