changed delete pipeline request to getters and setters in right format and validate the provided id in the setId(...) method

This commit is contained in:
Martijn van Groningen 2016-01-20 16:00:44 +01:00
parent f546b27ea0
commit b0c7096e2f
6 changed files with 13 additions and 13 deletions

View File

@ -25,6 +25,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;
@ -32,11 +33,11 @@ public class DeletePipelineRequest extends AcknowledgedRequest<DeletePipelineReq
private String id;
public void id(String id) {
this.id = id;
public void setId(String id) {
this.id = Objects.requireNonNull(id);
}
public String id() {
public String getId() {
return id;
}

View File

@ -29,7 +29,7 @@ public class DeletePipelineRequestBuilder extends ActionRequestBuilder<DeletePip
}
public DeletePipelineRequestBuilder setId(String id) {
request.id(id);
request.setId(id);
return this;
}

View File

@ -113,7 +113,7 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust
* Deletes the pipeline specified by id in the request.
*/
public void delete(ClusterService clusterService, DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener) {
clusterService.submitStateUpdateTask("delete-pipeline-" + request.id(), new AckedClusterStateUpdateTask<WritePipelineResponse>(request, listener) {
clusterService.submitStateUpdateTask("delete-pipeline-" + request.getId(), new AckedClusterStateUpdateTask<WritePipelineResponse>(request, listener) {
@Override
protected WritePipelineResponse newResponse(boolean acknowledged) {
@ -133,11 +133,11 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust
return currentState;
}
Map<String, PipelineConfiguration> pipelines = currentIngestMetadata.getPipelines();
if (pipelines.containsKey(request.id()) == false) {
throw new ResourceNotFoundException("pipeline [{}] is missing", request.id());
if (pipelines.containsKey(request.getId()) == false) {
throw new ResourceNotFoundException("pipeline [{}] is missing", request.getId());
} else {
pipelines = new HashMap<>(pipelines);
pipelines.remove(request.id());
pipelines.remove(request.getId());
ClusterState.Builder newState = ClusterState.builder(currentState);
newState.metaData(MetaData.builder(currentState.getMetaData())
.putCustom(IngestMetadata.TYPE, new IngestMetadata(pipelines))

View File

@ -40,7 +40,7 @@ public class RestDeletePipelineAction extends BaseRestHandler {
@Override
protected void handleRequest(RestRequest restRequest, RestChannel channel, Client client) throws Exception {
DeletePipelineRequest request = new DeletePipelineRequest();
request.id(restRequest.param("id"));
request.setId(restRequest.param("id"));
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
client.deletePipeline(request, new AcknowledgedRestListener<>(channel));

View File

@ -200,7 +200,7 @@ public class IngestClientIT extends ESIntegTestCase {
assertThat(doc.get("processed"), equalTo(true));
DeletePipelineRequest deletePipelineRequest = new DeletePipelineRequest();
deletePipelineRequest.id("_id");
deletePipelineRequest.setId("_id");
WritePipelineResponse response = client().deletePipeline(deletePipelineRequest).get();
assertThat(response.isAcknowledged(), is(true));

View File

@ -23,7 +23,6 @@ import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ingest.DeletePipelineRequest;
import org.elasticsearch.action.ingest.PutPipelineRequest;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.bytes.BytesArray;
@ -120,7 +119,7 @@ public class PipelineStoreTests extends ESTestCase {
// Delete pipeline:
DeletePipelineRequest deleteRequest = new DeletePipelineRequest();
deleteRequest.id("_id");
deleteRequest.setId("_id");
clusterState = store.innerDelete(deleteRequest, clusterState);
store.innerUpdatePipelines(clusterState);
assertThat(store.get("_id"), nullValue());
@ -181,7 +180,7 @@ public class PipelineStoreTests extends ESTestCase {
assertThat(pipeline.getProcessors().get(0).getType(), equalTo("set"));
DeletePipelineRequest deleteRequest = new DeletePipelineRequest();
deleteRequest.id(id);
deleteRequest.setId(id);
clusterState = store.innerDelete(deleteRequest, clusterState);
store.innerUpdatePipelines(clusterState);
pipeline = store.get(id);